From 6fbacdaf73115b07c654f8be801b780406e6f3ca Mon Sep 17 00:00:00 2001 From: eowca <4008965+eowca@users.noreply.github.com> Date: Thu, 26 Nov 2026 02:39:23 +0100 Subject: [PATCH] Document and test the hosted ancestor-review pin rollout Co-Authored-By: Codex --- SETUP.md | 6 +++++ tests/test_hosted.py | 55 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/SETUP.md b/SETUP.md index d2153ef9..79d04e41 100644 --- a/SETUP.md +++ b/SETUP.md @@ -466,6 +466,12 @@ the consumer CI pin that supplies `loopzero.hosted` or `loopzero.eligibility` eligibility workflow for the existing PR, or run the command below with its unchanged source SHA. The refreshed reader can use the approval already on GitHub. +For inherited review coverage, advance both source and candidate workflow pins to +a revision containing [23219dd3 (#1081)](https://github.com/feder-positronics/loop-zero/commit/23219dd39e641549164c346e137f4e09718115f6). +The updated reader accepts an ancestor approval only across verified clean merges +from the configured base. After deploying both pins, refresh eligibility for open +sources judged by the older reader so their statuses reflect the updated policy. + From a trusted base checkout, run: ```sh diff --git a/tests/test_hosted.py b/tests/test_hosted.py index e15e7912..28dfd14c 100644 --- a/tests/test_hosted.py +++ b/tests/test_hosted.py @@ -2,6 +2,8 @@ import json import subprocess import sys +from contextlib import nullcontext +from functools import partial from pathlib import Path from types import SimpleNamespace @@ -10,6 +12,7 @@ from loopzero import github, hosted from loopzero.candidate import CandidateError, CandidateRaceError from tests import test_github as fixtures +from tests.conftest import git from tests.test_candidate import event as candidate_event from tests.test_candidate import payloads as candidate_payloads from tests.test_candidate import status as candidate_status @@ -97,6 +100,58 @@ def test_source_publication_is_bound_to_live_review(publisher, case, blocker, st assert status != "pending" or statuses[-1]["description"] == "Awaiting trusted review of current source head" +@pytest.mark.parametrize("candidate", [False, True]) +@pytest.mark.parametrize("change", ["exact", "ordinary", "clean merge"]) +def test_hosted_review_coverage_after_source_head_changes( + publisher, git_repo, monkeypatch, candidate, change, +): + git(git_repo, "switch", "-qc", "source") + git(git_repo, "commit", "-qm", "reviewed source", "--allow-empty") + reviewed = git(git_repo, "rev-parse", "HEAD").strip() + git(git_repo, "switch", "-q", "main") + git(git_repo, "commit", "-qm", "base advance", "--allow-empty") + base = git(git_repo, "rev-parse", "HEAD").strip() + git(git_repo, "switch", "-q", "source") + if change == "ordinary": + git(git_repo, "commit", "-qm", "unreviewed source", "--allow-empty") + elif change == "clean merge": + git(git_repo, "merge", "-q", "--no-edit", "main") + head = git(git_repo, "rev-parse", "HEAD").strip() + source = fixtures.rest_pr_json(pr_json(headRefOid=head)) + source["base"]["sha"] = base + publisher.respond(f"api repos/{REPO}/pulls/7", source) + publisher.respond(f"api repos/{REPO}/pulls/7/reviews?per_page=100&page=1", [{ + "state": "COMMENTED", "commit_id": reviewed, "user": {"login": "trusted-publisher"}, + "body": f"\n" + "loopzero primary review by claude: **approve** (0 critical, 0 important, 0 suggestion)", + }]) + publisher.respond(f"api repos/{REPO}/compare/{reviewed}...{head}", {"status": "ahead"}) + monkeypatch.setattr(hosted.candidate_mod, "fetched_git", + lambda *_: nullcontext(partial(git, git_repo))) + + target = head + if candidate: + target = HEAD + Path("event.json").write_text(json.dumps({ + "action": "opened", "pull_request": {"number": 9, "head": {"sha": target}}, + })) + publisher.respond(f"api repos/{REPO}/pulls/9", fixtures.rest_pr_json( + pr_json(number=9, headRefOid=target), branch="mergify/merge-queue/main", + )) + monkeypatch.setattr(hosted.candidate_mod, "attest_candidate", + lambda _event, *, source_policy, **_: source_policy(7, source)) + publisher.respond(f"api repos/{REPO}/statuses/{target}", {}) + + if change == "ordinary" and candidate: + with pytest.raises(hosted.LoopZeroError, match="no review recorded"): + hosted.main() + else: + assert hosted.main() == 0 + states = [json.loads(call["--input"])["state"] for call in publisher.calls if "--input" in call] + assert states == ["pending", ("failure" if candidate else "pending") + if change == "ordinary" else "success"] + + def test_merged_source_refresh_publishes_nothing(publisher): body = json.dumps({"head": {"sha": HEAD, "ref": "lz/task"}, "user": {"login": "author"}, "merged": True, "title": "before\u2028after"}, ensure_ascii=False)