Repository navigation
Check the local receipt before fetching remote readiness evidence #1819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cffba38
c58f677
1ba887c
4d64916
eac1be9
b4c8925
62f0f95
bff5500
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -190,8 +190,8 @@ def _require_task_branch(config: Config, branch: str) -> None: | |
| ) | ||
|
|
||
|
|
||
| def _require_pr(config: Config, branch: str, *, allow_merged: bool = False) -> github.PR: | ||
| pr = github.pr_for_branch(config.repo, branch) | ||
| def _require_pr(config: Config, branch: str, *, allow_merged: bool = False, list_only: bool = False) -> github.PR: | ||
| pr = github.pr_for_branch(config.repo, branch, list_only=list_only) | ||
| if pr is None: | ||
| raise CliError(f"no pull request for {branch}; run `loopzero pr` first") | ||
| if pr.state != "OPEN" and not (allow_merged and pr.state == "MERGED"): | ||
|
|
@@ -283,8 +283,11 @@ def _readiness( | |
| ) -> github.Readiness: | ||
| if hold := github.merge_hold(pr.number, pr.labels): | ||
| return github.Readiness(False, (hold,)) | ||
| if reviews is None: | ||
| reviews = _pr_reviews(config.repo, pr.number) | ||
| report = _load_report(wt) | ||
| receipt_problem = _check_report_problem(report, wt, config, head) | ||
| if receipt_problem and reviews is None: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Make full status diagnostics an explicit choice Supplying preloaded reviews now also disables the receipt short-circuit. A readiness caller that starts caching reviews would silently resume CI and Mergify lookups for invalid receipts. Give |
||
| return github.Readiness(False, (receipt_problem,)) | ||
| reviews = _pr_reviews(config.repo, pr.number) if reviews is None else reviews | ||
| publishers = config.review_publishers or (github.login(),) | ||
| review = eligibility.readiness_review( | ||
| reviews, head, publishers, repo=config.repo, number=pr.number, base_branch=config.base_branch, | ||
|
|
@@ -306,14 +309,9 @@ def _readiness( | |
| ), | ||
| publishers=publishers, | ||
| ) | ||
| report = _load_report(wt) | ||
| receipt_problem = _check_report_problem(report, wt, config, head) | ||
| if receipt_problem: | ||
| result = github.Readiness( | ||
| ready=False, | ||
| reasons=(*result.reasons, receipt_problem), | ||
| ) | ||
| elif announce_receipt: | ||
| result = (github.Readiness(False, (*result.reasons, receipt_problem)) | ||
| if receipt_problem else result) | ||
| if announce_receipt and not receipt_problem: | ||
| _print_receipt(wt, report, "accepted") | ||
| if config.merge_strategy == "mergify" and pr.state == "OPEN": | ||
| behind = github.behind_reason(pr, head if review else None) | ||
|
|
@@ -445,7 +443,7 @@ def _load_report(wt: Path) -> CheckReport | None: | |
| raise TypeError("dirty must be a bool") | ||
| return CheckReport(head=str(data["head"]), dirty=dirty, results=results, | ||
| settings_sha256=data.get("settings_sha256")) | ||
| except (TypeError, KeyError, ValueError) as exc: | ||
| except (OSError, TypeError, KeyError, ValueError) as exc: | ||
| print(f"warning: ignoring unreadable {path}: {exc}", file=sys.stderr) | ||
| return None | ||
|
|
||
|
|
@@ -1247,7 +1245,8 @@ def _pr_readiness( | |
| """PR plus readiness; readiness is None only for an already merged PR (allow_merged).""" | ||
| head = worktree.head(wt) | ||
| _require_task_branch(config, branch) | ||
| pr = _require_pr(config, branch, allow_merged=allow_merged) | ||
| with github.bounded_reads(float("inf"), token=None): | ||
| pr = _require_pr(config, branch, allow_merged=allow_merged, list_only=True) | ||
| _require_pushed(pr, head) | ||
| if pr.state == "MERGED": | ||
| return pr, None | ||
|
|
@@ -1536,8 +1535,9 @@ def _wait_for_checks( | |
| previous = config | ||
| for _ in _poll_until(started, timeout, bounded=bounded): | ||
| if initial is not None: | ||
| readiness = initial | ||
| initial = None | ||
| readiness, initial = initial, None | ||
| elif problem := _check_report_problem(_load_report(wt), wt, config, pr.head_sha): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. important: Check the current workflow before diagnosing a receipt during a wait The poll precheck compares the receipt with the configuration captured when the wait started. If the workflow changes and a fresh check passes under the new plan during the sleep, both |
||
| return current, github.Readiness(False, (problem,)), kicked | ||
| else: | ||
| current = github.pr_view(config.repo, pr.number) | ||
| previous = _verify_wait_snapshot(args, wt, config, pr.head_sha, current.head_sha, previous) | ||
|
|
@@ -1555,8 +1555,7 @@ def _wait_for_checks( | |
| pending = _pending_checks( | ||
| config, current, readiness, allow_skipped=kicked or (allow_skipped and not current.is_draft), | ||
| ) | ||
| if pending or readiness.ready: | ||
| _print_wait_changes(shown, pending) | ||
| _print_wait_changes(shown, pending if pending or readiness.ready else shown) | ||
| if not pending: | ||
| return current, readiness, kicked | ||
| shown = pending | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
important: Revalidate the receipt before acting on passing remote gates
If another
loopzero checkreplaces a passing receipt with a failed or incomplete one while review and CI reads are in flight,_readinessstill returns success using the earlier receipt.readycan mark the PR ready, andmerge --waitcan merge or request Mergify admission. The poll precheck also misses this when the gates turn green on that same poll. Keep the early rejection and revalidate the current receipt before accepting readiness or performing a gated write. Add a replay that invalidates the receipt during a remote gate read.