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)
| 444 | // restart silently undoes the switch. SetActive must roll back on Save failure |
| 445 | // so both views stay in lockstep. |
| 446 | func 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. |
| 465 | func TestActiveProfileResolvesByName(t *testing.T) { |