package main import ( "os" "path/filepath" "testing" ) func TestReadReloadTarget_missing(t *testing.T) { got := readReloadTarget(filepath.Join(t.TempDir(), "reload.txt")) if got != "" { t.Fatalf("expected empty string for missing file, got %q", got) } } func TestReadReloadTarget_empty(t *testing.T) { f := filepath.Join(t.TempDir(), "reload.txt") if err := os.WriteFile(f, []byte(""), 0o644); err != nil { t.Fatal(err) } got := readReloadTarget(f) if got != "" { t.Fatalf("expected empty string for empty file, got %q", got) } } func TestReadReloadTarget_star(t *testing.T) { f := filepath.Join(t.TempDir(), "reload.txt") if err := os.WriteFile(f, []byte("*\n"), 0o644); err != nil { t.Fatal(err) } got := readReloadTarget(f) if got != "" { t.Fatalf("expected empty string for '*', got %q", got) } } func TestReadReloadTarget_agentID(t *testing.T) { f := filepath.Join(t.TempDir(), "reload.txt") if err := os.WriteFile(f, []byte("assistant-bot\n"), 0o644); err != nil { t.Fatal(err) } got := readReloadTarget(f) if got != "assistant-bot" { t.Fatalf("expected 'assistant-bot', got %q", got) } } func TestReadReloadTarget_whitespace(t *testing.T) { f := filepath.Join(t.TempDir(), "reload.txt") if err := os.WriteFile(f, []byte(" asistente-2 \n"), 0o644); err != nil { t.Fatal(err) } got := readReloadTarget(f) if got != "asistente-2" { t.Fatalf("expected 'asistente-2', got %q", got) } } // ── isSpecialConfig tests ───────────────────────────────────────────────── func TestIsSpecialConfig_matchesLoadedSpecial(t *testing.T) { dir := t.TempDir() cfg := filepath.Join(dir, "config.yaml") if err := os.WriteFile(cfg, []byte(` special: id: orchestrator type: orchestrator enabled: true llm: primary: provider: openai `), 0o644); err != nil { t.Fatal(err) } loaded := map[string]bool{"orchestrator": true} if !isSpecialConfig(cfg, loaded) { t.Fatal("expected isSpecialConfig to return true for loaded orchestrator") } } func TestIsSpecialConfig_agentConfigNotSpecial(t *testing.T) { dir := t.TempDir() cfg := filepath.Join(dir, "config.yaml") // An AgentConfig doesn't have special.id, so LoadSpecial will fail validation. if err := os.WriteFile(cfg, []byte(` agent: id: father-bot enabled: true matrix: homeserver: "https://example.com" user_id: "@father:example.com" llm: primary: provider: claude-code `), 0o644); err != nil { t.Fatal(err) } loaded := map[string]bool{"orchestrator": true} if isSpecialConfig(cfg, loaded) { t.Fatal("expected isSpecialConfig to return false for agent config") } } func TestIsSpecialConfig_emptyLoadedMap(t *testing.T) { if isSpecialConfig("any-path", nil) { t.Fatal("expected false when no specials loaded") } if isSpecialConfig("any-path", map[string]bool{}) { t.Fatal("expected false when empty specials map") } }