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 <noreply@anthropic.com>
This commit is contained in:
parent
58c350c2c8
commit
074ee339b2
2 changed files with 60 additions and 20 deletions
|
|
@ -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 |
|
||||
|---|---|---|---|
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue