AI-powered virtual executive team — a single coherent executive persona backed by 8 specialist agents (FastAPI + Next.js).
chore(ci): let the release PR's version bump pass the arch-doc check (#248)
Rufusb2e0aacff6c4
diff --git a/packages/core/tests/unit/test_pr_checks.py b/packages/core/tests/unit/test_pr_checks.pyindex 535e9c76..6c4918ce 100644--- a/packages/core/tests/unit/test_pr_checks.py+++ b/packages/core/tests/unit/test_pr_checks.py@@ -3,6 +3,7 @@from __future__ import annotationsimport importlib.util+import jsonimport subprocessimport sysfrom pathlib import Path@@ -173,6 +174,95 @@ def test_parse_added_lines_only_trusts_headers() -> None:}+def test_drift_ignores_release_please_version_bump() -> None:+ main_py = PKG + "api/main.py"+ bump = {+ "changed": {main_py},+ "added_lines": {main_py: [' version="0.4.2", # x-release-please-version']},+ "removed_lines": {main_py: [' version="0.4.1", # x-release-please-version']},+ }+ assert _level(pr_checks.check_arch_drift, **bump) == "PASS"+ assert _level(pr_checks.check_tests_present, **bump) == "PASS"++ models_py = PKG + "api/models.py"+ bump = {+ "changed": {models_py},+ "added_lines": {models_py: [' version: str = "1.0.0-rc.1" # x-release-please-version']},+ "removed_lines": {models_py: [' version: str = "0.4.2" # x-release-please-version']},+ }+ assert _level(pr_checks.check_arch_drift, **bump) == "PASS"+++def test_release_please_files_match_its_config() -> None:+ config = json.loads((_SCRIPT.parents[1] / "release-please-config.json").read_text())+ generic = {+ f["path"]+ for pkg in config["packages"].values()+ for f in pkg.get("extra-files", [])+ if f.get("type") == "generic"+ }+ assert generic == pr_checks.RELEASE_PLEASE_FILES+++def test_drift_counts_a_marked_bump_outside_release_please_files() -> None:+ router = PKG + "orchestrator/router.py"+ change = {+ "changed": {router},+ "added_lines": {router: ['SCHEMA_VERSION = "2.0.0" # x-release-please-version']},+ "removed_lines": {router: ['SCHEMA_VERSION = "1.0.0" # x-release-please-version']},+ }+ assert _level(pr_checks.check_arch_drift, **change) == "FAIL"+++_MARK = " # x-release-please-version"+++ ("added", "removed"),+ [+ # code beside the bump+ (['version="0.4.2"' + _MARK, "x = 1"], ['version="0.4.1"' + _MARK]),+ (['version="0.4.2"' + _MARK], ["x = 1"]),+ (['version="0.4.2"' + _MARK], []),+ # other edits on a marked line+ (["SOME_FLAG = True" + _MARK], ["SOME_FLAG = False" + _MARK]),+ (['version="0.4.2", debug=True' + _MARK], ['version="0.4.1"' + _MARK]),+ (['name="0.4.2"' + _MARK], ['version="0.4.1"' + _MARK]),+ (['version="0.4.1"'], ['version="0.4.1"' + _MARK]),+ ],+)+def test_drift_still_counts_code_beside_a_version_bump(+ added: list[str], removed: list[str]+) -> None:+ main_py = PKG + "api/main.py"+ change = {+ "changed": {main_py},+ "added_lines": {main_py: added},+ "removed_lines": {main_py: removed},+ }+ assert _level(pr_checks.check_arch_drift, **change) == "FAIL"+++def test_parse_removed_lines_keys_by_new_path() -> None:+ diff = "\n".join(+ [+ "diff --git a/x.py b/x.py",+ "--- a/x.py",+ "+++ b/x.py",+ "@@ -1,2 +1 @@",+ "--- a", # a removed line that reads "-- a"+ "-old",+ "+new",+ "diff --git a/gone.py b/gone.py",+ "--- a/gone.py",+ "+++ /dev/null",+ "@@ -1 +0,0 @@",+ "-bye",+ ]+ )+ assert pr_checks._parse_removed_lines(diff) == {"x.py": ["-- a", "old"]}++# --- tests-present -----------------------------------------------------------@@ -234,6 +324,34 @@ def test_collect_and_main_against_a_real_repo(assert "waived (Arch-Docs: n/a - from the PR body)" in capsys.readouterr().out+def test_main_passes_a_release_please_bump(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]+) -> None:+ repo = tmp_path+ _git(repo, "init", "-q", "-b", "main")+ _git(repo, "config", "user.email", "[email protected]")+ _git(repo, "config", "user.name", "t")+ main_py = repo / PKG / "api" / "main.py"+ main_py.parent.mkdir(parents=True)+ main_py.write_text('app = App(\n version="0.4.1", # x-release-please-version\n)\n')+ _git(repo, "add", "-A")+ _git(repo, "commit", "-qm", "base")+ _git(repo, "checkout", "-qb", "release")+ monkeypatch.chdir(repo)+ monkeypatch.delenv("PR_BODY", raising=False)++ main_py.write_text('app = App(\n version="0.4.2", # x-release-please-version\n)\n')+ _git(repo, "commit", "-qam", "chore(main): release 0.4.2")+ assert pr_checks.main(["--base", "main"]) == 0+ assert "PASS arch-doc-drift no documented module changed" in capsys.readouterr().out++ main_py.write_text(+ 'app = App(\n version="0.4.2", # x-release-please-version\n debug=True,\n)\n'+ )+ assert pr_checks.main(["--base", "main"]) == 1+ assert "FAIL arch-doc-drift" in capsys.readouterr().out++def test_collect_survives_odd_files_and_git_config(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:@@ -275,8 +393,18 @@ def test_main_reports_missing_base(tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]) -> None:_git(tmp_path, "init", "-q", "-b", "main")- _git(tmp_path, "-c", "[email protected]", "-c", "user.name=t", "commit", "-q",- "--allow-empty", "-m", "base")+ _git(+ tmp_path,+ "-c",+ "[email protected]",+ "-c",+ "user.name=t",+ "commit",+ "-q",+ "--allow-empty",+ "-m",+ "base",+ )monkeypatch.chdir(tmp_path)assert pr_checks.main(["--base", "origin/nope"]) == 2assert "is 'origin/nope' fetched?" in capsys.readouterr().outdiff --git a/scripts/pr_checks.py b/scripts/pr_checks.pyindex f15491a5..c57965cf 100644--- a/scripts/pr_checks.py+++ b/scripts/pr_checks.py@@ -15,6 +15,10 @@ Checks (see CLAUDE.md -> "Architecture Docs" and "PR Requirements"):evals/_scenarios/ change- tests-present WARN openexecutive/ code changed with no tests/ change+A release-please version bump is not a code change: when a file release-please+manages only has the version number rewritten on its marked lines (the release+PR's bump), it counts for neither arch-doc-drift nor tests-present.+A change that does not alter what a section describes can waive the driftcheck with a line in a commit message or the PR description:@@ -84,6 +88,12 @@ STUB_RE = re.compile(r"\bTODO\b|\bFIXME\b|raise NotImplementedError|pass\s+#\s*stub|\.\.\.\s*#\s*stub")CODE_EXT = (".py", ".ts", ".tsx", ".js", ".jsx")+# release-please rewrites the version on lines ending in this marker in its+# "generic" extra-files. Keep in step with release-please-config.json (a test+# checks); any other file carrying the marker gets no exemption.+VERSION_MARKER = "x-release-please-version"+RELEASE_PLEASE_FILES = {PKG + "api/main.py", PKG + "api/models.py"}+SEMVER_RE = re.compile(r"\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?")# These files name the stub patterns themselves.STUB_EXEMPT = {"scripts/pr_checks.py", TESTS + "unit/test_pr_checks.py"}@@ -98,8 +108,33 @@ class Change:renamed: set[str] = field(default_factory=set)# path -> lines the diff adds to that fileadded_lines: dict[str, list[str]] = field(default_factory=dict)+ # path -> lines the diff removes from that file+ removed_lines: dict[str, list[str]] = field(default_factory=dict)waiver_text: str = ""+ def version_bump_only(self, path: str) -> bool:+ """True when the diff to path only rewrites marked version numbers.++ Each removed line must match its added line once the version is+ masked, so other edits on a marked line still count as code.+ """+ if path not in RELEASE_PLEASE_FILES:+ return False+ added = self.added_lines.get(path, [])+ removed = self.removed_lines.get(path, [])+ if not added or len(added) != len(removed):+ return False+ return all(+ VERSION_MARKER in new+ and SEMVER_RE.search(new)+ and SEMVER_RE.sub("", new) == SEMVER_RE.sub("", old)+ for old, new in zip(removed, added, strict=True)+ )++ def code_changed(self) -> set[str]:+ """Changed paths, less release-please version bumps."""+ return {p for p in self.changed if not self.version_bump_only(p)}+@dataclassclass Result:@@ -124,7 +159,7 @@ def check_arch_drift(c: Change) -> Result:for p in c.changedif p.startswith(PREBUILT) and p.endswith(".json") and "/" not in p[len(PREBUILT) :]}- modules = sorted({m for p in c.changed if (m := _module_of(p)) and m not in NON_DOC})+ modules = sorted({m for p in c.code_changed() if (m := _module_of(p)) and m not in NON_DOC})if not modules:return Result(name, "PASS", "no documented module changed")new_modules = {@@ -200,7 +235,7 @@ def check_eval_scenarios(c: Change) -> Result:def check_tests_present(c: Change) -> Result:code = [p- for p in c.changed+ for p in c.code_changed()if p.startswith(PKG) and p.endswith(".py") and _module_of(p) not in NON_DOC]if not code or any(p.startswith(TESTS) for p in c.changed):@@ -241,6 +276,15 @@ def _unquote(path: str) -> str:def _parse_added_lines(diff: str) -> dict[str, list[str]]:+ return _parse_diff_lines(diff, "+")+++def _parse_removed_lines(diff: str) -> dict[str, list[str]]:+ """Removed lines, keyed by the file's new path (a deleted file has none)."""+ return _parse_diff_lines(diff, "-")+++def _parse_diff_lines(diff: str, sign: str) -> dict[str, list[str]]:out: dict[str, list[str]] = {}current: str | None = Nonein_header = False@@ -253,7 +297,7 @@ def _parse_added_lines(diff: str) -> dict[str, list[str]]:current = target[2:] if target.startswith("b/") else Noneelif line.startswith("@@"):in_header = False- elif current and not in_header and line.startswith("+"):+ elif current and not in_header and line.startswith(sign):out.setdefault(current, []).append(line[1:])return out@@ -281,6 +325,7 @@ def collect(base: str, extra_waiver: Iterable[str] = ()) -> Change:"--src-prefix=a/", "--dst-prefix=b/", merge_base,)added_lines = _parse_added_lines(diff)+ removed_lines = _parse_removed_lines(diff)for path in _git("ls-files", "-z", "--others", "--exclude-standard").split("\0"):if not path:@@ -294,7 +339,9 @@ def collect(base: str, extra_waiver: Iterable[str] = ()) -> Change:passwaiver = _git("log", "--format=%B", f"{merge_base}..HEAD")- return Change(changed, added, renamed, added_lines, "\n".join([waiver, *extra_waiver]))+ return Change(+ changed, added, renamed, added_lines, removed_lines, "\n".join([waiver, *extra_waiver])+ )def main(argv: list[str] | None = None) -> int: