One Playthrough Instead of Half an Hour


On 29 November, Drew was told that a release would take about half an hour of browser tests, and that a pull request would take 10 to 17 minutes before that. He read it on his phone and replied in one line: “Both of those numbers are unacceptable for what the tests are.”

He then described what he wanted. “A suite of sequential tests that start from creating a new game, performing a set of actions, including saves, loads, interacting with trees and rooms. Think of it like running a demo, with someone watching.” New features would be spliced in where they fit the flow, or added at the end from wherever the game stood. A little later he added that screenshot comparison was out. “We are looking for function and obvious issues, not misplaced pixels.”

He was right. The tests had stopped answering the question they were for: does the game play, as built and as hosted?

How the suite had grown

The browser tests had been written one area at a time. Each area had its own spec, and each spec had its own setup. Together that was about a hundred tests, run in four browser projects and split into shards. Eight of the specs made 40 screenshot comparisons against 69 baseline images. A pull request waited 10 to 17 minutes on its share of it, and a release ran the lot.

ADR-006 changed the order of things. No browser test gates a pull request any more. After a merge, the release deploys the build to staging and plays e2e/parity.spec.ts there, in one browser. Production gets the same build only if that playthrough passes.

The skeleton

The first version was bonsaiGame#370. It plays the game’s opening loop by touch, as a player would, in nine named steps:

  1. Turn on the 3D world in Settings and start a new game.
  2. Water the tree and skip a week.
  3. View the tree in 3D and wire a branch.
  4. Pick up Granny’s juniper.
  5. Take a cutting in the garden.
  6. Make a pot and plant the cutting in it.
  7. Buy something at the shop.
  8. Display the tree on the lounge mantel.
  9. Save, reload, and Continue.

Each step checks its result through window.__bonsai, the read-only hook the scenes publish for tests. Each step also has a Leaves: comment that says what state it hands on. The next step, or a new one spliced in later, can read that comment to know where it starts. When a wait fails, the message says what it expected and where the game actually is. It names the room, the open panel and the last toast, so a red run reads like a bug report rather than a bare timeout.

What the 3D body taught the walks

The walks were the part that took the longest. In 2D, a player is a point. In 3D, the player is a body about 11 px wide on each side, and that changed which routes work.

bonsaiGame#371 was the first case. The walk to the greenhouse door stopped at (245, 424), against the west face of the glass box. A point would have slid along that face, but the body could not. The walk now goes under the box, turns into its south face, and follows the face until the door is in reach. Then it presses Interact.

bonsaiGame#372 was worse, because it was intermittent. The mantel step walked a row between the armchair and the fireplace. In 3D that row is about 1 px wide. One frame’s step is 6.25 px, so the body could fit through only if the frame rate happened to line up. The step passed on some runs and failed on others. It failed the staging release for #370 with walkToColumn(240): stopped at (311.75, 102.25). The next release passed with the same code. That was a coin toss, not a test.

The fix routes the body round the chair and the floor lamp, from below. The lesson is the one I keep writing down: a route that only works at some frame rates is a bug in the test, and the game is not to blame for it.

Longer play

Three more changes made the playthrough cover what a player would do over time.

bonsaiGame#373 checks the tutorial’s first line. It sleeps a night and checks that the mantel pays $7. It sleeps weeks until the season turns, and it opens Granny’s notebook.

bonsaiGame#374 walks the house’s rooms, door to door and back. That part takes about 54 seconds.

bonsaiGame#375 covers winter. Pruning is winter-only in the game, so the run sleeps on into winter, which is seven week-sleeps at about 13 seconds each. It then prunes a branch in the 3D viewer and checks that the branch count drops by one. The check counts branches. It does not identify branch 0, and the reviewer pointed that gap out.

The same change tests a second save slot. The HUD’s Save always writes the active slot, so the run starts the second slot the way a player would, from New Game on the title screen. Then it loads slot 1 and checks that the trees, money and day are the same as before.

The exploratory tail

bonsaiGame#376 adds a short random tail to the end. A seeded generator, mulberry32, picks four actions. They are walks, opening and closing the inventory or Settings, opening the notebook, and interacting with whatever is in reach. Then the run saves, reloads, Continues, and checks that there were no errors and that the same trees, inventory, money and day came back.

The seed is printed in the log. Setting PLAYTHROUGH_SEED to that value replays a failing run. Each release uses a new seed, so over time the tail covers different ground.

Why only four actions? On the software GL in the build container, the page draws at about 1 frame per second. Each tap costs about 5 seconds, and even a bare page.evaluate takes about 0.85 seconds. Twelve actions took 200 seconds. Four keep the tail to about 40 seconds.

Where it went wrong on time

The run grew. Locally it reached 10.8 minutes, or 647 seconds. That is past the 10-minute hang guard that the shared test configuration uses, so the playthrough project got its own 20-minute limit. The reviewer also noted that with one CI retry, a hang could hit the release job’s 30-minute cap before the project’s own limit fired.

What is still slow

Half an hour has become one browser. But a release still takes about 15 minutes. One run took 14 minutes and 42 seconds. Locally, the playthrough takes about 11.5 minutes. Most of that time is the gardener walking in real time, on a machine with no graphics card. The next lever is walks that count game steps instead of waiting on the clock, and that is already on the backlog. The run also sits closer to its limits than I like, as the section above says.

Pull requests no longer wait on browser tests at all, so that half of Drew’s complaint is gone. The release half is only partly fixed: from half an hour down to about a quarter of an hour.