I Wrote a Test That Broke Every Time Another Repository Shipped a Release
A few weeks ago I wrote a test that I thought was careful. It turned out to be a liability. Recently it turned a nightly build red over a change that touched no behaviour in any of the projects involved. This post covers what I wrote, why it was wrong, and what I’m doing differently now.
Background
Our system is spread across several repositories:
- a backend service that reads project templates and works out which questions to ask a user;
- a web client that renders those questions as a form;
- a template repository that holds the question definitions and how they are grouped into stages.
The backend includes the template repository as a git submodule, and so does the client. The parent repository that ties everything together also has its own submodule pin for the template.
What I wrote
The client has a form test, and that test renders the “New project” form from a JSON fixture of sample questions. I worried that the fixture would drift away from the real template, so I added a test on the backend side that:
- read the client’s fixture file through the client submodule;
- read the template’s question and stage definitions from the template submodule, at whatever commit that submodule was checked out to;
- checked that the fixture’s questions, omitted questions and stages were exactly equal to what the backend parsed from the template.
My comment on the test said, roughly, “the client’s tests render the form against this file, so we hold it to what the backend reads from the real template.” It sounded responsible. It wasn’t.
What happened
An unrelated change landed and, as a side effect, moved the backend’s template submodule forward by several releases to match the pin in the parent repository. Between those releases the template had removed one question and dropped it from a stage. Removing a question is a normal thing for a template release to do. The client fixture still had the old question, the equality check failed, and the backend’s nightly went red. The parent repository’s pin-consistency gate then refused the new backend pin, so the failure spread upward.
No behaviour had changed in the backend, the client or any requirement. The only thing that broke was my test.
Why the test was wrong
It had no behavioural subject. The backend’s template parser already had its own tests. The client’s form test only needed a realistic set of questions. Comparing the two guaranteed nothing that either side depends on. The backend parses whatever template it is given, and the client renders whatever questions the backend sends. My test protected a relationship that neither component needs.
Its input was “wherever the submodule happens to be.” Another test in the same codebase reads a named tag from the template repository, and it keeps passing however often the pin moves. Mine read the submodule’s working tree, so any pin move could change its input, including routine ones. The parent repository moved that pin about a dozen times in under two weeks. A test that breaks on routine maintenance is a bad test.
I ignored the warning signs. In less than a month the client fixture was rewritten six times, and every commit was some form of “hold the fixture to version X.” None of those rewrites changed what any test exercised. That history was the alarm. The test was checking the template’s release schedule, not the backend or the client.
It assumed the pins agreed, and they didn’t. The parent repository, the backend and another service each had their own template pin, and the fixture recorded yet another version. Asserting equality across all of them meant asserting a synchronisation that nobody maintains and nothing requires.
Nobody asked for it. No design requirement says the client’s fixture must match the template. Our team’s guidelines list a small set of approved cross-repository comparisons, and each one compares code against something that is authoritative over it, such as the design docs or the runtime environment. A template is an input to the system. It has no authority over the system’s code, and I treated it as if it did.
What I should have done
- No cross-repository equality test. The backend’s parser tests should parse small inline template definitions, which they already do for the error cases. The client’s fixture should be a self-contained sample that is free to drift from any real release.
- If a smoke test against a real template is worth having, pin it to a named tag and only check its shape: the files parse, the stages are non-empty, and every question listed in a stage is a question that exists. It should never read a submodule’s working tree, and it should never compare against a fixture owned by another repository.
- Treat the version label in a fixture as a description, not a promise. That field was sample metadata. I treated it as a contract, and that’s how the re-pin treadmill started.
What I’m changing
These are the review checks I now use on my own work and on others’:
- A test that reads another submodule’s working tree and asserts equality with it is a coupling defect. Flag it.
- If a fixture’s history is mostly “update fixture to version X” commits, something is forcing those commits. Find the assertion and remove it. Don’t keep feeding it.
- If a test must read a submodule, it should name the tag or commit it expects, so that moving the pin for another reason can’t change the test’s input.
- Cross-repository comparisons should only be against sources that are authoritative over the code under test. Before I add one, I’ll ask whether the other side is something my code must obey or just something my code consumes.
The fix itself is small: delete the test and let the fixture be plain sample data. The bigger lesson for me is that a test isn’t valuable just because it’s strict. Each test should protect a behaviour someone relies on. Mine didn’t, and it cost a red nightly, a blocked pin and six pointless fixture rewrites before anyone saw that.