diff options
Diffstat (limited to 'internal/role/role_test.go')
| -rw-r--r-- | internal/role/role_test.go | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/internal/role/role_test.go b/internal/role/role_test.go new file mode 100644 index 0000000..6d2294e --- /dev/null +++ b/internal/role/role_test.go @@ -0,0 +1,73 @@ +package role + +import ( + "encoding/json" + "reflect" + "testing" +) + +func TestRoleConfig_JSONRoundTrip(t *testing.T) { + rc := RoleConfig{ + Role: "coder", + SystemPrompt: "You are a careful coding agent.", + Tools: []string{"Bash", "Read", "Edit"}, + SandboxKind: "docker", + DefaultBudgetUSD: 1.5, + EscalationLadder: []Tier{ + { + Candidates: []Rung{ + {Provider: "local", Model: "llama3.1:8b"}, + }, + SelectionMode: "single", + MaxRetries: 2, + }, + { + Candidates: []Rung{ + {Provider: "groq", Model: "llama-3.3-70b-versatile"}, + {Provider: "openrouter", Model: "meta-llama/llama-3.3-70b-instruct:free"}, + }, + SelectionMode: "round_robin", + MaxRetries: 1, + }, + { + Candidates: []Rung{ + {Provider: "anthropic", Model: "claude-sonnet-5"}, + }, + MaxRetries: 0, + }, + }, + } + + b, err := json.Marshal(rc) + if err != nil { + t.Fatalf("Marshal: %v", err) + } + + var got RoleConfig + if err := json.Unmarshal(b, &got); err != nil { + t.Fatalf("Unmarshal: %v", err) + } + + if !reflect.DeepEqual(rc, got) { + t.Errorf("round trip mismatch:\n want: %+v\n got: %+v", rc, got) + } +} + +func TestTier_EffectiveSelectionMode(t *testing.T) { + cases := []struct { + name string + tier Tier + want string + }{ + {"empty defaults to round_robin", Tier{}, "round_robin"}, + {"explicit single", Tier{SelectionMode: "single"}, "single"}, + {"explicit round_robin", Tier{SelectionMode: "round_robin"}, "round_robin"}, + } + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + if got := c.tier.EffectiveSelectionMode(); got != c.want { + t.Errorf("got %q, want %q", got, c.want) + } + }) + } +} |
