Skip to content

Commit edea33c

Browse files
brabojclaude
andauthored
feat(efficacy): a self-test check for eight rules that had none (#123)
Each rule a script already followed now has a check that fails without it: the web tools refused, ruff and mypy on the harness's configuration, coverage missing when the lock refuses a test dependency, the judging order the seed's alone with the map out of the judge's reach, the checklist's 13 items read alike on every arm, a drifted control base refused, and a generation record beside every generated arm. The judge's order and map path move into small functions the check can call. FR-02-07 and FR-02-08 are marked untestable: no script applies them. FR-09-06 waits for probes.py to have a self-test. Claude-Session: https://claude.ai/code/session_01DpT5xPFWEQr1bipxbbKBRF Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e6b491d commit edea33c

6 files changed

Lines changed: 160 additions & 17 deletions

File tree

‎docs/coverage.md‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ when:
4949
| FR-02-04 | Self-test | `report.py` "every per-KLOC row carries the static margin"<br>`report.py` "every primary the judge asks for is led with, worded and given its margins" |
5050
| FR-02-05 | Self-test | `report.py` "round 5 holds adherence within one item, 8 pp" |
5151
| FR-02-06 | Self-test | `report.py` "a rise inside the band is held"<br>`report.py` "a rise wholly past the band is worse"<br>`report.py` "one that straddles the band is undecided"<br>`report.py` "a band that holds zero is held"<br>`report.py` "round 5 reads a 10 % rise in app code as held" |
52-
| FR-02-07 | Missing | #109 |
53-
| FR-02-08 | Missing | #109 |
52+
| FR-02-07 | Untestable | No script applies it: from round 5d adherence decides nothing, so the rule binds a person reading an earlier round's report. |
53+
| FR-02-08 | Untestable | No script calls a trim free; a person reading the report applies it, on the held rows the report prints. |
5454
| FR-02-09 | Self-test | `report.py` "from six blocks no interval is called descriptive"<br>`report.py` "a round too small to decide says so in the report and the appendix" |
5555

5656
## 03 Trial count and escalation
@@ -83,7 +83,7 @@ when:
8383
| FR-05-01 | Self-test | `harness.py` "the scratch home is the home"<br>`harness.py` "the settings file carries the rules and the isolation"<br>`harness.py` "a trial reads the workspace's project settings and no other source" |
8484
| FR-05-02 | Self-test | `harness.py` "ANTHROPIC_API_KEY is removed"<br>`harness.py` "CLAUDECODE is removed"<br>`harness.py` "VIRTUAL_ENV is removed"<br>`harness.py` "the interpreter leaves PATH" |
8585
| FR-05-03 | Self-test | `harness.py` "other trials, their change tasks, home and void are denied"<br>`harness.py` "this repository and the scoring area are denied"<br>`harness.py` "tarballs and run records are denied"<br>`harness.py` "the templates source is denied whenever one is set"<br>`harness.py` "the trial's own workspace is not denied" |
86-
| FR-05-04 | Missing | #109 |
86+
| FR-05-04 | Self-test | `harness.py` "a trial may not fetch or search the web" |
8787
| FR-05-05 | Self-test | `harness.py` "a planted Git helper answers outside a trial"<br>`harness.py` "it does not answer inside one" |
8888
| FR-05-06 | Self-test | `harness.py` "every kill by name meets a deny rule" |
8989
| FR-05-07 | Self-test | `harness.py` "every call reaching past the trial is flagged"<br>`harness.py` "the root, another pen and a climb out of the pen are flagged"<br>`harness.py` "a fetch of the templates is flagged, and only that"<br>`harness.py` "a kill by name that ran, or never answered, is a hit"<br>`harness.py` "a scorable trial with a reach becomes reached"<br>`harness.py` "the trial's own paths are not flagged, a pip extra included" |
@@ -106,18 +106,18 @@ when:
106106
| -- | ---- | ---------- |
107107
| FR-07-01 | Self-test | `score.py` "the battery installs from a lock it resolved" |
108108
| FR-07-02 | Self-test | `score.py` "only the tools reach the lock"<br>`score.py` "the lock carries none of the trial's dependencies" |
109-
| FR-07-03 | Missing | #109 |
109+
| FR-07-03 | Self-test | `score.py` "ruff and mypy take the harness's configuration, not the trial's" |
110110
| FR-07-04 | Self-test | `score.py` "a scoring environment runs the spec's Python"<br>`score.py` "no Python at the spec's version refuses to score"<br>`score.py` "a score on another Python refuses the root"<br>`report.py` "scores on two Pythons are refused" |
111111
| FR-07-05 | Self-test | `score.py` "the planted package is discovered"<br>`score.py` "an empty tree yields no roots" |
112112
| FR-07-06 | Self-test | `score.py` "every extra and every group requirement is installed" |
113-
| FR-07-07 | Missing | #109 |
113+
| FR-07-07 | Self-test | `score.py` "a test dependency the lock refuses leaves coverage missing" |
114114

115115
## 08 Flexibility
116116

117117
| ID | Kind | Checked by |
118118
| -- | ---- | ---------- |
119119
| FR-08-01 | Self-test | `judge.py` "the trial's code reaches the bundle"<br>`judge.py` "scoring's output and the environment's stay out of the bundle"<br>`judge.py` "the skills arm's skills stay out of the bundle" |
120-
| FR-08-02 | Missing | #109 |
120+
| FR-08-02 | Self-test | `judge.py` "one seed gives one judging order"<br>`judge.py` "the order is not the arms' order, and holds every repeat"<br>`judge.py` "the unblinding map is written outside the bundles the judge reads" |
121121
| FR-08-03 | Self-test | `judge.py` "a path naming the trial is a leak"<br>`judge.py` "an escaped path naming the trial is a leak"<br>`judge.py` "a leak in a directory the copy skips is found"<br>`judge.py` "a bundle holding neither has no leak"<br>`generate_arm.py` "the leak scan reports a planted token and passes clean text" |
122122

123123
## 09 Scoring
@@ -128,7 +128,7 @@ when:
128128
| FR-09-02 | Self-test | `score.py` "an application that seeds on start, and has no default secret, boots under scoring"<br>`score.py` "a build capped below Python 3.13 installs" |
129129
| FR-09-03 | Self-test | `score.py` "an hx-* error is set aside and another counts" |
130130
| FR-09-04 | Self-test | `score.py` "app code is the app's Python and templates, not its tests"<br>`score.py` "test code is a tests directory or a pytest name, anywhere"<br>`score.py` "docs and configuration count toward no size"<br>`score.py` "committed bytecode and a database are artifacts nobody asked for" |
131-
| FR-09-05 | Missing | #109 |
131+
| FR-09-05 | Self-test | `score.py` "the checklist holds 13 items and reads none as any arm" |
132132
| FR-09-06 | Missing | #109 |
133133
| FR-09-07 | Self-test | `score.py` "churn counts an edit and a new file, not an environment"<br>`score.py` "the churn plant landed" |
134134
| FR-09-08 | Self-test | `harness.py` "the change prompt names the API and fields the grader drives"<br>`harness.py` "the change prompt is read whole from its file" |
@@ -145,7 +145,7 @@ when:
145145
| FR-10-05 | Self-test | `report.py` "a direction the other judge reverses loses its verdict"<br>`report.py` "a direction both judges read keeps its verdict"<br>`report.py` "a contrast the other judge did not read keeps its verdict"<br>`report.py` "the rounds' own judge is caught posing as the other" |
146146
| FR-10-06 | Self-test | `report.py` "the judge is checked by its evidence, not a person" |
147147
| FR-10-07 | Self-test | `control/control.py` "the domain imports flask"<br>`control/control.py` "ValidationError derives from TariffError"<br>`control/control.py` "the secret key is a literal"<br>`control/control.py` "customer data is written to the log" |
148-
| FR-10-08 | Missing | #109 |
148+
| FR-10-08 | Self-test | `control/control.py` "a base archive with another sha256 is refused" |
149149
| FR-10-09 | Untestable | A judged control root is read by hand, and [validation](validation.md) records each reading. |
150150

151151
## 11 Security and data protection
@@ -179,7 +179,7 @@ when:
179179
| ID | Kind | Checked by |
180180
| -- | ---- | ---------- |
181181
| FR-13-01 | Self-test | `harness.py` "the record is written as every trial starts and ends"<br>`harness.py` "every trial records the CLI's version, read as it starts" |
182-
| FR-13-02 | Missing | #109 |
182+
| FR-13-02 | Self-test | `generate_arm.py` "every generated arm's file has its generation record beside it" |
183183
| FR-13-03 | Self-test | `archive.py` "readings, judgings, map and lock come; bundles do not"<br>`archive.py` "the original tarball's hash is recorded"<br>`archive.py` "the revisions are recorded"<br>`archive.py` "a reading changed in the archive fails the verify" |
184184
| FR-13-04 | Self-test | `archive.py` "a reading changed after the stamp is a problem"<br>`archive.py` "the report refuses docs/audits/ without a current stamp"<br>`report.py` "a report into a templates source's docs/audits needs the stamp" |
185185
| FR-13-05 | Self-test | `archive.py` "the restored root reads as the original does"<br>`archive.py` "a restored record points at the restored tarball and void"<br>`archive.py` "a restored transcript keeps its time" |

‎tests/efficacy/control/control.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,17 @@ def main(argv):
755755
try:
756756
made = build(os.path.join(scratch, "run"))
757757
rows = landings(made)
758+
759+
# A base whose content changed would compare a later run against
760+
# a different application, so any digest but the pinned one stops
761+
# the build.
762+
try:
763+
pinned(BASE, "0" * 64)
764+
refused = False
765+
except ControlError:
766+
refused = True
767+
rows.append(("a base archive with another sha256 is refused",
768+
{}, refused))
758769
finally:
759770
shutil.rmtree(scratch, ignore_errors=True)
760771
elif options.root:

‎tests/efficacy/generate_arm.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,22 @@ def self_test():
505505
print("FAIL: the budget clause is not in short's instruction alone")
506506
return 1
507507
print("the budget is stated in short's instruction and no other")
508+
509+
# A generated file without its record cannot say which source, model and
510+
# ref made it, so the report could not cite how its arm was built.
511+
for arm in GENERATED:
512+
path = record_path(arm)
513+
if not os.path.isfile(output_path(arm)):
514+
continue
515+
try:
516+
with io.open(path, encoding="utf-8") as handle:
517+
record = json.load(handle)
518+
except (OSError, ValueError):
519+
record = {}
520+
if record.get("arm") != arm or record.get("outcome") != "generated":
521+
print("FAIL: %s has no generation record beside it" % arm)
522+
return 1
523+
print("every generated arm's file has its generation record beside it")
508524
return 0
509525

510526

‎tests/efficacy/harness.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3472,7 +3472,14 @@ def round5_checks():
34723472
checks.append(("a trial reads the workspace's project settings and no "
34733473
"other source",
34743474
argv[argv.index("--setting-sources") + 1] == "project"))
3475-
listed = "review\n- write-tests\n`add-check`\ndataviz"
3475+
3476+
# The web tools go after the flag that names them; anything else there
3477+
# would be read as one more tool to refuse, or as the prompt.
3478+
refused = (argv[argv.index("--disallowed-tools") + 1:][:2]
3479+
if "--disallowed-tools" in argv else [])
3480+
checks.append(("a trial may not fetch or search the web",
3481+
sorted(refused) == ["WebFetch", "WebSearch"]))
3482+
listed ="review\n- write-tests\n`add-check`\ndataviz"
34763483
checks.append(("the skills probe finds a listed kind and names a missing "
34773484
"one",
34783485
missing_skills(listed, ["add-check", "review",

‎tests/efficacy/judge.py‎

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ def highest_label(judging):
739739
match = re.match(r"T(\d+)\.json$", os.path.basename(file))
740740
if match:
741741
numbers.append(int(match.group(1)))
742-
path = os.path.join(judging, "map.json")
742+
path = unblinding_map(judging)
743743
if os.path.isfile(path):
744744
with io.open(path, encoding="utf-8") as handle:
745745
for label in json.load(handle).get("blind", {}).values():
@@ -749,6 +749,24 @@ def highest_label(judging):
749749
return max(numbers)
750750

751751

752+
# Where the bundles go, under the judging area; the judge is pointed here and
753+
# nowhere else.
754+
BUNDLES = "bundles"
755+
756+
757+
def judging_order(wanted, owed, seed):
758+
"""Every judging owed, in an order the seed alone decides."""
759+
shuffler = random.Random(seed)
760+
order = [name for name in wanted for _ in range(owed[name])]
761+
shuffler.shuffle(order)
762+
return order
763+
764+
765+
def unblinding_map(judging):
766+
"""Where the map from blind labels back to trials is kept."""
767+
return os.path.join(judging, "map.json")
768+
769+
752770
def blind_labels(order, after):
753771
"""A blind label per trial in `order`, numbered from `after` + 1, so a
754772
root holding an earlier round's judgings never reuses one of theirs."""
@@ -841,7 +859,7 @@ def judge_trials(options, available, wanted):
841859
lib.print_verdict(False, "no trial judged")
842860
return 2
843861

844-
bundles = os.path.join(judging, "bundles")
862+
bundles = os.path.join(judging, BUNDLES)
845863
os.makedirs(bundles, exist_ok=True)
846864

847865
# Shuffled with a recorded seed, so the order is reproducible and is not
@@ -852,9 +870,7 @@ def judge_trials(options, available, wanted):
852870
# list is shuffled together, so its repeats are spread through the run
853871
# rather than made back to back. Each repeat is a separate blind label: it
854872
# is a separate reading of the same tree, and the report means them.
855-
shuffler = random.Random(options.seed)
856-
order = [name for name in wanted for _ in range(owed[name])]
857-
shuffler.shuffle(order)
873+
order = judging_order(wanted, owed, options.seed)
858874
labels = blind_labels(range(len(order)), highest_label(judging))
859875
repeats = {}
860876

@@ -911,7 +927,7 @@ def judge_trials(options, available, wanted):
911927

912928
# The unblinding map, written last and kept out of the bundles directory
913929
# the judge was pointed at. An earlier round's entries stay in it.
914-
path = os.path.join(judging, "map.json")
930+
path = unblinding_map(judging)
915931
mapping = {"seed": options.seed, "blind": {}, "repeats": {}}
916932
if os.path.isfile(path):
917933
with io.open(path, encoding="utf-8") as handle:
@@ -1208,6 +1224,27 @@ def refuses(call):
12081224
return checks
12091225

12101226

1227+
def order_checks(scratch):
1228+
"""The judging order is the seed's alone, and the key stays out of the
1229+
judge's reach."""
1230+
wanted = ["hybrid-1", "inline-1", "none-1", "reference-1", "skills-1"]
1231+
owed = {name: 3 for name in wanted}
1232+
first = judging_order(wanted, owed, 20260912)
1233+
judging = os.path.join(scratch, "order", "judge")
1234+
bundles = os.path.abspath(os.path.join(judging, BUNDLES))
1235+
return [
1236+
("one seed gives one judging order",
1237+
first == judging_order(wanted, owed, 20260912)
1238+
and first != judging_order(wanted, owed, 1)),
1239+
("the order is not the arms' order, and holds every repeat",
1240+
first != sorted(first) and sorted(first) == sorted(
1241+
name for name in wanted for _ in range(3))),
1242+
("the unblinding map is written outside the bundles the judge reads",
1243+
not os.path.abspath(unblinding_map(judging)).startswith(
1244+
bundles + os.sep)),
1245+
]
1246+
1247+
12111248
def label_checks(scratch):
12121249
"""Blind labels continue past an earlier round's, and a judged trial is
12131250
known by its canonical name."""
@@ -1333,6 +1370,7 @@ def self_test():
13331370
checks = bundle_checks(scratch)
13341371
checks.extend(spec_checks(scratch))
13351372
checks.extend(label_checks(scratch))
1373+
checks.extend(order_checks(scratch))
13361374
checks.extend(launch_checks(scratch))
13371375
checks.extend(backend_checks(scratch))
13381376
checks.extend(claim_checks(scratch))

‎tests/efficacy/score.py‎

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,75 @@ def boot_checks(scratch, venv):
17231723
'''
17241724

17251725

1726+
def ruler_checks(scratch):
1727+
"""Prove the rulers take the harness's configuration, and that a test
1728+
dependency the lock will not admit leaves coverage missing.
1729+
1730+
The tools are stubbed: what is checked is the command each is given and
1731+
what is recorded when an install fails, not the tools themselves.
1732+
"""
1733+
called = []
1734+
1735+
def stub_module(venv, module, args, cwd=None, timeout=TOOL_TIMEOUT):
1736+
called.append((module, list(args)))
1737+
return {"failed": "stubbed", "status": 1, "stdout": "", "stderr": "",
1738+
"argv": [module] + list(args)}
1739+
1740+
def refusing_pip(venv, *args, **kwargs):
1741+
return {"failed": None, "status": 1, "stdout": "",
1742+
"stderr": "ResolutionImpossible: ruff conflicts with the lock",
1743+
"argv": ["pip"] + list(args)}
1744+
1745+
planted = os.path.join(scratch, "conflict")
1746+
os.makedirs(os.path.join(planted, "tests"))
1747+
with io.open(os.path.join(planted, "pyproject.toml"), "w",
1748+
encoding="utf-8") as handle:
1749+
handle.write(PLANTED_TEST_DEPENDENCIES)
1750+
saved = {name: globals()[name] for name in ("run_module", "pip")}
1751+
globals().update(run_module=stub_module, pip=refusing_pip)
1752+
try:
1753+
roots = [os.path.join(planted, "pkg")]
1754+
ruff_findings(planted, planted, roots, {})
1755+
ruff_format(planted, planted, roots, {})
1756+
mypy_errors(planted, planted, roots, {})
1757+
conflicted = own_test_coverage(planted, planted, roots, {})
1758+
finally:
1759+
globals().update(saved)
1760+
ruff_args = [args for module, args in called if module == "ruff"]
1761+
mypy_args = [args for module, args in called if module == "mypy"]
1762+
return [
1763+
("ruff and mypy take the harness's configuration, not the trial's",
1764+
len(ruff_args) == 2 and len(mypy_args) == 1
1765+
and all(RUFF_CONFIG in args for args in ruff_args)
1766+
and MYPY_CONFIG in mypy_args[0]),
1767+
("a test dependency the lock refuses leaves coverage missing",
1768+
conflicted.get("value") is None
1769+
and "would not install beside the scoring lock"
1770+
in (conflicted.get("missing") or "")
1771+
and "ResolutionImpossible" in (conflicted.get("missing") or "")),
1772+
]
1773+
1774+
1775+
def adherence_checks(scratch):
1776+
"""Prove the checklist holds its 13 items and reads the bare arm as it
1777+
reads any other."""
1778+
planted = os.path.join(scratch, "adherence")
1779+
os.makedirs(planted)
1780+
scores = {"ruff": measured(0), "mypy": measured(0),
1781+
"ruff_format": measured(0), "coverage": measured({"line": 85}),
1782+
"complexity": measured({"over_15": 0}),
1783+
"discovery": {"roots": [os.path.join(planted, "src", "pkg")]},
1784+
"structure": measured({"exception_bases": ["PkgError"],
1785+
"print_calls": [], "citations": [],
1786+
"logging": {"used": True,
1787+
"null_handler": True}})}
1788+
read = {arm: adherence(planted, dict(scores, arm=arm))
1789+
for arm in ("none", "hybrid")}
1790+
return [("the checklist holds 13 items and reads none as any arm",
1791+
read["none"].get("total_items") == 13
1792+
and read["none"] == read["hybrid"])]
1793+
1794+
17261795
def coverage_checks(scratch):
17271796
"""Prove the coverage run installs what the trial's tests declare.
17281797
@@ -1920,7 +1989,9 @@ def self_test():
19201989
+ lock_checks() + html_checks() + readonly_checks(scratch)
19211990
+ lock_source_checks(scratch) + unrun_checks(scratch)
19221991
+ claim_checks(scratch) + security_checks(scratch)
1923-
+ coverage_checks(scratch) + python_files_checks(scratch)
1992+
+ coverage_checks(scratch) + ruler_checks(scratch)
1993+
+ adherence_checks(scratch)
1994+
+ python_files_checks(scratch)
19241995
+ scope_checks(scratch))
19251996
dropped = create_venv(os.path.join(scratch, "dropped"))
19261997
drop_venv(dropped)

0 commit comments

Comments
 (0)