From bab5dd653039d026eb3d4e46da7aafef7137fe7c Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Sat, 19 Sep 2026 03:52:04 -0400 Subject: fix: journal in-game room insert/remove, rewrite non-room room refs on rename/swap, seed admin grid from edited room, type action switches --- internal/game/swapid_content_test.go | 64 ++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 internal/game/swapid_content_test.go (limited to 'internal/game/swapid_content_test.go') diff --git a/internal/game/swapid_content_test.go b/internal/game/swapid_content_test.go new file mode 100644 index 0000000..f1eb978 --- /dev/null +++ b/internal/game/swapid_content_test.go @@ -0,0 +1,64 @@ +package game + +// Regression: `swapid` rewrites structural room references in non-room content +// files (modules, triggers, items, ...) as well as in data/rooms. Before this, +// only room YAML was scanned, so a transport destination or trigger teleport +// silently kept pointing at the pre-swap ID. + +import ( + "os" + "path/filepath" + "strings" + "testing" +) + +func TestSwapIDRewritesNonRoomContent(t *testing.T) { + h := newHarness(t) + h.seedAccount("admin") + h.seedCharacter("admin", "admin") + acc, err := h.g.AccountStore.LoadAccount("admin") + if err != nil { + t.Fatal(err) + } + acc.Admin = true + if err := h.g.AccountStore.SaveAccount(acc); err != nil { + t.Fatal(err) + } + sess, _ := h.connect("admin") + + // A transport module destination and an author value that equals a room ID. + modulesDir := filepath.Join(h.dir, "modules") + if err := os.MkdirAll(modulesDir, 0o755); err != nil { + t.Fatal(err) + } + modulePath := filepath.Join(modulesDir, "transport_home.yaml") + if err := os.WriteFile(modulePath, []byte("name: Home\ncategory: transport\ndestination: 1\n"), 0o644); err != nil { + t.Fatal(err) + } + itemsDir := filepath.Join(h.dir, "items") + if err := os.MkdirAll(itemsDir, 0o755); err != nil { + t.Fatal(err) + } + itemPath := filepath.Join(itemsDir, "gem.yaml") + if err := os.WriteFile(itemPath, []byte("name: gem\nvalue: 1\n"), 0o644); err != nil { + t.Fatal(err) + } + + h.g.RunOnOwner(func() { h.g.executeSwapID(sess, []string{"1", "2"}, "swapid 1 2") }) + + module, err := os.ReadFile(modulePath) + if err != nil { + t.Fatal(err) + } + if !strings.Contains(string(module), "destination: 2") { + t.Errorf("module destination not swapped: %s", module) + } + // value: 1 is an author value, not a structural room reference. + item, err := os.ReadFile(itemPath) + if err != nil { + t.Fatal(err) + } + if !strings.Contains(string(item), "value: 1") { + t.Errorf("author value equal to a swapped ID was rewritten: %s", item) + } +} -- cgit v1.2.3