From 87d08f0151e643951769e323995f1c5ed89ee200 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Fri, 18 Sep 2026 01:50:17 -0400 Subject: fix: harden economy recovery, shutdown concurrency, world validation, and inventory-loss paths --- internal/validate/regression_test.go | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 internal/validate/regression_test.go (limited to 'internal/validate/regression_test.go') diff --git a/internal/validate/regression_test.go b/internal/validate/regression_test.go new file mode 100644 index 0000000..53475bd --- /dev/null +++ b/internal/validate/regression_test.go @@ -0,0 +1,45 @@ +package validate + +import ( + "path/filepath" + "testing" + + "thehouseoficarus/internal/behavior" +) + +// TestDropTableCycleIsAnError: a self/mutual drop-table reference must be a +// startup ERROR, because ResolveDrop recurses and would otherwise overflow the +// goroutine stack at runtime. +func TestDropTableCycleIsAnError(t *testing.T) { + dir := t.TempDir() + writeFile(t, filepath.Join(dir, "drops", "a.yaml"), "id: a\ndrops:\n - table: b\n weight: 1\n") + writeFile(t, filepath.Join(dir, "drops", "b.yaml"), "id: b\ndrops:\n - table: a\n weight: 1\n") + behavior.ClearDropIndex() + defer behavior.ClearDropIndex() + + issues := validateDropTableCycles(Source{DataDir: dir}, dropTableIDSet(dir)) + if len(issues) == 0 { + t.Fatal("expected a cycle error for a <-> b") + } + for _, issue := range issues { + if issue.Level != "ERROR" { + t.Fatalf("cycle issue must be ERROR: %+v", issue) + } + } +} + +// TestNonNumericRoomFilenameIsAnError: the room index only accepts numeric +// stems, so a backup file must be flagged instead of silently ignored. +func TestNonNumericRoomFilenameIsAnError(t *testing.T) { + dir := t.TempDir() + writeFile(t, filepath.Join(dir, "rooms", "1001.yaml"), "id: 1001\nname: real\n") + writeFile(t, filepath.Join(dir, "rooms", "1001_copy.yaml"), "id: 1001\nname: copy\n") + + issues := validateRoomFilenames(dir) + if len(issues) != 1 { + t.Fatalf("expected exactly one filename issue, got %+v", issues) + } + if issues[0].Level != "ERROR" { + t.Fatalf("expected ERROR, got %+v", issues[0]) + } +} -- cgit v1.2.3