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) } }