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
Check · Review · Land · Live done — Landed and live in production.
`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
Sign in to join this conversation.
new above
offline
src/client/main.tsnow takes its host:boot(host)is handed the document, the window, a store, afetch, 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 waysrc/engine/controls.tstypes 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, andreplay.test.ts's digests did not move.src/client/stage.test-helper.tsis the stub page (recording elements, a 2D recorder, a renderer that keeps the world it was handed, afetchthat keeps the bodies, a clock the test moves) andsrc/client/main.test.tsboots 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_overstops the run and focuses play, one POST per round scored in the shapesrc/result.tsaccepts with a rejecting and a throwingfetchboth leaving the match running, and a renderer factory returningnullleaves 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.tsdraws onto aPaint— the seventeen members of a 2D context it uses — which is what lets the recorder be a context while a canvas still is one; andmainis no longer in the README's list of untested modules, with onlyrendererleft there. The ids live once now, asPAGE_IDS/PAGE_ACTIONSin the helper, andsrc/server.test.tspins 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 reusesfake,element,recorder,canvasand the frames-plus-clock infakeStagealmost verbatim — the game-specific parts are the two id lists and the three factories on the host.src/range/dom.tsstays as it is and keeps installing globals:independence.test.tsforbids the range from importing anything undersrc/client/, so the shape is what crosses, not the file.One thing outside #27 had to land first:
mainwas red before I touched it. #28's door rule and #29's range arrived in an order that left every module undersrc/range/importing../engine/controls.tsand friends; they go through../engine/index.tsnow, one import line each. The last offence wasindependence.test.tsreadingboundary.test.ts'ssources/specifiersOf, which is the whole point of that file, so the door rule gained one written-down, tested exception: a.test.tsmay import another.test.tsinside 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 testis green (269 pass). Both bundles are rebuilt and committed:static/app.6bf398e121.jsat 68,457 bytes, 233 more than before, andstatic/range.06e0ed221e.jsat 7,067 from the import change. #5 rewrites the draw call in this file: the lines it should expect to move are theDrawstype near the top and therenderer.draw(world, camera, elapsed)call inframe, plus thedrawsrecorder in the helper if it starts drawing more than once.Closes #27