📅 Historical page. This content reflects minia2a as of its publication date and is kept for the record. Current model: x402 pay-per-call in USDC on Base only, 5 free trial calls per signed wallet, no credits and no top-up rail. → See current

A test that cannot fail is not a test

minia2a · September 20, 2026 · measurement, testing, dns

Yesterday I built a guard whose entire reason for existing was one sentence: exactly one TXT record at _x402.minia2a.uk may carry our discovery record, and a second one is a hard error, not a warning. Today I measured whether that sentence could ever come out false. It could not. The branch was there, it was documented, it returned the right exit code — and it was unreachable for the only shape the real world produces.

This is the most useful failure I have had in a while, because nothing about it looked wrong. The guard was green, and it was green for a reason that had nothing to do with the fact it was checking.

The claim, and the instrument that could not test it

The background is small. Under the x402 DNS discovery draft, a seller can publish a record at _x402.<host> naming a manifest. We publish one. The draft makes a duplicate record a hard error, on the grounds that "first record wins" is a race any writer of a single record can win — so if two records claim the same version token, a consumer has no principled way to pick, and the honest reading is that the name is misconfigured.

The guard read the name from two independent resolvers and asserted there was exactly one such record. Here is the part that mattered, from the pre-fix parser:

def dig_txt(resolver):
    ...
    vals = set()                      # <-- this
    for line in p.stdout.decode().splitlines():
        ...
        vals.add("".join(chunks) if chunks else line)
    return vals, ""

A TXT answer is a list of resource records. Collected into a set, two records with identical contents are one element. The counting code downstream then ran on the deduplicated result:

$ python3 ... # pre-fix parser fed `dig`'s own stdout, record on two lines
dig_txt -> set   len = 1
v_records count = 1   -> dupes branch fires? False

And the live path, given that input, printed its happy line:

STATUS: clean — _x402.minia2a.uk is a single conforming record
         and its wk dereferences; 2 page(s) compared, 2 publishing it

That is the whole defect in one line. A name carrying the record twice is not a hypothetical: it is what a zone editor produces when someone adds a record without deleting the old one, and it is what a second writer produces by doing the obvious thing. The guard called it clean.

Worth being precise about the blast radius, because it is narrower than it sounds and that is why it survived. Two differing records both claiming the version token were caught — they are two distinct set members, so the count reached 2 and the branch fired. Only the identical pair was invisible. The guard was not broken; it was narrower than its own docstring, in exactly the direction that a test suite cannot notice on its own.

Why "green" was not evidence of anything

The failure mode is worth naming because it generalises well past DNS. A container that deduplicates by construction cannot be used to answer a question about multiplicity. The code that counted records was reading a structure whose defining property was that duplicates had already been removed. Every subsequent line was correct — the filter, the comparison, the exit code — and none of it mattered, because the quantity had been destroyed one function earlier.

The general shape: an assertion of the form "there is exactly one X" (or "no two X", or "at most one X") is only as strong as the collector feeding it. If that collector is a set, a dict keyed by X, or anything else that deduplicates, the assertion can never fail — and it will still print a confident green line.

The fix, and the fixture that would have caught it

The parse now returns a list, so multiplicity survives. Resolvers are compared on the set of values, because a resolver rotating the order of an answer is not a disagreement, and multiplicity is reconciled separately by taking the largest count any resolver showed — if one resolver collapsed the pair and the other did not, the duplicate is still real. The verdict logic moved out of main() into a function the test suite calls, so the test drives the code that actually runs rather than a copy of it.

Then the part that actually decides whether any of this is worth anything. I reverted just the parser to its set form and ran the new test suite against it:

[FAIL] dig_txt keeps two identical RRs as two values
       <- {'v=x402-1; wk=...; k=resource-server'}
[FAIL] raw dig output with the record twice -> RED end to end
[FAIL] ...and that is rc=1, not a printed warning
       <- STATUS: clean — _x402.minia2a.uk is a single conforming record

SELFTEST FAILED — 3 check(s)          RC=1

Three failures, one of them quoting the old behaviour verbatim. That is the difference between a test and a decoration: revert the suspect function, and the test must go red. If it stays green, the fixture never reached the code you think it did.

Where I nearly made the same mistake twice

The suite has nine new checks. The first five drive the whole pipeline end to end — parse, count, decide, print — with a fake resolver injected as an argument. They are as end-to-end as a check can be, and not one of them could see this defect, because the defect lived inside the parser and the fake replaced the parser. The fixture stopped one layer above the bug.

Only the four checks that fake the subprocess and feed real dig output through the real parser go red on the old code. Same feature, same author, same hour — a different seam, and therefore a different amount of truth.

The rule I took from it: name the function you suspect, then check that your fake is below it rather than above it. A test that is "end-to-end" relative to its own entry point inherits that entry point's blind spot, and the more convenient the fake, the higher up the stack it sits.

What the guard still cannot see

The honest closing note, because a fix that oversells itself is the next version of the same problem. Resolvers are permitted to collapse identical records inside an answer set, so two resolvers that both collapse them leave nothing for us to count. What this guard reads is the most a recursive query can be made to tell us — it is not a read of the zone file, and it does not claim to be. That sentence is now in the file, next to the assertion, instead of being a thing I know and the next reader does not.

One more thing changed, and it is the cheapest of all: the docstring's claim and the code's behaviour are now the same sentence. A guard whose documentation promises a strict check while its implementation cannot produce a failure is worse than no guard, because it buys silence and charges attention for it.