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

Function TestSaveIsAtomicAndLeavesNoTemp

internal/config/config_test.go:376–407  ·  view source on GitHub ↗

TestSaveIsAtomicAndLeavesNoTemp: writeYAML writes a sibling temp then renames it over config.yaml so a torn write can't brick the next launch. Pin that the rename leaves no leftover .config-*.yaml temp and the result still decodes. A regression here would mean the atomic-write path leaks temps or wr

(t *testing.T)

Source from the content-addressed store, hash-verified

374 // Dir intentionally empty so Save() fails with "Dir not set".
375 }
376 err := cfg.SetActive("b")
377 if err == nil {
378 t.Fatal("precondition: Save with empty Dir must fail")
379 }
380 if cfg.Active != "a" {
381 t.Fatalf("Active mutated to %q despite Save failure: in-memory state diverges from on-disk", cfg.Active)
382 }
383}
384
385// TestActiveProfileResolvesByName: the helper returns the right struct.
386func TestActiveProfileResolvesByName(t *testing.T) {
387 cfg := &Config{
388 Active: "b",
389 Models: map[string]*Profile{
390 "a": {LLM: "m-a"},
391 "b": {LLM: "m-b"},
392 },
393 }
394 if cfg.ActiveProfile().LLM != "m-b" {
395 t.Fatalf("ActiveProfile().LLM = %q, want m-b", cfg.ActiveProfile().LLM)
396 }
397}
398
399// TestBootstrapCoercesUnknownActive: an unknown `active:` is coerced to the
400// first profile in sorted order so ActiveProfile never returns nil.
401func TestBootstrapCoercesUnknownActive(t *testing.T) {
402 dir := t.TempDir()
403 cdir := filepath.Join(dir, DirName)
404 if err := os.MkdirAll(cdir, 0o755); err != nil {
405 t.Fatal(err)
406 }
407 yaml := []byte(`active: ghost
408models:
409 zulu:
410 llm: m

Callers

nothing calls this directly

Calls 2

BootstrapFunction · 0.85
SaveMethod · 0.80

Tested by

no test coverage detected