Skip to content

Fix debug test suite for Factorio 2.0#1575

Merged
grilledham merged 1 commit into
Refactorio:developfrom
lex:fix-debug-test-failures
Jul 11, 2026
Merged

Fix debug test suite for Factorio 2.0#1575
grilledham merged 1 commit into
Refactorio:developfrom
lex:fix-debug-test-failures

Conversation

@lex

@lex lex commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Fixes two long-standing failures in the in-game test runner (_DEBUG + /test-runner), both fallout from the Factorio 2.0 engine update.

Gui toggle test: 13 ~= 14 - after close count should be equal to before count

The top-button toggle test counted every child of the gui roots (top/left/center/screen). GUIs like the production hud hide their screen frame on close to preserve its dragged position instead of destroying it, so the count stayed one high after closing. The test now counts only visible elements, which keeps the "open shows something / close removes it" contract while allowing the hide-on-close pattern.

helper.lua: bad argument #1 to 'rawset' (table expected, got userdata)

Helper.modify_lua_object monkey-patched fields directly onto LuaObjects (player.print, game.get_player, ...) with rawset. That worked in Factorio 1.1 where LuaObjects were Lua tables, but they are userdata since 2.0, so every test using it errored. This PR adds:

  • Helper.fake_lua_object(object, overrides) — a proxy table that reads and writes through to the wrapped LuaObject except for the overridden fields.
  • Helper.modify_global(context, name, value) — replaces a global (e.g. game) with such a proxy until test teardown.

The death corpse tags, restart command and landfill remover tests are migrated to the new helpers; modify_lua_object now raises a clear error when given a LuaObject. This is safe for these tests because the features under test only read through the player object (print, admin, force, ...) and never pass it back into engine APIs.

Verified in-game on a vanilla-mod map: the Gui toggle tests and death corpse tags test now pass. The restart command and landfill remover suites are migrated mechanically but were not exercised, as those features are not loaded on the default map.

🤖 Generated with Claude Code

Two long-standing failures in the in-game test runner:

- The Gui top-button toggle test counted all children of the gui roots,
  but GUIs like the production hud hide their screen frame on close to
  preserve its position rather than destroying it. Count only visible
  elements so hide-on-close toggles pass.

- Helper.modify_lua_object rawset fields on LuaObjects, which worked in
  Factorio 1.1 where they were tables but errors since 2.0 where they
  are userdata. Add Helper.fake_lua_object (a table that reads and
  writes through to the wrapped object except for overridden fields)
  and Helper.modify_global (replaces e.g. the game global until
  teardown), and migrate the death corpse tags, restart command and
  landfill remover tests to them.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@grilledham grilledham left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing the tests.

@grilledham grilledham merged commit 9773ac7 into Refactorio:develop Jul 11, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants