Skip to main content
← All Posts

we wrote four tests that couldn’t fail

Cases in Steward used to be a place to write down that something went wrong. In October they became a workflow.

Cases are numbered now. Status transitions are enforced rather than suggested, so you can’t move a case somewhere that makes no sense. Closing one requires a resolution code. There are categories you manage yourself instead of ones we picked. And there’s a real detail page instead of a row in a list.

The piece we thought about most is the queue order. A support queue sorted by age tells you what’s oldest, which is almost never what you should do next. This one ranks by severity, account tier and health band combined, so a medium-severity case from a struggling enterprise customer outranks an urgent one from a healthy small account. You can pin things to the top when the formula is wrong, because it will sometimes be wrong.

All of that — the transition map and the priority formula — lives in one file used by the worker, the front end and the fixtures. One definition, three consumers. If the rules disagree anywhere it’s because they were defined in more than one place, so they aren’t.

Then we audited the tests

And found four that were incapable of failing.

The worst one checked whether a status transition was allowed. It did that by comparing the function’s SQL output against the rule it was meant to be checking — the function’s own logic, copied into the test as the expected value.

So delete a transition from the real map and the test passes. Add a wrong one and it passes. Invert the whole rule and it passes, because the expectation comes from the same source as the behaviour. It’s a test asserting that the code equals itself. It contributes coverage and verifies nothing.

We don’t think we wrote those cynically. We think we wrote them the way you do when you’re trying to get a suite green and you can see the right answer in the implementation in front of you. The expected value comes from reading the code instead of from deciding what the behaviour should be, and the test you end up with looks exactly like a real one.

All four got rewritten, and every one was then confirmed to fail when the thing it guards is broken. That last step is the only part that matters. A test you haven’t watched fail is a hypothesis.

The cursor that pointed at nothing

The queue rewrite nearly shipped a pagination bug. The old ranking was a small number, 0 to 3. The new composite one goes up to 1322. Pagination encodes its position into a cursor, and the cursor was still being built from the old route-local rank while the repository compared against the new one.

Page one would have looked perfect and page two would have been empty. Not an error, not a crash — a queue that appears to end after the first screen.

We caught it by writing the design up before writing the code, which we don’t always do and which worked here precisely because the two numbers live in different files. Reading either one on its own tells you nothing is wrong.

Settings versus preferences

Smaller change, bigger effect than it deserves. Settings used to be one page holding both “how this workspace works” and “how I like my screen.” Those are different things with different audiences, and mixing them means an admin hunting for a billing-adjacent setting wades through font size.

They’re two separate pages now, each tab role-gated, each addressable by its own URL so you can link someone straight to the thing you’re talking about. Preferences gained an appearance panel too: theme, text size, reduced motion.

Also in: an import wizard that can match accounts on four different keys with a strict precedence order and normalised domain matching, because every customer’s spreadsheet identifies accounts differently and the one thing you must not do is guess. A consent gate, a public trust page, legal links in the footer. Guided tours across eleven routes.

Two self-inflicted ones

The cases detail page refactor broke assignee display. Reassigning worked and then the UI showed the old owner again, because a cache key wasn’t invalidated — a successful change that looks like it was rejected, which is the worst possible way for a write to appear to fail. And the resolve button on the account panel started returning a validation error. Both ours, both from the same refactor, both fixed within days.

Custom fields on cases got cut from the release. The table’s constraint can’t be altered in SQLite without rebuilding it, so allowing cases there needs its own migration done carefully, and we’d rather ship cases without custom fields than ship a rushed table rebuild.

The repository also changed GitHub organisations late in the month, which moved CI onto self-hosted Windows runners. Billing and third-party sign-in are still on hold, untouched again.

— Bruno