diff options
| author | Morgan Lunt <morganl@anthropic.com> | 2026-09-24 21:27:42 -0700 |
|---|---|---|
| committer | Morgan Lunt <morganl@anthropic.com> | 2026-09-24 21:27:42 -0700 |
| commit | d3a40f72165764888f9a57a3e93db86e88f8e063 (patch) | |
| tree | 89f5fc7b623dfe09b6d994aa608c291fa35da01d /plugins/code-modernization | |
| parent | ff833bd7231262a8521ab3728c5625dc6c4f4a1d (diff) | |
code-modernization: approve a difference once per input
An independent check of a rewritten batch job found differences on two new
inputs of one family (a blank numeric field the rewrite rejects on purpose
and the old program reads as zero). Each input has several output files, so
accepting the deviation meant three or four hand-written entries per input.
A top-level "approvedInputs": {"F23": "reason"} in a cases file now approves
every case that shares that input label. A reason is still required (blank
approves nothing), a case's own reason wins, a missing file is never turned
into a pass, and the result still lists the difference as approved.
Diffstat (limited to 'plugins/code-modernization')
3 files changed, 26 insertions, 5 deletions
diff --git a/plugins/code-modernization/commands/modernize-verify.md b/plugins/code-modernization/commands/modernize-verify.md index e189d201..a1129954 100644 --- a/plugins/code-modernization/commands/modernize-verify.md +++ b/plugins/code-modernization/commands/modernize-verify.md @@ -122,8 +122,8 @@ a rule is wrong, say so and leave the file as it is. Refresh the report (`python3 "${CLAUDE_PLUGIN_ROOT}/scripts/build_report.py" $system`, a convenience: if it fails or `python3` is missing, say so in one line and carry on), then name the next step. **PARTLY PROVEN or NOT PROVEN:** turn each reason, in order, into a command. A failure caused by this machine: run the suite where the tool works (a terminal outside the sandbox, or CI), then run this -command again. A difference the notes call intended: a person records it (`approvedDifference` in the case, or the table in -`BASELINE.md`); you never do. P0 rules no test names: add the rule id to each test that pins it, then run this again. Any other failing +command again. A difference the notes call intended: a person records it (once per input with `"approvedInputs": {"F23": "why"}` at the top of +`fresh-cases.json`, or `approvedDifference` in one case, or the table in `BASELINE.md`); you never do. P0 rules no test names: add the rule id to each test that pins it, then run this again. Any other failing test or difference: `/code-modernization:modernize-transform $system <module>`, or for an uplift `/code-modernization:modernize-uplift $system` (also for a baseline typed by hand, which is measured again in its Step 4, and for a silent delta no test names, which gets a characterization test there). Removed or changed test files are a person's review, never yours to undo. diff --git a/plugins/code-modernization/scripts/compare.py b/plugins/code-modernization/scripts/compare.py index 137007f1..4a1e4429 100644 --- a/plugins/code-modernization/scripts/compare.py +++ b/plugins/code-modernization/scripts/compare.py @@ -23,6 +23,10 @@ position of a difference and a variable-length match still compares equal. A cas differs different; the first difference is recorded (a person may approve it: differs-approved) missing a file is absent, unreadable or outside the cases folder. Never a pass. +A person who accepts a difference records it on the case (`"approvedDifference": "why"`), or once for every +case that shares an `input` label with a top-level `"approvedInputs": {"F23": "why"}`. A reason is required either way, and an approved difference is still listed as a +difference in the result. + Numbers that a run legitimately prints a little differently (floating-point results from another compiler or math library) can be compared within a declared tolerance, per case or for all cases: @@ -262,14 +266,15 @@ def rel_to(path, folder): return path -def judge(case, index, base, out_dir, allow_outside, default_tolerance=None): +def judge(case, index, base, out_dir, allow_outside, default_tolerance=None, approved_inputs=None): """-> (case record, legacy bytes or None, masks).""" cid = clip(str(case.get("id") or "C%02d" % (index + 1)), 80) masks = parse_masks(case.get("mask"), cid) tol = parse_tolerance(case["tolerance"] if "tolerance" in case else default_tolerance, cid) rec = {"id": cid, "title": clip(case.get("title"), 300), "verdict": "missing", "reason": "", "legacyPath": "", "newPath": "", "legacySha256": "", "newSha256": "", - "masked": [m[2] for m in masks], "approvedDifference": clip(case.get("approvedDifference"), 500), + "masked": [m[2] for m in masks], + "approvedDifference": clip(case.get("approvedDifference") or (approved_inputs or {}).get(str(case.get("input", "")), ""), 500), "note": clip(case.get("note"), 500)} data, problems = {}, [] for side in ("legacy", "new"): @@ -388,10 +393,11 @@ def run(cases_path, out_path=None, allow_outside=False): base = os.path.dirname(os.path.abspath(cases_path)) out_dir = os.path.dirname(os.path.abspath(out_path)) if out_path else base records, items, ids = [], [], set() + approved = {str(k): v for k, v in spec["approvedInputs"].items() if isinstance(v, str) and v.strip()} if isinstance(spec.get("approvedInputs"), dict) else {} for i, case in enumerate(spec["cases"]): if not isinstance(case, dict): raise InputError("case %d is not an object" % (i + 1)) - rec, data, masks, tol = judge(case, i, base, out_dir, allow_outside, spec.get("tolerance")) + rec, data, masks, tol = judge(case, i, base, out_dir, allow_outside, spec.get("tolerance"), approved) if rec["id"] in ids: raise InputError("duplicate case id %r" % rec["id"]) ids.add(rec["id"]) diff --git a/plugins/code-modernization/scripts/tests/test_compare_tolerance.py b/plugins/code-modernization/scripts/tests/test_compare_tolerance.py index 648cc76f..1bc1300a 100644 --- a/plugins/code-modernization/scripts/tests/test_compare_tolerance.py +++ b/plugins/code-modernization/scripts/tests/test_compare_tolerance.py @@ -121,6 +121,21 @@ class ToleranceTests(unittest.TestCase): res = self.run_cases([self.case("a", legacy, new, tolerance=TOL)]) self.assertEqual(res["cases"][0]["verdict"], "differs") + def test_an_input_can_be_approved_once_for_every_case_that_shares_its_label(self): + cases = [self.case("F23-a", b"one\n", b"two\n", input="F23"), self.case("F23-b", b"x\n", b"y\n", input="F23"), + self.case("F24-a", b"p\n", b"q\n", input="F24"), self.case("F25-a", b"same\n", b"same\n", input="F25")] + res = self.run_cases(cases, approvedInputs={"F23": "system owner accepts deviation 4", "F25": " ", "F99": "no such input"}) + verdicts = {r["id"]: r["verdict"] for r in res["cases"]} + self.assertEqual(verdicts, {"F23-a": "differs-approved", "F23-b": "differs-approved", "F24-a": "differs", "F25-a": "same"}) + self.assertEqual(res["totals"]["differsApproved"], 2) + self.assertIn("system owner accepts deviation 4", res["cases"][0]["reason"]) + self.assertEqual(res["cases"][2]["approvedDifference"], "") # a blank reason approves nothing + # a case's own reason wins, and a per-input approval never turns a missing file into a pass + own = self.run_cases([self.case("G1", b"a\n", b"b\n", input="G", approvedDifference="own reason"), dict(self.case("G2", b"a\n", b"a\n", input="G"), new="new/nothing")], + approvedInputs={"G": "input reason"}) + self.assertEqual(own["cases"][0]["approvedDifference"], "own reason") + self.assertEqual(own["cases"][1]["verdict"], "missing") + def test_masks_and_tolerance_work_together(self): res = self.run_cases([self.case("a", b"at 2026-09-24 10:00:00 value 2.0000000001\n", b"at 2027-01-01 11:11:11 value 2.0000000002\n", mask=[{"regex": r"\d{4}-\d\d-\d\d \d\d:\d\d:\d\d", "why": "run time"}], tolerance=TOL)]) |
