|
| 1 | +package doctor |
| 2 | + |
| 3 | +import ( |
| 4 | + "os" |
| 5 | + "path/filepath" |
| 6 | + "testing" |
| 7 | + |
| 8 | + "github.com/steveyegge/gastown/internal/config" |
| 9 | +) |
| 10 | + |
| 11 | +func TestNewGroqCompoundCheck(t *testing.T) { |
| 12 | + c := NewGroqCompoundCheck() |
| 13 | + if c.Name() != "groq-compound-json" { |
| 14 | + t.Errorf("Name() = %q, want %q", c.Name(), "groq-compound-json") |
| 15 | + } |
| 16 | + if c.Description() == "" { |
| 17 | + t.Error("Description() is empty") |
| 18 | + } |
| 19 | + if c.Category() != CategoryInfrastructure { |
| 20 | + t.Errorf("Category() = %v, want %v", c.Category(), CategoryInfrastructure) |
| 21 | + } |
| 22 | + if c.CanFix() { |
| 23 | + t.Error("CanFix() = true, want false") |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +func TestGroqCompoundConfigured_EmptyTownRoot(t *testing.T) { |
| 28 | + c := NewGroqCompoundCheck() |
| 29 | + if c.groqCompoundConfigured("") { |
| 30 | + t.Error("groqCompoundConfigured(\"\") = true, want false") |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +func TestGroqCompoundConfigured_NoSettingsFile(t *testing.T) { |
| 35 | + tmp := t.TempDir() |
| 36 | + c := NewGroqCompoundCheck() |
| 37 | + if c.groqCompoundConfigured(tmp) { |
| 38 | + t.Error("groqCompoundConfigured with no settings file = true, want false (default agent is claude)") |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +func TestGroqCompoundConfigured_DefaultAgent(t *testing.T) { |
| 43 | + tmp := t.TempDir() |
| 44 | + settings := config.NewTownSettings() |
| 45 | + settings.DefaultAgent = string(config.AgentGroqCompound) |
| 46 | + writeTownSettings(t, tmp, settings) |
| 47 | + |
| 48 | + c := NewGroqCompoundCheck() |
| 49 | + if !c.groqCompoundConfigured(tmp) { |
| 50 | + t.Error("groqCompoundConfigured = false, want true when DefaultAgent is groq-compound") |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +func TestGroqCompoundConfigured_RoleAgent(t *testing.T) { |
| 55 | + tmp := t.TempDir() |
| 56 | + settings := config.NewTownSettings() |
| 57 | + settings.RoleAgents["refinery"] = string(config.AgentGroqCompound) |
| 58 | + writeTownSettings(t, tmp, settings) |
| 59 | + |
| 60 | + c := NewGroqCompoundCheck() |
| 61 | + if !c.groqCompoundConfigured(tmp) { |
| 62 | + t.Error("groqCompoundConfigured = false, want true when a role uses groq-compound") |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +func TestGroqCompoundConfigured_NoMatch(t *testing.T) { |
| 67 | + tmp := t.TempDir() |
| 68 | + settings := config.NewTownSettings() |
| 69 | + settings.RoleAgents["refinery"] = "claude" |
| 70 | + writeTownSettings(t, tmp, settings) |
| 71 | + |
| 72 | + c := NewGroqCompoundCheck() |
| 73 | + if c.groqCompoundConfigured(tmp) { |
| 74 | + t.Error("groqCompoundConfigured = true, want false when no role uses groq-compound") |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +func TestGroqCompoundCheck_Run_SkipWhenNotConfigured(t *testing.T) { |
| 79 | + tmp := t.TempDir() |
| 80 | + c := NewGroqCompoundCheck() |
| 81 | + res := c.Run(&CheckContext{TownRoot: tmp}) |
| 82 | + if res.Status != StatusOK { |
| 83 | + t.Errorf("Run status = %v, want OK (skip path)", res.Status) |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +func TestGroqCompoundCheck_Run_WarnWhenNoAPIKey(t *testing.T) { |
| 88 | + tmp := t.TempDir() |
| 89 | + settings := config.NewTownSettings() |
| 90 | + settings.DefaultAgent = string(config.AgentGroqCompound) |
| 91 | + writeTownSettings(t, tmp, settings) |
| 92 | + |
| 93 | + t.Setenv("GROQ_API_KEY", "") |
| 94 | + c := NewGroqCompoundCheck() |
| 95 | + res := c.Run(&CheckContext{TownRoot: tmp}) |
| 96 | + if res.Status != StatusWarning { |
| 97 | + t.Errorf("Run status = %v, want Warning when GROQ_API_KEY missing", res.Status) |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +func writeTownSettings(t *testing.T, townRoot string, settings *config.TownSettings) { |
| 102 | + t.Helper() |
| 103 | + dir := filepath.Join(townRoot, "settings") |
| 104 | + if err := os.MkdirAll(dir, 0755); err != nil { |
| 105 | + t.Fatalf("mkdir settings: %v", err) |
| 106 | + } |
| 107 | + if err := config.SaveTownSettings(config.TownSettingsPath(townRoot), settings); err != nil { |
| 108 | + t.Fatalf("SaveTownSettings: %v", err) |
| 109 | + } |
| 110 | +} |
0 commit comments