From 628864937ff09136fa195505320eca959b73c3bd Mon Sep 17 00:00:00 2001
From: le king fu
Date: Sat, 24 Oct 2026 21:51:27 -0400
Subject: [PATCH] fix(scripts): read comments by extension, lock origins by
canonical form (#476)
meaningful() now depends on the file extension: in .rs, .ts, .tsx and .js
only a line that starts with // is a comment (// @ts- and /// /-/-.tgz for the key
and version that package-lock.json gives at the PR head (read from the
API only when the diff adds a resolved line). A tarball of another package
on registry.npmjs.org, or another index on github.com, used to pass.
CONSENT_FILES adds the Feedback Hub consent (LogViewerCard.tsx,
FeedbackConsentDialog.tsx), and a fetchPrice( added outside
PriceFetchControl.tsx and the tests is high. is_test() replaces the
substring match on "test", which also skipped DownloadLatestButton.tsx.
PROBES take the hunks of a synthetic diff: one probe per "toujours"
pattern that no PR of #344-#452 exercises, an attribute and a comment
added to lib.rs, both lock origins and a canonical bump, both new consent
files, a new fetchPrice caller and a test that calls it. A lock probe's
hunk covers the whole file, its post-image being the lock at the head.
The docstring lists what the script does not model, and says that a PR's
level is read in REVIEW.md, never in its output.
Co-Authored-By: Claude Opus 5.5
---
scripts/review-levels.py | 256 ++++++++++++++++++++++++++++++---------
1 file changed, 200 insertions(+), 56 deletions(-)
diff --git a/scripts/review-levels.py b/scripts/review-levels.py
index 470ee1b..54ef75f 100755
--- a/scripts/review-levels.py
+++ b/scripts/review-levels.py
@@ -11,16 +11,38 @@ with its trial level (pilot document, section 4.3) and its REVIEW.md level,
then the distributions for the 39 reference PRs and for the whole range
(a set with no PR in the range is skipped).
--check compares the patterns of this script with the first column of the
-Haut table of REVIEW.md, runs the offline PROBES (a path and its expected
-level), and exits 1 on any difference: a PR that changes the Niveaux
-section updates this script in the same diff.
+Haut table of REVIEW.md, runs the offline PROBES (a path, the hunks of a
+synthetic diff, the expected level), and exits 1 on any difference: a PR
+that changes the Niveaux section updates this script in the same diff.
+--check does not prove the conditions of the table: they stay with the
+high-level review.
-The content conditions of the Haut table are approximated from the diff:
-lib.rs (only generate_handler![] entries are exempt), Tauri configuration
-and manifests (only the app's version is exempt), lock files (a package
-added or removed, an origin changed), check workflows (a change that can
-turn a failing check green, read against the PR's merge base), network
-calls (reqwest in Rust, fetch to an absolute URL in TS), consent files.
+A PR's level is read in REVIEW.md, never in this script's output (neither
+/pr-review, #457, nor the pilot, #458, runs it on an open PR): the content
+conditions of the Haut table are only approximated from the diff.
+- Comments, by file extension: a line that starts with // in .rs, .ts, .tsx
+ and .js (// @ts- and /// {t("feedback.consent.body")}
\n+ {t("feedback.consent.short")}
', "haut"),
+ ("src/components/balance/SnapshotLineRow.tsx",
+ '@@ -1 +1,2 @@\n import { prices } from "../../services/balance.service";\n'
+ '+void prices.fetchPrice(symbol, date);', "haut"),
+ ("src/services/balance.service.test.ts",
+ '@@ -1 +1,2 @@\n import { prices } from "./balance.service";\n'
+ '+const result = await prices.fetchPrice("AAPL", "2026-04-25");', "normal"),
]
+def image(hunks, post):
+ """The post-image (at the head) or the pre-image (at the base) of a probe's hunks."""
+ keep = "+" if post else "-"
+ return "\n".join(l[1:] for l in (hunks or "").split("\n") if l[:1] in (" ", keep))
+
+
def check():
"""Compare this script's patterns with the first column of the Haut table, then run PROBES."""
text = open(REVIEW_MD, encoding="utf-8").read()
@@ -358,8 +500,10 @@ def check():
for pattern in sorted(extra):
print(f"{label}: {pattern}")
failed = documented != coded
- for path, want in PROBES:
- got = review_level(0, [{"filename": path, "status": "changed"}], "", None)[0]
+ for path, hunks, want in PROBES:
+ diff = f"diff --git a/{path} b/{path}\n--- a/{path}\n+++ b/{path}\n{hunks}\n" if hunks else ""
+ got = review_level(0, [{"filename": path, "status": "changed"}], diff, "base", "head",
+ lambda p, ref, h=hunks: image(h, ref == "head"))[0]
if got != want:
print(f"probe: {path} is {got}, expected {want}")
failed = True
@@ -393,9 +537,9 @@ def main():
files += fb
fpage += 1
diff = get(f"/pulls/{n}.diff", raw=True).decode("utf-8", "replace")
- merge_base = get(f"/pulls/{n}")["merge_base"]
+ pr = get(f"/pulls/{n}")
trial = trial_level([f["filename"] for f in files])
- level, triggers = review_level(n, files, diff, merge_base)
+ level, triggers = review_level(n, files, diff, pr["merge_base"], pr["head"]["sha"])
rows.append((n, trial, level, triggers))
print(f"#{n}\t{'ref' if n in REF39 else ' '}\t{trial}\t{level}\t{'; '.join(triggers)}")
for label, keep in (("39 reference PRs", lambda n: n in REF39), (f"{len(rows)} PRs #{first}-#{last}", lambda n: True)):