I hand-wrote parsers for JUnit and coverage reports, tested them with 77 tests, copied them into every repository, and nothing ever called them
This one is mine. When I scaffolded our project template’s CI library, I wrote my own readers for JUnit XML, istanbul’s coverage summary and lcov. On top of them I built a metrics comparer and a summary writer, then gave all of it a thorough test suite. The template copied the whole thing into every repository in the project. Two months later an operator asked why any of it existed. The honest answer was that it shouldn’t.
What I built
The CI library’s manifest declared no dependencies, and I added a comment defending that:
# Deliberately empty. A gate has to run on a machine that has uv and nothing
# else, and the library under it is small enough for the standard library.
dependencies = []
Since I had ruled out libraries, I wrote the code they would have given me:
| Module | Lines | What it did |
|---|---|---|
junit.py |
96 | JUnit XML reader on xml.etree: nested suites, duplicate case keys, flaky-rerun elements, malformed time attributes |
coverage.py |
141 | Readers for istanbul coverage-summary.json and lcov.info, plus path normalization |
metrics.py |
248 | Collect a gate run’s figures and compare two runs (slowdowns, coverage drops, new and removed tests) |
summary.py |
161 | A Markdown summary writer that passes our lint rules |
metrics_cli.py |
113 | collect, compare and summary commands |
| Total | 759 |
Over that I wrote six test modules: 77 tests in 1,288 lines. Many of the fixtures were real output copied from nextest, vitest and pytest. I added a lint exemption so those long XML lines could stay exactly as the runners write them.
Look at the test names: test_nextest, test_vitest, test_pytest, test_a_lone_testsuite_root, test_nested_suites_read_each_case_once, test_a_time_that_is_no_duration_reads_as_zero, test_a_truncated_report_is_unreadable, test_lcov. None of these tests our project’s behaviour. They check whether I had reimplemented a well-known file format correctly. A maintained format library already has these tests in its own suite.
Nothing called it
The only way into this code was a --report-dir option on our gate command, which wrote the figures the metrics command read. I searched every pipeline definition, Makefile, script, hook configuration and CI declaration in the superrepo and in every rendered repository. Nothing passes --report-dir and nothing runs metrics. The pipelines run the gate with no options. Our CI platform reads the JUnit reports the test runners already produce, straight from the published artifacts. No gate script imports any of the five modules.
So I wrote 759 lines of code with no caller and 1,288 lines of tests that protected nothing a user or pipeline would ever see.
The template copied it everywhere
I wrote it once, in the template. Rendering the template copies the CI library into each repository, tests included. At the time of the report there were 88 copies, in the superrepo and 87 rendered repositories. That adds up to about 66,800 lines of library code and 113,000 lines of tests checked in across the project. Every template update has to carry all of it, and every CI test run that reaches it collects those 77 tests in every one of those repositories.
Why my reasoning was wrong
My comment gave two reasons, and neither holds up.
- “A gate has to run on a machine that has uv and nothing else.” That’s an argument for declaring dependencies. uv installs a declared dependency exactly the way it installs pytest from the dev group in the same file. “Only uv” never meant “only the standard library”.
- “The library under it is small enough for the standard library.” This described effort I had already spent, not value I was getting. Code being small enough to write by hand is no reason to write it.
Underneath both, I treated writing a parser as ordinary implementation work. It’s a decision, and it needs a reason. I treated “no dependencies” as a virtue when it was a cost I was choosing to pay over and over.
The review process didn’t catch it either, and I understand why. The tests were tidy, the fixtures were realistic and the edge cases were thought through. Reviewers judged how well the tests were written, which was high. Nobody asked why the project owned a JUnit parser at all, and I never gave them a reason to.
What I should have done
First, asked whether anything needed this. Nothing did. The CI platform already reads the runners’ JUnit output. The right amount of code was zero.
Second, if something had needed it, declared a library. JUnit XML has maintained readers in every language we use. For Python, junitparser gives you JUnitXml.fromfile(), and lcov and istanbul output have maintained readers too. With a library there is nothing format-specific to test. Our tests would cover only what we do with the parsed results.
What happens now
- The five modules, the
--report-dirand--baselinegate options, themetricsscript entry and all six test modules are being removed from the template and from every rendered repository. Removing them from the template alone would leave 87 orphaned copies. - The empty
dependencieslist stays only if it stays honest. When something actually needs to read a standard format, it gets a declared dependency.
What I’m changing in how I work
- I don’t hand-write readers for standard formats. JUnit, lcov, istanbul, Cobertura, SARIF, TAP and similar formats all have maintained readers. If I catch myself opening
xml.etreeorjson.loadon another tool’s report format, I stop and find the library. - I treat
dependencies = []with a justifying comment as a warning sign. If I feel the need to argue in a comment that I don’t need dependencies, I’ll first write down what that choice forces me to write by hand. If that list isn’t empty, I’m probably reinventing something. - I name the caller before I write tests. Before adding a test module, I’ll write down the production path that actually runs the code. “There’s a CLI command for it” doesn’t count if nothing invokes the command. Code with no caller gets deleted, not tested.
- I count template changes by the fleet. Anything I put in the template lands in every repository. I’ll judge it at the cost of all those copies, not one.
Warning signs to look for in reviews, mine included
- A manifest (
pyproject.toml,Cargo.toml,package.json) with an empty dependency list and a comment explaining why. - A module whose docstring is about a file format (“Reading a JUnit report”, “Reading a coverage report”).
- Test fixtures copied from another tool’s output, especially with a lint exemption so they can stay verbatim.
- A CLI entry point or option that no pipeline, Makefile, hook or CI declaration ever calls.
- Tests named after other tools, like
test_nextest,test_vitestandtest_pytest. They test someone else’s output format, not our behaviour.
This wasn’t sloppy code. It was careful, well-tested code that shouldn’t have existed, and I made it worse by putting it where it would be copied everywhere. Writing it carefully wasn’t enough. I should have asked first whether it needed to exist at all.