Jon

What unit tests cannot catch

2026-11-28

I wrote this post with the help of Claude, an AI model, from my own notes.

In May I shipped a fix to noteser that passed 1,462 automated tests and broke on a real phone anyway. Here is the whole story, because the failure is more useful than the fix.

I wrote in Building with zero hand-written code that I do not read every line of noteser. What I do instead is move fast and test. This post is about where testing stops.

The change

noteser keeps every note as a plain Markdown file in a GitHub repo you own. Sync is the part I care about most, and the part most likely to lose data if I get it wrong, so it has the heaviest test coverage in the app. The change was a sync fix. Nothing exotic. I ran the suite, 1,462 tests green, and I pushed it.

Then I opened the app on my phone, and sync hung.

What the tests could not see

The tests run in Node, against a simulated fetch layer. They prove the logic: given these local edits and these remote edits, the three-way merge produces the right result. That logic was correct. It is still correct. The tests were not lying.

The break was somewhere the tests do not live. Two things stacked up:

Neither of those is a logic bug. A unit test asserts that a function returns the right value. It does not assert that WebKit will keep a connection open long enough on a phone on a train. That is not a gap in my tests. It is a category of thing tests do not cover, no matter how many you write.

Tests prove logic. They do not prove reality. 1,462 of them proved the merge was correct and told me nothing about the timeout or the browser.

The revert

Here is the part I am actually happy about. The production fix came out cleanly. It had gone out as one merge, so I reverted that merge: no force-push, no history lost, no half-state left in anyone's vault. Production went back to exactly where it was, and the bad version of the code is still in history if I ever want to read it again. Rolling back a feature was just rolling back a commit.

Then I rebuilt the same fix, and this time I changed the order of operations. Instead of pushing to production and finding out on my phone, I shipped it to a preview build first and tested it on the actual phone, on a real network, with a real vault. The timeout got a saner value. The WebKit behavior got handled where it actually happens. Only after the phone confirmed it did the fix go to production.

Same fix, second time, validated where it would break.

It came back in September

Four months later, sync on my own vault stopped with "Sync timed out." Different code, same category of bug.

By then the suite had grown past 3,300 tests, and I had a live harness that runs real sync scenarios against a test repo on GitHub. Neither caught it. The cause was the vault's attachments folder: 175 images, 83 MiB. Sync downloaded all of them inside a 45-second watchdog and saved nothing until the whole batch had landed, so every retry started from zero and died at the same point.

The harness missed it for a plain reason: its test repo is tiny. It proves sync is correct. It says nothing about how long sync takes on a real vault. The fix had two parts. Save each image the moment it arrives, so a retry keeps what it already has. Download images in the background, outside the watchdog, so they no longer count against it. It went to the beta build first, and only then to production.

The lesson, narrow and honest

I am not going to tell you tests are pointless. They caught plenty that night that I never saw, and they are the reason I trust the merge logic at all. The narrow lesson is this:

Some changes can only be verified on the device they run on, with the data they will really see. Anything that touches mobile browser behavior, network timing, or large transfers is in that set. For those changes, the test suite is necessary and not sufficient. The last step is a real phone and a real vault.

So the rule I kept: ship risky sync and mobile changes to a preview first, and test them on the device, with a real vault, before production. Not every change. Just the ones where the failure lives in a place the tests cannot reach.

1,462 green tests felt like proof. It was proof of the logic. The phone was the proof of the reality, and the phone is the only one that gets to vote on whether sync actually works.


I also wrote a book: Night Builds, about how I use Claude to build real systems next to a full-time job. It is on Kindle.