From 446c059ab2acb3e60176265a2d46243c0e6eb033 Mon Sep 17 00:00:00 2001 From: scuttletoby <123843277+scuttletoby@users.noreply.github.com> Date: Tue, 17 Nov 2026 17:22:16 +0000 Subject: [PATCH 1/3] fork-ci pr-queue: parse and validate the `review` block (PK10 C1) New module review_config.py: parse_review() reads the optional `review` block of the queue's config (path rules with weights, lens prompts, min_lenses, the round cap) into a frozen value, or raises ConfigError naming every problem at once. config.py gets one optional `review` key; a config without it behaves exactly as before. Nothing reads the block yet (C2 does). Refused: a rule with fewer different lenses (by lens.lens_key) than min_lenses of its weight, lens names lens.names_a_lens rejects, two lens names the gate reads as one, a lens without an entry, no catch-all `**` rule (or a light one, or a rule after it), no critical rule, empty lenses on a non-light rule, rounds.max below approach_at, an approach lens without an entry, globs outside the documented dialect, prompt paths that leave the repo, any version but 1. README "Review rules" documents the keys, the glob dialect, built-in protected paths, shadow vs enforce, fail closed and the release-pin-then-add order. review.recommended.json is the example with made-up paths; a test parses it. Co-Authored-By: Claude Opus 5.5 --- .github/fork-ci-tests.txt | 1 + fork-ci/actions/pr-queue/README.md | 62 ++++ fork-ci/actions/pr-queue/config.py | 21 +- .../actions/pr-queue/review.recommended.json | 24 ++ fork-ci/actions/pr-queue/review_config.py | 298 +++++++++++++++ .../actions/pr-queue/review_config.test.py | 343 ++++++++++++++++++ 6 files changed, 747 insertions(+), 2 deletions(-) create mode 100644 fork-ci/actions/pr-queue/review.recommended.json create mode 100644 fork-ci/actions/pr-queue/review_config.py create mode 100644 fork-ci/actions/pr-queue/review_config.test.py diff --git a/.github/fork-ci-tests.txt b/.github/fork-ci-tests.txt index 631a787c5f1ed..0c9b154ee9817 100644 --- a/.github/fork-ci-tests.txt +++ b/.github/fork-ci-tests.txt @@ -51,6 +51,7 @@ fork-ci/actions/job-changed/job-changed.test.py ~16s fork-ci/actions/pinned/pinned.test.py fork-ci/actions/pr-queue/lens.test.py fork-ci/actions/pr-queue/pr_queue.test.py ~23s +fork-ci/actions/pr-queue/review_config.test.py fork-ci/actions/pr-queue/tested-base/tested_base.test.py fork-ci/actions/test-select/test-select.test.py ~15s fork-ci/actions/test-select/trace-check.test.py diff --git a/fork-ci/actions/pr-queue/README.md b/fork-ci/actions/pr-queue/README.md index 206018bde0354..12cf7e938c37e 100644 --- a/fork-ci/actions/pr-queue/README.md +++ b/fork-ci/actions/pr-queue/README.md @@ -42,6 +42,68 @@ an error: the queue then exits non-zero and touches no pull request. | `list_limit` | no | How many open pull requests to read (default 50). | | `update_when_base_was_red` | no | `true` updates a behind pull request whose required checks failed only because the base commit they tested failed them too (section "The base was red"). Set it only when the job of every required check runs the `tested-base` action. Default `false`. | | `head_check_app` | no | The id of the GitHub App that alone posts `head_check` (the head gate, `../head-check/README.md`, "The gate"). The queue then counts only that App's newest check run of that name and ignores a job or commit status of the same name from anyone else; it skips a pull request whose gate check it cannot read. Add it only after every queue that reads this config runs a release that knows it: an older release refuses an unknown key. | +| `review` | no | Which changed paths need which lens reads, and the round cap (section "Review rules"). Without it the queue and the gate behave as before. | + +## Review rules + +The optional `review` block of the config says which changed paths need which +lens reads and caps the review rounds. This release only reads and checks it: +nothing judges a pull request by it yet, so a config with the block behaves like +one without it. `review.recommended.json` (next to this file) is a complete +example with made-up paths; a test parses it. Real paths, lens names and prompt +files belong in the project's own config. + +Every key is required and an unknown key is an error, as in the rest of the +config. A wrong block makes the whole config invalid, naming every problem at +once. + +| Key | Meaning | +| ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `version` | `1`. Any other version is refused by name (a newer one: update the pinned release first). | +| `mode` | `shadow`: the gate keeps judging by its `required-lenses` input and only reports what the path rules would have said. `enforce`: the path rules decide. | +| `rules` | An ordered list of `{"name", "weight", "paths", "lenses"}`. A changed file belongs to the first rule with a matching glob. `weight` is `critical`, `normal` or `light`; `lenses` are names from `lenses`. | +| `lenses` | `{"": {"prompt": ""}}`: every lens a rule or `rounds` names, with its prompt file (repo-relative, no `..`, no leading `/`, no glob characters). | +| `min_lenses` | `{"critical", "normal", "light"}`: the fewest different lenses a rule of that weight must list, 0-10, never falling with weight. | +| `rounds` | `{"approach_at", "max", "approach_lens"}`: from round `approach_at` the approach lens is required too; after round `max` a person must write an override comment or close the pull request. `max` is not below `approach_at`. | +| `findings` | `true` or `false`: lens comments carry `blocker:`, `major:` and `minor:` lines, and a blocker or major at the head fails the gate. | +| `state_line` | `true` or `false`: a required lens comment needs a `state:` line to count. | + +The config is refused when: + +- a rule lists fewer different lenses than `min_lenses` of its weight. "Different" + is as the gate reads lens names (section "Lens comments"): case, blanks and a + trailing round marker do not count, so `data r1` and `data r2` are one lens; +- two names in `lenses` are one lens to the gate in that way; +- a lens name names no lens (a ``, a bare round marker such as `r2`, + nothing), or a rule or `rounds.approach_lens` names a lens with no entry in + `lenses` (names match exactly); +- a `critical` or `normal` rule has `"lenses": []` (only `light` may); +- no rule has the catch-all path `**`, the catch-all rule is `light`, or a rule + comes after the catch-all rule (it could never match): a new folder must never + fall to no rule or to no lens; +- there is no `critical` rule (the built-in protected paths below take its lenses); +- a glob is not in the dialect below, or a rule name or glob is written twice. + +**Globs.** Paths are repo-relative and use `/`. `*` is any characters inside one +path segment, `**` is any number of whole segments (it must be a segment of its +own: `src/**/*.py`, not `src/**.py`), `?` is one character inside a segment. +There are no braces, character classes, `!` negation or backslashes, and no +empty, `.` or `..` segments. The gate and T3 match with this dialect, so a glob +means the same thing on both sides. + +**Built-in protected paths.** The config file itself, every lens prompt file and +`.github/workflows/**` always count as critical, whatever the rules say, with the +lenses of the first critical rule. So a pull request that weakens the rules needs +the critical lenses, and it is judged by the old rules: the gate reads the config +from the base tip only. + +**Fail closed.** When the gate cannot read the changed paths or fetch the base, +the pull request counts as the heaviest weight, or the gate fails. Never a pass. + +**Adding the block.** A release that does not know the `review` key refuses the +whole config (an unknown key), so: release first, then pin that release in every +caller of the queue and the gate, then add the key. Roll back in the reverse order: +remove the key, then the pin. ## Lens comments diff --git a/fork-ci/actions/pr-queue/config.py b/fork-ci/actions/pr-queue/config.py index 2090c800dadf4..ebb8b2faa5c58 100644 --- a/fork-ci/actions/pr-queue/config.py +++ b/fork-ci/actions/pr-queue/config.py @@ -38,6 +38,7 @@ class Config: update_when_base_was_red: bool = False head_check_app: int = None delete_branch: bool = False # read and checked, never used: the queue deletes no branch (README.md, "Config") + review: object = None # review_config.ReviewRules, or None without the key: nothing reads it yet def ready(self, n): """The command that re-arms PR n after a lens read, as the project writes it.""" @@ -65,6 +66,12 @@ def _int(lo, hi): return lambda v: isinstance(v, int) and not isinstance(v, bool) and lo <= v <= hi +def _review(v): + """The `review` block's own parser names its problems (a ConfigError); imported here, as it imports this module.""" + import review_config + return review_config.parse_review(v, 'review') is not None + + # key: (required, check, what a valid value is) KEYS = { 'required_checks': (True, lambda v: isinstance(v, list) and v != [] and all(map(_text, v)) and len(set(v)) == len(v), @@ -92,6 +99,7 @@ def _int(lo, hi): 'head_check_app': (False, _int(1, 2 ** 53), 'the id of the GitHub App that alone posts head_check (the head gate): the queue then counts ' 'only that App\'s check runs of that name'), + 'review': (False, _review, 'the review rules block (README.md, "Review rules")'), } @@ -110,8 +118,14 @@ def parse(text, where='config'): if key not in raw: if required: problems.append(f'{key} is missing: {what}') - elif not ok(raw[key]): - problems.append(f'{key} is {json.dumps(raw[key])[:80]}: must be {what}') + else: + try: + good = ok(raw[key]) + except ConfigError as e: # a block with its own parser (review) names its own problems + problems.append(str(e)) + continue + if not good: + problems.append(f'{key} is {json.dumps(raw[key])[:80]}: must be {what}') if not problems and raw['head_check'] not in raw['required_checks']: problems.append(f'head_check {raw["head_check"]!r} is not one of required_checks') if not problems and raw.get('poll_seconds', 5) > raw.get('wait_seconds', 60): @@ -119,6 +133,9 @@ def parse(text, where='config'): if problems: raise ConfigError(f'{where}: ' + '; '.join(problems)) override = raw.pop('override') + if 'review' in raw: + import review_config + raw['review'] = review_config.parse_review(raw['review'], 'review') return Config(required_checks=frozenset(raw.pop('required_checks')), bot_logins=tuple(raw.pop('bot_logins')), lens_author_associations=tuple(raw.pop('lens_author_associations')), override_prefix=override['prefix'], override_association=override['author_association'], **raw) diff --git a/fork-ci/actions/pr-queue/review.recommended.json b/fork-ci/actions/pr-queue/review.recommended.json new file mode 100644 index 0000000000000..93f821114bfb4 --- /dev/null +++ b/fork-ci/actions/pr-queue/review.recommended.json @@ -0,0 +1,24 @@ +{ + "version": 1, + "mode": "shadow", + "rules": [ + { + "name": "data", + "weight": "critical", + "paths": ["src/storage/**", "migrations/**"], + "lenses": ["data-1", "data-2"] + }, + { "name": "docs", "weight": "light", "paths": ["docs/**", "**/*.md"], "lenses": [] }, + { "name": "code", "weight": "normal", "paths": ["**"], "lenses": ["code"] } + ], + "lenses": { + "data-1": { "prompt": ".github/lenses/data.md" }, + "data-2": { "prompt": ".github/lenses/data.md" }, + "code": { "prompt": ".github/lenses/code.md" }, + "approach": { "prompt": ".github/lenses/approach.md" } + }, + "min_lenses": { "critical": 2, "normal": 1, "light": 0 }, + "rounds": { "approach_at": 3, "max": 4, "approach_lens": "approach" }, + "findings": true, + "state_line": true +} diff --git a/fork-ci/actions/pr-queue/review_config.py b/fork-ci/actions/pr-queue/review_config.py new file mode 100644 index 0000000000000..9c61a210e8416 --- /dev/null +++ b/fork-ci/actions/pr-queue/review_config.py @@ -0,0 +1,298 @@ +"""The `review` block of the queue's config: which paths need which lens reads, and the round cap (README.md, "Review +rules"). + +Only parsed and checked here; nothing judges a pull request by it yet. Strict like config.py: every key is required, +an unknown key or a wrong value is an error, and every problem is named at once. A rule set that could leave a changed +path without the lenses its weight needs is refused, never repaired: no hidden defaults in the merge path. + +Globs use one small dialect, so the Python gate and T3 match a path the same way: `*` any characters inside one path +segment, `**` any number of whole segments (only as a segment of its own), `?` one character inside a segment. Paths +are repo-relative with `/`. No braces, character classes, `!` or backslashes. +""" +import json +import re +from dataclasses import dataclass + +import lens +from config import ConfigError + +VERSION = 1 +MODES = ('shadow', 'enforce') +WEIGHTS = ('critical', 'normal', 'light') # heaviest first +CATCH_ALL = '**' +KEYS = ('version', 'mode', 'rules', 'lenses', 'min_lenses', 'rounds', 'findings', 'state_line') +RULE_KEYS = ('name', 'weight', 'paths', 'lenses') +ROUND_KEYS = ('approach_at', 'max', 'approach_lens') +MAX_LENSES = 10 +MAX_ROUNDS = 20 +# Characters of glob dialects this one does not have: a project that wrote `{a,b}`, `[ab]` or `!x` would otherwise get +# a rule that silently matches nothing it meant. +NOT_IN_DIALECT = re.compile(r'[{}\[\]!\\]') + + +@dataclass(frozen=True) +class Rule: + name: str + weight: str + paths: tuple + lenses: tuple + + +@dataclass(frozen=True) +class Lens: + name: str + prompt: str + + +@dataclass(frozen=True) +class MinLenses: + critical: int + normal: int + light: int + + +@dataclass(frozen=True) +class Rounds: + approach_at: int + max: int + approach_lens: str + + +@dataclass(frozen=True) +class ReviewRules: + version: int + mode: str + rules: tuple # of Rule, in the order written: a changed path belongs to the first rule that matches it + lenses: tuple # of Lens, in the order written + min_lenses: MinLenses + rounds: Rounds + findings: bool + state_line: bool + + def lens(self, name): + return next((x for x in self.lenses if x.name == name), None) + + +def _text(v): + return isinstance(v, str) and v.strip() == v and v != '' and '\n' not in v and '\r' not in v + + +def _int(v, lo, hi): + return isinstance(v, int) and not isinstance(v, bool) and lo <= v <= hi + + +def _show(v): + return json.dumps(v)[:80] + + +def _path_problem(p): + """Why `p` is no repo-relative path in `/` form, or None.""" + if not _text(p): + return 'must be a non-empty line without surrounding blanks' + if p.startswith('/'): + return 'must be repo-relative (no leading /)' + if NOT_IN_DIALECT.search(p): + return 'has a character the dialect does not have ({, }, [, ], !, \\)' + if any(seg in ('', '.', '..') for seg in p.split('/')): + return 'has an empty, . or .. segment' + return None + + +def glob_problem(g): + """Why `g` is not a glob of the dialect (module doc), or None.""" + why = _path_problem(g) + if why: + return why + if any('**' in seg and seg != '**' for seg in g.split('/')): + return '** must be a whole segment (write a/**/b or **/*.md, not a** or **.md)' + return None + + +def prompt_problem(p): + why = _path_problem(p) + if why: + return why + if '*' in p or '?' in p: + return 'is a file path, not a glob' + return None + + +def _keys(obj, keys, where, problems): + """True when `obj` is an object; names its unknown and missing keys.""" + if not isinstance(obj, dict): + problems.append(f'{where} is {_show(obj)}: must be an object') + return False + problems.extend(f'{where}: unknown key {k!r} (known: {", ".join(keys)})' for k in obj if k not in keys) + problems.extend(f'{where}: {k} is missing' for k in keys if k not in obj) + return True + + +def _lens_name(name, where, problems): + if not _text(name) or not lens.names_a_lens(name): + problems.append(f'{where} {_show(name)} names no lens (a placeholder, a round marker, blanks or nothing)') + return False + return True + + +def _lenses(raw, problems): + """{name: prompt} of the valid entries; problems for the rest, and for two names the gate reads as one lens.""" + out, by_key = {}, {} + if not isinstance(raw, dict) or raw == {}: + problems.append(f'lenses is {_show(raw)}: must be an object of lens name -> {{"prompt": ""}}') + return out + for name, entry in raw.items(): + where = f'lenses[{name!r}]' + if not _lens_name(name, 'lens name', problems): + continue + key = lens.lens_key(name) + if key in by_key: + problems.append(f'lens names {by_key[key]!r} and {name!r} are one lens to the gate (both read as ' + f'{key!r}): rename one') + continue + by_key[key] = name + if not _keys(entry, ('prompt',), where, problems) or 'prompt' not in entry: + continue + why = prompt_problem(entry['prompt']) + if why: + problems.append(f'{where}.prompt {_show(entry["prompt"])} {why}') + continue + out[name] = entry['prompt'] + return out + + +def _min_lenses(raw, problems): + if not _keys(raw, WEIGHTS, 'min_lenses', problems): + return None + bad = [w for w in WEIGHTS if w in raw and not _int(raw[w], 0, MAX_LENSES)] + problems.extend(f'min_lenses.{w} is {_show(raw[w])}: must be a whole number 0-{MAX_LENSES}' for w in bad) + if bad or any(w not in raw for w in WEIGHTS): + return None + if not raw['critical'] >= raw['normal'] >= raw['light']: + problems.append('min_lenses must not fall with weight: critical >= normal >= light') + return MinLenses(**raw) + + +def _rules(raw, declared, mins, problems): + if not isinstance(raw, list) or raw == []: + problems.append(f'rules is {_show(raw)}: must be a non-empty list of rules') + return () + rules, names, catch_all = [], set(), None + for i, r in enumerate(raw): + where, before = f'rules[{i}]', len(problems) + if not _keys(r, RULE_KEYS, where, problems): + continue + if 'name' in r: + if not _text(r['name']): + problems.append(f'{where}.name is {_show(r["name"])}: must be a non-empty line') + elif r['name'] in names: + problems.append(f'{where}: rule name {r["name"]!r} is written twice') + else: + names.add(r['name']) + where = f'{where} ({r["name"]!r})' + weight = r.get('weight') + if 'weight' in r and weight not in WEIGHTS: + problems.append(f'{where}.weight is {_show(weight)}: must be one of {", ".join(WEIGHTS)}') + weight = None + paths = r.get('paths') + if 'paths' in r: + if not isinstance(paths, list) or paths == []: + problems.append(f'{where}.paths is {_show(paths)}: must be a non-empty list of globs') + paths = None + else: + for g in paths: + why = glob_problem(g) + if why: + problems.append(f'{where}.paths: {_show(g)} {why}') + if len(set(map(json.dumps, paths))) != len(paths): + problems.append(f'{where}.paths has a glob written twice') + if catch_all is not None: + problems.append(f'{where} comes after the catch-all rule {catch_all} and can never match: ' + f'move it above') + elif CATCH_ALL in paths: + catch_all = where + if weight == 'light': + problems.append(f'{where} is the catch-all ** rule and must not be light: a new folder ' + f'must never need no lens') + names_ = r.get('lenses') + if 'lenses' in r: + if not isinstance(names_, list): + problems.append(f'{where}.lenses is {_show(names_)}: must be a list of lens names') + names_ = None + else: + good = [n for n in names_ if _lens_name(n, f'{where}.lenses:', problems)] + for n in good: + if n not in declared: + problems.append(f'{where}.lenses: {n!r} has no entry in lenses') + if len(set(good)) != len(good): + problems.append(f'{where}.lenses has a name written twice') + if names_ == [] and weight not in (None, 'light'): + problems.append(f'{where} is {weight} with no lenses: only a light rule may have none') + elif weight and mins: + keys = {lens.lens_key(n) for n in good} + need = getattr(mins, weight) + if len(keys) < need: + problems.append(f'{where}: {weight} needs {need} different lens{"es" if need != 1 else ""}, ' + f'found {len(keys)} (names that differ only in case, blanks or a round ' + f'marker such as r2 are one lens)') + if len(problems) == before: + rules.append(Rule(r['name'], weight, tuple(paths), tuple(names_))) + if catch_all is None: + problems.append(f'no rule has the catch-all path {CATCH_ALL!r}: a new folder must never fall to no rule') + if not any(isinstance(r, dict) and r.get('weight') == 'critical' for r in raw): + problems.append('no critical rule: the built-in protected paths (the config, every lens prompt, ' + '.github/workflows/**) take the lenses of the first critical rule') + return tuple(rules) + + +def _rounds(raw, declared, problems): + if not _keys(raw, ROUND_KEYS, 'rounds', problems): + return None + ok = True + for k in ('approach_at', 'max'): + if k in raw and not _int(raw[k], 1, MAX_ROUNDS): + problems.append(f'rounds.{k} is {_show(raw[k])}: must be a whole number 1-{MAX_ROUNDS}') + ok = False + if ok and 'approach_at' in raw and 'max' in raw and raw['max'] < raw['approach_at']: + problems.append(f'rounds.max {raw["max"]} is below rounds.approach_at {raw["approach_at"]}: the approach ' + f'lens would never be asked for') + ok = False + if 'approach_lens' in raw: + name = raw['approach_lens'] + if not _lens_name(name, 'rounds.approach_lens', problems): + ok = False + elif name not in declared: + problems.append(f'rounds.approach_lens {name!r} has no entry in lenses') + ok = False + if not ok or any(k not in raw for k in ROUND_KEYS): + return None + return Rounds(raw['approach_at'], raw['max'], raw['approach_lens']) + + +def parse_review(obj, where='review'): + """ReviewRules from the parsed `review` value, or ConfigError naming every problem at once.""" + problems = [] + if not isinstance(obj, dict): + raise ConfigError(f'{where} is {_show(obj)}: must be an object (README.md, "Review rules")') + if 'version' in obj and not (_int(obj['version'], VERSION, VERSION)): + # Another version may have other keys: naming them all as unknown would only hide the one real problem. + newer = _int(obj['version'], VERSION + 1, 2 ** 31) + raise ConfigError(f'{where}: version {_show(obj["version"])} is not {VERSION}, the only version this release ' + f'reads' + (': update the pinned release first' if newer else '')) + problems.extend(f'unknown key {k!r} (known: {", ".join(KEYS)})' for k in obj if k not in KEYS) + problems.extend(f'{k} is missing' for k in KEYS if k not in obj) + if 'mode' in obj and obj['mode'] not in MODES: + problems.append(f'mode is {_show(obj["mode"])}: must be one of {", ".join(MODES)}') + for k in ('findings', 'state_line'): + if k in obj and not isinstance(obj[k], bool): + problems.append(f'{k} is {_show(obj[k])}: must be true or false') + lenses = _lenses(obj['lenses'], problems) if 'lenses' in obj else {} + # Every name written in `lenses`, even one whose entry is wrong: that entry's own problem is named once, not again + # as "no entry" by each rule that lists it. + declared = set(obj['lenses']) if isinstance(obj.get('lenses'), dict) else set() + mins = _min_lenses(obj['min_lenses'], problems) if 'min_lenses' in obj else None + rules = _rules(obj['rules'], declared, mins, problems) if 'rules' in obj else () + rounds = _rounds(obj['rounds'], declared, problems) if 'rounds' in obj else None + if problems: + raise ConfigError(f'{where}: ' + '; '.join(problems)) + return ReviewRules(obj['version'], obj['mode'], rules, tuple(Lens(n, p) for n, p in lenses.items()), mins, + rounds, obj['findings'], obj['state_line']) diff --git a/fork-ci/actions/pr-queue/review_config.test.py b/fork-ci/actions/pr-queue/review_config.test.py new file mode 100644 index 0000000000000..63ba8060cc3f7 --- /dev/null +++ b/fork-ci/actions/pr-queue/review_config.test.py @@ -0,0 +1,343 @@ +"""Tests of review_config.py and the `review` key of config.py (run: python3 fork-ci/actions/pr-queue/review_config.test.py).""" +import copy, json, os, re, sys, unittest +from unittest import mock + +sys.dont_write_bytecode = True # no __pycache__ next to the scripts + +HERE = os.path.dirname(os.path.abspath(__file__)) +sys.path.insert(0, HERE) +import config # noqa: E402 +import review_config as rc # noqa: E402 + +RECOMMENDED = os.path.join(HERE, 'review.recommended.json') +README = os.path.join(HERE, 'README.md') +BASE = { + 'required_checks': ['build', 'test'], 'merge_method': 'squash', 'bot_logins': ['review-bot'], + 'lens_author_associations': ['OWNER'], 'override': {'prefix': 'tool ready --head', 'author_association': 'OWNER'}, + 'ready_command': 'tool ready {pr}', 'push_command': 'tool push', 'lens_format_doc': 'docs/review.md', + 'head_check': 'test', +} + + +def recommended(): + with open(RECOMMENDED, encoding='utf-8') as f: + return json.load(f) + + +def refusal(block): + """The ConfigError text parse_review raises for `block`; fails the test when it parses.""" + try: + rc.parse_review(block) + except config.ConfigError as e: + return str(e) + raise AssertionError(f'parsed, should be refused: {json.dumps(block)[:200]}') + + +class Recommended(unittest.TestCase): + def test_the_shipped_example_parses(self): + r = rc.parse_review(recommended()) + self.assertEqual(r.version, 1) + self.assertEqual(r.mode, 'shadow') + self.assertEqual([x.name for x in r.rules], ['data', 'docs', 'code']) + self.assertEqual(r.rules[0], rc.Rule('data', 'critical', ('src/storage/**', 'migrations/**'), + ('data-1', 'data-2'))) + self.assertEqual(r.rules[1].lenses, ()) + self.assertEqual(r.lens('code'), rc.Lens('code', '.github/lenses/code.md')) + self.assertIsNone(r.lens('nope')) + self.assertEqual(r.min_lenses, rc.MinLenses(2, 1, 0)) + self.assertEqual(r.rounds, rc.Rounds(3, 4, 'approach')) + self.assertIs(r.findings, True) + self.assertIs(r.state_line, True) + + def test_owner_numbers(self): + """Owner decisions: critical = two lenses, approach lens from round 3, cap 4.""" + r = rc.parse_review(recommended()) + self.assertEqual((r.min_lenses.critical, r.rounds.approach_at, r.rounds.max), (2, 3, 4)) + + def test_in_a_whole_config(self): + cfg = config.parse(json.dumps(dict(BASE, review=recommended()))) + self.assertEqual(cfg.review, rc.parse_review(recommended())) + + def test_example_paths_are_made_up(self): + """The fork is public: the shipped example holds only these made-up paths (a change here is a deliberate one).""" + r = rc.parse_review(recommended()) + self.assertEqual(sorted({g for rule in r.rules for g in rule.paths} | {x.prompt for x in r.lenses}), + ['**', '**/*.md', '.github/lenses/approach.md', '.github/lenses/code.md', + '.github/lenses/data.md', 'docs/**', 'migrations/**', 'src/storage/**']) + + def test_readme_names_every_key(self): + with open(README, encoding='utf-8') as f: + text = f.read() + section = text[text.index('## Review rules'):text.index('## Lens comments')] + for k in rc.KEYS: + self.assertIn(f'`{k}`', section) + self.assertIn('release first, then pin', section) + self.assertIn('`.github/workflows/**`', section) + + +class StateQuestion(unittest.TestCase): + """Runs again, meets old, empty or newer state.""" + + def test_config_without_review_is_todays(self): + cfg = config.parse(json.dumps(BASE)) + self.assertIsNone(cfg.review) + self.assertEqual(cfg, config.Config( + required_checks=frozenset(['build', 'test']), merge_method='squash', bot_logins=('review-bot',), + lens_author_associations=('OWNER',), override_prefix='tool ready --head', override_association='OWNER', + ready_command='tool ready {pr}', push_command='tool push', lens_format_doc='docs/review.md', + head_check='test')) + + def test_empty_object_names_every_missing_key(self): + why = refusal({}) + for k in rc.KEYS: + self.assertIn(f'{k} is missing', why) + + def test_null_and_list_are_refused(self): + self.assertIn('must be an object', refusal(None)) + self.assertIn('must be an object', refusal([])) + with self.assertRaisesRegex(config.ConfigError, r'review is null: must be an object'): + config.parse(json.dumps(dict(BASE, review=None))) + + def test_newer_version_is_named_alone(self): + block = dict(recommended(), version=2, rules='a v2 shape', extra=True) + why = refusal(block) + self.assertIn('version 2 is not 1', why) + self.assertIn('update the pinned release', why) + self.assertNotIn('unknown key', why) + self.assertNotIn('rules', why) + + def test_odd_versions(self): + for v in (0, '1', 1.0, True, None): + self.assertIn('is not 1', refusal(dict(recommended(), version=v)), v) + self.assertNotIn('update the pinned', refusal(dict(recommended(), version=v))) + + def test_key_written_twice(self): + text = json.dumps(dict(BASE, review=recommended())) + text = text.replace('"mode": "shadow"', '"mode": "enforce", "mode": "shadow"') + with self.assertRaisesRegex(config.ConfigError, 'key written twice: mode'): + config.parse(text) + + def test_only_light_rules_matching_is_allowed_but_the_catch_all_is_not_light(self): + """A light rule before the catch-all may need no lens; a light catch-all would leave every new folder with + none.""" + self.assertEqual(rc.parse_review(recommended()).rules[1].weight, 'light') + block = recommended() + block['rules'][2]['weight'] = 'light' + block['rules'][2]['lenses'] = [] + self.assertIn('catch-all ** rule and must not be light', refusal(block)) + + def test_same_lens_key_in_lenses(self): + block = recommended() + block['lenses']['Data-1 r2'] = {'prompt': '.github/lenses/data.md'} + self.assertIn("'data-1' and 'Data-1 r2' are one lens to the gate", refusal(block)) + + def test_same_lens_key_in_a_rule_is_one_lens(self): + block = recommended() + block['lenses'] = {'data r1': {'prompt': 'a.md'}, 'code': {'prompt': 'c.md'}, 'approach': {'prompt': 'p.md'}} + block['rules'][0]['lenses'] = ['data r1', 'data r2'] + why = refusal(block) + self.assertIn("rules[0] ('data'): critical needs 2 different lenses, found 1", why) + self.assertIn("'data r2' has no entry in lenses", why) + + def test_unknown_key_refusal_names_review_on_an_older_release(self): + """An older release has no `review` row: it refuses the whole config and names the key.""" + old = {k: v for k, v in config.KEYS.items() if k != 'review'} + with mock.patch.object(config, 'KEYS', old): + with self.assertRaisesRegex(config.ConfigError, r"unknown key 'review'"): + config.parse(json.dumps(dict(BASE, review=recommended()))) + + def test_parsing_twice_gives_an_equal_value(self): + text = json.dumps(dict(BASE, review=recommended())) + a, b = config.parse(text), config.parse(text) + self.assertEqual(a, b) + self.assertEqual(hash(a), hash(b)) + self.assertIsNot(a.review, b.review) + + def test_frozen(self): + r = rc.parse_review(recommended()) + with self.assertRaises(Exception): + r.mode = 'enforce' + self.assertIsInstance(r.rules, tuple) + self.assertIsInstance(r.rules[0].paths, tuple) + + def test_input_is_not_changed(self): + block = recommended() + before = copy.deepcopy(block) + rc.parse_review(block) + config.parse(json.dumps(dict(BASE, review=block))) + self.assertEqual(block, before) + + +class Refusals(unittest.TestCase): + def test_every_problem_at_once(self): + block = recommended() + block['mode'] = 'loud' + block['findings'] = 'yes' + block['rules'][0]['lenses'] = ['data-1'] + block['rounds']['max'] = 2 + block['surprise'] = 1 + why = refusal(block) + for part in ("unknown key 'surprise'", 'mode is "loud"', 'findings is "yes"', + 'critical needs 2 different lenses, found 1', 'rounds.max 2 is below rounds.approach_at 3'): + self.assertIn(part, why) + + def test_unknown_and_missing_keys_inside(self): + block = recommended() + block['rules'][0]['weigth'] = 'critical' + del block['rules'][0]['weight'] + block['lenses']['code']['model'] = 'x' + block['rounds'].pop('approach_lens') + block['min_lenses'].pop('light') + why = refusal(block) + self.assertIn("rules[0]: unknown key 'weigth'", why) + self.assertIn('rules[0]: weight is missing', why) + self.assertIn("lenses['code']: unknown key 'model'", why) + self.assertIn('rounds: approach_lens is missing', why) + self.assertIn('min_lenses: light is missing', why) + + def test_names_a_lens(self): + for bad in ('', 'r2', 're-check', ' code', '', '***'): + block = recommended() + block['lenses'][bad] = {'prompt': 'x.md'} + self.assertIn('names no lens', refusal(block), bad) + block = recommended() + block['rules'][2]['lenses'] = ['code', 'r3'] + self.assertIn('rules[2] (\'code\').lenses: "r3" names no lens', refusal(block)) + block = recommended() + block['rounds']['approach_lens'] = '' + self.assertIn('rounds.approach_lens "" names no lens', refusal(block)) + + def test_lens_without_entry(self): + block = recommended() + block['rules'][2]['lenses'] = ['Code'] + self.assertIn("'Code' has no entry in lenses", refusal(block)) + block = recommended() + block['rounds']['approach_lens'] = 'design' + self.assertIn("rounds.approach_lens 'design' has no entry in lenses", refusal(block)) + + def test_no_catch_all(self): + block = recommended() + block['rules'][2]['paths'] = ['src/**'] + self.assertIn("no rule has the catch-all path '**'", refusal(block)) + + def test_rule_after_catch_all(self): + block = recommended() + block['rules'].append({'name': 'late', 'weight': 'critical', 'paths': ['db/**'], 'lenses': ['data-1', 'data-2']}) + self.assertIn("rules[3] ('late') comes after the catch-all rule", refusal(block)) + + def test_no_critical_rule(self): + block = recommended() + del block['rules'][0] + self.assertIn('no critical rule', refusal(block)) + + def test_empty_lenses_only_on_light(self): + for weight in ('critical', 'normal'): + block = recommended() + block['rules'][0]['weight'] = weight + block['rules'][0]['lenses'] = [] + self.assertIn(f'is {weight} with no lenses', refusal(block)) + block = recommended() + block['min_lenses']['light'] = 1 + block['min_lenses']['normal'] = 1 + self.assertIn("rules[1] ('docs'): light needs 1 different lens, found 0", refusal(block)) + + def test_min_lenses_values(self): + for bad in (-1, 11, '2', True, 1.5): + block = recommended() + block['min_lenses']['normal'] = bad + self.assertIn('min_lenses.normal is', refusal(block), bad) + block = recommended() + block['min_lenses'] = {'critical': 1, 'normal': 2, 'light': 0} + self.assertIn('critical >= normal >= light', refusal(block)) + + def test_rounds(self): + for k, bad in (('max', 0), ('max', 21), ('approach_at', '3'), ('approach_at', False)): + block = recommended() + block['rounds'][k] = bad + self.assertIn(f'rounds.{k} is', refusal(block)) + block = recommended() + block['rounds'] = {'approach_at': 4, 'max': 4, 'approach_lens': 'approach'} + self.assertEqual(rc.parse_review(block).rounds, rc.Rounds(4, 4, 'approach')) + block['rounds']['max'] = 3 + self.assertIn('rounds.max 3 is below rounds.approach_at 4', refusal(block)) + + def test_rule_shape(self): + block = recommended() + block['rules'][1]['name'] = 'data' + block['rules'][0]['weight'] = 'heavy' + block['rules'][2]['paths'] = [] + block['rules'][2]['lenses'] = 'code' + why = refusal(block) + self.assertIn("rules[1]: rule name 'data' is written twice", why) + self.assertIn('weight is "heavy"', why) + self.assertIn('paths is []', why) + self.assertIn('lenses is "code"', why) + block = recommended() + block['rules'][0]['lenses'] = ['data-1', 'data-2', 'data-1'] + self.assertIn('has a name written twice', refusal(block)) + block = recommended() + block['rules'][0]['paths'] = ['a/**', 'a/**'] + self.assertIn('has a glob written twice', refusal(block)) + self.assertIn('rules is []', refusal(dict(recommended(), rules=[]))) + self.assertIn('rules[0] is "x": must be an object', refusal(dict(recommended(), rules=['x']))) + for bad in ('', ' data', 'a\nb', 3): + block = recommended() + block['rules'][0]['name'] = bad + self.assertIn('rules[0].name is', refusal(block), bad) + + def test_config_names_review_and_other_problems_together(self): + block = recommended() + block['mode'] = 'loud' + with self.assertRaises(config.ConfigError) as e: + config.parse(json.dumps(dict(BASE, merge_method='fast', review=block)), 'repo/.github/queue.json') + why = str(e.exception) + self.assertTrue(why.startswith('repo/.github/queue.json: '), why) + self.assertIn('merge_method is "fast"', why) + self.assertIn('review: mode is "loud"', why) + + def test_lenses_shape(self): + self.assertIn('lenses is {}', refusal(dict(recommended(), lenses={}))) + block = recommended() + block['lenses']['code'] = '.github/lenses/code.md' + self.assertIn("lenses['code'] is", refusal(block)) + + +class Globs(unittest.TestCase): + GOOD = ('**', 'src/**', '**/*.md', 'a/**/b', '*.py', 'docs/?/x', '.github/workflows/**', 'a/b.c-d_e/f', + '**/**', 'src/*/test/**') + BAD = ('/src/**', 'src/**.py', 'a**', '**b/c', 'src/{a,b}/**', 'src/[ab]/**', '!src/**', 'src\\x', 'a//b', + 'a/', './a', 'a/../b', '..', '.', '', ' a', 'a\nb', 5, None) + + def test_dialect(self): + for g in self.GOOD: + self.assertIsNone(rc.glob_problem(g), g) + for g in self.BAD: + self.assertIsNotNone(rc.glob_problem(g), g) + + def test_a_bad_glob_refuses_the_config(self): + block = recommended() + block['rules'][0]['paths'] = ['src/{storage,db}/**', '/abs/**'] + why = refusal(block) + self.assertIn('"src/{storage,db}/**" has a character the dialect does not have', why) + self.assertIn('"/abs/**" must be repo-relative', why) + + def test_prompt_paths(self): + for good in ('.github/lenses/data.md', 'review/x.md', 'a'): + self.assertIsNone(rc.prompt_problem(good), good) + for bad in ('/etc/x.md', '../x.md', 'a/../x.md', 'lenses/*.md', 'a?.md', '', 'a\\b.md', 3): + self.assertIsNotNone(rc.prompt_problem(bad), bad) + block = recommended() + block['lenses']['code'] = {'prompt': '../outside.md'} + why = refusal(block) + self.assertIn("lenses['code'].prompt \"../outside.md\" has an empty, . or .. segment", why) + self.assertNotIn('no entry', why) # the entry's own problem, named once + + def test_readme_dialect_matches(self): + """The README names the characters the parser refuses.""" + with open(README, encoding='utf-8') as f: + text = f.read() + self.assertTrue(re.search(r'no braces, character classes, `!`\s+negation or backslashes', text)) + + +if __name__ == '__main__': + unittest.main() From 173c9586be72bcb4caea6b2e52a250e634d7f9f4 Mon Sep 17 00:00:00 2001 From: scuttletoby <123843277+scuttletoby@users.noreply.github.com> Date: Tue, 17 Nov 2026 17:44:06 +0000 Subject: [PATCH 2/3] pr-queue review block: any glob that matches every path is the catch-all; lens names as the gate reads them Round-1 lens on #301: `**/*` or `*/**` was not seen as the catch-all, so a light `**/*` rule first needed no lens anywhere and a normal one above a critical rule hid it. Now the first rule with a glob that matches every path is the catch-all. Also: a lens name the gate would read as another (`data *2*`, a reviewer: field) is refused; an unknown min_lenses key is named instead of a TypeError; the dialect says matching is case-sensitive and covers dot-names. Co-Authored-By: Claude Opus 5.5 --- fork-ci/actions/pr-queue/README.md | 13 +++--- fork-ci/actions/pr-queue/review_config.py | 39 +++++++++++++--- .../actions/pr-queue/review_config.test.py | 45 ++++++++++++++++++- 3 files changed, 85 insertions(+), 12 deletions(-) diff --git a/fork-ci/actions/pr-queue/README.md b/fork-ci/actions/pr-queue/README.md index 12cf7e938c37e..764fcb937cbdb 100644 --- a/fork-ci/actions/pr-queue/README.md +++ b/fork-ci/actions/pr-queue/README.md @@ -75,12 +75,14 @@ The config is refused when: trailing round marker do not count, so `data r1` and `data r2` are one lens; - two names in `lenses` are one lens to the gate in that way; - a lens name names no lens (a ``, a bare round marker such as `r2`, - nothing), or a rule or `rounds.approach_lens` names a lens with no entry in + nothing), or the gate would read it as another name in a lens header (Markdown + such as `data *2*`, or a `reviewer:` / `read at` field), or a rule or `rounds.approach_lens` names a lens with no entry in `lenses` (names match exactly); - a `critical` or `normal` rule has `"lenses": []` (only `light` may); -- no rule has the catch-all path `**`, the catch-all rule is `light`, or a rule - comes after the catch-all rule (it could never match): a new folder must never - fall to no rule or to no lens; +- no rule has a catch-all path (`**`, or any glob that matches every path such as + `**/*` or `*/**`), the catch-all rule is `light`, or a rule comes after the + catch-all rule (it could never match): a new folder must never fall to no rule + or to no lens; - there is no `critical` rule (the built-in protected paths below take its lenses); - a glob is not in the dialect below, or a rule name or glob is written twice. @@ -88,7 +90,8 @@ The config is refused when: path segment, `**` is any number of whole segments (it must be a segment of its own: `src/**/*.py`, not `src/**.py`), `?` is one character inside a segment. There are no braces, character classes, `!` negation or backslashes, and no -empty, `.` or `..` segments. The gate and T3 match with this dialect, so a glob +empty, `.` or `..` segments. Matching is case-sensitive, and `*`, `**` and `?` +also match names that start with `.` (`**` matches `.github/x`). The gate and T3 match with this dialect, so a glob means the same thing on both sides. **Built-in protected paths.** The config file itself, every lens prompt file and diff --git a/fork-ci/actions/pr-queue/review_config.py b/fork-ci/actions/pr-queue/review_config.py index 9c61a210e8416..2f9ff3208ab4b 100644 --- a/fork-ci/actions/pr-queue/review_config.py +++ b/fork-ci/actions/pr-queue/review_config.py @@ -7,7 +7,12 @@ Globs use one small dialect, so the Python gate and T3 match a path the same way: `*` any characters inside one path segment, `**` any number of whole segments (only as a segment of its own), `?` one character inside a segment. Paths -are repo-relative with `/`. No braces, character classes, `!` or backslashes. +are repo-relative with `/`. No braces, character classes, `!` or backslashes. Matching is case-sensitive, and `*`, +`**` and `?` also match names that start with `.` (`**` matches `.github/x`): a matcher that skips dot-names by +default must be told not to. + +The catch-all rule is the first rule with a glob that matches every path (`**`, `**/*`, `*/**`, `**/?*` ...), however +it is written; a rule after it can never match. """ import json import re @@ -98,6 +103,19 @@ def _path_problem(p): return None +def _matches_any_segment(seg): + """`seg` (no `**`) matches every path segment: segments are never empty, so `*`, `?`, `*?*` do; `??` does not.""" + return set(seg) <= {'*', '?'} and seg.count('?') <= 1 + + +def matches_every_path(g): + """The valid glob `g` matches every repo-relative path: it has a `**` segment and at most one other segment, which + matches any segment (every path has at least one segment).""" + segs = g.split('/') + rest = [s for s in segs if s != '**'] + return len(rest) < len(segs) and len(rest) <= 1 and all(_matches_any_segment(s) for s in rest) + + def glob_problem(g): """Why `g` is not a glob of the dialect (module doc), or None.""" why = _path_problem(g) @@ -131,6 +149,14 @@ def _lens_name(name, where, problems): if not _text(name) or not lens.names_a_lens(name): problems.append(f'{where} {_show(name)} names no lens (a placeholder, a round marker, blanks or nothing)') return False + # The gate reads a lens name out of a comment header after dropping Markdown and field text: a name it would read + # as another one (`data *2*` reads as `data 2`) would count as two lenses here and as one there. + header = lens.lens_header(f'lens: {name}') + if header is None or lens.lens_key(header[0]) != lens.lens_key(name): + read = 'nothing' if header is None else repr(header[0]) + problems.append(f'{where} {_show(name)} reads as {read} in a lens header (Markdown, a reviewer: or read at ' + f'field): write it the way the gate reads it') + return False return True @@ -165,7 +191,7 @@ def _min_lenses(raw, problems): return None bad = [w for w in WEIGHTS if w in raw and not _int(raw[w], 0, MAX_LENSES)] problems.extend(f'min_lenses.{w} is {_show(raw[w])}: must be a whole number 0-{MAX_LENSES}' for w in bad) - if bad or any(w not in raw for w in WEIGHTS): + if bad or any(w not in raw for w in WEIGHTS) or any(k not in WEIGHTS for k in raw): return None if not raw['critical'] >= raw['normal'] >= raw['light']: problems.append('min_lenses must not fall with weight: critical >= normal >= light') @@ -208,11 +234,11 @@ def _rules(raw, declared, mins, problems): if catch_all is not None: problems.append(f'{where} comes after the catch-all rule {catch_all} and can never match: ' f'move it above') - elif CATCH_ALL in paths: + elif any(isinstance(g, str) and not glob_problem(g) and matches_every_path(g) for g in paths): catch_all = where if weight == 'light': - problems.append(f'{where} is the catch-all ** rule and must not be light: a new folder ' - f'must never need no lens') + problems.append(f'{where} is the catch-all rule (a glob that matches every path, such as ' + f'**) and must not be light: a new folder must never need no lens') names_ = r.get('lenses') if 'lenses' in r: if not isinstance(names_, list): @@ -237,7 +263,8 @@ def _rules(raw, declared, mins, problems): if len(problems) == before: rules.append(Rule(r['name'], weight, tuple(paths), tuple(names_))) if catch_all is None: - problems.append(f'no rule has the catch-all path {CATCH_ALL!r}: a new folder must never fall to no rule') + problems.append(f'no rule has the catch-all path {CATCH_ALL!r} (or another glob that matches every path): a ' + f'new folder must never fall to no rule') if not any(isinstance(r, dict) and r.get('weight') == 'critical' for r in raw): problems.append('no critical rule: the built-in protected paths (the config, every lens prompt, ' '.github/workflows/**) take the lenses of the first critical rule') diff --git a/fork-ci/actions/pr-queue/review_config.test.py b/fork-ci/actions/pr-queue/review_config.test.py index 63ba8060cc3f7..4659d0de06081 100644 --- a/fork-ci/actions/pr-queue/review_config.test.py +++ b/fork-ci/actions/pr-queue/review_config.test.py @@ -124,7 +124,8 @@ def test_only_light_rules_matching_is_allowed_but_the_catch_all_is_not_light(sel block = recommended() block['rules'][2]['weight'] = 'light' block['rules'][2]['lenses'] = [] - self.assertIn('catch-all ** rule and must not be light', refusal(block)) + self.assertIn('is the catch-all rule (a glob that matches every path, such as **) and must not be light', + refusal(block)) def test_same_lens_key_in_lenses(self): block = recommended() @@ -225,6 +226,48 @@ def test_rule_after_catch_all(self): block['rules'].append({'name': 'late', 'weight': 'critical', 'paths': ['db/**'], 'lenses': ['data-1', 'data-2']}) self.assertIn("rules[3] ('late') comes after the catch-all rule", refusal(block)) + def test_every_path_glob_is_the_catch_all_however_written(self): + """`**/*`, `*/**`, `**/?*` match every path like `**`: such a rule first and light would need no lens anywhere, + and a critical rule below it could never match (both were accepted when only the text `**` counted).""" + for g in ('**/*', '*/**', '**/?*', '**/**', '**/*?*'): + block = recommended() + block['rules'].insert(0, {'name': 'all', 'weight': 'light', 'paths': ['docs/**', g], 'lenses': []}) + self.assertIn("rules[0] ('all') is the catch-all rule", refusal(block), g) + block = recommended() + block['rules'].insert(0, {'name': 'all', 'weight': 'normal', 'paths': [g], 'lenses': ['code']}) + why = refusal(block) + self.assertIn("rules[1] ('data') comes after the catch-all rule", why, g) + block = recommended() + block['rules'][2]['paths'] = [g] + self.assertEqual(rc.parse_review(block).rules[2].paths, (g,), g) + + def test_globs_that_miss_some_path_are_no_catch_all(self): + for g in ('*', '*/*/**', '**/??', '**/*.md', 'src/**', '**/a*', '?'): + self.assertFalse(rc.matches_every_path(g), g) + block = recommended() + block['rules'][2]['paths'] = [g] + self.assertIn("no rule has the catch-all path '**'", refusal(block), g) + for g in ('**', '**/*', '*/**', '**/*/**', '**/?', '**/*?', '**/**/*'): + self.assertTrue(rc.matches_every_path(g), g) + + def test_lens_name_the_gate_reads_as_another(self): + """`data *2*` is `data 2` to the gate (it drops Markdown before reading the name); `x reviewer: y` is `x`.""" + for bad in ('data *2*', 'data `2`', 'code reviewer: me', 'code read at: abcdef1', '_code_ more'): + block = recommended() + block['lenses'][bad] = {'prompt': '.github/lenses/data.md'} + self.assertIn(f'lens name {json.dumps(bad)} reads as', refusal(block), bad) + block = recommended() + block['lenses']['data 2'] = {'prompt': '.github/lenses/data.md'} + block['lenses']['data reviewer 2'] = {'prompt': '.github/lenses/data.md'} + block['rules'][0]['lenses'] = ['data 2', 'data reviewer 2'] + rc.parse_review(block) + + def test_unknown_key_in_min_lenses_is_named_not_a_crash(self): + block = recommended() + block['min_lenses']['huge'] = 3 + why = refusal(block) + self.assertIn("min_lenses: unknown key 'huge'", why) + def test_no_critical_rule(self): block = recommended() del block['rules'][0] From 41e359921d4a71e9ed4ddfa5cd1258312282f6f1 Mon Sep 17 00:00:00 2001 From: scuttletoby <123843277+scuttletoby@users.noreply.github.com> Date: Tue, 17 Nov 2026 17:58:37 +0000 Subject: [PATCH 3/3] pr-queue review block: a lone ? is no catch-all segment (#301 round 2) `?` matches exactly one character, so `**/?`, `?/**` and `**/?/**` miss almost every path but were taken as the catch-all. A segment matches every name only with a `*` and at most one `?`. A rule after the catch-all now says "or drop it, if it matches every path too" (moving a second catch-all above only swaps which one never matches). Co-Authored-By: Claude Opus 5.5 --- fork-ci/actions/pr-queue/review_config.py | 7 ++++--- fork-ci/actions/pr-queue/review_config.test.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/fork-ci/actions/pr-queue/review_config.py b/fork-ci/actions/pr-queue/review_config.py index 2f9ff3208ab4b..40fca74289366 100644 --- a/fork-ci/actions/pr-queue/review_config.py +++ b/fork-ci/actions/pr-queue/review_config.py @@ -104,8 +104,9 @@ def _path_problem(p): def _matches_any_segment(seg): - """`seg` (no `**`) matches every path segment: segments are never empty, so `*`, `?`, `*?*` do; `??` does not.""" - return set(seg) <= {'*', '?'} and seg.count('?') <= 1 + """`seg` (no `**`) matches every path segment: segments are never empty, so `*`, `*?`, `*?*` do; `?` and `??` + (exactly one or two characters) do not.""" + return set(seg) <= {'*', '?'} and '*' in seg and seg.count('?') <= 1 def matches_every_path(g): @@ -233,7 +234,7 @@ def _rules(raw, declared, mins, problems): problems.append(f'{where}.paths has a glob written twice') if catch_all is not None: problems.append(f'{where} comes after the catch-all rule {catch_all} and can never match: ' - f'move it above') + f'move it above (or drop it, if it matches every path too)') elif any(isinstance(g, str) and not glob_problem(g) and matches_every_path(g) for g in paths): catch_all = where if weight == 'light': diff --git a/fork-ci/actions/pr-queue/review_config.test.py b/fork-ci/actions/pr-queue/review_config.test.py index 4659d0de06081..4ef59affacd9f 100644 --- a/fork-ci/actions/pr-queue/review_config.test.py +++ b/fork-ci/actions/pr-queue/review_config.test.py @@ -242,12 +242,12 @@ def test_every_path_glob_is_the_catch_all_however_written(self): self.assertEqual(rc.parse_review(block).rules[2].paths, (g,), g) def test_globs_that_miss_some_path_are_no_catch_all(self): - for g in ('*', '*/*/**', '**/??', '**/*.md', 'src/**', '**/a*', '?'): + for g in ('*', '*/*/**', '**/??', '**/*.md', 'src/**', '**/a*', '?', '**/?', '?/**', '**/?/**', '**/??*'): self.assertFalse(rc.matches_every_path(g), g) block = recommended() block['rules'][2]['paths'] = [g] self.assertIn("no rule has the catch-all path '**'", refusal(block), g) - for g in ('**', '**/*', '*/**', '**/*/**', '**/?', '**/*?', '**/**/*'): + for g in ('**', '**/*', '*/**', '**/*/**', '**/*?', '**/?*', '**/*?*', '**/**/*'): self.assertTrue(rc.matches_every_path(g), g) def test_lens_name_the_gate_reads_as_another(self):