Skip to content

[Types] LLM env layer (emmylua config, type stubs, manual fixes)#7447

Draft
keithharvey wants to merge 12 commits intobeyond-all-reason:masterfrom
keithharvey:fmt-llm-source
Draft

[Types] LLM env layer (emmylua config, type stubs, manual fixes)#7447
keithharvey wants to merge 12 commits intobeyond-all-reason:masterfrom
keithharvey:fmt-llm-source

Conversation

@keithharvey
Copy link
Copy Markdown
Contributor

@keithharvey keithharvey commented Apr 16, 2026

Part of BAR type-error cleanup. Human-curated env layer that prepares the codebase for the LLM type-fix pass.

This branch carries:

  • .emmyrc.json globals and analyzer config
  • types/* stubs for vendored/generated declarations
  • Explicit type ignores for known dead code
  • CI gate configuration
  • Manual source fixes that require human judgement

Branch Topology

All branches in the BAR type-error cleanup stack. Regenerated deterministically by just bar::fmt-mig-generate. Generated 2026-04-17 00:53:39 UTC.

Leaves — each targets master, mergeable independently:

Branch Command Diff vs master Units
fmt stylua 1434 files, +178566 −184590 ✅ pass
mig-bracket bar-lua-codemod bracket-to-dot 341 files, +7604 −7604 ✅ pass
mig-rename-aliases bar-lua-codemod rename-aliases 165 files, +353 −353 ✅ pass
mig-detach-bar-modules bar-lua-codemod detach-bar-modules 175 files, +1436 −1303 ✅ pass
mig-i18n bar-lua-codemod i18n-kikito 19 files, +105 −1187 ✅ pass
mig-spring-split bar-lua-codemod spring-split 762 files, +9639 −9635 ✅ pass
mig-integration-tests <hand curated> 22 files, +139 −89 ✅ pass
mig-busted-types <hand curated> 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 1465 files, +188501 −193927 ✅ pass
fmt-llm-source 1494 files, +189260 −194248 82 files, +823 −385 n/a
fmt-llm 1495 files, +189425 −194275 55 files, +192 −54 ✅ pass

keithharvey and others added 12 commits April 16, 2026 15:56
Add Utilities, I18N, Debug, Lava, and GetModOptionsCopy to the
System tables in luaui/system.lua and luarules/system.lua so that
widgets and gadgets can access them after detach-bar-modules moves
them off the Spring table.

Also add .luarc.json globals and type stubs for LSP support.
Replaces the vendored gajop/i18n fork with the upstream i18n package
via lux. The mig-i18n branch applies the codemod that rewrites the
wrapper and call sites to use this dependency.
Restructures the 20 files under luaui/Tests/, luaui/TestsExamples/,
plus the headless-only common/testing/infologtest.lua, from bare-
global hook declarations to a return-table shape. Updates the
dbg_test_runner widget to read test hooks from the returned table.

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`, `skip`, `cleanup`. To keep
emmylua happy, .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.

Minimal shape change per file — just prepend `local` to each top-
level `function` declaration, and append a final `return { ... }`
block listing whichever lifecycle hooks (skip/setup/test/cleanup)
that file actually defines. Original indentation and formatting
preserved (no stylua reformatting noise — the fmt transform runs
after this one in the mig pipeline).

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
Vendored LuaCATS annotations for busted/luassert to provide
IntelliSense for the unit-test surface. Lives on its own leaf so the
discussion around 'vendoring LuaCATS types' can happen in isolation —
prior pushback on the same direction in an earlier unit-testing PR
makes this the right place to litigate it rather than burying it in a
broader env commit.

Why vendored instead of declared as a Lux dep: Lux does not yet
support pulling LuaCATS annotations from library deps, and quick
attempts to wire this up in Lux failed. Upstream tracking issue:
lumen-oss/lux#953 — once that lands, these
directories should be deleted in favor of declaring busted as a
normal Lux dev-dep.

Sources (pinned SHAs):
  - types/busted/   https://github.com/LuaCATS/busted
                    @ 5ed85d0e016a5eb5eca097aa52905eedf1b180f1
  - types/luassert/ https://github.com/LuaCATS/luassert
                    @ d3528bb679302cbfdedefabb37064515ab95f7b9

See types/busted/provenance.md and types/luassert/provenance.md for
per-directory upstream refs + license status.
Env layer that sits between `mig` and the LLM triage pass. Creates
the emmylua config, per-class type stubs, the CI gate, source fixes
for bugs the tightened globals list unmasks, and a type stub for the
integration-test DSL.

Single commit on `fmt-llm-source`. Two concerns that used to live
here have been split off into their own leaf branches for isolated
PR discussion:

  - Vendored LuaCATS busted+luassert types → mig-busted-types
    (carried-commit leaf off busted-types-curated)
  - Integration-test return-table restructure + runner patch →
    mig-integration-tests (carried-commit leaf off
    integration-tests-curated)

Both live in TRANSFORMS now, so mig composes them in, and this env
commit assumes both landed. If either leaf gets rejected, a follow-up
env commit re-adds its compensating kludge (busted globals +
`spec/` ignoreDir for rejected busted-types; `luaui/Tests`/
`luaui/TestsExamples` ignoreDir + delete `types/Test.lua` for
rejected integration-tests).

Contents:
  - .emmyrc.json: scoped globals (engine sandbox, BAR module globals
    from detach-bar-modules, BAR sandbox entries, handful of
    BAR-defined CMD_*). Busted framework names intentionally absent —
    covered by mig-busted-types. `workspace.ignoreDir` does not list
    luaui/Tests or luaui/TestsExamples — mig-integration-tests makes
    those files analyzable.
  - types/Test.lua (new, ---@meta): integration-test DSL type
    declarations. Signatures extracted from the inline `Test` table
    in luaui/Widgets/dbg_test_runner.lua:662 + extras from
    common/testing/test_extra_utils.lua.
  - types/*.lua: BAR-defined class stubs (Widget, Gadget, Addon,
    UnitDef, Callins, GL, LuaShader/Module, VBO/VAO, BarLuaShader,
    Spring augments, etc.).
  - .github/workflows/type_check.yml: CI gate running emmylua_check.
  - Source fixes surfaced by tightening:
    - luaui/system.lua: Commands = Commands → Commands = Game.Commands
      (the bare Commands global was a dangling reference previously
      masked by the indiscriminate globals list).
    - luaui/Widgets/gui_pip.lua: forward-decl for `UpdateGuishaderBlur`
      — StartMaximizeAnimation (line 4307) calls it before the
      `local function UpdateGuishaderBlur` definition at line 4310.
  - Small per-file type/source cleanups carried over from the prior
    LLM pass.

Per PR review by Watch The Fort: globals are a code smell outside
engine-defined tables. Scope kept to declared globals that are
either (a) engine-provided sandbox members, (b) BAR module globals
intentionally hoisted off Spring.* by detach-bar-modules, or
(c) BAR-defined custom command constants with known providers.
The old README duplicated setup instructions that now live in
BAR-Devtools. Replace the development section with a pointer to
the Devtools repo and keep only the game-specific .sdd setup steps.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

Integration Test Results

0 tests   - 16   0 ✅  - 8   0s ⏱️ -3s
0 suites  -  1   0 💤  - 8 
0 files    -  1   0 ❌ ±0 

Results for commit dcc143b. ± Comparison against base commit e1db694.

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