Skip to content

Commit 773e811

Browse files
luisleo526claude
andcommitted
Merge main (b7bea58, #407) into fu/cr245-release-bump-exemption-v2
One conflict, scripts/test_ci_preflight.py (add/add in the same place, after the run-json-harness test): main added test_duplicate_test_name_stages_are_binding_and_pin_the_source_root (#407); this branch added test_release_bump_contract_and_gate_tests_remain_binding (CR-245). Both are kept, unchanged and unrelated, one blank line between them. Auto-merged without conflict: .github/workflows/ci.yml, AGENTS.md, scripts/ci_preflight.py (main added the duplicate-test-names stages; this branch's release-gate pins are untouched), scripts/test_ci_verify.py. New from main: scripts/check_duplicate_test_names.py, scripts/test_check_duplicate_test_names.py. scripts/ci_release_gate.py, scripts/test_ci_release_gate.py, .github/workflows/release.yml and docs/ci.md did not change on main and are as in the branch. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2 parents 46bfa21 + b7bea58 commit 773e811

7 files changed

Lines changed: 700 additions & 32 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ name: CI
22

33
on:
44
pull_request:
5+
# LB-387: suite jobs skip on a draft PR (the required aggregate then fails, never passes);
6+
# ready_for_review starts the full run when the PR is marked ready.
7+
# converted_to_draft re-runs the workflow so its failing aggregate supersedes the earlier ready run.
8+
types: [opened, synchronize, reopened, ready_for_review, converted_to_draft]
59

610
permissions:
711
contents: read
812

913
# Post-merge events live in ci-post.yml; this file only schedules PR jobs.
1014
concurrency:
11-
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
15+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}-${{ github.event.pull_request.draft && 'draft' || 'ready' }}
1216
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
1317

1418
env:
@@ -222,7 +226,7 @@ jobs:
222226
223227
preflight:
224228
needs: [authz, changes]
225-
if: ${{ always() && needs.authz.result == 'success' }}
229+
if: ${{ !github.event.pull_request.draft && (always() && needs.authz.result == 'success') }}
226230
runs-on: ["self-hosted","pf-gcp-pr"]
227231
env:
228232
PF_CI_LABELS: '["self-hosted","pf-ci","pf-ci-x64-16"]'
@@ -282,7 +286,7 @@ jobs:
282286
# successful docs-only or GitHub-only answer skips scheduling; the aggregate
283287
# independently reads the PR diff before accepting the latter skip.
284288
needs: [authz, changes]
285-
if: ${{ always() && needs.authz.result == 'success' && (needs.changes.result != 'success' || (needs.changes.outputs.docs_only != 'true' && (github.event_name != 'pull_request' || needs.changes.outputs.github_only != 'true'))) }}
289+
if: ${{ !github.event.pull_request.draft && (always() && needs.authz.result == 'success' && (needs.changes.result != 'success' || (needs.changes.outputs.docs_only != 'true' && (github.event_name != 'pull_request' || needs.changes.outputs.github_only != 'true')))) }}
286290
# 360 minutes (the platform maximum): a full-set leg waits on the
287291
# test_ci_verify CTest row, 976-1288 s on the standard runners at
288292
# 0d76a099, which more cores do not shorten. No bound of ours may fail a
@@ -384,7 +388,7 @@ jobs:
384388
# separate parity verdict. build-gate independently verifies GitHub-only skips.
385389
corpus-parity-subset:
386390
needs: [authz, changes]
387-
if: ${{ always() && needs.authz.result == 'success' && (needs.changes.result != 'success' || (needs.changes.outputs.docs_only != 'true' && (github.event_name != 'pull_request' || needs.changes.outputs.github_only != 'true'))) }}
391+
if: ${{ !github.event.pull_request.draft && (always() && needs.authz.result == 'success' && (needs.changes.result != 'success' || (needs.changes.outputs.docs_only != 'true' && (github.event_name != 'pull_request' || needs.changes.outputs.github_only != 'true')))) }}
388392
uses: ./.github/workflows/corpus-parity-subset.yml
389393

390394
# Advisory aggregate context covering every GitHub Actions lane. The merge

‎AGENTS.md‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ Both C++ unit tests and full corpus verification must pass.
99
The merge ruleset requires `pineforge/verify` and `pineforge/parity` commit
1010
statuses on the PR head's exact tree. The maintainers post them from their own (private)
1111
verification tooling after full verification on their x86-64 build hosts and a
12-
parity verdict; an outside contributor cannot post them. GitHub Actions is advisory: PRs run Ubuntu Release/Debug and macOS Release; macOS Debug stays on non-PR events.
13-
PR Release, Ubuntu Debug, kernel-only, sanitizers and native jobs exclude the measured `slow` CTest rows; push-to-main and manual CI dispatch
14-
run every row, and a documentation-only change runs preflight alone among verification jobs.
15-
CI/native start with the canon `authz` job and every other job needs it. Heavy
16-
Linux lanes use `["self-hosted","pf-ci","pf-ci-x64-16"]`, light jobs use
17-
`["self-hosted","pf-ci","pf-ci-x64"]`, with no hosted fallback; macOS is the
18-
exception. Both aggregates always run and refuse non-success authz first.
12+
parity verdict; an outside contributor cannot post them. GitHub Actions is advisory: PRs build Ubuntu Release only (`ci.yml`); Debug, sanitizers, kernel-only and the macOS cell run post-merge (`ci-post.yml`).
13+
The PR build (`ci.yml`) runs only the `fast`-labelled CTest rows (`ctest -L '^fast$'`); the post-merge legs (`ci-post.yml`) run
14+
every row, and a documentation-only change runs preflight alone among verification jobs.
15+
The seven PR/post-merge verification and documentation workflows start with the canon `authz` job and every other job in them needs it; release uses its status gate and baseline promotion its `promote-guard`. Pull-request
16+
workflows (`ci.yml`, `corpus-parity-subset.yml`, `docs.yml`) run every job on `["self-hosted","pf-gcp-pr"]`;
17+
post-merge workflows (`ci-post.yml` and the workflows it calls) run on `["self-hosted","pf-gcp-post"]`, and
18+
release jobs on `["self-hosted","pf-gcp-main"]`. In the CI workflows the only hosted job is the macOS post-merge cell `build-macos`; `release.yml` also uses hosted arm64 and macOS prebuilt cells and `promote-baseline.yml` a hosted guard job. The `build-gate` jobs in `ci.yml` and `ci-post.yml` and `native-live.yml`'s `native-live-gate` always run and refuse a non-success authz result first.
1919
See `docs/ci.md` for the class table and docs-only exception. The commands below run the full sets.
2020

2121
```bash
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
#!/usr/bin/env python3
2+
"""Refuse duplicate methods, test functions, and class bindings.
3+
4+
Parses the Python test/driver inventory with ``ast``, never importing targets.
5+
Control-flow suites share their enclosing module or class namespace. Exits 1
6+
with ``file:line`` diagnostics for duplicates, absent inventory directories,
7+
or an inspection with no files or no ``test_*`` names; exits 0 otherwise.
8+
"""
9+
from __future__ import annotations
10+
11+
import argparse
12+
import ast
13+
from pathlib import Path
14+
import sys
15+
from typing import Iterable, Sequence
16+
import warnings
17+
18+
ROOT = Path(__file__).resolve().parent.parent
19+
TEST_GLOBS = (
20+
# CMake registers test_*, *_self_test, --self-test drivers and source
21+
# guards in scripts; tests also has e2e/receipt/equivalence driver names.
22+
# Scan the whole directories so those naming variants cannot evade this.
23+
('scripts', '*.py'),
24+
('docker', '*_test.py'),
25+
('tests', '*.py'),
26+
('tests/ownership', 'test_*.py'),
27+
('benchmarks', '*.py'),
28+
('benchmarks/tests', 'test_*.py'),
29+
)
30+
31+
32+
def default_test_files(root: Path = ROOT) -> list[Path]:
33+
if not root.is_dir():
34+
raise ValueError(f'missing repository root: {root}')
35+
files: list[Path] = []
36+
for subdir, pattern in TEST_GLOBS:
37+
directory = root / subdir
38+
if not directory.is_dir():
39+
raise ValueError(f'missing expected test directory: {directory}')
40+
files.extend(sorted(directory.glob(pattern)))
41+
return files
42+
43+
44+
def _scope_statements(nodes: Iterable[ast.AST]) -> Iterable[ast.stmt]:
45+
"""Walk all control-flow suites, stopping at namespace boundaries."""
46+
for node in nodes:
47+
if isinstance(node, ast.stmt):
48+
yield node
49+
if not isinstance(node, (ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef, ast.Lambda)):
50+
yield from _scope_statements(ast.iter_child_nodes(node))
51+
52+
53+
def _check_scope(
54+
path: Path,
55+
nodes: Iterable[ast.stmt],
56+
findings: list[tuple[Path, int, str]],
57+
class_name: str | None = None,
58+
) -> int:
59+
seen_functions: dict[str, int] = {}
60+
seen_classes: dict[str, int] = {}
61+
test_names = 0
62+
for stmt in _scope_statements(nodes):
63+
if isinstance(stmt, (ast.FunctionDef, ast.AsyncFunctionDef)):
64+
is_test = stmt.name.startswith('test_')
65+
test_names += int(is_test)
66+
if class_name is None and not is_test:
67+
continue
68+
kind = f'method {class_name}.{stmt.name}' if class_name else f'top-level test function {stmt.name}'
69+
if stmt.name in seen_functions:
70+
findings.append((
71+
path,
72+
stmt.lineno,
73+
f'duplicate {kind} '
74+
f'(first defined at line {seen_functions[stmt.name]})',
75+
))
76+
else:
77+
seen_functions[stmt.name] = stmt.lineno
78+
elif isinstance(stmt, ast.ClassDef):
79+
qualified = f'{class_name}.{stmt.name}' if class_name else stmt.name
80+
test_names += _check_scope(path, stmt.body, findings, qualified)
81+
# An empty body can inherit tests; refuse the rebinding without
82+
# trying to execute imports or resolve the class's ancestry.
83+
if stmt.name in seen_classes:
84+
findings.append((
85+
path,
86+
stmt.lineno,
87+
f'duplicate test class {qualified} '
88+
f'(first defined at line {seen_classes[stmt.name]})',
89+
))
90+
else:
91+
seen_classes[stmt.name] = stmt.lineno
92+
return test_names
93+
94+
95+
def _inspect_file(path: Path) -> tuple[list[tuple[Path, int, str]], int]:
96+
with warnings.catch_warnings():
97+
# Scanned source warnings must not leak or become parse failures under
98+
# a caller's warning-as-error policy. Actual syntax errors still fail.
99+
warnings.simplefilter('ignore')
100+
tree = ast.parse(path.read_text(encoding='utf-8'), filename=str(path))
101+
findings: list[tuple[Path, int, str]] = []
102+
test_names = _check_scope(path, tree.body, findings)
103+
return findings, test_names
104+
105+
106+
def check_file(path: Path) -> list[tuple[Path, int, str]]:
107+
return _inspect_file(path)[0]
108+
109+
110+
def collect_files(root: Path, paths: Sequence[Path]) -> list[Path]:
111+
if not paths:
112+
return default_test_files(root)
113+
collected: list[Path] = []
114+
for item in paths:
115+
if item.is_dir():
116+
if any((item / subdir).exists() for subdir, _ in TEST_GLOBS):
117+
collected.extend(default_test_files(item))
118+
else:
119+
collected.extend(sorted(item.glob('*.py')))
120+
else:
121+
collected.append(item)
122+
return list(dict.fromkeys(collected))
123+
124+
125+
def check_paths(paths: Sequence[Path]) -> list[tuple[Path, int, str]]:
126+
findings: list[tuple[Path, int, str]] = []
127+
test_names = 0
128+
for path in paths:
129+
file_findings, file_test_names = _inspect_file(path)
130+
findings.extend(file_findings)
131+
test_names += file_test_names
132+
if paths and test_names == 0:
133+
findings.append((paths[0], 1, 'no test names inspected'))
134+
return findings
135+
136+
137+
def parse_args(argv: Sequence[str] | None = None) -> argparse.Namespace:
138+
parser = argparse.ArgumentParser(description=__doc__)
139+
parser.add_argument(
140+
'--root',
141+
type=Path,
142+
default=ROOT,
143+
help='Repository root to scan when no explicit paths are given.',
144+
)
145+
parser.add_argument(
146+
'paths',
147+
nargs='*',
148+
type=Path,
149+
help='Optional explicit test files or directories to check.',
150+
)
151+
return parser.parse_args(argv)
152+
153+
154+
def main(argv: Sequence[str] | None = None) -> int:
155+
args = parse_args(argv)
156+
try:
157+
files = collect_files(args.root, args.paths)
158+
if not files:
159+
print('no test files inspected', file=sys.stderr)
160+
return 1
161+
findings = check_paths(files)
162+
except (OSError, SyntaxError, ValueError) as error:
163+
print(error, file=sys.stderr)
164+
return 1
165+
if findings:
166+
for path, lineno, detail in findings:
167+
print(f'{path}:{lineno}: {detail}', file=sys.stderr)
168+
return 1
169+
return 0
170+
171+
172+
if __name__ == '__main__':
173+
raise SystemExit(main())

‎scripts/ci_preflight.py‎

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@
4747
RELEASE_RUNNER = '["self-hosted","pf-gcp-main"]'
4848
CI_EVENTS = '''on:
4949
pull_request:
50+
# LB-387: suite jobs skip on a draft PR (the required aggregate then fails, never passes);
51+
# ready_for_review starts the full run when the PR is marked ready.
52+
# converted_to_draft re-runs the workflow so its failing aggregate supersedes the earlier ready run.
53+
types: [opened, synchronize, reopened, ready_for_review, converted_to_draft]
54+
'''
55+
CI_CONCURRENCY = '''concurrency:
56+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}-${{ github.event.pull_request.draft && 'draft' || 'ready' }}
57+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
5058
'''
5159
POST_CI_EVENTS = '''on:
5260
push:
@@ -170,14 +178,16 @@
170178
HEAVY_JOBS = frozenset(('sanitizers', 'kernel-only', 'native-live', 'corpus-parity'))
171179
AUTHZ_SUCCESS = "${{ needs.authz.result == 'success' }}"
172180
AUTHZ_ALWAYS = "${{ always() && needs.authz.result == 'success' }}"
181+
PREFLIGHT_IF = "${{ !github.event.pull_request.draft && (always() && needs.authz.result == 'success') }}"
173182
AUTHZ_FULL_SUCCESS = "${{ needs.authz.result == 'success' && github.event_name != 'pull_request' }}"
174183
DOCS_ONLY_SKIP = ("${{ always() && needs.authz.result == 'success' && (needs.changes.result != 'success' || "
175184
"needs.changes.outputs.docs_only != 'true') }}")
176185
# Only the scheduling hint comes from changes. The aggregate recomputes this
177186
# class from the event-bound API diff inside its own job.
178-
GITHUB_ONLY_SKIP = ("${{ always() && needs.authz.result == 'success' && (needs.changes.result != 'success' || "
187+
GITHUB_ONLY_SKIP = ("${{ !github.event.pull_request.draft && (always() && needs.authz.result == 'success' && "
188+
"(needs.changes.result != 'success' || "
179189
"(needs.changes.outputs.docs_only != 'true' && (github.event_name != 'pull_request' || "
180-
"needs.changes.outputs.github_only != 'true'))) }}")
190+
"needs.changes.outputs.github_only != 'true')))) }}")
181191
HEAVY_SKIP = DOCS_ONLY_SKIP
182192
SLOW_PREFLIGHT_IF = AUTHZ_ALWAYS
183193
BUILD_VERIFY_RUN = ' '.join(r'''|
@@ -1225,7 +1235,12 @@ def authz_workflow_findings(workflow: str, name: str, aggregate: str) -> list[st
12251235
if events is None or 'pull_request_target' in events:
12261236
findings.append(f'{name} must use readable events without pull_request_target')
12271237
pr = re.search(r'(?m)^ pull_request:[^\n]*(?:\n(?: [^\n]*|[ \t]*))*', workflow)
1228-
if name == 'ci.yml' and (not pr or pr[0].strip() != 'pull_request:'):
1238+
if name == 'ci.yml' and (not pr or pr[0].strip() != (
1239+
'pull_request:\n'
1240+
' # LB-387: suite jobs skip on a draft PR (the required aggregate then fails, never passes);\n'
1241+
' # ready_for_review starts the full run when the PR is marked ready.\n'
1242+
' # converted_to_draft re-runs the workflow so its failing aggregate supersedes the earlier ready run.\n'
1243+
' types: [opened, synchronize, reopened, ready_for_review, converted_to_draft]')):
12291244
findings.append('ci.yml must run on every pull_request without event filters')
12301245
if _job_values(workflow, 'permissions') != ['contents: read']:
12311246
findings.append(f'{name} must retain contents: read workflow permissions')
@@ -1446,6 +1461,8 @@ def pipeline_workflow_findings(workflow: str, name: str, *, pr: bool) -> list[st
14461461
events = CI_EVENTS if pr else POST_CI_EVENTS
14471462
if _job_block(workflow, 'on') != _code(events):
14481463
findings.append(f'{name} must keep its exact {"unfiltered PR" if pr else "main push, nightly and manual"} triggers')
1464+
if pr and _job_block(workflow, 'concurrency') != _code(CI_CONCURRENCY):
1465+
findings.append('ci.yml must keep its exact draft and ready concurrency groups')
14491466
jobs = _jobs(workflow)
14501467
proofs = PR_PROOF_JOBS if pr else PROOF_JOBS
14511468
expected_jobs = {'authz', 'changes', 'preflight', *proofs, 'build-gate'}
@@ -1471,7 +1488,7 @@ def pipeline_workflow_findings(workflow: str, name: str, *, pr: bool) -> list[st
14711488
findings.append("changes must publish the base's scripts/ci_verifier_paths.py answer, exactly")
14721489
preflight = jobs.get('preflight', '')
14731490
if (sorted(_needs(preflight)) != ['authz', 'changes']
1474-
or _job_values(preflight, 'if') != [AUTHZ_ALWAYS]):
1491+
or _job_values(preflight, 'if') != [PREFLIGHT_IF if pr else AUTHZ_ALWAYS]):
14751492
findings.append('preflight must follow authz and changes and run even if classification fails')
14761493
if (f' PINEFORGE_VERIFIER_SLOW: {PREFLIGHT_VERIFIER_SLOW}\n' not in preflight
14771494
or preflight.count('PINEFORGE_VERIFIER_SLOW:') != 1):
@@ -2010,6 +2027,11 @@ def check_commands(source: Path, output: Path | None = None,
20102027
[sys.executable, str(source / 'scripts/check_pine_to_native_coverage.py')]),
20112028
('doc-pine-coverage-tests',
20122029
[sys.executable, str(source / 'scripts/test_check_pine_to_native_coverage.py')]),
2030+
('duplicate-test-names-tests',
2031+
[sys.executable, str(source / 'scripts/test_check_duplicate_test_names.py')]),
2032+
('duplicate-test-names',
2033+
[sys.executable, str(source / 'scripts/check_duplicate_test_names.py'),
2034+
'--root', str(source)]),
20132035
]
20142036
if tier == 'github-only':
20152037
return [entry for entry in commands if entry[0] in GITHUB_ONLY_PREFLIGHT_STAGES]

0 commit comments

Comments
 (0)