From 35ddd0ad2215760bb1d3dc7724480f179ea33fa6 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Wed, 16 Sep 2026 21:05:39 -0400 Subject: fix: login account race, casino chip double-refund, room-create rollback, rename collision, fatal transport errors --- internal/admin/api_entity_path_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'internal/admin/api_entity_path_test.go') diff --git a/internal/admin/api_entity_path_test.go b/internal/admin/api_entity_path_test.go index 7abf65f..27ecbe8 100644 --- a/internal/admin/api_entity_path_test.go +++ b/internal/admin/api_entity_path_test.go @@ -8,6 +8,7 @@ import ( "strings" "testing" + "thehouseoficarus/internal/behavior" "thehouseoficarus/internal/config" "thehouseoficarus/internal/player" ) @@ -60,3 +61,35 @@ func TestEntityAPICannotEscapeData(t *testing.T) { t.Fatal("entity API escaped the data directory") } } + +// TestEntityRenameRejectsDuplicateIDInOtherDirectory: entity IDs are global +// across the type's subdirectory tree (the runtime path indexes resolve by +// filename anywhere under data/), so renaming into an ID that +// exists in a DIFFERENT directory must be rejected instead of creating a +// duplicate ID shadowed by whichever file the index finds first. +func TestEntityRenameRejectsDuplicateIDInOtherDirectory(t *testing.T) { + dir := t.TempDir() + for _, sub := range []string{"items/a", "items/b"} { + if err := os.MkdirAll(filepath.Join(dir, sub), 0o755); err != nil { + t.Fatal(err) + } + } + if err := os.WriteFile(filepath.Join(dir, "items/a/old.yaml"), []byte("name: Original\n"), 0o644); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(dir, "items/b/taken.yaml"), []byte("name: Existing\n"), 0o644); err != nil { + t.Fatal(err) + } + + if _, _, _, err := renameEntityFile(dir, "items", "old", "taken"); err == nil { + t.Fatal("rename accepted an ID that already exists in another directory") + } + if dups := behavior.CheckDuplicateIDs(filepath.Join(dir, "items")); len(dups) != 0 { + t.Fatalf("rename produced duplicate IDs: %+v", dups) + } + + // Renaming within the same directory to a free name still works. + if _, _, _, err := renameEntityFile(dir, "items", "old", "moved"); err != nil { + t.Fatalf("ordinary rename rejected: %v", err) + } +} -- cgit v1.2.3