fix(688): stop asserting live-corpus order statistics anywhere in the suite
Review round 2 (both reviewers, independently) found the round-1 fix incomplete: the live-corpus coupling survived in two more tests. This is the THIRD instance of one defect class in this change, so the fix is to remove the coupling rather than patch another site. BLOCKER — test_adding_ordinary_records still asserted live order statistics. The `if before.marks_tail:` guard made the PRECONDITION conditional but left the CONCLUSION (`assert not after.marks_tail`) an assertion about the live p90. Verified: appending 16 ordinary 30-line records — nothing long, nothing unusual — makes both sides true and fires it, reddening the blocking job for an unrelated author. Exactly what #688 exists to abolish. The v4-vs-v5 contrast moved to test_v4_would_have_reddened_where_v5_holds, built on a distribution the test OWNS, reproducing the shape that matters (a sparse gap just above the ceiling). The real-corpus test now asserts only the robust claims: the additions were counted, v5 holds, and the measured headroom. Same treatment for the "bad ceiling" teeth test, which hard-coded that 200/229/230 stay rejected on the live corpus — three new 200+ line records flip it. Teeth now demonstrated synthetically; the only live-corpus assertion left is that today's ceiling is accepted, which needs 38 over-ceiling or 718 short additions to break. The IFF drift test could lose its quiet branch: one 61-line record makes BOTH the 60 and 999 ceilings drift, at which point an UNCONDITIONAL notice would pass. Both ceilings are now DERIVED — p90 itself (always calibrated, since p90 <= p90 <= p95) and max+1 (always off the tail) — so each branch is guaranteed by construction, and the test asserts it exercised both. Added the missing regression test for the typed-mapping-key TypeError: removing `key=str` now fails a test instead of only a manual probe. Corrected against measurement: the v5 row of the record's own version table still stated the REJECTED first-draft bound (`0 < f < 1/3`) — the canonical artefact contradicting both the code and its own next paragraph; accepted range is 43..180, not "roughly 45..150"; breaching the cap takes 38 additions, not 37 (37 lands exactly on 0.25, which passes under `<=`); "5x headroom below the floor" was inverted; ci-cd.md said four versions "all ratcheted" when v1 was vacuous and v2 accepted an absurd ceiling; and the crosscheck record overstated protection — script-tests is NOT a required check, so "no broken record has reached main" is procedural, not structural. Evidence the coupling is actually gone: mid-fix the corpus sat at marks_tail=False (an edit pushed this branch's own record to 61 lines, moving p90) and the suite stayed fully green. Under the old assertions that state reddened CI. The record is trimmed back to 60 so main ships calibrated and no drift notice nags. Verification: 428 scripts/tests pass; ruff at baseline parity (47); validator exits 0 with no drift notice; corpus at p90=60, 18/183 over the ceiling. Decisions-Edit: yes Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1074,15 +1074,25 @@ def test_the_coarse_bound_REJECTS_a_badly_placed_ceiling_on_the_REAL_corpus():
|
||||
docstring itself offered as the case it catches, because one 230-line record keeps the count
|
||||
nonzero. A FRACTION floor is what restores the teeth, so pin it on the real corpus.
|
||||
"""
|
||||
recs = [r for r in dl.all_active_records() if r.key]
|
||||
assert len(recs) > 100, "corpus looks empty — this check would be vacuous"
|
||||
# The TEETH are demonstrated on an owned distribution, for the reason in
|
||||
# `test_v4_would_have_reddened_where_v5_holds`: an assertion that a specific absurd ceiling is
|
||||
# rejected by the LIVE corpus is itself growth-coupled (review found that three new 200+ line
|
||||
# records would flip the 200 arm). 100 records of 30 lines and one of 230 — an outlier-only
|
||||
# tail, which is precisely the shape a badly-placed ceiling fails to distinguish.
|
||||
synthetic = [_rec_body(f"a.s{i}", 30) for i in range(100)] + [_rec_body("a.outlier", 230)]
|
||||
|
||||
for bad in (200, 229, 230):
|
||||
cal = dv.ceiling_calibration(recs, bad)
|
||||
cal = dv.ceiling_calibration(synthetic, bad)
|
||||
assert not cal.flags_minority, (
|
||||
f"a ceiling of {bad} flags only {cal.n_over}/{cal.n} records and must be rejected, got {cal}"
|
||||
)
|
||||
assert not dv.ceiling_calibration(recs, 20).flags_minority, "a ceiling of 20 cuts into the bulk"
|
||||
assert not dv.ceiling_calibration(synthetic, 10).flags_minority, "a ceiling of 10 cuts into the bulk"
|
||||
|
||||
# The only claim made against the LIVE corpus is the robust one: today's ceiling is accepted.
|
||||
# Breaching it takes 38 consecutive over-ceiling additions (or 718 short ones by dilution), so
|
||||
# ordinary growth cannot red this.
|
||||
recs = [r for r in dl.all_active_records() if r.key]
|
||||
assert len(recs) > 100, "corpus looks empty — this check would be vacuous"
|
||||
assert dv.ceiling_calibration(recs, dv.RECORD_CEILING_DEFAULT).flags_minority
|
||||
|
||||
|
||||
@@ -1113,24 +1123,11 @@ def test_adding_ordinary_records_cannot_RED_the_blocking_property():
|
||||
f"the appended records were not counted: {before} -> {after}"
|
||||
)
|
||||
|
||||
# The v4 property is the one that reddened CI, and these additions break it — that is the whole
|
||||
# demonstration: the SAME corpus change that would have failed the old blocking assertion leaves
|
||||
# the v5 one satisfied. Guarded by `if`, never asserted: whether v4 currently holds is a fact
|
||||
# about the live distribution, and asserting it here would rebuild the very ratchet this test
|
||||
# exists to document. It is not hypothetical: an earlier draft of the record this branch adds
|
||||
# was 64 prose lines, which by itself moved p90 from 60 to 64 and broke v4 before either
|
||||
# synthetic addition was appended — i.e. this PR would have reddened the old blocking job.
|
||||
if before.marks_tail:
|
||||
assert not after.marks_tail, (
|
||||
f"these additions no longer break the old percentile property ({after}) — pick shapes "
|
||||
f"that do, or this test has stopped demonstrating anything"
|
||||
)
|
||||
|
||||
# ...and the v5 blocking property holds either way.
|
||||
# ...and the v5 blocking property holds.
|
||||
assert after.flags_minority, f"two ordinary additions reddened the blocking property: {after}"
|
||||
|
||||
# Headroom, stated as a number so a future reader can see how much slack there is: how many
|
||||
# consecutive over-ceiling records it would take to breach the bound.
|
||||
# Live headroom, as a number, so a future reader can see how much slack there actually is: how
|
||||
# many consecutive over-ceiling records it would take to BREACH the cap from here.
|
||||
n, over = after.n, after.n_over
|
||||
need = 0
|
||||
while (over + need) / (n + need) <= dv.CEILING_MINORITY_MAX:
|
||||
@@ -1138,6 +1135,38 @@ def test_adding_ordinary_records_cannot_RED_the_blocking_property():
|
||||
assert need > 20, f"only {need} over-ceiling additions would breach the bound — too tight"
|
||||
|
||||
|
||||
def test_v4_would_have_reddened_where_v5_holds():
|
||||
"""The v4-vs-v5 contrast, on a distribution the test OWNS rather than the live corpus.
|
||||
|
||||
THIRD TIME for this defect class in one change, which is why the fix is to remove the coupling
|
||||
rather than patch the instance. Round 1 of review caught it in the drift test; round 2 caught it
|
||||
here, in what looked like a safe `if before.marks_tail:` guard — the GUARD was conditional but
|
||||
the CONCLUSION was still an assertion about live order statistics, and appending 16 ordinary
|
||||
30-line records (nothing long, nothing unusual) makes `after.marks_tail` true again and fires it:
|
||||
|
||||
extra= 0 before(marks=True) after(marks=False) -> reds: False
|
||||
extra=16 before(marks=True) after(marks=True) -> reds: True
|
||||
|
||||
Nothing about this demonstration needs the real corpus. The synthetic base reproduces the shape
|
||||
that matters — a sparse gap just above the ceiling, exactly what #688 measured on `main` (60,
|
||||
61, 62, 63, then a jump to 81) — so two over-ceiling additions advance the p90 index off the
|
||||
ceiling and break v4, while v5 is untouched.
|
||||
"""
|
||||
base = (
|
||||
[_rec_body(f"a.s{i}", 30) for i in range(90)] # the bulk
|
||||
+ [_rec_body("a.edge", 60)] # sits exactly ON the ceiling, as main does today
|
||||
+ [_rec_body(f"a.l{i}", 112) for i in range(9)] # the tail, across a sparse gap
|
||||
)
|
||||
before = dv.ceiling_calibration(base, 60)
|
||||
assert (before.p90, before.p95) == (60, 112), before
|
||||
assert before.marks_tail and before.flags_minority, before
|
||||
|
||||
after = dv.ceiling_calibration(base + [_rec_body("new.a", 107), _rec_body("new.b", 107)], 60)
|
||||
|
||||
assert not after.marks_tail, f"v4 must break on these additions, or the contrast is empty: {after}"
|
||||
assert after.flags_minority, f"v5 must survive what broke v4: {after}"
|
||||
|
||||
|
||||
# --- #674: the validator cross-checks its own parse against PyYAML ------------------------------
|
||||
|
||||
|
||||
@@ -1215,6 +1244,22 @@ def test_crosscheck_REPORTS_an_impossible_date_instead_of_crashing(tmp_path):
|
||||
assert "ValueError" in faults[0], f"the fault must name the real exception: {faults[0]}"
|
||||
|
||||
|
||||
def test_crosscheck_survives_a_TYPED_mapping_key(tmp_path):
|
||||
"""PyYAML returns typed keys, so a stray `1: x` yields int 1 where the reader yields "1".
|
||||
|
||||
Sorting that mixed set raised `TypeError` — an uncaught traceback replacing what
|
||||
`_unknown_frontmatter_keys` used to report as an actionable error. Removing the `key=str` sort
|
||||
key restores the crash, and without this test every other test here stays green.
|
||||
"""
|
||||
pytest.importorskip("yaml")
|
||||
records, _ = _wing_with(tmp_path, "1: stray")
|
||||
|
||||
faults, ran = dv.pyyaml_frontmatter_faults(sorted(records.rglob("*.md")))
|
||||
assert ran
|
||||
assert faults, "a typed mapping key must be reported, not swallowed"
|
||||
assert any("1" in f for f in faults), faults
|
||||
|
||||
|
||||
def test_pyyaml_crosscheck_is_clean_on_the_REAL_corpus():
|
||||
"""No false positives. A cross-check that flags correct records would be reverted within a day."""
|
||||
pytest.importorskip("yaml")
|
||||
@@ -1310,18 +1355,30 @@ def test_main_reports_drift_IFF_the_ceiling_is_off_the_tail_boundary(capsys):
|
||||
is genuinely exercised, so this cannot pass by never firing.
|
||||
"""
|
||||
recs = [r for r in dl.all_active_records() if r.key]
|
||||
seen_drift = False
|
||||
lengths = sorted(dv.record_prose_lines(r) for r in recs)
|
||||
|
||||
for ceiling in (dv.RECORD_CEILING_DEFAULT, 999):
|
||||
# Both ceilings are DERIVED so each branch is guaranteed by construction, not by luck. Review
|
||||
# caught the earlier version relying on the live 60/999 pair: once one 61-line record lands,
|
||||
# BOTH of those drift, and an UNCONDITIONAL notice would have passed the test.
|
||||
# * p90 itself is always calibrated — `p90 <= p90 <= p95` holds for any distribution.
|
||||
# * one line above the longest record is always off the tail — it exceeds p95 by definition.
|
||||
quiet_ceiling = lengths[min(int(len(lengths) * 0.90), len(lengths) - 1)]
|
||||
drift_ceiling = lengths[-1] + 1
|
||||
|
||||
expectations = []
|
||||
for ceiling in (quiet_ceiling, drift_ceiling):
|
||||
expected = not dv.ceiling_calibration(recs, ceiling).marks_tail
|
||||
dv.main(["--record-ceiling", str(ceiling)])
|
||||
err = capsys.readouterr().err
|
||||
assert ("drifted from the tail boundary" in err) is expected, (
|
||||
f"ceiling {ceiling}: expected drift notice={expected}, got the opposite"
|
||||
)
|
||||
seen_drift |= expected
|
||||
expectations.append(expected)
|
||||
|
||||
assert seen_drift, "neither ceiling produced a drift notice — the test never exercised the notice"
|
||||
assert expectations == [False, True], (
|
||||
f"the two derived ceilings must exercise BOTH branches, got {expectations} — otherwise an "
|
||||
f"unconditional notice (or none at all) would pass this test"
|
||||
)
|
||||
|
||||
|
||||
def test_main_actually_REPORTS_the_ceiling_and_the_trend(capsys):
|
||||
|
||||
Reference in New Issue
Block a user