Skip to content

Close the remaining test-quality gaps from the audit (items 2, 3, 5, 7) - #1100

Open
ctdegroot wants to merge 7 commits into
mainfrom
claude/blissful-maxwell-a9drzw
Open

ctdegroot wants to merge 7 commits into
mainfrom
claude/blissful-maxwell-a9drzw

Conversation

@ctdegroot

Copy link
Copy Markdown
Member

Part of #726 (items 2, 3, 5 and 7). Still open under #726: bromate validation against published data (item 6), which needs measured trajectories this PR does not have.

Summary

The remaining test-quality items of the audit, apart from item 6.

Item 2: tests that checked a type, or a loose tolerance

  • tests/unit/test_parser.py: the twelve tests that asserted only the root node's type now also compare the whole parsed tree, e.g. MultiplyNode(MultiplyNode(ParamNode("k1"), SpeciesNode("O3")), SpeciesNode("Br-")), which pins associativity and operand order.
  • tests/integration/test_takacs.py: test_overall_mass_balance used rel=0.15. It now closes the heterotroph balance exactly, in − out = accumulation (the accumulation is each layer's volume times its XB_H rate) to 1e-10 of the inflow, and checks that out ≈ in to 1e-8 at steady state. The new test test_mass_balance_closes_while_the_blanket_moves does the same while a flow step moves the sludge blanket.

Item 3: error branches no test reaches
A coverage run of the fast tier, filtered to raise statements whose message no test mentions, left ten. Seven are reachable and are now tested:

  • read_matrix / read_table on an empty file, and a temperature correction with a blank theta name (test_study_files.py, test_model_spec.py).
  • BatchReactor.solve(t_span=None) passed explicitly.
  • predictive_band when every draw fails to solve (the test asserts that the first solve error is kept as __cause__), and when every draw finishes but overflows (C0 = 1e308).
  • Adding a unit whose model has the name of a unit already in the plant: the other side of the existing unit-named-after-a-model test.
  • A required catalogue setting that can only be given from Python, on a copy of the storage kind with that setting made required. No shipped kind has one yet.

The other three can't be reached from the public API; see below.

Item 5: the shared test_structure in the four test_asm3_2step* files
They are now one parametrized test_structure in test_asm3_2step.py, driven by a table of species, reactions, absent names and required conditions per model. Every assertion of the four copies is kept, and the exact set of required conditions is a new check.

Item 7: code only slow tests exercised
Three new fast tests:

  • BSM1 energy terms (test_bsm1.py): evaluate_bsm1's aeration, pumping and mixing energies and the OCI identity, computed by hand from the benchmark definitions on a PlantSolution built from the warm-start state. It also checks which tanks count as aerated.
  • Reverse-mode gradient through a layered biofilm solve (test_biofilm.py): three layers, checked against a central finite difference at rel=1e-5.
  • Cached recycle map on a small loop (test_recycle_cached_map.py): a mixer → 30 % splitter loop on the decay model. The test asserts M = [0.3, 0.3], a cached RHS bit-identical to the probed one, and the hand-computed RHS.

Things a reviewer should know

  • Item 5 removes test_structure from three files, so test integrity reports three findings and waits for the owner's test-weakening-approved label. No assertion is lost: each moved into a row of the table in test_asm3_2step.py.

  • Three raise sites are left untested because no public input reaches them:

    Site Why it can't be reached
    core/compiler.py:500 (undeclared species in a stoichiometry) Schema validation refuses the model first.
    plant/plant.py:1426 (model parameter vs flow setpoint name) add_unit refuses a unit named after a plant model, from both sides, and a unit's model is not reassigned afterwards.
    plant/plant.py:2699 (stream not yet available) Recycle edges are auto-seeded. A port that is declared but never produced fails earlier with a KeyError. The controller path passes every sensed source in.

    I left the code alone: whether to delete them is a separate decision.

  • The recycle test's loop goes through stateless units on purpose. A loop through a tank has M = 0, so a wrong M goes unseen there. The RHS comparison uses rtol=1e-10 because the fixed-point solve leaves about 1e-12 of round-off.

Testing

  • Each new or strengthened test was seen to fail on broken code, and the code was restored afterwards:
    • Parser: making * right-associative in core/precedence.py, and reversing the operands in parser.py.
    • Takács: reading the overflow from the wrong layer. The old rel=0.15 test still passed.
    • Recycle map: a wrong M.
    • Item 3 refusals: each check disabled in turn (batch.py, the from first_error chain in result.py, catalog.py, plant.py). The two empty-file and theta tests were confirmed to execute their raise lines.
  • After merging main: every test file this branch touches, in the fast tier, with test_spelling, test_suppressions, test_function_size and test_rule_references: 470 passed.
  • Full fast tier with coverage (three workers), before the merge: 5478 passed, 1 skipped.
  • ruff check: clean.
  • Not run: the slow and validation tiers. This PR changes only tests, and its new tests are all in the fast tier.

Found on the way, not changed here

  • evaluate_bsm1(plant, solution) with the default params=None raises KeyError on a hand-built PlantSolution whose plant hasn't built its parameter layout. The new energy test passes params explicitly.
  • The slow ASM1 recycle-map identity tests in test_recycle_cached_map.py can't detect a wrong M, because their loop runs through a tank. The new fast test covers that.
  • Under coverage with four xdist workers, worker gw3 crashed in test_precipitation.py::test_hydroxide_fraction_omits_species_and_precipitates. The test passes on its own, and three workers ran clean. Coverage from a crashed worker is lost, which made a first audit of untested raises overcount several-fold.

Generated by Claude Code

The four model files each pasted their own test_structure; one table-driven
test in test_asm3_2step.py now checks every member's size, the states and
processes it adds or inherits, those it replaces, and (new) its exact set of
required conditions.

Part of #726 (item 5).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The parser tests that checked only the root node's type now compare the
whole tree with one built by hand, so precedence, associativity and
argument order are pinned. The Takacs mass balance, allowed 15 % drift,
now checks inflow - outflow = accumulation in the layers to round-off, at
steady state and while the blanket moves; with the overflow read from the
wrong layer the old test passed and the new ones fail.

Part of #726 (item 2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
evaluate_bsm1 (its energy terms against the published BSM1 closed forms,
on the warm-start state without a solve), the cached recycle map (on a
two-species loop through stateless units, where M is 0.3 rather than the
zero a loop through a tank gives), and reverse-mode AD through the layered
biofilm solve (a three-layer film against a finite difference). Each was
seen to fail with the code under it broken.

Part of #726 (item 7).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An empty file read as a matrix or a table (the shared CSV reader's own
check; the trajectory reader's was already tested) and a blank theta
parameter name in a temperature correction.

Part of #726 (item 3).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The coverage run of the fast tier left eight raise sites in aquakin unexecuted
by any test. Four are reachable and now have tests that fail with the check
disabled:

- BatchReactor.solve(t_span=None) passed explicitly.
- predictive_band when every draw fails to solve (the first solve error is
  kept as the cause) and when every draw overflows without raising.
- A unit added after a unit already named after its model.
- A required catalogue setting that can only be given from Python.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copy link
Copy Markdown
Member Author

test integrity fails on exactly the three expected findings: test_structure removed from test_asm3_2step_anammox.py, test_asm3_2step_comammox.py and test_asm3_2step_n2o.py. Those copies moved into the parametrized test_structure in test_asm3_2step.py (item 5), one table row per model, with every assertion kept and the exact required-condition set added. Nothing else was flagged. This check needs the owner's test-weakening-approved label; there is no fix to push.


Generated by Claude Code

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants