MCPcopy Index your code
hub / github.com/codehamr/codehamr / TestRunSlashWarnsOnBrokenConfig

Function TestRunSlashWarnsOnBrokenConfig

internal/tui/tui_test.go:974–996  ·  view source on GitHub ↗

TestRunSlashWarnsOnBrokenConfig: a typo in config.yaml must not lock the user out of slash commands. The reload prints a one-line warning and keeps the previous in-memory cfg, so /models (and further editing) keep working with last-known-good state.

(t *testing.T)

Source from the content-addressed store, hash-verified

972// keeps the previous in-memory cfg, so /models (and further editing) keep
973// working with last-known-good state.
974func TestRunSlashWarnsOnBrokenConfig(t *testing.T) {
975 m := newTestModel(t, func(http.ResponseWriter, *http.Request) {})
976 prevActive := m.cfg.Active
977 prevModels := len(m.cfg.Models)
978 if err := os.WriteFile(filepath.Join(m.cfg.Dir, "config.yaml"),
979 []byte("active: [unterminated\nmodels: {{"), 0o600); err != nil {
980 t.Fatal(err)
981 }
982 out, _ := m.runSlash("/models")
983 final := out.(Model)
984 scroll := stripANSI(final.scroll.String())
985 if !strings.Contains(scroll, "config.yaml") {
986 t.Fatalf("scrollback should warn about broken config.yaml:\n%s", scroll)
987 }
988 if final.cfg.Active != prevActive {
989 t.Fatalf("broken-config reload must preserve previous Active, got %q want %q",
990 final.cfg.Active, prevActive)
991 }
992 if len(final.cfg.Models) != prevModels {
993 t.Fatalf("broken-config reload must preserve previous Models, got %d want %d",
994 len(final.cfg.Models), prevModels)
995 }
996}
997
998// TestSlashClearSurvivesBrokenConfig: with config.yaml unparseable, /clear must
999// still wipe history. The reload warning gets wiped with the rest of scrollback

Callers

nothing calls this directly

Calls 4

newTestModelFunction · 0.85
stripANSIFunction · 0.85
runSlashMethod · 0.80
StringMethod · 0.80

Tested by

no test coverage detected