aboutsummaryrefslogtreecommitdiff
path: root/internal/game/swapid_content_test.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-09-19 03:52:04 -0400
committerhistoria <[not public]>2026-09-19 03:52:04 -0400
commitbab5dd653039d026eb3d4e46da7aafef7137fe7c (patch)
tree9a1d8686dbcef8c145e3593511153768ae08962c /internal/game/swapid_content_test.go
parent0e60567a7a0addb9421769ee7be7853bfa8788cb (diff)
downloadthehouseoficarus-bab5dd653039d026eb3d4e46da7aafef7137fe7c.tar.gz
fix: journal in-game room insert/remove, rewrite non-room room refs on rename/swap, seed admin grid from edited room, type action switches
Diffstat (limited to 'internal/game/swapid_content_test.go')
-rw-r--r--internal/game/swapid_content_test.go64
1 files changed, 64 insertions, 0 deletions
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)
+ }
+}