package config import ( "os" "path/filepath" "reflect" "testing" ) func TestLoad_AutomationDefault(t *testing.T) { root := newRepo(t) cfg, err := Load(root, "") if err != nil { t.Fatal(err) } if cfg.Automation != DefaultAutomation { t.Errorf("Automation = %q, want %q", cfg.Automation, DefaultAutomation) } if cfg.AIBudget != DefaultAIBudget { t.Errorf("AIBudget = %d, want %d", cfg.AIBudget, DefaultAIBudget) } if cfg.AICommand != nil { t.Errorf("AICommand = %v, want nil", cfg.AICommand) } } func TestLoad_AutomationLevels(t *testing.T) { cases := map[string]Automation{ "manual": AutomationManual, "propose": AutomationPropose, "scaffold": AutomationScaffold, "auto": AutomationAuto, // Unknown / future value is tolerated and falls back to default. "galaxy-brain": DefaultAutomation, "": DefaultAutomation, } for in, want := range cases { t.Run(in, func(t *testing.T) { root := newRepo(t) wsDir := filepath.Join(root, "tester", DefaultWorkspace) if err := os.MkdirAll(wsDir, 0o755); err != nil { t.Fatal(err) } write(t, wsDir, "config.local", "automation="+in+"\n") cfg, err := Load(root, "") if err != nil { t.Fatalf("unknown automation must not error: %v", err) } if cfg.Automation != want { t.Errorf("automation=%q -> %q, want %q", in, cfg.Automation, want) } }) } } func TestAutomation_ConsentAndScaffold(t *testing.T) { if !AutomationAuto.ImpliesAIConsent() { t.Error("auto must imply AI consent") } for _, a := range []Automation{AutomationManual, AutomationPropose, AutomationScaffold} { if a.ImpliesAIConsent() { t.Errorf("%q must not imply AI consent", a) } } if !AutomationScaffold.ScaffoldsWorkflows() || !AutomationAuto.ScaffoldsWorkflows() { t.Error("scaffold and auto must scaffold workflows") } if AutomationManual.ScaffoldsWorkflows() || AutomationPropose.ScaffoldsWorkflows() { t.Error("manual/propose must not scaffold workflows") } } func TestLoad_AICommandAndBudget(t *testing.T) { root := newRepo(t) wsDir := filepath.Join(root, "tester", DefaultWorkspace) if err := os.MkdirAll(wsDir, 0o755); err != nil { t.Fatal(err) } write(t, wsDir, "config.local", "ai_command=my tool --flag\nai_budget=3\n") cfg, err := Load(root, "") if err != nil { t.Fatal(err) } if !reflect.DeepEqual(cfg.AICommand, []string{"my", "tool", "--flag"}) { t.Errorf("AICommand = %v", cfg.AICommand) } if cfg.AIBudget != 3 { t.Errorf("AIBudget = %d, want 3", cfg.AIBudget) } } func TestLoad_AIBudgetMalformed(t *testing.T) { for _, body := range []string{"ai_budget=nope\n", "ai_budget=-1\n"} { root := newRepo(t) wsDir := filepath.Join(root, "tester", DefaultWorkspace) if err := os.MkdirAll(wsDir, 0o755); err != nil { t.Fatal(err) } write(t, wsDir, "config.local", body) if _, err := Load(root, ""); err == nil { t.Errorf("expected error for %q", body) } } }