From c462a8006d01485164bd584b37d0416e3bd00d6f Mon Sep 17 00:00:00 2001 From: Branimir Georgiev <66906831+braboj@users.noreply.github.com> Date: Mon, 2 Nov 2026 17:02:17 +0200 Subject: [PATCH] feat(efficacy): a self-test check for eight rules that had none 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. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DpT5xPFWEQr1bipxbbKBRF --- docs/coverage.md | 18 ++++---- tests/efficacy/control/control.py | 11 +++++ tests/efficacy/generate_arm.py | 16 +++++++ tests/efficacy/harness.py | 9 +++- tests/efficacy/judge.py | 50 ++++++++++++++++++--- tests/efficacy/score.py | 73 ++++++++++++++++++++++++++++++- 6 files changed, 160 insertions(+), 17 deletions(-) diff --git a/docs/coverage.md b/docs/coverage.md index 313f2d0..dc78b2c 100644 --- a/docs/coverage.md +++ b/docs/coverage.md @@ -49,8 +49,8 @@ when: | FR-02-04 | Self-test | `report.py` "every per-KLOC row carries the static margin"
`report.py` "every primary the judge asks for is led with, worded and given its margins" | | FR-02-05 | Self-test | `report.py` "round 5 holds adherence within one item, 8 pp" | | FR-02-06 | Self-test | `report.py` "a rise inside the band is held"
`report.py` "a rise wholly past the band is worse"
`report.py` "one that straddles the band is undecided"
`report.py` "a band that holds zero is held"
`report.py` "round 5 reads a 10 % rise in app code as held" | -| FR-02-07 | Missing | #109 | -| FR-02-08 | Missing | #109 | +| 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. | +| FR-02-08 | Untestable | No script calls a trim free; a person reading the report applies it, on the held rows the report prints. | | FR-02-09 | Self-test | `report.py` "from six blocks no interval is called descriptive"
`report.py` "a round too small to decide says so in the report and the appendix" | ## 03 Trial count and escalation @@ -83,7 +83,7 @@ when: | FR-05-01 | Self-test | `harness.py` "the scratch home is the home"
`harness.py` "the settings file carries the rules and the isolation"
`harness.py` "a trial reads the workspace's project settings and no other source" | | FR-05-02 | Self-test | `harness.py` "ANTHROPIC_API_KEY is removed"
`harness.py` "CLAUDECODE is removed"
`harness.py` "VIRTUAL_ENV is removed"
`harness.py` "the interpreter leaves PATH" | | FR-05-03 | Self-test | `harness.py` "other trials, their change tasks, home and void are denied"
`harness.py` "this repository and the scoring area are denied"
`harness.py` "tarballs and run records are denied"
`harness.py` "the templates source is denied whenever one is set"
`harness.py` "the trial's own workspace is not denied" | -| FR-05-04 | Missing | #109 | +| FR-05-04 | Self-test | `harness.py` "a trial may not fetch or search the web" | | FR-05-05 | Self-test | `harness.py` "a planted Git helper answers outside a trial"
`harness.py` "it does not answer inside one" | | FR-05-06 | Self-test | `harness.py` "every kill by name meets a deny rule" | | FR-05-07 | Self-test | `harness.py` "every call reaching past the trial is flagged"
`harness.py` "the root, another pen and a climb out of the pen are flagged"
`harness.py` "a fetch of the templates is flagged, and only that"
`harness.py` "a kill by name that ran, or never answered, is a hit"
`harness.py` "a scorable trial with a reach becomes reached"
`harness.py` "the trial's own paths are not flagged, a pip extra included" | @@ -106,18 +106,18 @@ when: | -- | ---- | ---------- | | FR-07-01 | Self-test | `score.py` "the battery installs from a lock it resolved" | | FR-07-02 | Self-test | `score.py` "only the tools reach the lock"
`score.py` "the lock carries none of the trial's dependencies" | -| FR-07-03 | Missing | #109 | +| FR-07-03 | Self-test | `score.py` "ruff and mypy take the harness's configuration, not the trial's" | | FR-07-04 | Self-test | `score.py` "a scoring environment runs the spec's Python"
`score.py` "no Python at the spec's version refuses to score"
`score.py` "a score on another Python refuses the root"
`report.py` "scores on two Pythons are refused" | | FR-07-05 | Self-test | `score.py` "the planted package is discovered"
`score.py` "an empty tree yields no roots" | | FR-07-06 | Self-test | `score.py` "every extra and every group requirement is installed" | -| FR-07-07 | Missing | #109 | +| FR-07-07 | Self-test | `score.py` "a test dependency the lock refuses leaves coverage missing" | ## 08 Flexibility | ID | Kind | Checked by | | -- | ---- | ---------- | | FR-08-01 | Self-test | `judge.py` "the trial's code reaches the bundle"
`judge.py` "scoring's output and the environment's stay out of the bundle"
`judge.py` "the skills arm's skills stay out of the bundle" | -| FR-08-02 | Missing | #109 | +| FR-08-02 | Self-test | `judge.py` "one seed gives one judging order"
`judge.py` "the order is not the arms' order, and holds every repeat"
`judge.py` "the unblinding map is written outside the bundles the judge reads" | | FR-08-03 | Self-test | `judge.py` "a path naming the trial is a leak"
`judge.py` "an escaped path naming the trial is a leak"
`judge.py` "a leak in a directory the copy skips is found"
`judge.py` "a bundle holding neither has no leak"
`generate_arm.py` "the leak scan reports a planted token and passes clean text" | ## 09 Scoring @@ -128,7 +128,7 @@ when: | FR-09-02 | Self-test | `score.py` "an application that seeds on start, and has no default secret, boots under scoring"
`score.py` "a build capped below Python 3.13 installs" | | FR-09-03 | Self-test | `score.py` "an hx-* error is set aside and another counts" | | FR-09-04 | Self-test | `score.py` "app code is the app's Python and templates, not its tests"
`score.py` "test code is a tests directory or a pytest name, anywhere"
`score.py` "docs and configuration count toward no size"
`score.py` "committed bytecode and a database are artifacts nobody asked for" | -| FR-09-05 | Missing | #109 | +| FR-09-05 | Self-test | `score.py` "the checklist holds 13 items and reads none as any arm" | | FR-09-06 | Missing | #109 | | FR-09-07 | Self-test | `score.py` "churn counts an edit and a new file, not an environment"
`score.py` "the churn plant landed" | | FR-09-08 | Self-test | `harness.py` "the change prompt names the API and fields the grader drives"
`harness.py` "the change prompt is read whole from its file" | @@ -145,7 +145,7 @@ when: | FR-10-05 | Self-test | `report.py` "a direction the other judge reverses loses its verdict"
`report.py` "a direction both judges read keeps its verdict"
`report.py` "a contrast the other judge did not read keeps its verdict"
`report.py` "the rounds' own judge is caught posing as the other" | | FR-10-06 | Self-test | `report.py` "the judge is checked by its evidence, not a person" | | FR-10-07 | Self-test | `control/control.py` "the domain imports flask"
`control/control.py` "ValidationError derives from TariffError"
`control/control.py` "the secret key is a literal"
`control/control.py` "customer data is written to the log" | -| FR-10-08 | Missing | #109 | +| FR-10-08 | Self-test | `control/control.py` "a base archive with another sha256 is refused" | | FR-10-09 | Untestable | A judged control root is read by hand, and [validation](validation.md) records each reading. | ## 11 Security and data protection @@ -179,7 +179,7 @@ when: | ID | Kind | Checked by | | -- | ---- | ---------- | | FR-13-01 | Self-test | `harness.py` "the record is written as every trial starts and ends"
`harness.py` "every trial records the CLI's version, read as it starts" | -| FR-13-02 | Missing | #109 | +| FR-13-02 | Self-test | `generate_arm.py` "every generated arm's file has its generation record beside it" | | FR-13-03 | Self-test | `archive.py` "readings, judgings, map and lock come; bundles do not"
`archive.py` "the original tarball's hash is recorded"
`archive.py` "the revisions are recorded"
`archive.py` "a reading changed in the archive fails the verify" | | FR-13-04 | Self-test | `archive.py` "a reading changed after the stamp is a problem"
`archive.py` "the report refuses docs/audits/ without a current stamp"
`report.py` "a report into a templates source's docs/audits needs the stamp" | | FR-13-05 | Self-test | `archive.py` "the restored root reads as the original does"
`archive.py` "a restored record points at the restored tarball and void"
`archive.py` "a restored transcript keeps its time" | diff --git a/tests/efficacy/control/control.py b/tests/efficacy/control/control.py index d6d725b..1736b05 100644 --- a/tests/efficacy/control/control.py +++ b/tests/efficacy/control/control.py @@ -755,6 +755,17 @@ def main(argv): try: made = build(os.path.join(scratch, "run")) rows = landings(made) + + # A base whose content changed would compare a later run against + # a different application, so any digest but the pinned one stops + # the build. + try: + pinned(BASE, "0" * 64) + refused = False + except ControlError: + refused = True + rows.append(("a base archive with another sha256 is refused", + {}, refused)) finally: shutil.rmtree(scratch, ignore_errors=True) elif options.root: diff --git a/tests/efficacy/generate_arm.py b/tests/efficacy/generate_arm.py index 2211958..0193924 100644 --- a/tests/efficacy/generate_arm.py +++ b/tests/efficacy/generate_arm.py @@ -505,6 +505,22 @@ def self_test(): print("FAIL: the budget clause is not in short's instruction alone") return 1 print("the budget is stated in short's instruction and no other") + + # A generated file without its record cannot say which source, model and + # ref made it, so the report could not cite how its arm was built. + for arm in GENERATED: + path = record_path(arm) + if not os.path.isfile(output_path(arm)): + continue + try: + with io.open(path, encoding="utf-8") as handle: + record = json.load(handle) + except (OSError, ValueError): + record = {} + if record.get("arm") != arm or record.get("outcome") != "generated": + print("FAIL: %s has no generation record beside it" % arm) + return 1 + print("every generated arm's file has its generation record beside it") return 0 diff --git a/tests/efficacy/harness.py b/tests/efficacy/harness.py index bddd21a..02d5afe 100644 --- a/tests/efficacy/harness.py +++ b/tests/efficacy/harness.py @@ -3472,7 +3472,14 @@ def round5_checks(): checks.append(("a trial reads the workspace's project settings and no " "other source", argv[argv.index("--setting-sources") + 1] == "project")) - listed = "review\n- write-tests\n`add-check`\ndataviz" + + # The web tools go after the flag that names them; anything else there + # would be read as one more tool to refuse, or as the prompt. + refused = (argv[argv.index("--disallowed-tools") + 1:][:2] + if "--disallowed-tools" in argv else []) + checks.append(("a trial may not fetch or search the web", + sorted(refused) == ["WebFetch", "WebSearch"])) + listed ="review\n- write-tests\n`add-check`\ndataviz" checks.append(("the skills probe finds a listed kind and names a missing " "one", missing_skills(listed, ["add-check", "review", diff --git a/tests/efficacy/judge.py b/tests/efficacy/judge.py index 1f60a72..c739065 100644 --- a/tests/efficacy/judge.py +++ b/tests/efficacy/judge.py @@ -739,7 +739,7 @@ def highest_label(judging): match = re.match(r"T(\d+)\.json$", os.path.basename(file)) if match: numbers.append(int(match.group(1))) - path = os.path.join(judging, "map.json") + path = unblinding_map(judging) if os.path.isfile(path): with io.open(path, encoding="utf-8") as handle: for label in json.load(handle).get("blind", {}).values(): @@ -749,6 +749,24 @@ def highest_label(judging): return max(numbers) +# Where the bundles go, under the judging area; the judge is pointed here and +# nowhere else. +BUNDLES = "bundles" + + +def judging_order(wanted, owed, seed): + """Every judging owed, in an order the seed alone decides.""" + shuffler = random.Random(seed) + order = [name for name in wanted for _ in range(owed[name])] + shuffler.shuffle(order) + return order + + +def unblinding_map(judging): + """Where the map from blind labels back to trials is kept.""" + return os.path.join(judging, "map.json") + + def blind_labels(order, after): """A blind label per trial in `order`, numbered from `after` + 1, so a root holding an earlier round's judgings never reuses one of theirs.""" @@ -841,7 +859,7 @@ def judge_trials(options, available, wanted): lib.print_verdict(False, "no trial judged") return 2 - bundles = os.path.join(judging, "bundles") + bundles = os.path.join(judging, BUNDLES) os.makedirs(bundles, exist_ok=True) # Shuffled with a recorded seed, so the order is reproducible and is not @@ -852,9 +870,7 @@ def judge_trials(options, available, wanted): # list is shuffled together, so its repeats are spread through the run # rather than made back to back. Each repeat is a separate blind label: it # is a separate reading of the same tree, and the report means them. - shuffler = random.Random(options.seed) - order = [name for name in wanted for _ in range(owed[name])] - shuffler.shuffle(order) + order = judging_order(wanted, owed, options.seed) labels = blind_labels(range(len(order)), highest_label(judging)) repeats = {} @@ -911,7 +927,7 @@ def judge_trials(options, available, wanted): # The unblinding map, written last and kept out of the bundles directory # the judge was pointed at. An earlier round's entries stay in it. - path = os.path.join(judging, "map.json") + path = unblinding_map(judging) mapping = {"seed": options.seed, "blind": {}, "repeats": {}} if os.path.isfile(path): with io.open(path, encoding="utf-8") as handle: @@ -1208,6 +1224,27 @@ def refuses(call): return checks +def order_checks(scratch): + """The judging order is the seed's alone, and the key stays out of the + judge's reach.""" + wanted = ["hybrid-1", "inline-1", "none-1", "reference-1", "skills-1"] + owed = {name: 3 for name in wanted} + first = judging_order(wanted, owed, 20260912) + judging = os.path.join(scratch, "order", "judge") + bundles = os.path.abspath(os.path.join(judging, BUNDLES)) + return [ + ("one seed gives one judging order", + first == judging_order(wanted, owed, 20260912) + and first != judging_order(wanted, owed, 1)), + ("the order is not the arms' order, and holds every repeat", + first != sorted(first) and sorted(first) == sorted( + name for name in wanted for _ in range(3))), + ("the unblinding map is written outside the bundles the judge reads", + not os.path.abspath(unblinding_map(judging)).startswith( + bundles + os.sep)), + ] + + def label_checks(scratch): """Blind labels continue past an earlier round's, and a judged trial is known by its canonical name.""" @@ -1333,6 +1370,7 @@ def self_test(): checks = bundle_checks(scratch) checks.extend(spec_checks(scratch)) checks.extend(label_checks(scratch)) + checks.extend(order_checks(scratch)) checks.extend(launch_checks(scratch)) checks.extend(backend_checks(scratch)) checks.extend(claim_checks(scratch)) diff --git a/tests/efficacy/score.py b/tests/efficacy/score.py index b7506f3..4d9afbf 100644 --- a/tests/efficacy/score.py +++ b/tests/efficacy/score.py @@ -1723,6 +1723,75 @@ def boot_checks(scratch, venv): ''' +def ruler_checks(scratch): + """Prove the rulers take the harness's configuration, and that a test + dependency the lock will not admit leaves coverage missing. + + The tools are stubbed: what is checked is the command each is given and + what is recorded when an install fails, not the tools themselves. + """ + called = [] + + def stub_module(venv, module, args, cwd=None, timeout=TOOL_TIMEOUT): + called.append((module, list(args))) + return {"failed": "stubbed", "status": 1, "stdout": "", "stderr": "", + "argv": [module] + list(args)} + + def refusing_pip(venv, *args, **kwargs): + return {"failed": None, "status": 1, "stdout": "", + "stderr": "ResolutionImpossible: ruff conflicts with the lock", + "argv": ["pip"] + list(args)} + + planted = os.path.join(scratch, "conflict") + os.makedirs(os.path.join(planted, "tests")) + with io.open(os.path.join(planted, "pyproject.toml"), "w", + encoding="utf-8") as handle: + handle.write(PLANTED_TEST_DEPENDENCIES) + saved = {name: globals()[name] for name in ("run_module", "pip")} + globals().update(run_module=stub_module, pip=refusing_pip) + try: + roots = [os.path.join(planted, "pkg")] + ruff_findings(planted, planted, roots, {}) + ruff_format(planted, planted, roots, {}) + mypy_errors(planted, planted, roots, {}) + conflicted = own_test_coverage(planted, planted, roots, {}) + finally: + globals().update(saved) + ruff_args = [args for module, args in called if module == "ruff"] + mypy_args = [args for module, args in called if module == "mypy"] + return [ + ("ruff and mypy take the harness's configuration, not the trial's", + len(ruff_args) == 2 and len(mypy_args) == 1 + and all(RUFF_CONFIG in args for args in ruff_args) + and MYPY_CONFIG in mypy_args[0]), + ("a test dependency the lock refuses leaves coverage missing", + conflicted.get("value") is None + and "would not install beside the scoring lock" + in (conflicted.get("missing") or "") + and "ResolutionImpossible" in (conflicted.get("missing") or "")), + ] + + +def adherence_checks(scratch): + """Prove the checklist holds its 13 items and reads the bare arm as it + reads any other.""" + planted = os.path.join(scratch, "adherence") + os.makedirs(planted) + scores = {"ruff": measured(0), "mypy": measured(0), + "ruff_format": measured(0), "coverage": measured({"line": 85}), + "complexity": measured({"over_15": 0}), + "discovery": {"roots": [os.path.join(planted, "src", "pkg")]}, + "structure": measured({"exception_bases": ["PkgError"], + "print_calls": [], "citations": [], + "logging": {"used": True, + "null_handler": True}})} + read = {arm: adherence(planted, dict(scores, arm=arm)) + for arm in ("none", "hybrid")} + return [("the checklist holds 13 items and reads none as any arm", + read["none"].get("total_items") == 13 + and read["none"] == read["hybrid"])] + + def coverage_checks(scratch): """Prove the coverage run installs what the trial's tests declare. @@ -1920,7 +1989,9 @@ def self_test(): + lock_checks() + html_checks() + readonly_checks(scratch) + lock_source_checks(scratch) + unrun_checks(scratch) + claim_checks(scratch) + security_checks(scratch) - + coverage_checks(scratch) + python_files_checks(scratch) + + coverage_checks(scratch) + ruler_checks(scratch) + + adherence_checks(scratch) + + python_files_checks(scratch) + scope_checks(scratch)) dropped = create_venv(os.path.join(scratch, "dropped")) drop_venv(dropped)