| 1 | package config |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "testing" |
| 6 | ) |
| 7 | |
| 8 | func TestPreReviewEnabled_defaults(t *testing.T) { |
| 9 | cfg := Defaults() |
| 10 | if !cfg.PreReviewEnabled() { |
| 11 | t.Error("expected pre-review to be enabled by default") |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | func TestPreReviewEnabled_explicit(t *testing.T) { |
| 16 | enabled := true |
| 17 | cfg := Config{PreReview: &PreReviewConfig{Enabled: &enabled}} |
| 18 | if !cfg.PreReviewEnabled() { |
| 19 | t.Error("expected pre-review to be enabled") |
| 20 | } |
| 21 | |
| 22 | disabled := false |
| 23 | cfg = Config{PreReview: &PreReviewConfig{Enabled: &disabled}} |
| 24 | if cfg.PreReviewEnabled() { |
| 25 | t.Error("expected pre-review to be disabled") |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | func TestPreReviewModel_defaults(t *testing.T) { |
| 30 | cfg := Defaults() |
| 31 | if got := cfg.PreReviewModel(); got != "haiku" { |
| 32 | t.Errorf("PreReviewModel() = %q, want %q", got, "haiku") |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | func TestPreReviewModel_configured(t *testing.T) { |
| 37 | cfg := Config{PreReview: &PreReviewConfig{ReviewModel: "sonnet"}} |
| 38 | if got := cfg.PreReviewModel(); got != "sonnet" { |
| 39 | t.Errorf("PreReviewModel() = %q, want %q", got, "sonnet") |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | func TestPreReviewLinters_defaults(t *testing.T) { |
| 44 | cfg := Defaults() |
| 45 | if linters := cfg.PreReviewLinters(); linters != nil { |
| 46 | t.Errorf("expected nil linters by default, got %v", linters) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | func TestPreReviewLinters_configured(t *testing.T) { |
| 51 | cfg := Config{PreReview: &PreReviewConfig{Linters: []string{"go vet ./..."}}} |
| 52 | linters := cfg.PreReviewLinters() |
| 53 | if len(linters) != 1 || linters[0] != "go vet ./..." { |
| 54 | t.Errorf("unexpected linters: %v", linters) |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | func TestPreReviewBlockOn_defaults(t *testing.T) { |
| 59 | cfg := Defaults() |
| 60 | if got := cfg.PreReviewBlockOn(); got != "high" { |
| 61 | t.Errorf("PreReviewBlockOn() = %q, want %q", got, "high") |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | func TestPreReviewBlockOn_configured(t *testing.T) { |
| 66 | cfg := Config{PreReview: &PreReviewConfig{BlockOn: "critical"}} |
| 67 | if got := cfg.PreReviewBlockOn(); got != "critical" { |
| 68 | t.Errorf("PreReviewBlockOn() = %q, want %q", got, "critical") |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | func TestPreReviewMaxFixRounds_defaults(t *testing.T) { |
| 73 | cfg := Defaults() |
| 74 | if got := cfg.PreReviewMaxFixRounds(); got != 2 { |
| 75 | t.Errorf("PreReviewMaxFixRounds() = %d, want %d", got, 2) |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | func TestPreReviewMaxFixRounds_configured(t *testing.T) { |
| 80 | cfg := Config{PreReview: &PreReviewConfig{MaxFixRounds: 5}} |
| 81 | if got := cfg.PreReviewMaxFixRounds(); got != 5 { |
| 82 | t.Errorf("PreReviewMaxFixRounds() = %d, want %d", got, 5) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | func TestProseDefaults(t *testing.T) { |
| 87 | cfg := Defaults() |
| 88 | p := cfg.Prose() |
| 89 | if p.TimeoutSeconds != 600 || p.MaxInputBytes != 40000 || !*p.Enabled { |
| 90 | t.Errorf("Prose() = timeout %d, max input %d, enabled %v; want 600, 40000, true", p.TimeoutSeconds, p.MaxInputBytes, *p.Enabled) |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | // The writer's model is pre_review.prose.writer's, else klaus's prose model |
| 95 | // for the backend (agy's alone), else the backend's general default; its |
| 96 | // effort skips the middle step. The checker's skips klaus's prose model. |
| 97 | func TestProseModels(t *testing.T) { |
| 98 | for _, tc := range []struct { |
| 99 | name, config, kind string |
| 100 | writer, checker [2]string // model, effort |
| 101 | }{ |
| 102 | {"agy with no settings", `{}`, "agy", |
| 103 | [2]string{"gemini-4-hydrogen-high", ""}, [2]string{"", ""}}, |
| 104 | {"agy over its general default", `{"backends": {"agy": {"model": "gemini-general", "effort": "low"}}}`, "agy", |
| 105 | [2]string{"gemini-4-hydrogen-high", "low"}, [2]string{"gemini-general", "low"}}, |
| 106 | {"agy prose settings", `{"backends": {"agy": {"model": "gemini-general", "effort": "low"}}, |
| 107 | "pre_review": {"prose": {"writer": {"agy": {"model": "gemini-writer", "effort": "high"}}, "checker": {"agy": {"model": "gemini-checker"}}}}}`, "agy", |
| 108 | [2]string{"gemini-writer", "high"}, [2]string{"gemini-checker", "low"}}, |
| 109 | {"codex has no prose model", `{"backends": {"codex": {"model": "gpt-general", "effort": "medium"}}}`, "codex", |
| 110 | [2]string{"gpt-general", "medium"}, [2]string{"gpt-general", "medium"}}, |
| 111 | {"codex prose effort only", `{"backends": {"codex": {"model": "gpt-general"}}, |
| 112 | "pre_review": {"prose": {"writer": {"codex": {"effort": "high"}}}}}`, "codex", |
| 113 | [2]string{"gpt-general", "high"}, [2]string{"gpt-general", ""}}, |
| 114 | {"another backend's prose settings", `{"pre_review": {"prose": {"writer": {"agy": {"model": "gemini-writer"}}}}, "default_agent_model": "sonnet"}`, "claude", |
| 115 | [2]string{"sonnet", ""}, [2]string{"sonnet", ""}}, |
| 116 | } { |
| 117 | t.Run(tc.name, func(t *testing.T) { |
| 118 | var cfg Config |
| 119 | if err := json.Unmarshal([]byte(tc.config), &cfg); err != nil { |
| 120 | t.Fatal(err) |
| 121 | } |
| 122 | if m, e := cfg.ProseWriter(tc.kind); [2]string{m, e} != tc.writer { |
| 123 | t.Errorf("ProseWriter(%s) = %q, %q; want %q", tc.kind, m, e, tc.writer) |
| 124 | } |
| 125 | if m, e := cfg.ProseChecker(tc.kind); [2]string{m, e} != tc.checker { |
| 126 | t.Errorf("ProseChecker(%s) = %q, %q; want %q", tc.kind, m, e, tc.checker) |
| 127 | } |
| 128 | }) |
| 129 | } |
| 130 | } |