Skip to content
Closed
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
4 changes: 3 additions & 1 deletion scripts/ai-accounts/ai-accounts
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,9 @@ def cmd_run(providers: str, argv: list[str], retry_exit: set[int] | None = None,
t = threading.Thread(target=pump, daemon=True)
t.start()
code = proc.wait()
t.join()
t.join(timeout=1)
if t.is_alive():
return code
text = b"".join(seen).decode("utf-8", "replace")
retryable = code != 0 and (retry_exit is None or code in retry_exit)
if (not retryable or attempt == 2 or not model or providers not in PROVIDERS
Expand Down
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 @@ -1216,10 +1216,10 @@ def _load_review(


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 @@ -1247,7 +1247,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 @@ -1675,7 +1675,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
6 changes: 6 additions & 0 deletions tests/test_ai_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ def test_codex_requires_requested_model_evidence(helper, monkeypatch):
assert helper.active('codex') == 'main'


def test_run_returns_after_leader_exits_with_inherited_stderr(helper):
argv = [helper.sys.executable, helper.__file__, 'run', 'claude', '--', helper.sys.executable,
'-c', 'import subprocess, sys; subprocess.Popen(["sleep", "6"]); sys.exit(7)']
assert helper.subprocess.run(argv, timeout=5).returncode == 7


@pytest.mark.parametrize('providers,explicit,retry_safe,runs,active', [
('claude,codex', False, False, 1, 'a'), ('claude', False, False, 1, 'b'),
('claude', False, True, 2, 'b'), ('claude', True, True, 1, 'a')])
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)

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