Skip to content

[Tests] Restructure integration tests to table-return shape#7437

Draft
keithharvey wants to merge 1 commit intobeyond-all-reason:masterfrom
keithharvey:mig-integration-tests
Draft

[Tests] Restructure integration tests to table-return shape#7437
keithharvey wants to merge 1 commit intobeyond-all-reason:masterfrom
keithharvey:mig-integration-tests

Conversation

@keithharvey
Copy link
Copy Markdown
Contributor

@keithharvey keithharvey commented Apr 14, 2026

Part of BAR type-error cleanup. Rebuilds idempotently from master via just bar::fmt-mig-generate.

# integration-tests - restructure luaui/Tests and luaui/TestsExamples files
# from bare-global hook declarations to a return-table shape; patch the
# dbg_test_runner widget to read hooks from the returned table. Carried-
# commit leaf — no codemod; curated branch holds the hand-authored commit.

Carried-commit leaf. Restructures luaui/Tests/ and luaui/TestsExamples/ (20 files) from bare-global hook declarations to a return { ... } shape, and patches dbg_test_runner.lua to read hooks from the returned table. Isolated so the convention change can be discussed/reverted independently.

Branch Topology

All branches in the BAR type-error cleanup stack. Regenerated deterministically by just bar::fmt-mig-generate. Generated 2026-04-14 18:57:59 UTC.

Leaves — each targets master, mergeable independently:

Branch Command Diff vs master Units
fmt stylua 1421 files, +178457 −184495 ✅ pass
mig-bracket bar-lua-codemod bracket-to-dot 341 files, +7632 −7632 ✅ pass
mig-rename-aliases bar-lua-codemod rename-aliases 164 files, +352 −352 ✅ pass
mig-detach-bar-modules bar-lua-codemod detach-bar-modules 173 files, +1434 −1301 ✅ pass
mig-i18n bar-lua-codemod i18n-kikito 19 files, +105 −1187 ✅ pass
mig-spring-split bar-lua-codemod spring-split 760 files, +9591 −9587 ✅ pass
mig-integration-tests bar-lua-codemod integration-tests 21 files, +1230 −1151 ✅ pass
mig-busted-types bar-lua-codemod busted-types 12 files, +1501 −0 ✅ pass

Rollups — composite branches stacking the leaves and (for fmt-llm) the env + LLM layers:

Branch Diff vs master Diff vs mig Units
mig 1452 files, +189169 −194574 ✅ pass
fmt-llm 1480 files, +189970 −194795 126 files, +861 −281 ✅ pass

Restructures the 20 files under luaui/Tests/ and luaui/TestsExamples/
from bare-global hook declarations to a return-table shape, and
updates the dbg_test_runner widget to read test hooks from the table
returned by the chunk.

Motivation: the pre-existing shape required the test files to run
under setfenv(chunk, testEnvironment) and define `function test()`,
`function setup()`, etc. as bare module-level globals that setfenv
redirected into the environment. That works at runtime but emmylua
can't model the sandboxing — it sees 20 files declaring project-wide
globals like `test`, `setup`, `widget`, `unitID`, `initialCameraState`,
etc. To analyze the test files, .emmyrc.json had to blacklist both
test directories under workspace.ignoreDir — a kludge on clearly-ours
code. Lives on its own leaf so the convention change can be discussed
in isolation.

Shape change, per file:
  function skip()    return ... end        ─┐
  function setup()   ... end                 │   return {
  function test()    ... end                 ├─▶   skip = function() return ... end,
  function cleanup() ... end                ─┘     setup = function() ... end,
                                                   test = function() ... end,
                                                   cleanup = function() ... end,
                                                 }

Cross-hook shared state (e.g. `widget`, `initialCameraState`, mocks
whose .remove() gets called in cleanup) now declared as file-scope
locals above the return block, so the hook closures capture them
without leaking the names into emmylua's project globals.

Helper functions (runCritterTest, runDistanceTest, test_factory_*,
sanityChecks/failingTests/etc. in selftests) converted from bare
globals to `local function` above the return block — they're only
called from other hooks in the same file.

Runner patch — luaui/Widgets/dbg_test_runner.lua, loadTestFromFile:
  - capture the return value of pcall(chunk)
  - require it to be a table
  - merge its keys into testEnvironment so runTestInternal still reads
    bare `skip`/`setup`/`test`/`cleanup` under setfenv(testEnvironment)
@github-actions
Copy link
Copy Markdown
Contributor

Integration Test Results

16 tests  ±0   7 ✅  - 1   3s ⏱️ -1s
 1 suites ±0   7 💤  - 1 
 1 files   ±0   2 ❌ +2 

For more details on these failures, see this check.

Results for commit 1b891a9. ± Comparison against base commit 5a1fd3e.

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.

1 participant