MCPcopy Create free account
hub / github.com/codehamr/codehamr / TestSetActiveRevertsOnSaveFailure

Function TestSetActiveRevertsOnSaveFailure

internal/config/config_test.go:446–462  ·  view source on GitHub ↗

TestSetActiveRevertsOnSaveFailure guards in-memory/on-disk drift on Save failure. If SetActive mutates Active before a failed Save, ActiveProfile() reads the wrong endpoint while config.yaml still names the old profile, and restart silently undoes the switch. SetActive must roll back on Save failure

(t *testing.T)

Source from the content-addressed store, hash-verified

444// restart silently undoes the switch. SetActive must roll back on Save failure
445// so both views stay in lockstep.
446func TestSetActiveRevertsOnSaveFailure(t *testing.T) {
447 cfg := &Config{
448 Active: "a",
449 Models: map[string]*Profile{
450 "a": {LLM: "ma"},
451 "b": {LLM: "mb"},
452 },
453 // Dir intentionally empty so Save() fails with "Dir not set".
454 }
455 err := cfg.SetActive("b")
456 if err == nil {
457 t.Fatal("precondition: Save with empty Dir must fail")
458 }
459 if cfg.Active != "a" {
460 t.Fatalf("Active mutated to %q despite Save failure - in-memory state diverges from on-disk", cfg.Active)
461 }
462}
463
464// TestActiveProfileResolvesByName: the helper returns the right struct.
465func TestActiveProfileResolvesByName(t *testing.T) {

Callers

nothing calls this directly

Calls 1

SetActiveMethod · 0.95

Tested by

no test coverage detected