Skip to content

test: promote the menu-flush fixture rule into lib (24 hand-rolled copies) #72

Description

@mtklein

24 test files carry a hand-rolled copy of the same fixture hazard, and it is a correctness rule rather than cosmetic duplication: in Wait mode, a bystander's open command window freezes the battle clock, so a queued action never reaches the top of the queue and the test hangs. The hang then surfaces as a timeout somewhere unrelated.

It has been rediscovered and rewritten independently at least four times — battle_thief.lua:388-404 (which measured the mechanism), battle_rage.lua:349-356 (same hazard, third shape), and again during the v0.9 test audit while fixing battle_walletmp. Separately, 18 files poke the shared list-cursor block ($895F/$892B) by hand for the same reason.

Proposed: H.flushMenus{ pin = fn, except = slot } in tools/tests/lib/ot6.lua — drive until $7BCA == 0, pulsing A with $895F..$896A zeroed so every bystander takes row 0 and can never fire a second real action.

This should go in ahead of the pure line-count dedup below, because a missing flush produces a mystery hang and the helpers below only save typing.

The rest of the duplication census

Mechanically extracted across all 328 tools/tests/*.lua, de-variant-ed:

helper definitions distinct bodies proposed
map() 135 2 (hex case only) H.mapLow()
sw(id) 126 5 textual, 1 semantic H.storySwitch(id) -> 0|1
bright() 109 1, verbatim H.brightness() -> 0..15
killBitAll() 66 4, but 65 of 66 semantically identical H.killBitAll()
settled() 41 3 semantic shapes H.settled{ world, n } — collapses 32
landed(m, n) 23 9, top two differ only in a log string H.landed(mapId, n) — collapses 17
pressWalk(...) 21 19 byte-identical H.pressWalk(dir, pred, maxFrames, what)

Plus two more sequence duplications:

  • Battle-fixture entrywaitFrames(20), loadState(STATE), waitFrames(10), enterEncounter(), waitFrames(240) verbatim in 25 files (16 suite tests including battle_trueknight, 9 probes). H.enterFixtureBattle(state, settle).
  • Cold-boot ContinuewaitFrames(350), repeatN(5,{start,25}), waitFrames(120), repeatN(3,{a,40}), waitFrames(300), repeatN(3,{a,60}) in 24 files. H.coldContinue().

Caution

Every one of these edits 20-135 call sites at once, in a suite that has just been shown to contain checks that pass while being wrong (#71). A mechanical sweep that silently changes a predicate's timing would be very hard to spot. Land them one helper at a time, and for each, confirm the affected tests still fail when they should — not merely that they still pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions