Commit Graph
5 Commits
Author SHA1 Message Date
Hasan BasbunarandClaude Opus 5.5 d1c153b8c6 tests: an environment given back, a count that is the one declared, and lifecycle.py's mutation floor at 95 %
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 13:12:13 +01:00
Hasan BasbunarandClaude Opus 5.5 9647f98f1f tests: the last ones that read the code as it was; install: what keeps sudo's timestamp leaves no child behind
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 09:24:55 +01:00
Hasan BasbunarandClaude Opus 5 bc1fcf4d78 tests: 100% on the two pure modules, and the number that proves 100% is not enough
"Is 100% coverage impossible?" was worth answering by measuring rather than
arguing, and the two answers are different in a way that is more useful than
either alone.

100% IS reachable. lifecycle.py and recipes.py are both at 100% branch coverage
now (303 and 263 statements, 164 and 140 branches, nothing missed, nothing
partial). It took one afternoon and two declared exclusions, both provably
unreachable rather than merely awkward: the elif chain in parse_boot_log ends in
a defensive break that needs a marker name the chain does not handle, and
`if stage in STAGES` followed by `for s in STAGES: if s == stage: break` cannot
finish the loop. The first carries a pragma AND
test_every_marker_is_handled_by_the_chain, which parses the function's own AST
and fails the day a marker is declared without an arm: strictly stronger than
covering the branch would have been.

The statements found on the way were not plumbing. outcome_kind's own "in flight"
and "no end logged" branches had never been called, because parse_feed sets those
kinds itself. The drain-ceiling LOG LINE had never been parsed in a test, though
the verdict for ceiling > 0 was covered through a hand-built dict. The other five
were malformed-timestamp paths, which is what a truncated journal line produces.
recipes.py gave up six more, among them the guard that raises when a serving
placeholder is left unsubstituted (it exists because that happened) and
presence() coping with a malformed recipe read from disk.

And here is the answer that matters: lifecycle.py at 100% coverage scores 91.7%
on mutation. Seventeen injected faults its 139 tests do not notice, in code where
every branch executes. Coverage measures execution; only mutation measures
detection. 100% mutation score is genuinely unreachable, and not for want of
effort: equivalent mutants exist and deciding equivalence is undecidable. Four
concrete ones from this repo are tabulated in TESTING.md, including
`weight_ends >= 2` to `> 2`, which no log can distinguish because you cannot end
a load you did not begin.

Also in here: the whole GET surface of the cockpit, which was uncovered. Among it
a real boundary, /api/logs/<name>, which takes a name from the URL and hands it to
a command: eleven refused names now, and the answer that the action registry is
published to the UI without its argv. cockpit.py 61 -> 71%.

Two more bugs in my own tooling. The coverage gate did not run property_checks.py
and therefore reported three validate() branches as uncovered while they were
being exercised 300 times each. And tests/mutation.py raised ValueError on a
relative module path, because the copy-based walk locates the module relative to
REPO: dashboard/lifecycle.py, the way anyone would type it, was broken.

Floors: lifecycle and recipes pinned at 100% (a module allowed to slip back is
worse than one that never got there), cockpit 70%, total 89%, mutation 91% and
79%. 447 tests in the dashboard suite. CI local 38/38.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-10 14:46:49 +02:00
Hasan BasbunarandClaude Opus 5 54e6fbd613 tests: concurrency, the relay boundary, and a mutation runner that cannot corrupt the tree
Three more classes the suite had no answer for, and one hazard in my own tool.

CONCURRENCY (dashboard/tests/test_concurrency.py, 9 tests). Every other suite
drives one request at a time, which is not how this stack is used: a person
clicks Switch in one tab while the autoheal fires and a second tab polls. The
cockpit's whole safety story is that only ONE privileged action runs, and nothing
tested it. 24 callers released from one barrier, eight attempts per property:
exactly one gets 202 and the other 23 get 409 with the running job named; a
refused parameter and an unknown action never take the lock, so they cannot cost
the next caller its turn; the lock is released even when starting raises (the
test makes it raise on purpose); the audit log has one unbroken JSON line per
started job, parsed back to prove no line was torn. Plus the shared state: the
snapshot the SSE stream serializes stays serializable under four writers, the
event ring stays bounded under six, and CpuTracker never returns a percentage
outside 0 to 100 while sampled from four threads.

THE RELAY BOUNDARY (12 property checks). agent_relay puts a browser interface on
a tailnet in front of an opencode that can run commands. Generated inputs now
assert that only the relay's own origin is ever allowed, that "null" never is (a
sandboxed iframe and a file:// page both send it), that host_name never returns a
port, that no caller header survives under a name the relay owns, and that the
upstream can never set a cookie named like the cockpit session, which would be
session fixation on the cockpit.

