Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Rollout paragraph could state the unsafe window explicitly

The paragraph says to advance both pins, then refresh. It does not say that until both pins move, an older candidate or source reader can still accept an approval followed by an ordinary commit. It also does not say that statuses already published by the old reader stay green until refreshed. One sentence would make the order easier to follow for the coordinator who owns both pins: treat sources as unverified until both pins and the refresh are done, and refresh with the unchanged source SHA using the command below.

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
Expand Down
54 changes: 54 additions & 0 deletions tests/test_hosted.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess
import sys
from contextlib import nullcontext
from functools import partial
from pathlib import Path
from types import SimpleNamespace

Expand All @@ -11,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
Expand Down Expand Up @@ -108,6 +110,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"<!-- loopzero:review v=1 head={reviewed} kind=primary source=model -->\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",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Candidate case replaces the whole attestation, not just its transport

The test monkeypatches hosted.candidate_mod.attest_candidate with a lambda that calls source_policy(7, source) directly. As a result, the candidate rows never run candidate.attest_candidate/_attest: no Mergify lineage, no source-to-candidate compare, and no check that the policy runs on the attested source. The acceptance criteria asked for stubbed GitHub and candidate transport. What these rows actually cover is hosted._run's candidate policy closure plus eligibility.evaluate. They do not show that the real candidate path hands this source to the policy. Smallest fix: keep the real attest_candidate and stub only github.api_get/mergify.api_get with the payload helpers from tests/test_candidate.py (as tests/test_hosted.py already does around line 208). Otherwise, rename or comment the test so it does not claim end-to-end candidate coverage.

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]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Expected-state expression relies on non-obvious conditional precedence

["pending", ("failure" if candidate else "pending") if change == "ordinary" else "success"] is correct, but it takes some precedence reasoning to see that the outer conditional applies only to the second element. A small expected-state table keyed by (change, candidate) would be easier to check and extend. Also, the candidate+ordinary failure status comes from _mark_refresh_failed (generic "Eligibility refresh failed" message), not from a policy verdict. Consider asserting the description too, so a regression in which path produced the failure is caught.

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)
Expand Down
Loading