diff --git a/docs/ci-cd.md b/docs/ci-cd.md index 52d8cc765..e574e6776 100644 --- a/docs/ci-cd.md +++ b/docs/ci-cd.md @@ -62,12 +62,14 @@ step is now continuous. The release boundary is instead where you: — a **non-blocking `::warning::`** naming every record over it. This is the actionable signal: it points at a file. The 60 is derived from the distribution, not picked as a round number. Its **calibration is guarded in two pieces of different robustness** (ersatztv#688), because - four earlier single-assertion versions all ratcheted: + four earlier single-assertion versions all failed — the first two by being vacuous or + accepting an absurd ceiling, the last two by ratcheting: - **blocking** (`script-tests`) — only the coarse property that the ceiling flags a **meaningful minority** of records (`0.02 <= fraction_over <= 0.25`). One record moves a - fraction by at most 1/N, so routine growth cannot cross it: from today's 18/183 it takes 37 - consecutive over-ceiling additions. The floor is a fraction rather than "at least one - record", which would accept any ceiling up to 229 on the live corpus. + fraction by at most 1/N, so routine growth cannot cross it: from today's 18/183 it takes 38 + consecutive over-ceiling additions, or 718 short ones to dilute below the floor. The floor is + a fraction rather than "at least one record", which would accept any ceiling up to 229 on the + live corpus; as a fraction the accepted range is 43..180. - **reported, never asserted** — the fine claim that the ceiling sits between the **90th and 95th percentile**, i.e. at the tail boundary. `main()` prints a `::notice::` when it drifts. It is an order statistic over a sparse distribution, so a single new record could move p90 by diff --git a/docs/decisions/records/docs/corpus-size-signal.md b/docs/decisions/records/docs/corpus-size-signal.md index 12183bbee..09b7f5157 100644 --- a/docs/decisions/records/docs/corpus-size-signal.md +++ b/docs/decisions/records/docs/corpus-size-signal.md @@ -57,7 +57,7 @@ Getting there took five versions, and the failures are the useful part: | v2 | a minimum gap WIDTH | a ceiling of 200 also sits in a wide gap — it passed | | v3 | 2-12% fraction band + "clear air" above | **hostage to an unrelated record**: one ordinary 62-line addition reddened it with the ceiling correctly placed, and the only remedy was to RAISE the ceiling — this very treadmill, as a hard failure in what #631 makes a blocking job. The fraction band had the same coupling more slowly (12 more long records breached it), and `0 <= headroom` was vacuous. | | v4 | `p90 <= ceiling <= p95` | percentiles move with the corpus, but an order statistic over a SPARSE distribution is a STEP function. The lengths above the ceiling ran 60, 61, 62, 63 then jumped to 81, so ONE record moved p90 by twenty lines. It reddened the blocking job twice live (#672, #706), and both times the only in-scope remedy was to trim the new record to fit the constant — the v3 ratchet, pointed at record authors | -| v5 | coarse `0 < fraction_over < 1/3` asserted; fine `p90 <= ceiling <= p95` REPORTED | splits the claim by robustness instead of hunting for a better single assertion (#688) | +| v5 | coarse `0.02 <= fraction_over <= 0.25` asserted; fine `p90 <= ceiling <= p95` REPORTED | splits the claim by robustness instead of hunting for a better single assertion (#688) | **v5 is not a fifth attempt at the same shape — it stops trying.** Four versions failed because they all asserted, in the blocking job, a property of a corpus the commit under test does not control. @@ -72,9 +72,9 @@ cap, against **one** record to break v4. `0 < fraction_over < 1/3`, which measured against the real corpus accepted **every ceiling from 39 to 229** — including the ceiling of 200 the draft itself offered as the case it catches, because a single 230-line record keeps the count nonzero. A bound that a deliberately absurd value satisfies -is not a guard. At a 2% floor and a 25% cap the accepted range is roughly 45..150: a ceiling of 200 -flags 0.5% of records and is rejected, a ceiling of 20 flags 60% and is rejected, and today's 9.8% -sits with about 5x headroom below the floor and 37 additions below the cap. +is not a guard. At a 2% floor and a 25% cap the accepted range is **43..180** (measured, contiguous): +a ceiling of 200 flags 0.5% of records and is rejected, a ceiling of 20 flags 60% and is rejected, +and today's 9.8% sits about 5x ABOVE the floor and 38 over-ceiling additions below the cap. The honest cost, stated rather than buried: **nothing now forces a re-derivation.** The ceiling can drift while only a notice complains. That is accepted on the same reasoning this record already diff --git a/docs/decisions/records/docs/frontmatter-pyyaml-crosscheck.md b/docs/decisions/records/docs/frontmatter-pyyaml-crosscheck.md index 163816b98..0a08e88b7 100644 --- a/docs/decisions/records/docs/frontmatter-pyyaml-crosscheck.md +++ b/docs/decisions/records/docs/frontmatter-pyyaml-crosscheck.md @@ -58,13 +58,15 @@ to `pyyaml_frontmatter_faults`, so the tool and the suite cannot drift on the de **What this buys, stated precisely, because it is less than it looks.** In CI `decisions-guard` installs nothing, so the validator there always takes the skip path, by design; and `script-tests` -already went red on both hazards before this change. So **`main` was never reachable by a broken -record, and still isn't — the CI delta is close to zero.** What this fixes is the case #674 actually -described: the LOCAL loop, where the validator is the tool a developer or agent reaches for directly -and it printed OK on a corrupt file — plus the standing disagreement between the tool and its own -suite, now impossible because they share one implementation. +already went red on both hazards before this change, and an advisory red still blocks the merge gate +(#598). So **no broken record has reached `main`, and the CI delta here is close to zero** — though +that protection is procedural rather than structural, since `script-tests` is not a REQUIRED check +and `decisions-guard`, which is, runs without PyYAML and so always skips this cross-check. What this +fixes is the case #674 actually +described: the LOCAL loop, where the validator is the tool an agent reaches for directly and it +printed OK on a corrupt file — plus the tool/suite disagreement, now impossible. -**Limits, and the positive control.** It does not catch a mis-parse both parsers agree on; the guard -is strong, not total, the same qualification `record_wing_faults` carries. The suite pins that -`record_wing_faults` ALONE still reports both hazard files as clean — without that, the cross-check +**Limits, and the positive control.** It does not catch a mis-parse both parsers agree on — strong, +not total, the same qualification `record_wing_faults` carries. The suite pins that +`record_wing_faults` ALONE still reports both hazard files as clean; without that, the cross-check could be deleted and the tests would stay green while the guard vanished. diff --git a/scripts/decisions_validate.py b/scripts/decisions_validate.py index fa367b293..c2fd318f0 100644 --- a/scripts/decisions_validate.py +++ b/scripts/decisions_validate.py @@ -758,7 +758,7 @@ class CeilingCalibration(NamedTuple): n_over: int fraction_over: float marks_tail: bool # the FINE claim: p90 <= ceiling <= p95 - flags_minority: bool # the COARSE claim: 0 < fraction_over < CEILING_MINORITY_MAX + flags_minority: bool # the COARSE claim: MINORITY_MIN <= fraction_over <= MINORITY_MAX def ceiling_calibration(records, ceiling: int) -> CeilingCalibration: @@ -776,8 +776,9 @@ def ceiling_calibration(records, ceiling: int) -> CeilingCalibration: `flags_minority` — `CEILING_MINORITY_MIN <= fraction_over <= CEILING_MINORITY_MAX`. Deliberately coarse, and what the blocking test asserts. Each added record moves a fraction by at most 1/N, so - routine growth cannot cross it: measured live at 18/183 (9.8%), reaching the 25% cap takes 37 - consecutive over-ceiling additions, against ONE record to break `marks_tail`. + routine growth cannot cross it: measured live at 18/183 (9.8%), BREACHING the 25% cap takes 38 + consecutive over-ceiling additions (37 lands exactly on 0.25, which still passes under `<=`), + or 718 short ones to dilute below the floor — against ONE record to break `marks_tail`. It still catches genuine mis-calibration in both directions, measured on the real corpus: a ceiling of 20 flags 60% of records (cutting into the bulk, so every author learns to ignore it), diff --git a/scripts/tests/test_decisions_validate.py b/scripts/tests/test_decisions_validate.py index 56146552f..bea4de3c4 100644 --- a/scripts/tests/test_decisions_validate.py +++ b/scripts/tests/test_decisions_validate.py @@ -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):