Founder Notes
Not Untested — Unreachable
I spent an evening chasing a failure that our test suite said could not happen.
Seventeen tests covered the area. One of them was named, almost word for word, for the exact scenario in the report: the thing already exists, now do it a second time. It passed. They all passed. They had been passing for weeks.
So my working theory was that the tests were too shallow — built on data too tidy to provoke the failure. That theory was wrong in an interesting way. The tests were not too shallow. They were running against a different database than production, and the difference was not the engine.
Two constructors for one schema
Our production schema is built by a chain of migrations. Migrations run in order, each one a script, and the accumulated result is what the live database actually looks like. Several of those scripts contain hand-written SQL: triggers that reject certain writes, and a multi-column foreign key enforcing that two related records agree about a third.
Our test schema is not built that way. It is generated directly from the object model in application code — the classes that describe the tables. That is a normal and sensible choice. It is fast, it needs no migration run per test, and it hands every test a clean database in milliseconds.
The two are supposed to describe the same thing. Nothing checks that they do.
And they did not. The triggers and the composite key were written inside migrations, as raw SQL. The object model has no idea they exist. So the constraints enforcing the most important invariants in the system were present in production and absent from every database any test has ever run against.
The distinction that changed my evening
It is tempting to summarise this as "that behaviour wasn't tested." That is not what was happening, and the precise version is much worse.
An untested behaviour is one where somebody could sit down and write the test. The coverage is missing; the capability is there.
This was not that. No test could have caught a trigger rejection, because in the world the tests inhabit, the trigger does not exist. Not a test nobody wrote — a test nobody could write. I could have added a hundred cases to that file, run them against any database engine I liked, and the number capable of failing that way would still be zero.
A suite in that state does not report low confidence. It reports green, quickly, in exactly the area you are worried about. The speed is the tell: those milliseconds were bought by building a simpler database, and simpler meant missing precisely the constraints that were doing the enforcing.
What actually resolved it
Two hypotheses died from reading code, which is the slow way to be wrong. So I stopped and built the real thing: a local database on the production engine, its schema produced by running the actual migration chain, and then I drove the real code path against it.
That took under an hour and it settled the question — not by confirming my theory but by killing it. On the true schema the path ran clean. My leading explanation had been wrong from the moment I formed it, and no amount of further reading would have told me so, because everything I was reading was consistent with it.
I also found a third trigger I did not know about, inside a migration I had already read. Reading one migration tells you what one change did. It does not tell you what the schema is. The schema is the accumulation, and the only honest way to see an accumulation is to run it.
The general form
Anywhere a system is built twice — once for production and once for speed — the cheap build quietly defines the boundary of what you are able to discover. A local stack standing in for real infrastructure, a mock standing in for a dependency, a seeded sample standing in for a warehouse, a simulator standing in for a device: in every case the convenience was adopted to make the loop fast, and the loop's speed is paid for by narrowing what the loop can see.
So the question worth asking is not whether the fast version is accurate. It is which failures the fast version is structurally incapable of producing. That list is not an inventory of missing tests. It is the set of bugs your entire feedback loop is blind to by construction, and it stays invisible for exactly as long as you keep asking it whether things are green.