Your test suite is a tax: we cut 57,600 tests to 3,030

Lorenzo Wynberg10 min readEngineering
The headline "Your test suite is a tax." beside a before and after comparison: 57,600 tests and a 24 minute gate against 3,030 tests and a 5 minute gate

Your test suite is a tax. You pay it on every gate, every pull request and every agent run, and you keep paying long after the test stopped telling you anything.

We built Trinity in about a year, mostly with agents. Agents write tests faster than they write the product. By the time we looked, the repo held 2.01 million lines of code, and 1.05 million of them were tests. The tests outweighed the roughly 960,000-line product they guarded.

Then we cut them. Here is what we measured, the line we drew, and the tools we spend the effort on instead.

The same repo, before and after the cut
Tests in the gate~57,600~3,030
Test code1.05 M lines107 k lines
Test step1,077 s142 s
Whole gate~24 min~5 min
Gate log27 MB2.3 MB

The suite that ate the product

Before the cut, the gate ran about 57,600 tests: 45,453 across 3,506 files in the desktop app, and 12,125 on the website.

One gate run took about 24 minutes on a quiet machine and 45 minutes on a loaded one. The test step alone took 1,077 seconds. The log it left behind was 27 MB, which no human and few agents will read.

The worst part sat under the test runner. In the desktop app's suite, nearly three quarters of worker time went to module import, not testing: 4,868 seconds importing against 1,746 seconds running tests. We were paying for a mountain of files to load, so each one could assert something small.

A project reaches a point where you cannot get anything done because you are waiting on gates all day. CI minutes grow and grow. Developers wait on long gates for no good reason, and agents wait with them.

So what do you cut, and what do you keep?

Tautological tests cost ten times what they catch

Most of that pile was tautological. A mock that echoes its own calls. A count of exports. A test that a button has the label the code gives it. Each one asserts something a person or an agent would catch in seconds by running the product.

Each one also costs ten times what it catches. It costs a slice of every gate, forever. It costs an import. It costs the agent that trips it and rewrites the assertion to match the new code, which proves nothing.

Agents make this worse, because writing a test is cheap for them and reading the bill is not their job. Left alone, they will happily guard every line. Someone has to set the price.

The line: three reasons to commit a test

We wrote the price down as a rule. A test is committed only when one of these holds:

  1. It must be right

    Money, auth, security, secrets, data integrity, sync, parsers. These failures are not allowed to ship, so the guard exists from the first commit.

  2. It recurred after a hand check

    The same thing broke again after someone checked it by hand. That earns one guard: one case, pinning the decision. An agent whose change trips it asks instead of rewriting it.

  3. The failure is invisible and costly

    Nobody running the product would notice it, and it hurts once it ships.

Every committed test names which of the three it meets and the failure it guards. Everything else is a hand check, or a probe recorded in the hand-back and never committed. The default for a new test is no.

Probes: ask once, read the answer, move on

A probe is a check you run once to answer the question in front of you. You run it, read it, act on it, and write down what it showed. Then it is gone.

Probes are where most of our old tests belonged. "Does this render in both themes?" is a good question to ask once. It is a terrible question to re-ask on every gate, forever.

The value is in the answer, not the artifact. A probe that tells you the method does something non-obvious has done its job the moment you act on it. Keeping the probe around does not make the answer more true. It only means you re-ask a settled question on every gate.

Measurements are the worst offenders

The biggest tax came from measurements committed as tests: sweeps over every plan or route, long renders, timings, theme and browser loops. They take the longest, they answer a question that rarely changes, and they re-run on every gate.

A measurement is a probe with a long run time. Treat it like one.

If the number is worth keeping, you do not re-measure it per gate. You cache it.

The measurement cache: measure once, check in milliseconds

A measurement, cached instead of re-run
1Measure on demand

A tool re-measures only the stale rows, on your own machines.

pnpm levels:measure
2Commit the result

Each row carries a hash of the subject and a hash of the measuring code.

levels.json
3Check in milliseconds

No build, no run. Each row reads current, stale or unmeasured.

pnpm levels:check
4Gate runs the check

The gate never measures. Stale rows fail it and name what to re-measure.

gate

The pattern has four parts:

  • A tool makes the measurement on demand, on your own machines, for stale rows only.
  • The result is committed as data. Each row carries a hash of the subject it measured and a hash of the code that measures it.
  • A staleness check reports current, stale or unmeasured in milliseconds. It does no build and no run.
  • The gate runs only that check. A test may read the stored result. It never re-measures.

