From f2ec8430ca349563b50bd89aeea25ddfba3b5a72 Mon Sep 17 00:00:00 2001 From: Mai Xuan Van Date: Tue, 22 Sep 2026 19:07:35 +0700 Subject: [PATCH] fix(audit): make the release-boundary check reproducible and stop it failing on its own fixture `tools/machine_semantic_audit.py` reported FAIL with 18 findings on a clean clone, and the committed receipt claimed PASS with 0 findings over 52 files while the tree holds 218. Three defects, each verified by measurement before the fix. 1. The audit flagged its own rights-cleared fixture. The 18 PNGs under `experiments/six_arm/dataset/images/` are synthetic and are not source-derived: all are 96x96 RGB with IDAT 27760 of 27648 raw bytes (compression ratio 0.996) and 9210-9215 distinct colours per 9216 pixels. That is incompressible noise; a page or figure crop compresses 5-50x and reuses colours heavily. Each file is content-bound by sha256 and byte size in `dataset/dataset_manifest.json` (all 18 verified, 0 mismatches), and that manifest declares the set a rights-cleared synthetic contract fixture, so untracking the images would break the fixture rather than improve the boundary. They are allow-listed instead, individually rather than by directory, so an unexpected 19th image in that directory still raises `unexpected_media`. 2. The receipt was hashed into its own digest, so it could never be accurate. Writing the receipt changed the digest it records; iterating write/audit four times produced four different digests and never converged. A committed receipt is therefore unsatisfiable by construction, which is why the stale one survived unnoticed. The receipt is now excluded from the digest input only. It is still scanned for forbidden strings and secrets like any other text file -- excluding it from scanning as well was tried first and rejected by mutation test (a forbidden token placed inside the receipt stopped being flagged). 3. A directory exclusion containing a separator could never match. The exclusion set is compared against `p.parts`, whose components never contain a slash, so the literal `"src/ecm_tqag.egg-info"` excluded nothing. After `pip install -e .` the egg-info files entered the digest: measured `2d0ac94d...` (218 files) clean versus `60140bec...` (224 files) built. A reviewer following README section 7 after installing the package computed a different digest from the committed receipt, so the receipt was irreproducible. Exclusions now match per path component via `EXCLUDED_PARTS`. The receipt is regenerated and now reproduces exactly, including after an editable install. Mutation-verified, because a check never observed red is not evidence: | mutation | expected | observed | | --- | --- | --- | | add a 19th undeclared PNG | FAIL | exit 1, `unexpected_media` on that file | | forbidden token in a new .md | FAIL | exit 1, `forbidden_baseline` | | forbidden token inside the receipt | FAIL | exit 1, flagged against the receipt | | create `src/ecm_tqag.egg-info/` (6 files) | digest unchanged | digest unchanged, 218 files | | create `.pytest_cache/junk.txt` | digest unchanged | digest unchanged | | remove every mutation | PASS | exit 0, 0 findings | CI steps reproduced in a fresh venv: `pytest` exit 0 (35 passed, 2 skipped); `ecm-tqag validate fixtures/packages` exit 0; audit exit 0, PASS, 0 findings. Not changed: `semantic_validation` stays `false`, and the audit still checks strings and file classes only. A PASS here means no unexpected media and no forbidden string was found, not that any semantic or rights claim was validated. --- machine-policy-audit.json | 4 +-- tools/machine_semantic_audit.py | 44 +++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/machine-policy-audit.json b/machine-policy-audit.json index 6cfaabb..91c97a7 100644 --- a/machine-policy-audit.json +++ b/machine-policy-audit.json @@ -1,8 +1,8 @@ { "audit_kind": "deterministic-string-and-boundary-check", - "checked_file_count": 52, + "checked_file_count": 218, "findings": [], - "repo_tree_digest": "e0bd715476dc3a06a4bccb915abb41bccd677dccc74cee64d66ab6bbe04dadeb", + "repo_tree_digest": "6dc0737daa52eaecc7106c87282917269fce0422075f4cab0bc634337f9f2fe6", "schema": "ecm-tqag.machine-policy-audit.v1", "semantic_validation": false, "status": "PASS" diff --git a/tools/machine_semantic_audit.py b/tools/machine_semantic_audit.py index 311d8d5..4186136 100644 --- a/tools/machine_semantic_audit.py +++ b/tools/machine_semantic_audit.py @@ -19,8 +19,48 @@ "secret": re.compile(r"(?:gho_|hf_[A-Za-z0-9]{20,}|sk-[A-Za-z0-9]{20,})"), "absolute_private_path": re.compile(r"/(?:home|workspace|Users)/[A-Za-z0-9_.-]+/"), } +# The committed audit receipt records this digest, so it cannot also be an input +# to it: hashing it in makes the digest change on every write, so no committed +# receipt could ever match and the file is unsatisfiable by construction. It is +# excluded from the digest ONLY -- it is still scanned for forbidden strings and +# secrets like any other text file. +RECEIPT="machine-policy-audit.json" +# Directory components never counted as repository content. Matching is per path +# component, so an entry containing a separator could never match: the previous +# "src/ecm_tqag.egg-info" literal silently excluded nothing, and the editable +# install's egg-info files entered the digest. A reviewer who follows README +# section 7 after `pip install -e .` therefore computed a different digest from +# the committed receipt, which made the receipt irreproducible. +EXCLUDED_PARTS={".git",".venv","build","dist","__pycache__",".pytest_cache", + "ecm_tqag.egg-info"} ALLOWED_MEDIA={ "fixtures/tiny-grid.png", # optional future synthetic fixture + # Rights-cleared synthetic contract fixture for the six-arm experiment. + # Verified synthetic, not source-derived: 96x96 RGB, IDAT 27760/27648 bytes + # (compression ratio 0.996) with 9210-9215 distinct colours per 9216 pixels + # -- incompressible noise, whereas a page or figure crop compresses 5-50x and + # reuses colours. Each file is content-bound by sha256 and byte size in + # experiments/six_arm/dataset/dataset_manifest.json, so untracking it would + # break that fixture. Listed individually on purpose: an unexpected new image + # in this directory must still raise unexpected_media. + "experiments/six_arm/dataset/images/synthetic_diagram_01.png", + "experiments/six_arm/dataset/images/synthetic_diagram_02.png", + "experiments/six_arm/dataset/images/synthetic_diagram_03.png", + "experiments/six_arm/dataset/images/synthetic_diagram_04.png", + "experiments/six_arm/dataset/images/synthetic_diagram_05.png", + "experiments/six_arm/dataset/images/synthetic_diagram_06.png", + "experiments/six_arm/dataset/images/synthetic_diagram_07.png", + "experiments/six_arm/dataset/images/synthetic_diagram_08.png", + "experiments/six_arm/dataset/images/synthetic_diagram_09.png", + "experiments/six_arm/dataset/images/synthetic_diagram_10.png", + "experiments/six_arm/dataset/images/synthetic_diagram_11.png", + "experiments/six_arm/dataset/images/synthetic_diagram_12.png", + "experiments/six_arm/dataset/images/synthetic_diagram_13.png", + "experiments/six_arm/dataset/images/synthetic_diagram_14.png", + "experiments/six_arm/dataset/images/synthetic_diagram_15.png", + "experiments/six_arm/dataset/images/synthetic_diagram_16.png", + "experiments/six_arm/dataset/images/synthetic_diagram_17.png", + "experiments/six_arm/dataset/images/synthetic_diagram_18.png", } def sha(p:Path)->str: @@ -31,7 +71,7 @@ def audit(repo:Path, manuscript:Path|None)->dict: roots=[repo] for root in roots: for p in sorted(root.rglob("*")): - if not p.is_file() or any(x in p.parts for x in {".git",".venv","build","dist","__pycache__",".pytest_cache","src/ecm_tqag.egg-info"}): continue + if not p.is_file() or any(part in EXCLUDED_PARTS for part in p.parts): continue rel=p.relative_to(repo).as_posix(); checked.append(rel) if rel == "tools/machine_semantic_audit.py": continue if p.suffix.lower() in MEDIA_SUFFIXES and rel not in ALLOWED_MEDIA: @@ -59,7 +99,7 @@ def audit(repo:Path, manuscript:Path|None)->dict: required=["machine-only","fallible machine semantic judgments","no external human annotator"] for phrase in required: if phrase.lower() not in text.lower(): findings.append({"rule":"missing_machine_only_disclosure","phrase":phrase,"file":"MANUSCRIPT"}) - return {"schema":"ecm-tqag.machine-policy-audit.v1","audit_kind":"deterministic-string-and-boundary-check","semantic_validation":False,"checked_file_count":len(checked),"findings":findings,"status":"PASS" if not findings else "FAIL","repo_tree_digest":hashlib.sha256("\n".join(f"{x}\0{sha(repo/x)}" for x in checked if not x.startswith("/") and (repo/x).is_file()).encode()).hexdigest()} + return {"schema":"ecm-tqag.machine-policy-audit.v1","audit_kind":"deterministic-string-and-boundary-check","semantic_validation":False,"checked_file_count":len(checked),"findings":findings,"status":"PASS" if not findings else "FAIL","repo_tree_digest":hashlib.sha256("\n".join(f"{x}\0{sha(repo/x)}" for x in checked if not x.startswith("/") and (repo/x).is_file() and x != RECEIPT).encode()).hexdigest()} def main()->int: ap=argparse.ArgumentParser(); ap.add_argument("--repo",type=Path,default=Path(".")); ap.add_argument("--manuscript",type=Path); ap.add_argument("--output",type=Path)