diff options
| author | historia <[not public]> | 2026-09-16 21:05:39 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-09-16 21:05:39 -0400 |
| commit | 35ddd0ad2215760bb1d3dc7724480f179ea33fa6 (patch) | |
| tree | 3e9acf5e8a690544ecee1ec03af888ee28dd05b8 /internal/admin/api_entity_path_test.go | |
| parent | 6ef40a5739f1723ec26cc32dfc48fe764f776dca (diff) | |
| download | thehouseoficarus-35ddd0ad2215760bb1d3dc7724480f179ea33fa6.tar.gz | |
fix: login account race, casino chip double-refund, room-create rollback, rename collision, fatal transport errors
Diffstat (limited to 'internal/admin/api_entity_path_test.go')
| -rw-r--r-- | internal/admin/api_entity_path_test.go | 33 |
1 files changed, 33 insertions, 0 deletions
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/<subdir>), 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) + } +} |