THE PATCH CLIs, measured honestly. patch-yarn.py read 0% while being genuinely
tested, because its suite drives it as a subprocess and coverage cannot see into
a child. Running main() in process makes the number true and adds the cases a
CLI test reaches least: 0% to 94%. Writing them corrected two more of my own
assumptions rather than the code's, and the tests are better for it: the tool
writes rope_type/factor/original_max_position_embeddings into rope_parameters
rather than a rope_scaling key, so the test now pins the factor at 4.0 against
the 262144 to 1010000 ratio, checks theta and the partial rotary factor survive,
checks the inner text_config is patched and not the outer, and checks the backup
is written before the rewrite.

MY OWN TOOL. tests/mutation.py edited the real file and restored it in a finally,
which is wrong twice: anything reading the repo at that instant sees a mutant (a
parallel test run reported 46 errors and one baffling parse failure, which was
this tool editing recipes.py underneath it), and a kill -9 between write and
restore leaves a mutated source staged for commit. It now copies the repo to a
temp directory and mutates the copy. Verified by killing a run mid-walk and
checking git diff. Same score, 90.8% and 80.0%.

420 offline test functions now, ~17,000 generated inputs per run, 84% branch
coverage on the dashboard and 47% on the root tools (was 38%). CI local 34/34.
TESTING.md carries the scoreboard and both of the mutation tool's bugs.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-10 12:56:15 +02:00
Hasan BasbunarandClaude Opus 5 2365b645cc tests: measure the suite instead of trusting it (coverage, properties, fuzz, mutation)
This project was written with an AI coding agent, so the failure mode to defend
against is not a forgotten case: it is code and tests written together from the
same assumption, both wrong in the same way, green anyway. Four gates were added
that a suite cannot satisfy by agreeing with itself.

Nobody had ever run coverage here. First measurement: 68% overall, 14% of
cockpit.py, 0% of build-token-map.py, conc-check.py and bench-agent.py. Now 84%
overall and 55% of cockpit.py, with a per-module floor in CI (raised in a commit,
never lowered quietly) and a total floor.

Property-based checks (dashboard/tests/property_checks.py, 29 checks x 300
generated inputs): every parser returns and never raises on log-shaped text,
outcome_kind is total, _switches matches whole arguments so no flag can answer
for another, drift is reflexive and symmetric, validate() never raises on
arbitrary JSON, and fit(pool, ceiling) never grants more than the pool, never a
negative budget, always whole thousands, never less context for a bigger pool.
Writing that last one corrected my own assumption rather than the code's: fit
rounds down to a thousand, so a pool too small for a thousand-token answer
correctly returns (0, 0).

Proxy fuzz and simulation (tests/proxy_fuzz.py, 16 checks): arbitrary bytes and
arbitrary JSON through the tool-schema sanitizer, 400-deep nesting, 200 tools at
once, plus the properties that matter: a clean body comes back BYTE-IDENTICAL, a
pattern Python can compile is never dropped, a dropped one genuinely does not
compile, the output is valid JSON whenever it changed, and sanitizing twice
changes nothing more. Then RelaySimulation, a Hypothesis state machine driving a
real proxy and a fake engine that reproduces SGLang's abort rule, through
generated client behaviour, checking after every step that no abort was discarded
by the engine and no request was aborted with an id the engine never had. The
2026-09-09 production bug, expressed as a property instead of a story.

Mutation score (tests/mutation.py): 210 mutants in lifecycle.py, 53 surviving,
74.8%. Each survivor was read and turned into a test that names it: two
MutantsThatSurvived classes, 39 tests, and one survivor removed by deleting an
`if` whose body was `pass` (it decided nothing, so four mutants in it were
undetectable by construction). Second run: 90.8%, the rest largely equivalent
mutants. recipes.py: 80.0%. Both gated with a floor.

The tool had the bug every home-made mutation runner has, and it is recorded in
TESTING.md because it matters: CPython validates a .pyc against source mtime AND
size, so two mutants of the same length written inside one mtime granularity are
indistinguishable to that check and the interpreter re-runs the previous mutant's
bytecode. It reported a mutant as surviving that the suite kills in one second by
hand. Fixed with a __pycache__ sweep and PYTHONDONTWRITEBYTECODE=1; the 94.2% it
printed first was not real, 90.8% is.

Also: tests/test_tools.py (25 tests) covers the three tools that had none, among
them the BPE construction ranking that decides which 65,536 rows the draft head
keeps, and conc-check's contamination verdict, which is the one that accuses the
engine rather than the model. tests/testpy.sh resolves an interpreter that has
the tooling, repo-local first, because ci-local.sh runs every step under a
throwaway HOME and a gate that silently skipped there would be exactly the green
that checks nothing.

TESTING.md documents the layers, the floors, and what the tests found.

CI local 34/34.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-10 12:39:09 +02:00