Make the budget gate's hard index-row limit actually fail

`check_index_rows` read `'warn' if hard else 'warn'` -- both branches identical -- so
INDEX_ROW_HARD was defined, computed, and unable to fail anything: an index row could grow
without bound while every gate stayed green.

Found by injecting an over-long row into SKILL.md and requiring the gate to fail. That is the
only way a dead threshold shows itself; a gate that has only ever been observed passing is not
evidence that it can see anything.

A test now pins both sides -- a row past the soft limit warns, a row past the hard limit fails
-- and it was checked against the pre-fix behaviour, where it fails.
This commit is contained in:
inliver233
2026-10-16 19:17:21 +08:00
parent ca38fa393d
commit b8aa0a529b
2 changed files with 29 additions and 1 deletions
+5 -1
View File
@@ -196,7 +196,11 @@ def check_index_rows(lines):
out = []
for section, key, size in long_rows:
hard = size > INDEX_ROW_HARD
out.append(('warn' if hard else 'warn',
# `hard` must actually escalate. This read `'warn' if hard else 'warn'` -- both branches the
# same -- so INDEX_ROW_HARD was defined, computed and never able to fail anything: an index
# row could grow without limit and CI stayed green. Found by injecting an over-long row and
# asking the gate to fail, which is the only way this class of defect shows up.
out.append(('fail' if hard else 'warn',
'%s: row for %s is %d chars (soft limit %d)%s' %
(section, key, size, INDEX_ROW_SOFT,
' -- that is a paragraph, not an index entry' if hard else '')))
+24
View File
@@ -88,3 +88,27 @@ def test_the_fallback_constant_is_the_calibrated_one(budget):
assert abs(budget.TOKENS_PER_CHAR - expected) < 0.25, (
"TOKENS_PER_CHAR is %.3f but this SKILL.md measures %.3f characters per token -- the "
"document changed, so recalibrate" % (budget.TOKENS_PER_CHAR, expected))
def test_an_index_row_past_the_hard_limit_fails_rather_than_warns(budget):
"""The hard index-row limit must escalate, or the limit it names is decorative.
It read `'warn' if hard else 'warn'` -- both branches identical -- so `INDEX_ROW_HARD` was
defined, computed, and unable to fail anything: an index row could grow without bound while
every gate stayed green. That is the same failure mode this file exists for, one level up: the
measurement happened and the verdict did not follow. It was found by injecting an over-long row
and requiring the gate to fail, which is the only way a dead limit shows itself -- a gate that
has only ever been seen passing is not evidence that it can see anything.
"""
def levels(desc_len):
lines = [
"## Symptom index",
"| What you observe | Load first |",
"| a row | %s |" % ("y" * desc_len),
]
return {level for level, _ in budget.check_index_rows(lines)}
assert levels(budget.INDEX_ROW_SOFT + 10) == {"warn"}
assert levels(budget.INDEX_ROW_HARD + 10) == {"fail"}, (
"a row past INDEX_ROW_HARD (%d chars) must fail the gate, not warn about it"
% budget.INDEX_ROW_HARD)