From 074ee339b21cfce0d3f505680b8f861682a31e89 Mon Sep 17 00:00:00 2001 From: le king fu Date: Sun, 25 Oct 2026 17:46:45 -0400 Subject: [PATCH 1/2] chore(review): check pattern classes and read multi-line fetch calls review-levels.py --check now sorts each row of the Haut table by its Condition column (always high when it starts with "toujours", conditional otherwise) and compares each class with the script: a pattern that moves from always to a condition on one side only fails the check. adds_network_call reads each hunk with its context lines, on the new and the old side: a fetch( split over two lines counts when either line is changed, the neighbour being changed or context and not matching alone. Calibration replayed on #14-#138: same level for every PR. Recorded in REVIEW.md. Fixes #143 Co-Authored-By: Claude Opus 5.5 --- REVIEW.md | 4 ++- scripts/review-levels.py | 76 ++++++++++++++++++++++++++++++---------- 2 files changed, 60 insertions(+), 20 deletions(-) diff --git a/REVIEW.md b/REVIEW.md index 4531e1a..e723cca 100644 --- a/REVIEW.md +++ b/REVIEW.md @@ -61,7 +61,9 @@ Tout le reste : écrans et composants de l'app et du site, traductions (`src/i18 ### Calibration -Rejouée le 2026-10-19 (#140) sur les 47 PR mergées de #14 à #138, avec `scripts/review-levels.py` (API Forgejo, lecture seule) ; `python3 scripts/review-levels.py --check` vérifie, sans réseau, que ses motifs sont ceux du tableau Haut. +Rejouée le 2026-10-19 (#140) sur les 47 PR mergées de #14 à #138, avec `scripts/review-levels.py` (API Forgejo, lecture seule) ; `python3 scripts/review-levels.py --check` vérifie, sans réseau, que ses motifs sont ceux du tableau Haut, chacun dans sa classe (« toujours » ou sous condition). + +Rejouée le 2026-10-25 (#143) sur les mêmes PR, après la lecture des `fetch(` sur deux lignes et du classement par condition : niveau identique PR par PR, aucun écart. De #139 à #161 (11 PR mergées), aucun écart non plus entre le script d'avant et celui-ci. | Ensemble | Bas | Normal | Haut | |---|---|---|---| diff --git a/scripts/review-levels.py b/scripts/review-levels.py index 14668d5..d8a9344 100755 --- a/scripts/review-levels.py +++ b/scripts/review-levels.py @@ -9,8 +9,10 @@ The first form reads the Forgejo API (token in $FORGEJO_TOKEN, else ~/.forgejo-token; read-only calls) and prints each merged PR of the range with its REVIEW.md level and the files that set it, then the distribution. --check compares the patterns of this script with the first column of the -Haut table of REVIEW.md and exits 1 if they differ: a PR that changes the -Niveaux section updates this script in the same diff. +Haut table of REVIEW.md, each in its class (a row whose Condition starts with +"toujours" is always high, any other row is conditional), and exits 1 if they +differ: a PR that changes the Niveaux section updates this script in the same +diff. The content conditions of the Haut table are approximated: app/_layout.tsx and app/(tabs)/settings.tsx (changed lines or hunk headers @@ -21,7 +23,10 @@ another key changed; version, overrides and ranges stay normal), lock files (a package name added or removed, a new origin, an integrity changed without a new version), all read as JSON at the merge base and at the merge commit; network calls (fetch to an absolute URL, or a base URL held by a constant or -a config field, in shipped code). +a config field, in shipped code). A fetch( split over two lines counts when +either line is changed, the other one being changed or context (#143); a +blank or comment line between the two breaks the pair. Removed lines count +like added ones. """ import itertools import json @@ -34,7 +39,7 @@ import urllib.request API = "https://git.lacompagniemaximus.com/api/v1/repos/maximus/simpl-liste" REVIEW_MD = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "REVIEW.md") -# REVIEW.md, table Haut: rows without a condition. +# REVIEW.md, table Haut: rows whose condition is "toujours". HIGH_ALWAYS = [ "src/lib/{authToken,logtoConfig,validation}.ts", "web/src/lib/{auth,logto,api}.ts", "web/src/middleware.ts", @@ -206,15 +211,35 @@ def app_json_beyond_version(merge_base, merged_sha): return norm(before) != norm(after) +FETCH_RE = re.compile(r"fetch\(\s*[`'\"]https?://") +BASE_URL_RE = re.compile(r"(?:\b(?:const|let|var)\s+\w+\s*=|^[+-]\s*\w+\s*:)\s*[`'\"]https?://") + + def adds_network_call(path, block): if not match(SHIPPED, path) or re.search(r"test", path): return False - for l in changed(block): - # fetch to an absolute URL, or a base URL held by a constant or a config - # field (a link in markup, href=..., does not count) - if re.search(r"fetch\(\s*[`'\"]https?://", l) or \ - re.search(r"(?:\b(?:const|let|var)\s+\w+\s*=|^[+-]\s*\w+\s*:)\s*[`'\"]https?://", l): - return True + for hunk in re.split(r"(?m)^(?=@@)", block)[1:]: + lines = [l for l in hunk.split("\n")[1:] if l[:1] in " +-"] + # each side of the hunk: the new file (context and added lines), then + # the old one (context and removed lines) + for mark in "+-": + side = [l for l in lines if l[:1] in (" ", mark)] + for i, l in enumerate(side): + if l[:1] != mark or not meaningful(l[1:]): + continue + # fetch to an absolute URL, or a base URL held by a constant or a + # config field (a link in markup, href=..., does not count). The + # base URL regex reads the raw line, its prefix anchors the field. + if FETCH_RE.search(l[1:]) or BASE_URL_RE.search(l): + return True + # a fetch( split over two lines: the neighbour, changed or + # context, must not match on its own + for a, b in ((side[i - 1] if i else None, l), (l, side[i + 1] if i + 1 < len(side) else None)): + if a is None or b is None: + continue + other = b if a is l else a + if FETCH_RE.search(a[1:].strip() + " " + b[1:].strip()) and not FETCH_RE.search(other[1:]): + return True return False @@ -262,21 +287,34 @@ CONDITIONAL = {LAYOUT, SETTINGS, APP_JSON, "REVIEW.md"} | PACKAGE_JSON | LOCKS def check(): - """Compare this script's patterns with the first column of the Haut table.""" + """Compare this script's patterns with the first column of the Haut table, + each in its class: always high when the Condition column starts with + "toujours", conditional otherwise (shipped code is conditional: network call).""" text = open(REVIEW_MD, encoding="utf-8").read() table = text.split("### Haut", 1)[1].split("\n\n", 2)[1] - documented = set() + documented = {"always": set(), "conditional": set()} for row in table.split("\n"): if not row.startswith("| ") or row.startswith("| Motif") or row.startswith("| fichier ajouté"): continue - documented.update(re.findall(r"`([^`]+)`", row.split(" | ")[0])) - coded = set(HIGH_ALWAYS) | set(SHIPPED) | CONDITIONAL - for label, extra in (("REVIEW.md only", documented - coded), ("script only", coded - documented)): - for pattern in sorted(extra): - print(f"{label}: {pattern}") - if documented != coded: + cells = row.split(" | ") + cls = "always" if cells[1].strip().startswith("toujours") else "conditional" + documented[cls].update(re.findall(r"`([^`]+)`", cells[0])) + coded = {"always": set(HIGH_ALWAYS), "conditional": set(SHIPPED) | CONDITIONAL} + gaps = 0 + for side, sets in (("REVIEW.md", documented), ("script", coded)): + for pattern in sorted(sets["always"] & sets["conditional"]): + print(f"both always and conditional in {side}: {pattern}") + gaps += 1 + for cls in ("always", "conditional"): + for label, extra in (("REVIEW.md only", documented[cls] - coded[cls]), + ("script only", coded[cls] - documented[cls])): + for pattern in sorted(extra): + print(f"{cls} in {label}: {pattern}") + gaps += 1 + if gaps: return 1 - print(f"ok: {len(coded)} patterns, identical to the Haut table of REVIEW.md") + print(f"ok: {len(coded['always'])} always and {len(coded['conditional'])} conditional patterns, " + "identical to the Haut table of REVIEW.md") return 0 -- 2.52.0 From d2212c3e682ff1accb3a3ba9de167890c881aee0 Mon Sep 17 00:00:00 2001 From: le king fu Date: Sun, 25 Oct 2026 19:26:55 -0400 Subject: [PATCH 2/2] chore(review): stop counting a removed network call as high adds_network_call now reads only the new side of each hunk (context and added lines): removing a fetch, a base URL constant or a config field no longer makes a PR high. The Haut table only names an added call or a change to what an existing call sends; the script was stricter. Calibration replayed on #14-#161: same level for every PR. Refs #143 Co-Authored-By: Claude Opus 5.5 --- REVIEW.md | 2 +- scripts/review-levels.py | 42 +++++++++++++++++++--------------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/REVIEW.md b/REVIEW.md index e723cca..d78e342 100644 --- a/REVIEW.md +++ b/REVIEW.md @@ -63,7 +63,7 @@ Tout le reste : écrans et composants de l'app et du site, traductions (`src/i18 Rejouée le 2026-10-19 (#140) sur les 47 PR mergées de #14 à #138, avec `scripts/review-levels.py` (API Forgejo, lecture seule) ; `python3 scripts/review-levels.py --check` vérifie, sans réseau, que ses motifs sont ceux du tableau Haut, chacun dans sa classe (« toujours » ou sous condition). -Rejouée le 2026-10-25 (#143) sur les mêmes PR, après la lecture des `fetch(` sur deux lignes et du classement par condition : niveau identique PR par PR, aucun écart. De #139 à #161 (11 PR mergées), aucun écart non plus entre le script d'avant et celui-ci. +Rejouée le 2026-10-25 (#143) sur les mêmes PR, après la lecture des `fetch(` sur deux lignes, du classement par condition, et sans plus compter le retrait d'un appel réseau (décision de Max du 2026-10-25, `/pr-brief` de la PR #163) : niveau identique PR par PR, aucun écart. De #139 à #161 (11 PR mergées), aucun écart non plus entre le script d'avant et celui-ci. | Ensemble | Bas | Normal | Haut | |---|---|---|---| diff --git a/scripts/review-levels.py b/scripts/review-levels.py index d8a9344..ce8a980 100755 --- a/scripts/review-levels.py +++ b/scripts/review-levels.py @@ -25,8 +25,9 @@ a new version), all read as JSON at the merge base and at the merge commit; network calls (fetch to an absolute URL, or a base URL held by a constant or a config field, in shipped code). A fetch( split over two lines counts when either line is changed, the other one being changed or context (#143); a -blank or comment line between the two breaks the pair. Removed lines count -like added ones. +blank or comment line between the two breaks the pair. Only the new side of +the diff is read: removing a call does not make a PR high (decision of Max, +2026-10-25, /pr-brief of PR #163). """ import itertools import json @@ -212,34 +213,31 @@ def app_json_beyond_version(merge_base, merged_sha): FETCH_RE = re.compile(r"fetch\(\s*[`'\"]https?://") -BASE_URL_RE = re.compile(r"(?:\b(?:const|let|var)\s+\w+\s*=|^[+-]\s*\w+\s*:)\s*[`'\"]https?://") +BASE_URL_RE = re.compile(r"(?:\b(?:const|let|var)\s+\w+\s*=|^\+\s*\w+\s*:)\s*[`'\"]https?://") def adds_network_call(path, block): if not match(SHIPPED, path) or re.search(r"test", path): return False for hunk in re.split(r"(?m)^(?=@@)", block)[1:]: - lines = [l for l in hunk.split("\n")[1:] if l[:1] in " +-"] - # each side of the hunk: the new file (context and added lines), then - # the old one (context and removed lines) - for mark in "+-": - side = [l for l in lines if l[:1] in (" ", mark)] - for i, l in enumerate(side): - if l[:1] != mark or not meaningful(l[1:]): + # the new side of the hunk: context and added lines + side = [l for l in hunk.split("\n")[1:] if l[:1] in " +"] + for i, l in enumerate(side): + if l[:1] != "+" or not meaningful(l[1:]): + continue + # fetch to an absolute URL, or a base URL held by a constant or a + # config field (a link in markup, href=..., does not count). The + # base URL regex reads the raw line, its prefix anchors the field. + if FETCH_RE.search(l[1:]) or BASE_URL_RE.search(l): + return True + # a fetch( split over two lines: the neighbour, added or context, + # must not match on its own + for a, b in ((side[i - 1] if i else None, l), (l, side[i + 1] if i + 1 < len(side) else None)): + if a is None or b is None: continue - # fetch to an absolute URL, or a base URL held by a constant or a - # config field (a link in markup, href=..., does not count). The - # base URL regex reads the raw line, its prefix anchors the field. - if FETCH_RE.search(l[1:]) or BASE_URL_RE.search(l): + other = b if a is l else a + if FETCH_RE.search(a[1:].strip() + " " + b[1:].strip()) and not FETCH_RE.search(other[1:]): return True - # a fetch( split over two lines: the neighbour, changed or - # context, must not match on its own - for a, b in ((side[i - 1] if i else None, l), (l, side[i + 1] if i + 1 < len(side) else None)): - if a is None or b is None: - continue - other = b if a is l else a - if FETCH_RE.search(a[1:].strip() + " " + b[1:].strip()) and not FETCH_RE.search(other[1:]): - return True return False -- 2.52.0