diff --git a/.github/workflows/README.md b/.github/workflows/README.md index 7821d66f9..7b22bddec 100644 --- a/.github/workflows/README.md +++ b/.github/workflows/README.md @@ -6,13 +6,13 @@ Three jobs run independently: | Job | Coverage | | --- | --- | -| Tests and static checks | `make ci-tests`: review guidance, naming, lint, the complete Python suite, Node UI/native-adapter tests and the fixture smoke test | +| Tests and static checks | `make ci-tests`: naming, lint, the complete Python suite, Node UI/native-adapter tests and the fixture smoke test | | Installation and packaging | Base installation and CLI language checks, sdist/pip installation, wheel smoke checks and all existing optional installation profiles | | Rendered reference and report checks | Chromium reference capture, report interactions and Web Search visual checks | The Python suite uses two workers with `--dist loadfile`, keeping each test file in one process. Slow-test durations appear in the job log. Local `make ci` remains serial by default; use `make ci PYTEST_ARGS='-n 2 --dist loadfile --durations=20'` for the same test scheduling. -`make review-check`, part of both `make ci-tests` and local `make ci`, verifies the pinned shared review guide and synchronization tool against `review-guidelines.lock.json`, and confirms that OCR loads the guide alongside its built-in rules. This offline integrity check needs no cross-repository credentials. Use `uv run --frozen python scripts/review_guidelines.py check --source ` to also compare the files with their recorded source commit. Shared requirements are maintained in `lexmount/ai-template-py`; Browser Eval's review supplement is the section after the repository supplement marker at the end of `docs/references/review-guidelines.md`; the lock covers only the text before it, and synchronization preserves it. +OCR loads `docs/references/review-guidelines.md`: the shared guide copied from `lexmount/ai-template-py`, with its source commit in the first line, followed by Browser Eval's supplement. To update the shared section, copy the new upstream text in an ordinary PR and update the commit. The existing `Python 3.11` status succeeds only when all three jobs succeed. A failed, cancelled or skipped job fails that status. New commits cancel obsolete CI runs for the same pull request. Main and tag runs each have a unique concurrency group, so a newer run cannot replace an earlier pending run. diff --git a/AGENTS.md b/AGENTS.md index 52a9cd095..6eea5f46e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,10 +1,9 @@ # Code review -Use [Review Guidelines](docs/references/review-guidelines.md). Its shared text and -`scripts/review_guidelines.py` are synchronized from the commit recorded in -`review-guidelines.lock.json`; change them in `lexmount/ai-template-py`. Browser -Eval's own requirements follow the repository supplement marker at the end of the -guide and are edited here. +Use the [review guidelines](docs/references/review-guidelines.md) that OCR loads. Their shared +section is copied from `lexmount/ai-template-py` at the commit named in the first +line; change it there and copy it here. The Browser Eval supplement at the end is +maintained in this repository. # Benchmark ownership diff --git a/Makefile b/Makefile index c49310c50..bc99107c6 100644 --- a/Makefile +++ b/Makefile @@ -58,11 +58,8 @@ fixture-smoke: runtime-check test: test-python test-ui test-native-adapters -.PHONY: review-check ci-tests -review-check: runtime-check - $(PY) scripts/review_guidelines.py check - -ci-tests: review-check naming-check lint-check test fixture-smoke +.PHONY: ci-tests +ci-tests: naming-check lint-check test fixture-smoke ci: ci-tests package-check diff --git a/docs/references/review-guidelines.md b/docs/references/review-guidelines.md index a12f5affe..69a80d7e1 100644 --- a/docs/references/review-guidelines.md +++ b/docs/references/review-guidelines.md @@ -1,17 +1,17 @@ + + # Review Guidelines The canonical version of this document lives in `lexmount/ai-template-py` at -`docs/references/review-guidelines.md`. Consumer repositories synchronize their -copies with `scripts/review_guidelines.py` and pin the source revision in -`review-guidelines.lock.json`. Change the canonical document rather than editing -a synchronized copy. A consumer adds its own requirements only after the -repository review supplement marker at the end of its copy; synchronization -preserves that section. +`docs/references/review-guidelines.md`. Consumer repositories copy it to the same +path, record the source commit in the first line and append their own supplement +at the end. Change shared text here rather than in a copy. OCR's official rules remain the foundation. This document adds shared review, -scope, and feedback requirements. The repository supplement at the end of this -document, when present, adds the consumer's domain requirements and entry points. Use the review language required by the user or -repository; preserve code identifiers, commands, schema values, and product names. +scope, and feedback requirements. The repository supplement at the end of a +consumer's copy adds its domain requirements and entry points. Use the review +language required by the user or repository; preserve code identifiers, commands, +schema values, and product names. ## Establish the review basis @@ -234,8 +234,6 @@ in those files. The work can close when valid in-scope findings are resolved and necessary verification passes. Add task requirements only when the user or repository maintainer explicitly changes the goal. - - ## Browser Eval review supplement Follow the repository review constraints in `AGENTS.md` and `CONTRIBUTING.md`. The following requirements belong to Browser Eval and supplement the shared criteria above and OCR's built-in rules. diff --git a/review-guidelines.lock.json b/review-guidelines.lock.json deleted file mode 100644 index 295f3c790..000000000 --- a/review-guidelines.lock.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "version": 1, - "repository": "lexmount/ai-template-py", - "revision": "984b8d5319ab3f87b13c2aae38ea9a7c795a3adf", - "files": { - "docs/references/review-guidelines.md": "98f93a11aefd1e003a778d889a77d9283b49ea786d7db3c38ed04005561cba06", - "scripts/review_guidelines.py": "6732c01ba592f098f32f76bad3ad5bde7d23002fc70a9acde2b16a48f6c0f96c" - } -} diff --git a/scripts/review_guidelines.py b/scripts/review_guidelines.py deleted file mode 100644 index a0c9e0de5..000000000 --- a/scripts/review_guidelines.py +++ /dev/null @@ -1,183 +0,0 @@ -"""Synchronize pinned review guidance and verify its local integrity.""" - -from __future__ import annotations - -import argparse -import hashlib -import json -from pathlib import Path -import re -import subprocess -import sys -from tempfile import TemporaryDirectory - - -REPOSITORY = "lexmount/ai-template-py" -FILES = ("docs/references/review-guidelines.md", "scripts/review_guidelines.py") -LOCK = "review-guidelines.lock.json" -# A consumer's copy of the guide may end with its own requirements after this -# line. The lock and source comparison cover only the shared text above it. -SUPPLEMENT = b"" - - -def git(root: Path, *args: str) -> bytes: - return subprocess.run( - ["git", "-C", str(root), *args], check=True, capture_output=True - ).stdout - - -def repository_root(path: Path) -> Path: - return Path(git(path, "rev-parse", "--show-toplevel").decode().strip()).resolve() - - -def is_source(root: Path) -> bool: - remote = git(root, "remote", "get-url", "origin").decode().strip().rstrip("/") - remote = remote.removesuffix(".git").replace("ssh://git@github.com/", "git@github.com:") - return remote in ( - f"git@github.com:{REPOSITORY}", - f"https://github.com/{REPOSITORY}", - ) - - -def shared_part(path: str, content: bytes) -> bytes: - if path != FILES[0]: - return content - shared, marker, _ = content.partition(SUPPLEMENT) - # Blank lines before the marker separate the sections and are not shared text. - return shared.rstrip(b"\n") + b"\n" if marker else shared - - -def local_part(path: str, content: bytes) -> bytes: - index = content.find(SUPPLEMENT) if path == FILES[0] else -1 - return b"" if index < 0 else b"\n" + content[index:] - - -def managed_path(root: Path, relative: str) -> Path: - path = root / relative - if path.exists() and not path.is_file(): - raise ValueError(f"Managed destination must be a file: {path}") - for candidate in (path, *path.parents): - if candidate == root: - break - if candidate.is_symlink(): - raise ValueError(f"Managed paths must not be symlinks: {candidate}") - if candidate != path and candidate.exists() and not candidate.is_dir(): - raise ValueError(f"Managed parent must be a directory: {candidate}") - return path - - -def digest(content: bytes) -> str: - return hashlib.sha256(content).hexdigest() - - -def source_files(source: Path, revision: str) -> dict[str, bytes]: - if not re.fullmatch(r"[0-9a-f]{40}", revision): - raise ValueError("Use a full 40-character source commit, not a moving ref") - if not is_source(source): - raise ValueError(f"Source origin must be {REPOSITORY}") - if git(source, "cat-file", "-t", revision).strip() != b"commit": - raise ValueError("The source revision must identify a commit") - contents = {path: git(source, "show", f"{revision}:{path}") for path in FILES} - if local_part(FILES[0], contents[FILES[0]]): - raise ValueError("The canonical guide must not contain a repository supplement") - return contents - - -def check_routing(root: Path) -> None: - config_path = root / ".opencodereview/rule.json" - if not config_path.exists(): - raise ValueError("Missing .opencodereview/rule.json") - rules = json.loads(config_path.read_text())["rules"] - if rules != [{"path": "**", "rule": FILES[0], "merge_system_rule": True}]: - raise ValueError("OCR must load the shared guide and retain built-in rules") - - -def check(root: Path, source: Path | None = None) -> None: - lock_path = managed_path(root, LOCK) - if not lock_path.exists(): - if not is_source(root): - raise ValueError(f"Missing {LOCK}; synchronize from {REPOSITORY}") - for path in FILES: - content = managed_path(root, path).read_bytes() - if not content.strip(): - raise ValueError(f"Empty source file: {path}") - if local_part(path, content): - raise ValueError("The canonical guide must not contain a repository supplement") - else: - lock = json.loads(lock_path.read_text()) - if lock.get("repository") != REPOSITORY or lock.get("version") != 1: - raise ValueError("Unsupported review source lock") - revision = lock["revision"] - if not isinstance(revision, str) or not re.fullmatch(r"[0-9a-f]{40}", revision): - raise ValueError("The source lock must pin a full commit") - if set(lock["files"]) != set(FILES): - raise ValueError("The lock must cover the guide and synchronization tool") - upstream = source_files(source, revision) if source is not None else None - for path in FILES: - local = shared_part(path, managed_path(root, path).read_bytes()) - if digest(local) != lock["files"][path]: - raise ValueError(f"Local drift: {path}; synchronize, do not edit the copy") - if upstream is not None and local != upstream[path]: - raise ValueError(f"Source mismatch at {revision}: {path}") - check_routing(root) - print(f"Review guidance verified: {root}") - - -def sync(source: Path, revision: str, targets: list[Path]) -> None: - contents = source_files(source, revision) - lock = { - "version": 1, - "repository": REPOSITORY, - "revision": revision, - "files": {path: digest(data) for path, data in contents.items()}, - } - prepared = [] - # Validate every destination before writing; repositories are then updated in turn. - for root in targets: - if is_source(root): - raise ValueError("Edit the canonical source directly; do not sync over it") - payloads = {**contents, LOCK: (json.dumps(lock, indent=2) + "\n").encode()} - for path in payloads: - managed_path(root, path) - guide = root / FILES[0] - if guide.exists(): - payloads[FILES[0]] += local_part(FILES[0], guide.read_bytes()) - check_routing(root) - prepared.append((root, payloads)) - for root, payloads in prepared: - with TemporaryDirectory(prefix=".review-guidelines-", dir=root) as directory: - staged = Path(directory) - for path, data in payloads.items(): - (staged / Path(path).name).write_bytes(data) - # Replace complete files on the same filesystem, publishing the lock last. - for path in payloads: - destination = managed_path(root, path) - destination.parent.mkdir(parents=True, exist_ok=True) - (staged / Path(path).name).replace(destination) - check(root, source) - - -def main() -> int: - parser = argparse.ArgumentParser(description=__doc__) - commands = parser.add_subparsers(dest="command", required=True) - verify = commands.add_parser("check", help="Check the pinned local files offline") - verify.add_argument("--source", type=Path, help="Also compare the pinned Git source") - update = commands.add_parser("sync", help="Update one or more repository checkouts") - update.add_argument("--source", type=Path, required=True) - update.add_argument("--ref", required=True, help="Full source commit") - update.add_argument("targets", nargs="+", type=Path) - args = parser.parse_args() - try: - if args.command == "check": - source = repository_root(args.source) if args.source else None - check(repository_root(Path.cwd()), source) - else: - sync(repository_root(args.source), args.ref, [repository_root(p) for p in args.targets]) - except (OSError, ValueError, KeyError, TypeError, subprocess.CalledProcessError) as exc: - print(f"Review guidance error: {exc}", file=sys.stderr) - return 1 - return 0 - - -if __name__ == "__main__": - raise SystemExit(main())