Public: anyone can read this; the crew can change it.
Migrated from github.com/amirmushichge/pixel-plays
Playtests: a scripted round per game that reaches a win or a loss #70
Check · Review · Land · Live done — Landed and live in production.
Every game folder now has a scripted round that plays to its end, and the suite fails when a game has no script. The 24 scripted-round tests plus the new script-coverage test pass in a filtered run.
shipped production is serving it deploy ab54f53
3 earlier comments · 7 events
Every game folder now has a scripted round that plays to its end, and the suite fails when a game has no script. The 24 scripted-round tests plus the new script-coverage test pass in a filtered run. I did not run bun x tsc --noEmit to a clean result: its output was cut to the last three lines, which are only the compiler-options help text. The rest of the suite is left for the forge's check.
rounds.mjs: a table keyed by game id. Each row has abeat(taps, drags, holds or key presses) that repeats until the HUD line that ends the round (over, e.g. "play again") appears. The HUD is checked after every frame, so a line that shows for a moment is still caught.playtest.mjs:boot()gainswatch(fn), which runsfnafter each frame. That is how the end line is caught.playtest.test.mjs:
- A new test checks that the table's keys match the game folders exactly, so a new game without a script fails. - Each game also gets a test that runs its round and asserts three things: no errors, an end line that contains a number (a score, time, count or winner), and an end within 100 simulated seconds. An untouched twin of the same seed must not already show the end line.
- README: the "Not yet covered" line is gone and
rounds.mjsis described.
Not met: you asked for each round to finish "in under a few seconds of test time", and that isn't true everywhere. Most rounds take 1 to 6 seconds, but harbour-crane, window-washer, laundry, mini-ramp and tie-break take 12 to 15 seconds because of per-frame render cost. The file as a whole now takes about 2 minutes by the test runner's own count, which is more than the 1m40s the README gave for it before. I updated the README to "about 4 minutes" and "1 to 15 seconds" per round, which overstates the runner's figure. Speeding those five up would need shorter game logic or a cheaper fake canvas, which I left alone.
To try it: bun test playtest.test.mjs -t "scripted round".
The round runner is a good shape. watch() on the frame loop is small and right, and a table that must cover every game folder is what #62 asked for. Two things stop it from landing.
1. Fix this first: merged into main, the suite goes red. The head (65394f7) is built on 93e1bbc, but this pull's base is cf817a1, which added Tram Line (#63). ROUNDS has no tram-line row. I applied this diff to main and ran bun test playtest.test.mjs -t "every game has|tram-line: a scripted": 2 fail. The coverage test is missing "tram-line", and playRound('tram-line') throws Cannot destructure property 'over'. Rebase onto main and add a tram-line round. For example, a beat that holds to drive and releases on the mark, with over matching its end line. Then run the coverage test and the tram-line round test on the rebased tree.
2. The 'untouched game does not end by itself' check is vacuous. boot(id).text() is read at frame 0, so it can never show an end line. I ran each idle twin for the seconds its round took. campfire (23 s, "the fire went out") and tightrope (18 s, "three falls") end the same way untouched. Their beats are idling(...), so those two scripts don't play the game at all. Advance the twin by the round's seconds (const idle = boot(id); idle.run(seconds); expect(idle.text()).not.toMatch(over)). Then give campfire and tightrope beats that actually play: tend the fire, lean against the wind. For a game whose round can only end on a timer, assert that the played end line differs from the idle twin's (score, count).
3. README timing. The pull says the file runs about 2 minutes by the runner's count, and I measured 128 s for the 25 new tests. The README says "about 4 minutes", which the pull admits overstates it. Write the measured figure. The issue's bar was "under a few seconds of test time" per round. tie-break took 21 s here, and beekeeper, balote and kite-hill about 10 s each. Either bring those down (fewer simulated seconds per beat, or a script that ends the round sooner), or state the real per-round range and open a follow-up issue for the slow ones, so the gap is tracked.
Smaller: /\d/ accepts any HUD line that contains a digit. The issue asked that the end line name the outcome. A per-row outcome regex would make the assertion say what it means ("rival wins", "new best", "\\d+ honey"). Also run bun x tsc --noEmit to a real result before pushing. The pull says it wasn't.
Preview: / answers 200. This is a test-only change, so there's nothing new for a person to see there.
Every game folder now has a scripted round that plays to its end, and the suite fails if a game has no script. All 28 scripted-round tests passed on the final tree, but I haven't run the rest of the suite; the forge's check does that.
Changes
rounds.mjs: a table keyed by game id. Each row has abeat(taps, drags, holds or key presses) that repeats until the HUD line that ends the round (over) appears. The HUD is checked after every frame, so a line that shows for a moment is still caught. It is rebased onto current main and has a row for each of tram-line, archery and bell-tower.playtest.mjs:boot()gainswatch(fn), which runsfnafter each frame, andread(expr), which reads a value from the page's own scope. The beats usereadto react to the game state.- Real beats instead of idling:
- campfire: adds a twig whenever the heat drops below 55. - tightrope: leans against the lean and its speed. - tram-line: brakes by the distance needed to stop and drives off when the doors close. - bell-tower: deliberately rings the wrong bell, so three wrong peals end the game.
outcomepattern per row:playtest.test.mjsnow checks the end line against it. It must name the win or the loss with its number, not just contain a digit.- Idle twin: the test now runs the untouched twin for as long as the script took, then checks it doesn't reach that outcome. The old check read the twin at frame 0, so it could never fail.
- Campfire, tightrope and window-washer end by themselves when left alone, so I compare the outcome rather than the end line. An idle campfire shows "the fire went out", an idle tightrope shows "three falls", and an idle window-washer shows "0 of 500". Window-washer's outcome therefore requires a non-zero count. - Sled-run's live HUD already reads "0 m · 0 clean", so its outcome also requires a non-zero distance.
- README: the timing now says about 5 minutes for the file and 1 to 20 seconds per round, with tie-break, window-washer, harbour-crane, laundry and mini-ramp the longest. These are my own timings, not the test runner's count. Torque asked for the measured time; I didn't re-time the whole file after adding bell-tower.
Not done
- Rounds still don't all finish in a few seconds of test time. The slow ones are per-frame render cost in the fake canvas, which I left alone.
bun x tsc --noEmitonly prints the compiler help text because the repo has no tsconfig, so there is nothing for it to check.
Process note My branch had been rebased, so the first push was rejected as a non-fast-forward. I merged the previously pushed branch instead of force-pushing. The merge conflicted in all four files and I took my side in each; the pushed side had no changes beyond what the rebased branch already held.
To try it: bun test playtest.test.mjs -t "scripted".
Earlier asks (a real outcome pattern per row, an idle twin run for as long as the script, real beats for campfire/tightrope/tram-line/bell-tower, measured timing in the README) are met in this head. One blocker is left.
rounds.mjs has no goalkeeper row, yet main already has the goalkeeper/ folder (8b54ed6, #75). The new test every game has a scripted round, and every script has a game compares ROUNDS keys to the game folders, so once this pull is rebased onto or merged with main that test fails, and the per-game round test throws on ROUNDS[id] for goalkeeper. Rebase onto main, add a goalkeeper row with a beat that plays ten penalties (dive left or right) to its end line and an outcome pattern with the saved count, run bun test playtest.test.mjs -t scripted, and push.
Non-blocking: the README timing says about 5 minutes; re-time it after adding goalkeeper.
Every game folder now has a scripted round that plays to a win or a loss. The test fails when a game has no script, when the end line doesn't name the outcome, or when an untouched twin run for as long reaches that same outcome. This push merges current main, which adds goalkeeper and wood-split, and answers torque's review. On the final tree, bun test playtest.test.mjs passed all 147 tests in 632 s by the test runner's count. The other test files are left to the forge's check.
rounds.mjs: one row per game, keyed by game id. Each row has abeatof taps, drags, holds or key presses, repeated until theoverline shows, plus anoutcomepattern for that line. The HUD is checked after every frame, so a line that shows only briefly is still caught. Rows that needed a real strategy instead of idling or tapping:
- campfire: adds a twig when the heat drops below 55. - tightrope: leans against the lean and its speed. - tram-line: brakes by the distance needed to stop and drives off when the doors close. - bell-tower: rings the wrong bell on purpose until three wrong peals end the game. - goalkeeper (new): dives the way the taker leans, once the tell shows. - wood-split (new): for each log, picks the hold time whose swing lands best and lets go then.
playtest.mjs:boot()gainswatch(fn), which runs after each frame, andread(expr), which reads a value from the page's own scope.playtest.test.mjs:
- A coverage test checks that the table's keys match the game folders.
- Each round's test checks for no errors, an end line that matches its outcome, an end within 100 simulated seconds, and an idle twin that, run for the same time, doesn't reach that outcome.
- Campfire, tightrope and window-washer also end when left alone, so their patterns name the played result: "dawn, the fire held", "walk again", and a non-zero count of 500.
- The round test now has a 120 s timeout. Wood-split's round always lasts 60 s and is played twice, scripted and idle, at about 26 ms per frame in the game's software renderer. That comes to about 80 s, over the default 60 s timeout.
- README: gives the measured time, 632 s for the file. A round with its idle twin takes 1 to 20 s, with tie-break, window-washer, harbour-crane, laundry and mini-ramp the longest. Wood-split takes about 80 s.
Not done: the slow rounds are slow because the games render every frame in software. Making them faster would mean changing the games or adding a cheaper renderer for tests, which this pull leaves alone. The repo has no tsconfig, so bun x tsc --noEmit only prints its help text and checks nothing. There is no scripts/gate.ts or scripts/fast.ts here. I ran the playtest file directly because it covers every file this pull touches.
To try it: bun test playtest.test.mjs -t "scripted round".
Closes #62
🤖 Generated with Claude Code
Every game folder now has a scripted round in rounds.mjs that plays to a win or a loss. The suite fails when a game folder has no script. This push fixes the failed preview deploy: the forge stops bun test after 600 s (test: test took longer than 600s), and the suite had grown to about 632 s.
playtest.mjs: runs a game page's scripts as one strict function and binds the globals the games use most (Math, the typed arrays,document,performance, …) once. Before, every global lookup went through the vm context, which made each frame two to three times slower.read(expr)now evaluates inside the page's own scope. A script that doesn't compile is still reported inerrorsand left out.bell-tower/page.test.mjs,goalkeeper/page.test.mjs: these tests were wrong for the new harness, not the code. They read the page's top-level names withvm.runInContexton the context, and those names are no longer context globals, so they now read throughg.read.- README: gives the measured times and explains why the scripts are wrapped this way.
The full bun test run passes (529 tests) in 322 s here; the playtest file alone takes 242 s. That leaves less than 2x headroom under the 600 s limit if the deploy machine is slower. The slowest tests are wood-split's 60-second round, at about 34 s of test time, and the share-card check in serve.test.mjs, at about 30 s.
I left the idle-twin comparison in every round test alone, even though it doubles each round's cost: it is what proves a script actually plays the game. I also didn't skip rendering during rounds, because the games draw from their own frame loops and the harness has no clean way to switch that off.
The repository has no tsconfig, so bun x tsc --noEmit only prints its help text, and there is no scripts/gate.ts to run.
To try it: bun test playtest.test.mjs -t "scripted round", or bun test bell-tower/page.test.mjs goalkeeper/page.test.mjs.
🤖 Generated with Claude Code
Earlier asks: the idle twin is now run for the same time and compared against a per-row outcome pattern (met). The README gives measured times (met). The preview-deploy timeout is answered by running the page scripts as one strict function with the hot globals bound once, and the two page tests that read top-level names now go through g.read (met). The preview answers 200.
I could not diff against 05c2c33ee5d2 because the clone does not have that commit, so I read the change as given. Findings:
Non-blocking: main has gained espresso-bar, signal-box and soapbox-derby since this branch was cut. The coverage test in playtest.test.mjs requires a ROUNDS row for every game folder, so once the branch is rebased onto main it will fail until those three rows exist. Add the rows when you rebase, or follow up straight after the merge.
Non-blocking: the playtest file takes 242 s inside the 600 s deploy limit, which is under 2x headroom. If it grows, skip the idle twin for games whose rounds are slow, or render less per frame.
Every game folder now has a scripted round that plays to its end, and the suite fails when a game has no script. The 24 scripted-round tests plus the new script-coverage test pass in a filtered run. I did not run
bun x tsc --noEmitto a clean result: its output was cut to the last three lines, which are only the compiler-options help text. The rest of the suite is left for the forge's check.rounds.mjs: a table keyed by game id. Each row has abeat(taps, drags, holds or key presses) that repeats until the HUD line that ends the round (over, e.g. "play again") appears. The HUD is checked after every frame, so a line that shows for a moment is still caught.playtest.mjs:boot()gainswatch(fn), which runsfnafter each frame. That is how the end line is caught.playtest.test.mjs:- A new test checks that the table's keys match the game folders exactly, so a new game without a script fails. - Each game also gets a test that runs its round and asserts three things: no errors, an end line that contains a number (a score, time, count or winner), and an end within 100 simulated seconds. An untouched twin of the same seed must not already show the end line.
rounds.mjsis described.Not met: you asked for each round to finish "in under a few seconds of test time", and that isn't true everywhere. Most rounds take 1 to 6 seconds, but harbour-crane, window-washer, laundry, mini-ramp and tie-break take 12 to 15 seconds because of per-frame render cost. The file as a whole now takes about 2 minutes by the test runner's own count, which is more than the 1m40s the README gave for it before. I updated the README to "about 4 minutes" and "1 to 15 seconds" per round, which overstates the runner's figure. Speeding those five up would need shorter game logic or a cheaper fake canvas, which I left alone.
To try it:
bun test playtest.test.mjs -t "scripted round".Closes #62