We have used this on a real project. An audio project keeps each preset's measured levels in a levels.json beside it, with a levels:check command. Measuring a preset means rendering audio, which is slow. Checking whether a preset's stored levels still match it is a couple of hash comparisons.

{
  "preset-a": {
    "subjectHash": "<hash of the preset>",
    "measurerHash": "<hash of the measuring code>",
    "levels": { "...": "..." }
  }
}

Change a preset and its row goes stale. Change the measuring code and every row goes stale. Touch nothing and the gate spends milliseconds proving that nothing moved.

tip

The hash on the measuring code is what keeps the cache honest. Without it, a fix to the tool leaves every old number looking current.

On-demand tests: valuable, kept, never gated

Cutting is not deleting everything. Some tests still answer a question someone will ask again: a real-git scenario, a real-browser journey, an end-to-end flow, a diagnostic for a subsystem that is hard to reason about.

Those go on demand. They stay in the repo, and no gate ever runs them. We kept 52 on-demand test files.

Value decides, not speed. A test that cannot fail, a wording check or a count of exports is not on-demand. It is deleted.

An on-demand file is named *.ondemand.test.ts, opens with the question it answers and when to run it, and runs through one command:

pnpm test:ondemand                      # list every on-demand file; run none
pnpm test:ondemand <path>...            # run the named files
pnpm test:ondemand --related <path>...  # run the ones related to what you changed

They run in three cases:

  • Work. A change touches the area, so the implementer runs the related on-demand checks once beside its targeted run.
  • Doubt. An agent suspects the code does not do what its name or comment says.
  • The owner asks.

A guard check makes sure no gate can ever collect one. pnpm lint:ondemand-never-gated fails when a default config could pick up an on-demand file, or when a script, workflow or hook names one. The tier stays closed because a tool says so, not because everyone remembers.

Comments replace tests as documentation

Many old tests existed to explain: this is what the method is for, this is the contract callers rely on, this is why it does the odd thing.

A test is a poor place to say that. What a probe establishes about a method goes in a comment at the method, where the next reader and the next agent will see it. A comment the code contradicts is fixed in the same change. A comment that restates the code is not written.

The comment, not a test, is the documentation.

Build tools that validate, not tests that re-ask

Here is the thesis. Spend the effort on tools that validate work, not on tests that re-ask the same question forever.

A committed test asks one question, on every gate, for the life of the repo. A validation tool answers whatever question you have today:

  • A driver that runs the real app through a journey and prints each result.
  • A checker that replays every migration into a fresh database and prints one table's live columns.
  • A script that calls a route with its dependency failing and shows what comes back.

When verifying something means a probe you will want again, we build or extend one of these. We do not commit a test. The tool is reusable and it costs nothing until someone runs it.

A test re-asks a question on every gate. A tool answers the question you have today.

Heavy gates belong at the boundaries

The other half of the bill is how often the heavy gate runs.

Where you areWhat runs
A story or sliceScoped checks on what changed
A checkpointThe full gate
The release tipThe full gate

Most heavy runs go on CI. An agent working a story runs checks scoped to its change, not the whole repo. The full gate runs at the boundaries where something is about to be trusted: a checkpoint, and the release tip. See how stories run, checkpoints and releases.

Nobody waits on a full gate to find out whether a typo in a label compiles.

What the cut bought us

After the cut, the gate holds about 3,030 tests, about 5% of what it did. The test step takes 142 seconds. The whole gate takes about 5 minutes. The log is 2.3 MB.

Test code is 107,000 lines, about 10% of the code. We kept 52 on-demand test files for the questions worth asking again.

The coverage that remains is the coverage that matters: money, auth, security, secrets, data integrity, sync and parsers, plus the guards that earned their place by recurring.

Trinity holds its agents to the same line

This is not only how we build Trinity. Trinity now holds its own agents to this line when it builds your app. Agents commit a test only when it clears the line, and they record everything else as a hand check or a probe instead of a pile of tests. Validation tools take the place of the pile.

For another bet on making checks cheap, read cheap diagnostics, where trying things cheaply is the point.

Where this leaves your suite

Look at your own gate. Find the tests that assert nothing a person would not catch in seconds, and the measurements that re-run for a number that has not changed. Delete them, cache them or move them on demand.

Then spend the time you got back on tools that tell you the truth about your work. A test suite is a tax, and the best tax cut is the one that does not cost you coverage.