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
3 changes: 3 additions & 0 deletions loopx/capabilities/pr_review_queue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,9 @@ The read-only command paginates GitHub review history and uses the latest submit
opinion per reviewer; a comment/pending review does not erase a blocker, and a
dismissed review does not resurrect older history. Its typed TS read model reports
`clear`, `verification_required`, or `hold`; these are not merge decisions.
Closeout checks that the base commit and changed-file count are stable across
the history read when the head is unchanged. If that comparison changes,
retry closeout with the current PR snapshot.
Review age or a different commit only identifies a finding to inspect, never proof
of resolution. The host independently verifies every old finding and inline comment,
checks owner authorization and GitHub/branch dismissal permissions, rechecks the
Expand Down
9 changes: 8 additions & 1 deletion loopx/capabilities/pr_review_queue/approval_closeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,14 @@ def read_github_approval_closeout(*, repository: str, exact_head: str) -> dict[s
login = resolve_current_github_login()
if not login:
raise ValueError("approval closeout requires authenticated reviewer identity")
fields = "number,headRefOid,state,reviewDecision,author,files,changedFiles"
fields = "number,headRefOid,baseRefOid,state,reviewDecision,author,files,changedFiles"
args = ["pr", "view", str(number), "--repo", repository, "--json", fields]
pr = run_gh_json(args)
if not isinstance(pr, dict):
raise ValueError("pull-request readback is incomplete")
base_oid = pr.get("baseRefOid")
if not isinstance(base_oid, str) or not base_oid.strip():
raise ValueError("pull-request comparison base is unavailable")
expected_files = pr.get("changedFiles")
if not isinstance(expected_files, int) or expected_files < 0:
raise ValueError("changed-file readback is incomplete")
Expand Down Expand Up @@ -101,6 +104,10 @@ def read_github_approval_closeout(*, repository: str, exact_head: str) -> dict[s
after = run_gh_json(args)
if not isinstance(after, dict) or after.get("number") != number or after.get("state") != pr.get("state"):
raise ValueError("pull-request identity or lifecycle changed during readback")
if after.get("headRefOid") == pr.get("headRefOid") and (
after.get("baseRefOid") != base_oid or after.get("changedFiles") != expected_files
):
raise ValueError("pull-request comparison changed during readback; retry closeout")
return plan_approval_closeout({"repository": repository, "expected_exact_head": exact_head,
"pull_request": pr, "readback_head": after.get("headRefOid"), "reviews": reviews,
"reviews_complete": True, "review_conclusions": conclusions})
40 changes: 39 additions & 1 deletion tests/capabilities/test_pr_review_approval_closeout.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def read(args, **_):
assert "--paginate" in args and "--slurp" in args
return [[review(1, "CHANGES_REQUESTED")], [own]]
assert "statusCheckRollup" not in args[-1]
return {"number": 42, "headRefOid": HEAD, "state": "OPEN",
return {"number": 42, "headRefOid": HEAD, "baseRefOid": OLD, "state": "OPEN",
"author": {"login": "contributor"}, "reviewDecision": "CHANGES_REQUESTED",
"files": [{"path": "loopx/runtime.py"}], "changedFiles": 1}

Expand All @@ -206,6 +206,44 @@ def read(args, **_):
assert "body" not in json.dumps(result)


@pytest.mark.parametrize("comparison_change", [
{"baseRefOid": "c" * 40},
{"changedFiles": 2},
{"baseRefOid": None},
])
def test_live_adapter_rejects_comparison_drift_at_unchanged_head(
monkeypatch, capsys, comparison_change,
):
from loopx.cli import main
import loopx.pr_review as pr_module
from loopx.capabilities.pr_review_queue import github_source

body = (Path(__file__).parents[2] / "examples/fixtures/pr-review.body.md").read_text()
body = body.replace("HEAD_OID", HEAD).replace("VERDICT", "APPROVE")
approval = review(3, "APPROVED", login="maintainer", head=HEAD) | {"body": body}
snapshot = {
"number": 42, "headRefOid": HEAD, "baseRefOid": OLD, "state": "OPEN",
"author": {"login": "contributor"}, "reviewDecision": "APPROVED",
"files": [{"path": "loopx/runtime.py"}], "changedFiles": 1,
}
readbacks = iter((snapshot, snapshot | comparison_change))

def read(args, **_):
if args[0] == "api":
return [[approval]]
fields = args[args.index("--json") + 1].split(",")
current = next(readbacks)
return {key: current[key] for key in fields if key in current}

monkeypatch.setattr(github_source, "run_gh_json", read)
monkeypatch.setattr(pr_module, "resolve_current_github_login", lambda: "maintainer")
result = main(["--format", "json", "pr-review", "--repo", "owner/repo",
"--check-approval-closeout", f"42@{HEAD}"])
payload = json.loads(capsys.readouterr().out)
assert result == 1, payload
assert "comparison changed during readback" in json.dumps(payload)


def test_cli_rejects_mixed_modes_before_github_read(monkeypatch, capsys):
from loopx.cli import main
from loopx.capabilities.pr_review_queue import github_source
Expand Down
Loading