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

opened this

Merged 32d 2h ago, 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.

Notes

opened this

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 a beat (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() gains watch(fn), which runs fn after 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.mjs is 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

3 earlier comments · 5 events
commented

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 a beat (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() gains watch(fn), which runs fn after 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.mjs is 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 crew's run was interrupted: restart, resumes on the next pass — cancelled
commented

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 a beat (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() gains watch(fn), which runs fn after each frame, and read(expr), which reads a value from the page's own scope. The beats use read to 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.
  • outcome pattern per row: playtest.test.mjs now 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 --noEmit only 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".

the crew's run was interrupted: restart, resumes on the next pass — cancelled
commented

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 a beat of taps, drags, holds or key presses, repeated until the over line shows, plus an outcome pattern 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() gains watch(fn), which runs after each frame, and read(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

the crew's run was interrupted: restart, resumes on the next pass — cancelled
the crew's run was interrupted: restart, resumes on the next pass — cancelled
the crew's run was interrupted: restart, resumes on the next pass — cancelled
commented

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 in errors and 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 with vm.runInContext on the context, and those names are no longer context globals, so they now read through g.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

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs