Files
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

26 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# Print the interpreter that has the test tooling (coverage, hypothesis), or
# python3 if the tooling is already there.
#
# The repo's RUNTIME is stdlib-only on purpose and that does not change. Only the
# measuring gates (coverage floors, property checks, mutation score) need pip
# packages, so they ask here rather than each hardcoding a path. On a GitHub
# runner the packages are pip-installed into python3 and this prints python3; on
# a developer box they live in a venv, and ci-local.sh runs every step under a
# throwaway HOME, so a venv found via $HOME would silently disappear and the gate
# would pass having measured nothing. Repo-local first for that reason.
set -u
want="${1:-coverage}"
REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
for cand in "${QWEN38_TEST_PYTHON:-}" "$REPO/.venv-test/bin/python" \
"$REPO/.venv/bin/python" "$HOME/.local/share/qwen38-testenv/bin/python" \
python3; do
[ -n "$cand" ] || continue
if command -v "$cand" >/dev/null 2>&1 && "$cand" -c "import $want" 2>/dev/null; then
echo "$cand"
exit 0
fi
done
echo "no interpreter has $want; python3 -m venv .venv-test && .venv-test/bin/pip install coverage hypothesis" >&2
exit 1