Repository navigation
Reuse trusted workflow content during source waits #1525
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
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 |
|---|---|---|
|
|
@@ -89,16 +89,39 @@ def base_revision(worktree: Path, base_branch: str) -> str: | |
| raise ConfigError(f"git rev-parse origin/{base_branch} failed: {message}") | ||
|
|
||
|
|
||
| def _remote_workflow(worktree: Path, branch: str) -> tuple[Config, str]: | ||
| def _has_replacement_refs(common_dir: Path) -> bool: | ||
| # A replacement can change what Git reads at a fixed object name. | ||
| for entry in ("refs/replace", "reftable"): | ||
| try: | ||
| (common_dir / entry).lstat() | ||
| except FileNotFoundError: | ||
| continue | ||
| except OSError: | ||
| return True | ||
| return True | ||
| try: | ||
| packed = (common_dir / "packed-refs").read_bytes() | ||
| except FileNotFoundError: | ||
| return False | ||
| except OSError: | ||
| return True | ||
| return b" refs/replace/" in packed | ||
|
|
||
|
|
||
| def _remote_workflow(worktree: Path, branch: str, previous: Config | None) -> tuple[Config, str]: | ||
| source = f"origin/{branch}:workflow.toml" | ||
| hint = "Fetch the trusted base workflow, or supply --config for bootstrap or an override." | ||
| directory_args = ["--path-format=absolute", "--git-common-dir"] if previous is not None else [] | ||
| resolved = _proc.run( | ||
| ["git", "rev-parse", "--verify", f"refs/remotes/origin/{branch}^{{commit}}"], | ||
| ["git", "rev-parse", *directory_args, "--verify", f"refs/remotes/origin/{branch}^{{commit}}"], | ||
| cwd=worktree, env_allowlist=worktree_mod.GIT_ENV, timeout=60, | ||
| ) | ||
| if resolved.exit_code != 0: | ||
| raise ConfigError(f"{source} has no remote-tracking base commit. {hint}") | ||
| revision = resolved.stdout.strip() | ||
| common_dir, _, revision = resolved.stdout.rstrip("\n").rpartition("\n") | ||
| if (previous is not None and previous.base_branch == branch and previous.trusted_base_revision == revision | ||
| and common_dir and not _has_replacement_refs(Path(common_dir))): | ||
| return previous, revision | ||
| shown = _proc.run( | ||
| ["git", "show", f"{revision}:workflow.toml"], | ||
| cwd=worktree, env_allowlist=worktree_mod.GIT_ENV, timeout=60, | ||
|
|
@@ -115,7 +138,7 @@ def _remote_workflow(worktree: Path, branch: str) -> tuple[Config, str]: | |
| raise ConfigError(f"{source}: {exc}. {hint}") from None | ||
|
|
||
|
|
||
| def load_trusted(worktree: Path) -> Config: | ||
| def load_trusted(worktree: Path, *, previous: Config | None = None) -> Config: | ||
| """Select delivery policy using Git's origin default and its trusted workflow.""" | ||
| prefix = "refs/remotes/origin/" | ||
| default = _proc.run( | ||
|
|
@@ -129,10 +152,10 @@ def load_trusted(worktree: Path) -> Config: | |
| "or supply --config for bootstrap or an override." | ||
| ) | ||
| branch = ref.removeprefix(prefix) | ||
| policy, revision = _remote_workflow(worktree, branch) | ||
| policy, revision = _remote_workflow(worktree, branch, previous) | ||
|
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: Split default/base configuration still rereads the default branch workflow every poll
|
||
| if policy.base_branch == branch: | ||
| return replace(policy, trusted_base_revision=revision) | ||
| base, revision = _remote_workflow(worktree, policy.base_branch) | ||
| base, revision = _remote_workflow(worktree, policy.base_branch, previous) | ||
| if base.base_branch != policy.base_branch: | ||
| raise ConfigError("trusted origin workflows disagree on repo.base; align them or supply --config") | ||
| return replace(base, trusted_base_revision=revision) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2391,14 +2391,14 @@ def test_skipped_required_check_activates_only_on_ready(wt, gh, capsys, head, dr | |
| assert all(c["argv"][:2] != ["pr", "ready"] for c in gh.calls) | ||
|
|
||
|
|
||
| def test_ready_wait_reports_initial_draft_blocker_once(wt, gh, capsys, monkeypatch, head): | ||
| def test_ready_wait_reports_initial_draft_blocker_once(wt, gh, capsys, monkeypatch, head, git_calls): | ||
| arm_approved_pr_with_check_result(gh, head, wt, "skipped", isDraft=True) | ||
| arm_check_progress(gh, head, "skipped", "skipped", "pending", "success") | ||
| gh.respond("pr ready", "") | ||
|
|
||
| git_calls.clear() | ||
| monkeypatch.setattr(cli, "_sleep", lambda _: None) | ||
| code, out, err = run(capsys, "ready", "--wait") | ||
|
|
||
| assert sum(call[0] == "show" and call[-1].endswith(":workflow.toml") for call in git_calls) == 1 | ||
|
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: Inline workflow-read count duplicates existing assert_git_cost helper The new assertion reimplements the |
||
| assert (code, err) == (0, "") | ||
| assert out.count("receipt accepted:") == 1 | ||
| assert without_accepted_receipt(out).splitlines() == [ | ||
|
|
||
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.
suggestion: Replacement-ref guard and cache-miss paths have no automated coverage
_has_replacement_refsis a new hand-written probe of Git's on-disk layout: the looserefs/replacedirectory,reftable, andpacked-refs. The only evidence for it is the manual check described in the task. No test runs the loose or packed replacement case, a ref move between polls, or the two-branch setup whereorigin/HEADdiffers fromrepo.base. If this guard regresses, the waiter could quietly keep using a stale parsed policy, and nothing would catch it. Two cheap tests would close the gap: one that writes arefs/replace/<sha>line topacked-refs, and one that movesorigin/<base>between polls, each asserting that the workflow blob is read again. Those tests would add lines, which conflicts with the no-net-test-lines goal, so this is non-blocking.