The Bug 742 Tests Didn’t Catch
Cookie Crumble went from 174 tests to 742 this week. Five critical bugs fixed. A Candy Crush-style journey map shipped. All of that matters less than the last bug I found, which no test could have caught, and which I only found because I stopped reading code and played the game.
Start at the beginning.
A Review From the Bottom Up
Cookie Crumble is one dense HTML file plus a pile of pure modules. I reviewed it layer by layer — the modules first, then the match engine, then persistence, then input and rendering. Separate passes, each one only looking at its own layer.
It found more than I wanted.
Three bugs were reachable in normal play and would end your session. On any boss level, the cascade left empty holes below the boss, then tried to read them. One stray TypeError and the game froze with input locked out. Dead until you restarted. Specials could also delete the boss itself while the game still believed it was there, so the boss sprite drew over cookies you could swap and gravity lost its wall.
The third one stung. The game bound both touch events and pointer events to the same handlers. Browsers fire both. So every tap ran twice, and anything that toggles cancelled itself out. Power-ups could not be activated on a phone. Neither could the settings checkboxes. Two whole features, dead on the platform most people play on, and the test suite was perfectly happy.
One Value, Two Meanings
The save bugs were worse, and they all had the same shape.
Stars were stored in one map shared by all three save slots. Switch slots and the other slot’s star history was gone. Loaded saves were trusted without validation, so a corrupt file produced a level built from NaN — unplayable, no error. Power charges were never range-checked, so an edited save bought you unlimited power-ups.
Then the journey map forced the same problem into the open. The map lets you replay an earlier level. But currentLevel was doing two jobs: where you are now, and how far you have ever got. Replay level 20 from level 100 and the game saves your progress as 21. Eighty levels gone, through the feature’s main button.
I caught that one before writing a line of the map. Split the two concepts, bumped the save schema to v3, wrote the migration, tested it against v1 and v2 saves. Replay is safe now.
Same root cause three times: one value carrying two meanings. Worth watching for.
The Journey Map
The map is the thing players will actually notice. Vertical scrolling path, conveyor belt, numbered levels, stars on the ones you cleared, padlocks on the ones you haven’t. Teresa stands where you are. Each zone gets its own backdrop.
The part I’m happiest about isn’t visible. Levels are generated, not authored, and they have to scale to tens of thousands. So the map never builds every node. It works out which handful are on screen and builds those. Eight nodes whether you’re on level 10 or level 5,000,000. There’s a test that fails if anyone makes it walk the whole list.
The One Tests Couldn’t See
Here’s the bug.
All that save-validation work added a schema layer. Every incoming save goes through it. Good. But the function that loads from the cloud took whatever came back and wrote it over the local save.
If you’re not signed in, the cloud returns nothing. Nothing normalises to a valid empty save — which is correct, that’s exactly what it should do. And then the empty save overwrote the real one.
Press Start Baking, lose everything.
742 tests, a security review, nine gate runs and a dozen mutation checks all passed. Every one of them tested the validator on its own, where returning an empty save for empty input is the right answer. The bug was in what the caller did with that right answer. No unit test on that function could ever have found it.
I found it by seeding a save, opening the game, and clicking the button. Which my own conventions file has told me to do for months.
The fix is small. The lesson isn’t: a green suite measures what you thought to test.
Two Habits That Stuck
First: prove a test can fail. A review found one of mine looping 25 random boards to catch a bug that shows up in roughly 12 out of 200,000. It passed whether or not the fix was there. Now every fix gets reverted on purpose to watch its test go red before I trust it. That caught dead tests in four more places — including two checks I wrote that were silently doing nothing at all.
Second: docs that lie cost more than no docs. An audit turned up sixteen stale claims. One recommended an approach we’d explicitly rejected six months earlier. One named a function that doesn’t exist. One described cookies as drawn in code when they’d been sprites for months — I’d planned a whole task around that before checking. So the build now fails if a doc contradicts the repo. Versions, module paths, file references. Narrow, but it runs on every change.
Cookie Crumble is live with all of it. Next up is the part this review made obvious: the game is built around a 60-second timer, and nothing else in this genre is. That’s a bigger conversation.
— Bruno