Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions bundler/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ root back with `scripts[bundler.Rootname]` rather than a hardcoded string, and
round trips — bundle then unbundle, or unbundle then bundle, and compare — since that is the
property the rest of the tool depends on.

Two end-to-end fixtures (`bundled_core`, `bundled_lua`) are currently on the deny list in
[tests/e2e_test.go](../tests/e2e_test.go) because they require `src/` files the harness doesn't
supply. Wiring those up would give bundling real integration coverage.
Two end-to-end fixtures (`bundled_core` and `bundled_lua`) give bundling real integration coverage
through [tests/e2e_test.go](../tests/e2e_test.go): each is reversed (unbundled to `src/`) and built
back (re-bundled by resolving `require`), exercising the full round trip. `bundled_lua` nests its
bundled script inside an object, so the harness compares every bundled `LuaScript` by module-name
set at any depth, since bundling is formatting-sensitive.
6 changes: 4 additions & 2 deletions tests/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ What the comparison covers:
- `Date` and `EpochTime` are excluded — they are regenerated on every build by design.
- Any `float64` value is excluded. Numeric behavior is asserted in
[objects/numbersmoother_test.go](../objects/numbersmoother_test.go) instead.
- `bundled_core` and `bundled_lua` are on a deny list; they depend on `src/` files the harness
doesn't provide.
- Every bundled `LuaScript` is compared by module-name set, not just the top-level one. A bundled
script found at any nesting depth (e.g. inside an object in `ObjectStates`) is normalized the
same way, so nested scripts are not held to a stricter byte-for-byte standard than the root.
Non-bundled scripts are still compared exactly.

## Fixture locations

Expand Down
40 changes: 36 additions & 4 deletions tests/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
for _, path := range paths {
_, filename := filepath.Split(path)
testname := filename[:len(filename)-len(filepath.Ext(path))]
denyList := []string{
"bundled_core", // currently depends on src file that test doesn't know about
"bundled_lua", // currently depends on src file that test doesn't know about
}
denyList := []string{}

t.Run(testname, func(t *testing.T) {
for _, f := range denyList {
Expand Down Expand Up @@ -129,6 +126,13 @@
delete(got, "LuaScript")
}

// Object-level LuaScript (e.g. inside ObjectStates) is compared the
// same formatting-insensitive way as the top-level script above:
// bundling is order- and formatting-sensitive, so a bundled script
// is compared by its set of module names rather than byte-for-byte.
normalizeBundledLua(want)
normalizeBundledLua(got)

if diff := cmp.Diff(want, got, cmpopts.IgnoreMapEntries(ignoreUnpredictable)); diff != "" {
t.Errorf("want != got:\n%v\n", diff)
}
Expand All @@ -137,6 +141,34 @@
}
}

// normalizeBundledLua walks a decoded savegame and replaces every bundled
// LuaScript string it finds (at any nesting depth) with the set of module
// names that unbundle out of it. This mirrors how the top-level LuaScript is
// compared, so nested object scripts are not held to a stricter byte-for-byte
// standard than the root while still verifying that require resolution rebuilt
// the same set of modules. Non-bundled scripts are left untouched so their
// contents are still compared exactly.
func normalizeBundledLua(v interface{}) {
switch t := v.(type) {
case map[string]interface{}:
for k, val := range t {
if k == "LuaScript" {
if s, ok := val.(string); ok && bundler.IsBundled(s) {
if modules, err := bundler.UnbundleAll(s); err == nil {

Check failure on line 157 in tests/e2e_test.go

View workflow job for this annotation

GitHub Actions / build

assignment mismatch: 2 variables but bundler.UnbundleAll returns 3 values
t[k] = mapOfKeys(modules)
continue
}
}
}
normalizeBundledLua(val)
}
case []interface{}:
for _, val := range t {
normalizeBundledLua(val)
}
}
}

func mapOfKeys(m map[string]string) map[string]interface{} {
r := map[string]interface{}{}
for k := range m {
Expand Down
Loading