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
10 changes: 5 additions & 5 deletions src/loopzero/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ def cmd_pr(args: argparse.Namespace) -> int:
raise CliError(
f"PR head {pr.head_sha[:12]} is not in this worktree; fetch and integrate it first"
)
force_lease = not _is_ancestor(wt, pr.head_sha, head)
force_lease = pr.head_sha != head and not _is_ancestor(wt, pr.head_sha, head)
if force_lease:
previous_heads = _git(wt, "reflog", "show", "--format=%H", f"refs/heads/{branch}").splitlines()
if not any(_is_ancestor(wt, pr.head_sha, previous) for previous in previous_heads):
Expand Down Expand Up @@ -1184,10 +1184,10 @@ def _load_review(wt: Path, head: str, kind: str) -> ReviewResult:


def _pr_readiness(
wt: Path, config: Config, *, allow_merged: bool = False, workflow_wait: bool = False
wt: Path, config: Config, branch: str, *, allow_merged: bool = False, workflow_wait: bool = False
) -> tuple[github.PR, github.Readiness | None]:
"""PR plus readiness; readiness is None only for an already merged PR (allow_merged)."""
branch, head = worktree.branch(wt), worktree.head(wt)
head = worktree.head(wt)
_require_task_branch(config, branch)
pr = _require_pr(config, branch, allow_merged=allow_merged)
_require_pushed(pr, head)
Expand Down Expand Up @@ -1215,7 +1215,7 @@ def _cleanup(wt: Path, pr: github.PR) -> None:

def cmd_ready(args: argparse.Namespace) -> int:
wt, config = _context(args, pin_checks=True)
pr, readiness = _pr_readiness(wt, config, workflow_wait=args.wait is not None)
pr, readiness = _pr_readiness(wt, config, worktree.branch(wt), workflow_wait=args.wait is not None)
assert readiness is not None
waiting = _draft_checks_waiting(config, pr, readiness)
kicked = bool(waiting)
Expand Down Expand Up @@ -1643,7 +1643,7 @@ def cmd_merge(args: argparse.Namespace) -> int:
print(f"requested removal of PR #{pr.number} from Mergify")
return 0
pr, readiness = _pr_readiness(
wt, config, allow_merged=True, workflow_wait=args.wait is not None
wt, config, branch, allow_merged=True, workflow_wait=args.wait is not None
)
started = time.monotonic()
deadline = None if args.wait is None else started + args.wait
Expand Down
9 changes: 7 additions & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,12 +1111,14 @@ def test_progress_output_precedes_the_stderr_verdict_in_one_file(tmp_path: Path)


@pytest.mark.parametrize("corrupt_report", [False, True], ids=["no-report", "corrupt-report"])
def test_pr_updates_existing_open_pr(wt, gh, capsys, corrupt_report):
def test_pr_updates_existing_open_pr(wt, gh, capsys, corrupt_report, git_calls):
if corrupt_report:
(wt / ".loopzero" / "checks.json").write_text('{"results": "nope"}')
arm_pr_body_patch(gh, head_of(wt))

git_calls.clear()
code, out, err = run(capsys, "pr")
assert not any(call[:2] == ["merge-base", "--is-ancestor"] for call in git_calls)

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: The tests don't check the 10 and 7 process totals named in the acceptance criteria

The acceptance criteria call for measuring 10 Git processes on a same-head PR refresh and 7 on merge admission. The new tests only check that the redundant calls are gone: no merge-base --is-ancestor call, and exactly one branch --show-current call. That matches what the Notes say was intended, and it does guard the specific regression. But other extra Git launches could creep back into either path without any test failing. If the totals matter, add assert_git_cost(git_calls, 10, ...) and assert_git_cost(git_calls, 7, ...), using the existing helper at tests/test_cli.py:308, next to the targeted assertions. This is optional.


assert code == 0 and out == URL + "\n"
assert ("warning: ignoring unreadable" in err) == corrupt_report
Expand All @@ -1136,6 +1138,7 @@ def test_pr_aborts_when_ancestry_cannot_be_verified(wt, gh, fake_tool, tmp_path,
pushes = trace_pushes(fake_tool, tmp_path)
else:
arm_pr_body_patch(gh, head_of(wt))
git(wt, "commit", "--allow-empty", "-m", "Advance local head")
pushes = tmp_path / "pushes"
fake_tool("git", f'''\
if [ "$1" = "merge-base" ] && [ "$2" = "--is-ancestor" ]; then {probe}; fi
Expand Down Expand Up @@ -3708,7 +3711,7 @@ def test_merge_queued_prints_and_keeps_worktree(wt: Path, gh: FakeGh, capsys, he
@pytest.mark.parametrize("attested", [True, False])
@pytest.mark.parametrize("merge_state", ["BEHIND", "CLEAN"])
def test_mergify_merge_requests_once_for_behind_head(
wt: Path, gh: FakeGh, capsys, monkeypatch, attested, merge_state
wt: Path, gh: FakeGh, capsys, monkeypatch, attested, merge_state, git_calls
) -> None:
head = commit_mergify_configuration(wt)
arm_approved_ready_pr(gh, head, wt, isDraft=False, mergeStateStatus=merge_state)
Expand All @@ -3717,7 +3720,9 @@ def test_mergify_merge_requests_once_for_behind_head(
stub_mergify_admission(monkeypatch, configured=None)
monkeypatch.setattr(mergify, "request", lambda *args: requested.append(args))

git_calls.clear()
code, out, err = run(capsys, "merge")
assert git_calls.count(["branch", "--show-current"]) == 1

if attested:
assert (code, err) == (0, "")
Expand Down
Loading