Testing · Honesty

A census that could not read one way of naming a thing

A check that every route declares the names it reads called a correct route broken, because it did not know one way of declaring a name. We taught it that way.


Every route handler in the worker receives a bundle of things it might need: the request, the environment, the signed-in user, the venue. A handler that reads one of those names without first pulling it out of the bundle gets undefined, and undefined read in anger is a five-hundred error that a test cannot see unless it looks for exactly that. So we have a census: for every handler, take the names it declared, take the names it reads, and fail on any name read but not declared.

The census knows how a name gets declared. A plain assignment, an object pulled apart into named parts, a function parameter, an arrow function’s argument. It is careful about the difference between a parameter list and a call’s arguments, because an earlier version excused a live bug by reading a call as a declaration. What it did not know was the form we had just written in the status route: three results pulled out of one combined wait, as an array with three names in it.

So it reported that route as reading an undeclared name. The route was fine. The census was blind to one way of saying a thing, and a census with a blind spot does not report less, it reports confidently wrong, and the wrong answer is the kind that gets written down as a reason the next person trusts.

The easy fix would have been to rename the local variable to something the census did not recognise as a bundle name, and the test would have gone green. That would have hidden the blind spot rather than closed it, and the next handler written the same way would have been flagged, or worse, a handler with a real hole would have been excused by the same gap. Instead the census learned the array form, and gained a small test of its own: every declaring form it should accept, and three it must refuse — a call argument, an array used as a value, a comparison — so that widening it did not quietly make it accept everything.

A test that reads source code is a parser with opinions, and a parser with a missing case is wrong in a way that looks exactly like being right. The only defence is to give the parser its own tests, with the forms it must take and the look-alikes it must not, and to add to both lists every time it is caught.


Try it on tonight’s service.

Nothing to install, no card. Not better by the weekend? Close the tab.