REVIEW.md: Haut table conditions (canonical locks, consents, hooks) and the limits of the calibration script (#476) #499
2 changed files with 238 additions and 65 deletions
18
REVIEW.md
18
REVIEW.md
|
|
@ -15,30 +15,32 @@ Le niveau fixe la profondeur de la revue, que `/pr-review` règle pour chaque ni
|
|||
|
||||
Motifs : chemins depuis la racine. `*` ne traverse jamais un `/` ; `**/` vaut zéro, un ou plusieurs dossiers (`**/*.md` couvre `CLAUDE.md`, à la racine) ; `{a,b}` liste des variantes.
|
||||
|
||||
Commentaire, là où une condition dit « hors commentaires » : une ligne qui commence par `//` dans un fichier `.rs`, `.ts`, `.tsx` ou `.js`, sauf `// @ts-…` et `/// <reference …>`, qui agissent sur la compilation (un attribut `#[…]` ou `#![…]` est du code) ; une ligne qui commence par `#` dans un fichier `.toml`, `.yml` ou `.sh`, sauf un shebang `#!` ; aucune ligne d'un `.json`, d'un `.md` ou d'un fichier d'une autre extension.
|
||||
|
||||
### Haut
|
||||
|
||||
| Motif | Condition | Zone |
|
||||
|---|---|---|
|
||||
| `src-tauri/src/database/**` | toujours | Migrations, profils et données |
|
||||
| `src-tauri/src/lib.rs` | sauf si le diff se limite à des entrées de `generate_handler![…]` ou au module `tests` | Migrations (`migrations()`), plugins, deep link OAuth |
|
||||
| `src-tauri/src/lib.rs` | sauf si le diff, hors commentaires, se limite à des entrées de `generate_handler![…]` ou au module `tests` | Migrations (`migrations()`), plugins, deep link OAuth |
|
||||
| `src-tauri/src/commands/profile_commands.rs` | toujours | Migrations, profils et données |
|
||||
| `src-tauri/src/commands/{license_commands,entitlements,auth_commands,token_store,account_cache}.rs`, `src/services/{licenseService,authService}.ts`, `.claude/skills/issue-license/**` | toujours | Jetons, licence et édition |
|
||||
| `src-tauri/src/commands/balance_commands.rs` | le diff touche `fetch_price` ou la lecture du jeton d'activation | Jetons, licence et édition |
|
||||
| `src-tauri/src/commands/export_import_commands.rs` | toujours | Jetons, licence et édition (export chiffré) |
|
||||
| `src-tauri/src/commands/feedback_commands.rs`, `src/services/feedbackService.ts` | toujours | Vie privée |
|
||||
| code livré : `src/**`, `src-tauri/src/**`, `index.html`, `public/**` | le diff ajoute un appel réseau, change ce qu'un appel existant envoie (dont ses champs et leurs valeurs, et la façon dont les lignes du Journal partent avec une rétroaction : capture par `initLogCapture`, filtre et nombre par `getRecentErrorLogs`, composition dans `FeedbackDialog.tsx` ; hors le texte d'une ligne du Journal, nouvelle ou modifiée, qui relève des règles de la zone Vie privée à tout niveau : un fichier, jamais son dossier, et aucune donnée financière), ouvre une URL qui porte une donnée de l'utilisateur (donnée financière, identifiant, contenu d'un profil, ligne du Journal), ou retire ou contourne un consentement (celui des cours vit côté front : `src/components/balance/PriceFetchControl.tsx`, `src/components/settings/PriceFetchConsentToggle.tsx`) | Vie privée |
|
||||
| code livré : `src/**`, `src-tauri/src/**`, `index.html`, `public/**` | le diff ajoute un appel réseau, change ce qu'un appel existant envoie (dont ses champs et leurs valeurs, et la façon dont les lignes du Journal partent avec une rétroaction : capture par `initLogCapture`, filtre et nombre par `getRecentErrorLogs`, composition dans `FeedbackDialog.tsx` ; hors le texte d'une ligne du Journal, nouvelle ou modifiée, qui relève à tout niveau des règles de la zone Vie privée), ouvre une URL qui porte une donnée de l'utilisateur (donnée financière, identifiant, contenu d'un profil, ligne du Journal), ou retire ou contourne un consentement. L'app en a deux, tous deux côté front. Celui des cours vit dans `src/components/balance/PriceFetchControl.tsx` et `src/components/settings/PriceFetchConsentToggle.tsx`, et l'unique appel de `prices.fetchPrice`, dans `PriceFetchControl.tsx`, passe derrière lui : un appel ajouté ailleurs, hors des tests, est haut. Celui du Feedback Hub vit dans `openFeedback` de `src/components/settings/LogViewerCard.tsx`, seul chemin vers `FeedbackDialog`, et dans `src/components/settings/FeedbackConsentDialog.tsx` | Vie privée |
|
||||
| `src-tauri/capabilities/**` | toujours | Vie privée |
|
||||
| `src-tauri/{tauri*.conf.json*,Tauri*.toml}` | sauf si le diff se limite au champ `"version"` ; un fichier propre à une plateforme est fusionné avec `tauri.conf.json` | Vie privée (CSP), Release (updater, `beforeBuildCommand`) |
|
||||
| `.forgejo/workflows/release.yml`, `scripts/build-latest-json*`, `scripts/check-latest-json.jq`, `.claude/skills/release/scripts/**` | toujours | Release et mise à jour |
|
||||
| `src-tauri/build.rs`, `{vite,vitest,postcss}.config.*`, `.postcssrc*`, `.npmrc`, `**/rust-toolchain*`, `Cargo.{toml,lock}` à la racine | toujours | Release et mise à jour, CI et gardes (lu ou exécuté par le build de la release ou par `npm test`) |
|
||||
| fichier à la racine du dépôt ou directement dans `src-tauri/`, hors `*.md` | ajouté, renommé ou supprimé, comme tout fichier d'un dossier caché nouveau : une configuration nouvelle peut changer le build ou la CI sans motif qui la nomme | Release et mise à jour, CI et gardes |
|
||||
| `src-tauri/Cargo.toml`, `package.json` | sauf si le diff se limite au champ `version` de l'app (dépendances, features dont `dev-override`, `overrides`, scripts) | Dépendances ; Release pour les `scripts` de `package.json` |
|
||||
| `src-tauri/Cargo.lock`, `package-lock.json` | le diff ajoute ou retire un paquet (un bloc `[[package]]` dont la ligne `name =` apparaît ou disparaît, une seconde version d'un crate comprise ; une clé `"node_modules/<nom>"` qui apparaît ou disparaît), ou change l'origine d'un paquet : hôte ou schéma de `source` (Cargo) ou de `resolved` (npm), avec ou sans nouvelle version, ou `checksum`, `integrity` changés sans nouvelle version | Dépendances |
|
||||
| `src-tauri/Cargo.toml`, `package.json` | sauf si le diff, hors commentaires, se limite au champ `version` de l'app (dépendances, features dont `dev-override`, `overrides`, scripts) | Dépendances ; Release pour les `scripts` de `package.json` |
|
||||
| `src-tauri/Cargo.lock`, `package-lock.json` | le diff ajoute ou retire un paquet (un bloc `[[package]]` dont la ligne `name =` apparaît ou disparaît, une seconde version d'un crate comprise ; une clé `"node_modules/<nom>"` qui apparaît ou disparaît), ou change l'origine d'un paquet, avec ou sans nouvelle version : une `source` autre que l'index crates.io (`registry+https://github.com/rust-lang/crates.io-index`), un `resolved` hors de la forme canonique de sa clé et de sa version (`https://registry.npmjs.org/<nom>/-/<nom court>-<version>.tgz`, où `<nom>` suit le dernier `node_modules/` de la clé et `<nom court>` est ce nom sans sa portée `@…/`), ou un `checksum` ou un `integrity` changés sans nouvelle version | Dépendances |
|
||||
| `**/.cargo/**` | toujours | Dépendances |
|
||||
| `.forgejo/workflows/**` | fichier ajouté, ou diff qui ajoute une référence à `secrets` ou un déclencheur `pull_request_target`, qui exécute la définition de la base avec ses secrets pour toute PR, forks compris | CI et gardes |
|
||||
| `.forgejo/workflows/audit.yml` | le diff change une ligne active : sans déclencheur `pull_request`, il tourne pour la première fois sur `main` | CI et gardes |
|
||||
| `.forgejo/workflows/{check-rust,check-frontend}.yml` | le diff peut faire passer au vert ce qui échouait, par exemple : déclencheur retiré ou restreint (`paths`, `paths-ignore`, `branches`, `schedule`) ; étape de verdict modifiée ou retirée (`npm ci`, `npm run build`, `npm test`, `cargo check`, `cargo test`, `Verify …`, `cargo audit`) ; `continue-on-error` ou `\|\| true` ajouté ; étape `run:` ajoutée qui écrit `$GITHUB_ENV`, `$GITHUB_PATH` ou un fichier du dépôt ; action `uses:` ajoutée, hors cache ; étape d'installation modifiée (toolchain, binaire placé dans le `PATH`) ; `if:`, `defaults:`, `permissions:`, `env:` ou `container:` modifiés | CI et gardes |
|
||||
| `.claude/settings.json`, `.mcp.json` | toujours : hooks, permissions et serveurs MCP décident de ce que les agents exécutent sur le poste, sans CI pour le voir | CI et gardes |
|
||||
| `.claude/settings.json`, `.mcp.json` | toujours : hooks, permissions et serveurs MCP décident de ce que les agents exécutent sur le poste, sans CI pour le voir. Un fichier qu'ils font exécuter (script d'un hook, commande d'un serveur MCP) est haut comme eux, où qu'il soit dans le dépôt : c'est l'un de ces deux fichiers qui le nomme | CI et gardes |
|
||||
| `REVIEW.md` | le diff touche la section « Niveaux » | Règles de revue |
|
||||
|
||||
Restent au moins normaux, et leurs règles de zone s'appliquent quand même :
|
||||
|
|
@ -60,7 +62,7 @@ Tout le reste : code applicatif et tests, traductions (`src/i18n/locales/*.json`
|
|||
|
||||
### Calibration
|
||||
|
||||
Établie le 2026-10-17 (#456) sur les PR mergées de #344 à #452 : les 39 PR de référence du document de départ du pilote, dont la liste est figée dans la PR qui ferme #456, et la plage complète, alors 51 PR. Rejouée le 2026-10-24 (#462) sur la même plage, qui compte 52 PR depuis le merge de #450 le 2026-10-18.
|
||||
Établie le 2026-10-17 (#456) sur les PR mergées de #344 à #452 : les 39 PR de référence du document de départ du pilote, dont la liste est figée dans la PR qui ferme #456, et la plage complète, alors 51 PR. Rejouée le 2026-10-24 (#462) sur la même plage, qui compte 52 PR depuis le merge de #450 le 2026-10-18, puis le même jour par #476, à l'identique : même niveau et mêmes déclencheurs pour chacune des 52.
|
||||
|
||||
| Ensemble | Bas | Normal | Haut |
|
||||
|---|---|---|---|
|
||||
|
|
@ -68,10 +70,12 @@ Tout le reste : code applicatif et tests, traductions (`src/i18n/locales/*.json`
|
|||
| 39 PR de référence, ces motifs | 3 | 28 | 8 (21 %, pour une cible de 20 %) |
|
||||
| 52 PR de la plage, ces motifs | 6 | 34 | 12 (23 %) |
|
||||
|
||||
Niveau haut sur les 52 : licence (#359, #364, #366, #368, #386, #387, #388), migrations et profils (#394, #436), release (#414, #416, #418) ; parmi les 39 de référence, #386, #387, #388, #394, #414, #416, #418 et #436. L'écart à la cible est justifié dans la PR qui ferme #456, qui consigne aussi le niveau de chaque PR. Le script qui les calcule est `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 et que ses sondes donnent le niveau attendu : `.claude/skills/release/scripts/verify-release.sh` haut, `.claude/skills/release/SKILL.md` normal. Une même faute de frappe dans le tableau et dans le script passerait la comparaison, et le rejeu ne la verrait pas sur la ligne Release : chaque PR de la plage qui touche `verify-release.sh` touche aussi `release.yml`.
|
||||
Niveau haut sur les 52 : licence (#359, #364, #366, #368, #386, #387, #388), migrations et profils (#394, #436), release (#414, #416, #418) ; parmi les 39 de référence, #386, #387, #388, #394, #414, #416, #418 et #436. L'écart à la cible est justifié dans la PR qui ferme #456, qui consigne aussi le niveau de chaque PR. Le script qui les calcule est `scripts/review-levels.py` (API Forgejo, lecture seule). Il n'approche les conditions qu'en partie, et sa docstring liste ses écarts : commentaires reconnus par l'extension du fichier, module `tests` de `lib.rs` non exempté, origine d'un paquet jugée sur la forme canonique de sa `source` ou de son `resolved`, consentement repéré par mots-clés et par un `fetchPrice(` ajouté hors de `PriceFetchControl.tsx`, fichiers que font exécuter `.claude/settings.json` ou `.mcp.json` non détectés. Le niveau d'une PR se lit donc dans ce fichier, jamais dans la sortie du script. `python3 scripts/review-levels.py --check` vérifie, sans réseau, que ses motifs sont ceux du tableau Haut et que ses sondes, un chemin et au besoin un diff synthétique, donnent le niveau attendu : une par motif « toujours » qu'aucune PR de la plage n'exerce, les deux de la ligne Release (`.claude/skills/release/scripts/verify-release.sh` haut, `.claude/skills/release/SKILL.md` normal), et une par règle du script que la plage n'exerce pas non plus (attribut et commentaire ajoutés à `lib.rs`, `resolved` et `source` hors de la forme canonique, consentement du Feedback Hub, appel de `fetchPrice(`), plus la définition du commentaire, extension par extension. Une même faute de frappe dans le tableau et dans le script passe la comparaison : une sonde la fait échouer, alors que le rejeu ne la voit que si une PR de la plage a ce motif pour seul déclencheur haut (chaque PR de la plage qui touche `verify-release.sh` touche aussi `release.yml`). `--check` ne prouve pas les conditions du tableau : elles restent à la revue de niveau haut.
|
||||
|
||||
Deux lignes du tableau Haut sont assouplies par #462, après deux niveaux que le pilote #458 a jugés trop hauts. Sous `.claude/skills/release/`, la ligne Release ne désigne plus que `scripts/**` : #450, qui ne touchait que `SKILL.md`, est la seule PR de la plage qui change de niveau (haute, puis normale), et les 51 autres gardent le leur (6/33/12, comme au 2026-10-17). La ligne Vie privée ne compte plus le texte d'une ligne du Journal dans ce qu'un appel envoie : #491, jugée haute à sa revue pour ce seul motif, est hors de la plage, et le script, qui ne modélise pas cette condition, la classait déjà normale. Comme toute règle de ce fichier, les deux valent pour les PR relues après leur merge : le relevé du pilote garde le niveau calculé à la revue de #450 et de #491.
|
||||
|
||||
#476 assouplit à son tour deux lignes : `src-tauri/src/lib.rs` et `src-tauri/Cargo.toml`, `package.json` se jugent hors commentaires, et un diff qui n'y change que des commentaires sort normal. Sur ces lignes, elles ne protégeaient rien de ce que l'app exécute : un commentaire ne change ni le binaire ni la résolution des dépendances, un bloc de code d'un commentaire `///` de `lib.rs` n'est qu'un doctest, que le `cargo test --all-targets` de la CI ne lance même pas, et `package.json`, en JSON, n'a pas de commentaire. Seule la lecture ligne à ligne s'y trompe : la ligne d'une chaîne sur plusieurs lignes qui commence par `//` passe pour un commentaire. Aucune des 339 lignes de chaîne de `lib.rs` (le SQL des migrations et des tests) ne l'est au 2026-10-24, et le checksum de chaque migration publiée reste épinglé par `migration_checksums_match_the_released_ones`. Le script exemptait déjà ces lignes, et plus largement que la définition donnée sous les motifs : `#` et `//` dans tout fichier, si bien qu'un attribut `#[…]` de `lib.rs` passait pour un commentaire. Corrigé, il ne change le niveau d'aucune des 52 PR. La ligne des locks se resserre, puisqu'une archive d'un autre paquet sur `registry.npmjs.org` ou un autre index sur `github.com` passaient, mais elle ne compte plus une origine qui redevient canonique, comme un crate ramené d'une source git à l'index crates.io, qu'elle comptait avec tout changement d'hôte ou de schéma. Elle ne protégeait là rien que la forme canonique ne garantisse, le paquet venant alors du registre sous son nom et à sa version : aucune entrée des deux locks n'est hors de cette forme au 2026-10-24, et une entrée qui en sort ne peut plus entrer que par une PR haute.
|
||||
|
||||
Une PR qui modifie cette section dit, pour chaque motif retiré ou assoupli, ce qu'il protégeait, met `scripts/review-levels.py` à jour dans le même diff et le rejoue sur les mêmes PR ; le pilote #458 mesure si les niveaux tiennent.
|
||||
|
||||
## Ce qui compte par zone
|
||||
|
|
|
|||
|
|
@ -11,16 +11,39 @@ 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 COMMENT_PROBES (a line read as a
|
||||
comment or as code), 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 /// <reference stay code, like #[ and #!), with # in
|
||||
.toml, .yml and .sh (a #! shebang stays code), none in .json, .md or any
|
||||
other file. They and blank lines are skipped wherever the script reads
|
||||
the changed lines, while REVIEW.md says "hors commentaires" for lib.rs
|
||||
and the manifests only.
|
||||
- lib.rs: only generate_handler![] entries are exempt, not the tests module.
|
||||
- Tauri configuration and manifests: only a line that sets a version.
|
||||
- Lock files: a package added or removed; an added source or resolved
|
||||
outside its canonical form (the crates.io index; the npm tarball of the
|
||||
key's name at the version that the lock read at the PR head gives that
|
||||
key); a checksum or integrity added in a hunk that adds no version.
|
||||
- Check workflows: a change that can turn a failing check green, read
|
||||
against the PR's merge base; an env: block added at the workflow or job
|
||||
level, or a run: step that deletes or edits a file (rm, sed -i), comes
|
||||
out normal.
|
||||
- Network calls: reqwest in Rust, fetch to an absolute URL in TS; an opened
|
||||
URL is not seen.
|
||||
- Consents: a changed line that says "consent" in CONSENT_FILES, and a
|
||||
fetchPrice( added outside PriceFetchControl.tsx and the tests; a change
|
||||
without the word, or a new path to FeedbackDialog, is not seen.
|
||||
- Hooks and MCP servers: a file that .claude/settings.json or .mcp.json
|
||||
makes the agents run is not detected.
|
||||
"""
|
||||
import itertools
|
||||
import json
|
||||
|
|
@ -65,8 +88,18 @@ HIGH_ALWAYS = [
|
|||
"**/.cargo/**",
|
||||
".claude/settings.json", ".mcp.json",
|
||||
]
|
||||
# REVIEW.md, row "code livré": the price consent, then the Feedback Hub one
|
||||
# (openFeedback of LogViewerCard.tsx, the only path to FeedbackDialog).
|
||||
CONSENT_FILES = {"src/components/balance/PriceFetchControl.tsx",
|
||||
"src/components/settings/PriceFetchConsentToggle.tsx"}
|
||||
"src/components/settings/PriceFetchConsentToggle.tsx",
|
||||
"src/components/settings/LogViewerCard.tsx",
|
||||
"src/components/settings/FeedbackConsentDialog.tsx"}
|
||||
# The one caller of prices.fetchPrice, behind the price consent.
|
||||
PRICE_CALLER = "src/components/balance/PriceFetchControl.tsx"
|
||||
CRATES_IO = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
# Comment syntax by extension (REVIEW.md, "commentaire"); any other: none.
|
||||
SLASH_COMMENT = (".rs", ".ts", ".tsx", ".js")
|
||||
HASH_COMMENT = (".toml", ".yml", ".sh")
|
||||
TAURI_CONFIG = ["src-tauri/{tauri*.conf.json*,Tauri*.toml}"]
|
||||
CHECK_WORKFLOWS = {".forgejo/workflows/check-rust.yml", ".forgejo/workflows/check-frontend.yml"}
|
||||
SHIPPED = ["src/**", "src-tauri/src/**", "index.html", "public/**"]
|
||||
|
|
@ -84,6 +117,10 @@ def get(path, raw=False):
|
|||
return data if raw else json.loads(data)
|
||||
|
||||
|
||||
def raw_file(path, ref):
|
||||
return get(f"/raw/{path}?ref={ref}", raw=True).decode()
|
||||
|
||||
|
||||
def expand_braces(pat):
|
||||
m = re.search(r"\{([^{}]*)\}", pat)
|
||||
if not m:
|
||||
|
|
@ -118,47 +155,73 @@ def file_blocks(diff):
|
|||
return out
|
||||
|
||||
|
||||
def meaningful(text):
|
||||
def meaningful(text, path):
|
||||
"""False for a blank line and for a comment, by the extension of path."""
|
||||
t = text.strip()
|
||||
return t != "" and not t.startswith(("#", "//"))
|
||||
if t == "":
|
||||
return False
|
||||
if path.endswith(SLASH_COMMENT):
|
||||
# compiler directives are code, and so are #[...] and #! (no //)
|
||||
return not t.startswith("//") or re.match(r"//+\s*@ts-|///\s*<reference", t) is not None
|
||||
if path.endswith(HASH_COMMENT):
|
||||
return not t.startswith("#") or t.startswith("#!")
|
||||
return True
|
||||
|
||||
|
||||
def changed(block):
|
||||
def changed(block, path):
|
||||
return [l for l in block.split("\n")
|
||||
if l[:1] in "+-" and not l.startswith(("+++", "---")) and meaningful(l[1:])]
|
||||
if l[:1] in "+-" and not l.startswith(("+++", "---")) and meaningful(l[1:], path)]
|
||||
|
||||
|
||||
def lock_adds_or_removes(name, block):
|
||||
def is_test(path):
|
||||
return re.search(r"\.test\.[cm]?[jt]sx?$", path) is not None or path.startswith("src/test/")
|
||||
|
||||
|
||||
def npm_canonical(key, version):
|
||||
# the name follows the key's last node_modules/; a scoped tarball drops the scope
|
||||
name = key.rsplit("node_modules/", 1)[-1]
|
||||
return f"https://registry.npmjs.org/{name}/-/{name.split('/')[-1]}-{version}.tgz"
|
||||
|
||||
|
||||
def off_canonical(cargo, added, head):
|
||||
"""The added source or resolved values outside the canonical form of their package."""
|
||||
if cargo:
|
||||
return [s for s in added if s != CRATES_IO]
|
||||
try:
|
||||
packages = json.loads(head())["packages"]
|
||||
except (ValueError, KeyError, TypeError):
|
||||
return added # a lock that cannot be read at the head: the condition counts as met
|
||||
out = []
|
||||
for url in added:
|
||||
keys = [k for k, v in packages.items() if isinstance(v, dict) and v.get("resolved") == url]
|
||||
if not keys or any(url != npm_canonical(k, packages[k].get("version")) for k in keys):
|
||||
out.append(url)
|
||||
return out
|
||||
|
||||
|
||||
def lock_adds_or_removes(name, block, head):
|
||||
"""head() returns the lock at the PR head, read only when an origin line is added."""
|
||||
cargo = name.endswith("Cargo.lock")
|
||||
lines = block.split("\n")
|
||||
if cargo and any(re.match(r'^[+-]name = ', l) for l in lines):
|
||||
return True
|
||||
if not cargo and any(re.match(r'^[+-]\s+"node_modules/[^"]+": \{', l) for l in lines):
|
||||
return True
|
||||
source = r'^([+-])source = "([^"]+)"' if cargo else r'^([+-])\s+"resolved": "([^"]+)"'
|
||||
digest = r'^\+(checksum) = ' if cargo else r'^\+\s+"(integrity)": '
|
||||
# an origin outside the canonical form, with or without a new version
|
||||
source = r'^\+source = "([^"]+)"' if cargo else r'^\+\s+"resolved": "([^"]+)"'
|
||||
added = [m.group(1) for m in (re.match(source, l) for l in lines) if m]
|
||||
if added and off_canonical(cargo, added, head):
|
||||
return True
|
||||
# a checksum or integrity that changes without a new version
|
||||
digest = r'^\+checksum = ' if cargo else r'^\+\s+"integrity": '
|
||||
version = r'^\+version = ' if cargo else r'^\+\s+"version": '
|
||||
for hunk in re.split(r"(?m)^@@", block)[1:]:
|
||||
hl = hunk.split("\n")
|
||||
# an origin whose host or scheme changes, with or without a new version
|
||||
before, after = set(), set()
|
||||
for l in hl:
|
||||
m = re.match(source, l)
|
||||
if m:
|
||||
(before if m.group(1) == "-" else after).add(origin_of(m.group(2)))
|
||||
if after - before:
|
||||
return True
|
||||
# a checksum or integrity that changes without a new version
|
||||
if any(re.match(digest, l) for l in hl) and not any(re.match(version, l) for l in hl):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def origin_of(url):
|
||||
m = re.match(r"^([a-z+]+)://([^/]+)", url)
|
||||
return m.group(1) + "://" + m.group(2) if m else url
|
||||
|
||||
|
||||
STEP = re.compile(r"^\s*- (name|uses):")
|
||||
VERDICT = re.compile(r"npm ci|npm run build|npm test|cargo check|cargo test|cargo audit|cargo-audit|Verify", re.I)
|
||||
|
||||
|
|
@ -191,14 +254,14 @@ def regions(base):
|
|||
return region, lines
|
||||
|
||||
|
||||
def weakening(block, base):
|
||||
def weakening(path, block, base):
|
||||
"""Ways a check-workflow diff could turn a failing check green (empty = none)."""
|
||||
region, lines = regions(base)
|
||||
reasons, old, plus = set(), 0, []
|
||||
|
||||
def flush(pos):
|
||||
texts = [p[1:] for p in plus]
|
||||
active = [t for t in texts if meaningful(t)] # comments never count
|
||||
active = [t for t in texts if meaningful(t, path)] # comments never count
|
||||
if any(re.search(r"continue-on-error|\|\|\s*true", t) for t in active):
|
||||
reasons.add("continue-on-error or || true added")
|
||||
if any(re.search(r"GITHUB_ENV|GITHUB_PATH|npm pkg set|git checkout|git restore", t) for t in active):
|
||||
|
|
@ -209,7 +272,7 @@ def weakening(block, base):
|
|||
reasons.add("install step changes the toolchain or the PATH")
|
||||
if any(re.match(r"^(\s{4})?(if|defaults):", t) for t in active):
|
||||
reasons.add("job-level if/defaults changed")
|
||||
first = next((t for t in texts if meaningful(t)), None)
|
||||
first = next((t for t in texts if meaningful(t, path)), None)
|
||||
if first is None or STEP.match(first):
|
||||
return
|
||||
prev, nxt = region.get(pos - 1, "other"), region.get(pos, "other")
|
||||
|
|
@ -235,7 +298,7 @@ def weakening(block, base):
|
|||
plus.append(line); continue
|
||||
flush(old); plus = []
|
||||
if line.startswith("-") and not line.startswith("---"):
|
||||
if meaningful(line[1:]):
|
||||
if meaningful(line[1:], path):
|
||||
if re.match(r"^(\s{4})?(if|defaults):", line[1:]):
|
||||
reasons.add("job-level if/defaults changed")
|
||||
if re.search(r"rustup|toolchain|\bPATH\b|/bin/", line[1:]):
|
||||
|
|
@ -255,7 +318,7 @@ def weakening(block, base):
|
|||
|
||||
|
||||
def adds_network_call(path, block):
|
||||
if not match(SHIPPED, path) or re.search(r"test", path):
|
||||
if not match(SHIPPED, path) or is_test(path):
|
||||
return False
|
||||
for l in block.split("\n"):
|
||||
if l.startswith("+") and not l.startswith("+++"):
|
||||
|
|
@ -272,7 +335,8 @@ def trial_level(paths):
|
|||
return "bas" if all(match(TRIAL_LOW, p) for p in paths) else "normal"
|
||||
|
||||
|
||||
def review_level(number, files, diff, merge_base):
|
||||
def review_level(number, files, diff, merge_base, head, read=raw_file):
|
||||
"""read(path, ref) returns a file at the merge base or at the PR head."""
|
||||
blocks = file_blocks(diff)
|
||||
triggers = []
|
||||
for f in files:
|
||||
|
|
@ -281,25 +345,23 @@ def review_level(number, files, diff, merge_base):
|
|||
if match(HIGH_ALWAYS, path):
|
||||
triggers.append(path)
|
||||
elif path == "src-tauri/src/lib.rs":
|
||||
if [l for l in changed(b) if not re.match(r"^[+-]\s*commands::\w+,?\s*$", l)]:
|
||||
if [l for l in changed(b, path) if not re.match(r"^[+-]\s*commands::\w+,?\s*$", l)]:
|
||||
triggers.append(path)
|
||||
elif path == "src-tauri/src/commands/balance_commands.rs":
|
||||
hunks = re.split(r"(?m)^(?=@@)", b)[1:]
|
||||
if any(re.search(r"fetch_price|activation", h.split("\n")[0]) or
|
||||
any(re.search(r"fetch_price|activation", l) for l in changed(h)) for h in hunks):
|
||||
any(re.search(r"fetch_price|activation", l) for l in changed(h, path)) for h in hunks):
|
||||
triggers.append(path)
|
||||
elif match(TAURI_CONFIG, path) or path in ("src-tauri/Cargo.toml", "package.json"):
|
||||
if [l for l in changed(b) if not re.match(r'^[+-]\s*"?version"?\s*[:=]', l)]:
|
||||
if [l for l in changed(b, path) if not re.match(r'^[+-]\s*"?version"?\s*[:=]', l)]:
|
||||
triggers.append(path)
|
||||
elif path in ("src-tauri/Cargo.lock", "package-lock.json"):
|
||||
if lock_adds_or_removes(path, b):
|
||||
if lock_adds_or_removes(path, b, lambda: read(path, head)):
|
||||
triggers.append(path)
|
||||
elif path == ".forgejo/workflows/audit.yml" and changed(b):
|
||||
elif path == ".forgejo/workflows/audit.yml" and changed(b, path):
|
||||
triggers.append(path)
|
||||
elif path in CHECK_WORKFLOWS:
|
||||
wf = path.split("/")[-1]
|
||||
base = get(f"/raw/.forgejo/workflows/{wf}?ref={merge_base}", raw=True).decode()
|
||||
if weakening(b, base):
|
||||
if weakening(path, b, read(path, merge_base)):
|
||||
triggers.append(path)
|
||||
elif path.startswith(".forgejo/workflows/") and f["status"] == "added":
|
||||
triggers.append(path + " (new workflow)")
|
||||
|
|
@ -310,8 +372,11 @@ def review_level(number, files, diff, merge_base):
|
|||
added = [l for l in b.split("\n") if l.startswith("+") and not l.startswith("+++")]
|
||||
if path.startswith(".forgejo/workflows/") and any(re.search(r"\bsecrets\b|pull_request_target", l) for l in added):
|
||||
triggers.append(path + " (secrets or pull_request_target added)")
|
||||
if path in CONSENT_FILES and any(re.search(r"consent", l, re.I) for l in changed(b)):
|
||||
if path in CONSENT_FILES and any(re.search(r"consent", l, re.I) for l in changed(b, path)):
|
||||
triggers.append(path + " (consent)")
|
||||
if (match(SHIPPED, path) and not is_test(path) and path != PRICE_CALLER and any(
|
||||
l.startswith("+") and re.search(r"\bfetchPrice\(", l) for l in changed(b, path))):
|
||||
triggers.append(path + " (fetchPrice caller)")
|
||||
parts = path.split("/")
|
||||
top_level = len(parts) == 1 or (parts[0] == "src-tauri" and len(parts) == 2)
|
||||
new_hidden = f["status"] == "added" and any(
|
||||
|
|
@ -334,15 +399,112 @@ CONDITIONAL = {
|
|||
".forgejo/workflows/{check-rust,check-frontend}.yml", "REVIEW.md",
|
||||
}
|
||||
|
||||
# Offline probes run by --check. A typo shared by the Haut table and the
|
||||
# script passes the pattern comparison, and the replay cannot see it on the
|
||||
# Release row: every PR of the range that touches verify-release.sh also
|
||||
# touches release.yml (review of #498, mutation M4).
|
||||
# A lock probe's one hunk covers the whole file: its post-image is the lock
|
||||
# that the script reads at the PR head.
|
||||
NPM_OFF_CANONICAL = """@@ -1,10 +1,10 @@
|
||||
{
|
||||
"lockfileVersion": 3,
|
||||
"packages": {
|
||||
"node_modules/foo": {
|
||||
- "version": "1.2.3",
|
||||
- "resolved": "https://registry.npmjs.org/foo/-/foo-1.2.3.tgz",
|
||||
- "integrity": "sha512-b2xk"
|
||||
+ "version": "1.2.4",
|
||||
+ "resolved": "https://registry.npmjs.org/evil-foo/-/evil-foo-1.2.4.tgz",
|
||||
+ "integrity": "sha512-ZXZp"
|
||||
}
|
||||
}
|
||||
}"""
|
||||
NPM_CANONICAL_BUMP = """@@ -1,10 +1,10 @@
|
||||
{
|
||||
"lockfileVersion": 3,
|
||||
"packages": {
|
||||
"node_modules/foo/node_modules/@scope/bar": {
|
||||
- "version": "2.0.0",
|
||||
- "resolved": "https://registry.npmjs.org/@scope/bar/-/bar-2.0.0.tgz",
|
||||
- "integrity": "sha512-b2xk"
|
||||
+ "version": "2.0.1",
|
||||
+ "resolved": "https://registry.npmjs.org/@scope/bar/-/bar-2.0.1.tgz",
|
||||
+ "integrity": "sha512-ZXZp"
|
||||
}
|
||||
}
|
||||
}"""
|
||||
CARGO_OFF_INDEX = '''@@ -1,5 +1,5 @@
|
||||
[[package]]
|
||||
name = "foo"
|
||||
version = "1.2.4"
|
||||
-source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
+source = "registry+https://github.com/evil/crates.io-index"
|
||||
checksum = "e3b0c442"'''
|
||||
|
||||
# Offline probes run by --check: a path, the hunks of its diff (None: an empty
|
||||
# diff) and the expected level. A typo shared by the Haut table and the script
|
||||
# passes the pattern comparison, and the replay sees it only when a PR of the
|
||||
# range has that pattern for its only high trigger (review of #498, mutation
|
||||
# M4). Hence one probe per "toujours" pattern that no PR of #344-#452
|
||||
# exercises, the two of the Release row, and one per rule of this script that
|
||||
# the range does not exercise either (#476).
|
||||
PROBES = [
|
||||
(".claude/skills/release/scripts/verify-release.sh", "haut"),
|
||||
(".claude/skills/release/SKILL.md", "normal"),
|
||||
(".claude/skills/release/scripts/verify-release.sh", None, "haut"),
|
||||
(".claude/skills/release/SKILL.md", None, "normal"),
|
||||
(".claude/skills/issue-license/SKILL.md", None, "haut"),
|
||||
("src-tauri/src/commands/export_import_commands.rs", None, "haut"),
|
||||
("src-tauri/src/commands/feedback_commands.rs", None, "haut"),
|
||||
("src/services/feedbackService.ts", None, "haut"),
|
||||
("src-tauri/capabilities/default.json", None, "haut"),
|
||||
("src-tauri/build.rs", None, "haut"),
|
||||
("vite.config.ts", None, "haut"),
|
||||
(".postcssrc.json", None, "haut"),
|
||||
(".npmrc", None, "haut"),
|
||||
("src-tauri/rust-toolchain.toml", None, "haut"),
|
||||
("Cargo.toml", None, "haut"),
|
||||
(".cargo/audit.toml", None, "haut"),
|
||||
(".claude/settings.json", None, "haut"),
|
||||
(".mcp.json", None, "haut"),
|
||||
# an attribute is code, a // line a comment
|
||||
("src-tauri/src/lib.rs", '@@ -1 +1,2 @@\n+#[cfg(feature = "dev-override")]\n pub fn run() {', "haut"),
|
||||
("src-tauri/src/lib.rs", "@@ -1 +1,2 @@\n+// Builds the app.\n pub fn run() {", "normal"),
|
||||
("package-lock.json", NPM_OFF_CANONICAL, "haut"),
|
||||
("package-lock.json", NPM_CANONICAL_BUMP, "normal"),
|
||||
("src-tauri/Cargo.lock", CARGO_OFF_INDEX, "haut"),
|
||||
("src/components/settings/LogViewerCard.tsx",
|
||||
'@@ -21 +21 @@\n- const accepted = localStorage.getItem(FEEDBACK_CONSENT_KEY) === "true";\n'
|
||||
"+ const accepted = true;", "haut"),
|
||||
("src/components/settings/FeedbackConsentDialog.tsx",
|
||||
'@@ -47 +47 @@\n- <p>{t("feedback.consent.body")}</p>\n+ <p>{t("feedback.consent.short")}</p>', "haut"),
|
||||
("src/components/balance/SnapshotLineRow.tsx",
|
||||
'@@ -1 +1,2 @@\n import { prices } from "../../services/balance.service";\n'
|
||||
'+void prices.fetchPrice(symbol, date);', "haut"),
|
||||
("src/components/balance/PriceFetchControl.tsx",
|
||||
"@@ -111 +111,2 @@\n const result = await prices.fetchPrice(symbol, date);\n"
|
||||
"+ const again = await prices.fetchPrice(symbol, date);", "normal"),
|
||||
("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"),
|
||||
# a shipped file whose name holds "test" is not a test
|
||||
("src/components/shared/DownloadLatestButton.tsx",
|
||||
'@@ -2 +2,2 @@\n import { openUrl } from "@tauri-apps/plugin-opener";\n'
|
||||
'+void fetch("https://example.com/latest.json");', "haut"),
|
||||
]
|
||||
|
||||
# Offline probes of meaningful(): a path, a line, and whether it is a comment
|
||||
# in the sense of REVIEW.md ("commentaire", under the Motifs paragraph).
|
||||
COMMENT_PROBES = [
|
||||
("x.rs", "// a note", True), ("x.ts", "// a note", True),
|
||||
("x.tsx", "// a note", True), ("x.js", "// a note", True),
|
||||
("x.rs", "#[cfg(test)]", False), ("x.ts", "// @ts-expect-error", False),
|
||||
("x.ts", '/// <reference types="vite/client" />', False),
|
||||
("x.toml", "# a note", True), ("x.yml", "# a note", True), ("x.sh", "# a note", True),
|
||||
("x.sh", "#!/usr/bin/env bash", False),
|
||||
("x.yml", "// a note", False), ("x.json", "// a note", False), ("x.md", "# A title", False),
|
||||
]
|
||||
|
||||
|
||||
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."""
|
||||
|
|
@ -358,14 +520,21 @@ 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
|
||||
for path, line, comment in COMMENT_PROBES:
|
||||
if meaningful(line, path) == comment:
|
||||
print(f"comment probe: {line!r} in {path} is {'code' if comment else 'a comment'}, expected the other")
|
||||
failed = True
|
||||
if failed:
|
||||
return 1
|
||||
print(f"ok: {len(coded)} patterns, identical to the Haut table of REVIEW.md; {len(PROBES)} probes")
|
||||
print(f"ok: {len(coded)} patterns, identical to the Haut table of REVIEW.md; "
|
||||
f"{len(PROBES)} probes, {len(COMMENT_PROBES)} comment probes")
|
||||
return 0
|
||||
|
||||
|
||||
|
|
@ -393,9 +562,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)):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue