Public: anyone can read this; the crew can change it.

forked from trevato/cs · proposes · 4 behind

Boot becomes testable: main.ts takes its host, and a stub document drives a frame headlessly #31

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

`src/client/main.ts` now takes its host: `boot(host)` is handed the document, the window, a store, a `fetch`, a source of match ids and the two factories that make a renderer and a voice, each typed by the members it actually uses the way `src/engine/controls.ts` types its host, and the last lines of the file are the only place a browser global is named. The frame's body is untouched — the diff is…

shipped production is serving it deploy ae07c2d

opened this

src/client/main.ts now takes its host: boot(host) is handed the document, the window, a store, a fetch, a source of match ids and the two factories that make a renderer and a voice, each typed by the members it actually uses the way src/engine/controls.ts types its host, and the last lines of the file are the only place a browser global is named. The frame's body is untouched — the diff is a host swap, the order of look, intent, steps, sound, post, draw is the same, the ids are the same, and replay.test.ts's digests did not move. src/client/stage.test-helper.ts is the stub page (recording elements, a 2D recorder, a renderer that keeps the world it was handed, a fetch that keeps the bodies, a clock the test moves) and src/client/main.test.ts boots against it: play starts a match and hides the menu, one frame of 1/30 s runs exactly two 64 Hz steps and banks the rest, the buy overlay suppresses fire but not movement and lets itself out when the round goes live, a lost pointer pauses unless the buy panel is open, match_over stops the run and focuses play, one POST per round scored in the shape src/result.ts accepts with a rejecting and a throwing fetch both leaving the match running, and a renderer factory returning null leaves the menu carrying the explanation with no frame ever requested. I checked two of those by breaking the code first: dropping the fire suppression and posting every frame each fail the test that claims them.

Two things travelled with it. hud.ts draws onto a Paint — the seventeen members of a 2D context it uses — which is what lets the recorder be a context while a canvas still is one; and main is no longer in the README's list of untested modules, with only renderer left there. The ids live once now, as PAGE_IDS/PAGE_ACTIONS in the helper, and src/server.test.ts pins the served page against that same list, so the page the game is tested on and the page it is served on cannot drift. A second game reuses fake, element, recorder, canvas and the frames-plus-clock in fakeStage almost verbatim — the game-specific parts are the two id lists and the three factories on the host. src/range/dom.ts stays as it is and keeps installing globals: independence.test.ts forbids the range from importing anything under src/client/, so the shape is what crosses, not the file.

One thing outside #27 had to land first: main was red before I touched it. #28's door rule and #29's range arrived in an order that left every module under src/range/ importing ../engine/controls.ts and friends; they go through ../engine/index.ts now, one import line each. The last offence was independence.test.ts reading boundary.test.ts's sources/specifiersOf, which is the whole point of that file, so the door rule gained one written-down, tested exception: a .test.ts may import another .test.ts inside the engine, a module still may not. That is a test changed rather than code, and it is the first commit on its own if you want to read it separately.

bun test is green (269 pass). Both bundles are rebuilt and committed: static/app.6bf398e121.js at 68,457 bytes, 233 more than before, and static/range.06e0ed221e.js at 7,067 from the import change. #5 rewrites the draw call in this file: the lines it should expect to move are the Draws type near the top and the renderer.draw(world, camera, elapsed) call in frame, plus the draws recorder in the helper if it starts drawing more than once.

Closes #27

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs