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
21 changes: 12 additions & 9 deletions src/loopzero/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ def _wait_with_deadline(
allow_skipped=allow_skipped, initial=initial)
deadline = started + timeout
if time.monotonic() >= deadline:
_print_check_wait_timeout(pr)
_print_check_wait_timeout(pr, args)
return None
reported_timeout = False
try:
Expand All @@ -1299,17 +1299,20 @@ def _wait_with_deadline(
reported_timeout = waited is None
except github.ReadDeadline:
if not reported_timeout:
_print_check_wait_timeout(pr)
_print_check_wait_timeout(pr, args)
return None
return waited


def _print_check_wait_timeout(pr: github.PR) -> None:
if pr.mergeable == "UNKNOWN":
print(f"timed out waiting for GitHub to compute mergeability on {pr.head_sha[:12]}")
else:
print(f"timed out waiting for required checks on {pr.head_sha[:12]}")

def _print_check_wait_timeout(pr: github.PR, args: argparse.Namespace | None) -> None:
waiting_for = "GitHub to compute mergeability" if pr.mergeable == "UNKNOWN" else "required checks"
command = ["loopzero", args.command if args else "ready", "--wait"]
if args and args.config:
command.insert(1, f"--config={args.config}")
print(
f"timed out waiting for {waiting_for} on {pr.head_sha[:12]}. "
f"Run `{shlex.join(command)}` to resume on this head."
)

def _verify_wait_snapshot(
args: argparse.Namespace | None, wt: Path, config: Config, head: str, current_head: str,
Expand Down Expand Up @@ -1386,7 +1389,7 @@ def _wait_for_checks(
f"triggers and permissions for head {pr.head_sha[:12]}; after correcting the cause, "
"rerun the same `--wait` command"
)
_print_check_wait_timeout(current)
_print_check_wait_timeout(current, args)
return None


Expand Down
16 changes: 8 additions & 8 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2592,7 +2592,7 @@ def test_wait_for_github_mergeability(wt, gh, capsys, monkeypatch, command, sett
if settled == "CONFLICTING":
assert code == 1 and "has merge conflicts" in out + err
elif settled == "UNKNOWN":
assert code == 3 and "timed out waiting for GitHub to compute mergeability" in out
assert code == 3 and out.endswith(f"timed out waiting for GitHub to compute mergeability on {head[:12]}. Run `loopzero {command} --wait` to resume on this head.\n")
else:
assert code == (0 if command == "ready" else 3)
assert requests == ([(REPO, 7, head, "main")]
Expand Down Expand Up @@ -2683,12 +2683,12 @@ def sleep(seconds):
clock += seconds

monkeypatch.setattr(cli, "_sleep", sleep)
code, out, err = run(capsys, "ready", f"--wait={wait}")

(wt / "-retry config.toml").write_bytes((wt / "workflow.toml").read_bytes())
code, out, err = run(capsys, "--config", "./-retry config.toml", "ready", f"--wait={wait}")
assert (code, err) == (expected, "")
assert out.endswith({
0: f"ready: {URL}\n", 1: "not ready: required check 'checks' is failure\n",
3: f"timed out waiting for required checks on {head[:12]}\n",
3: f"timed out waiting for required checks on {head[:12]}. Run `loopzero '--config=-retry config.toml' ready --wait` to resume on this head.\n",
}[expected])


Expand Down Expand Up @@ -2773,7 +2773,7 @@ def advance(seconds):
[30.0, 5.0] if initial_pending else [30.0])
assert out.endswith(f"ready: {URL}\n" if expected == 0 else
"not ready: required check 'checks' is failure\n" if expected == 1 else
f"timed out waiting for required checks on {head[:12]}\n")
f"timed out waiting for required checks on {head[:12]}. Run `loopzero ready --wait` to resume on this head.\n")
assert sum(c["argv"][:2] == ["pr", "ready"] for c in gh.calls) == 1


Expand Down Expand Up @@ -2854,7 +2854,7 @@ def advance(seconds):
assert marked_at == [210.0]
assert sleeps == [30.0, 60.0, 120.0, 30.0] + ([] if run_appears else [30.0, 30.0])
assert out.endswith(f"ready: {URL}\n" if run_appears else
f"timed out waiting for required checks on {head[:12]}\n")
f"timed out waiting for required checks on {head[:12]}. Run `loopzero ready --wait` to resume on this head.\n")
assert sum(c["argv"][:2] == ["pr", "ready"] for c in gh.calls) == 1


Expand Down Expand Up @@ -3363,7 +3363,7 @@ def test_merge_wait_times_out_on_pending_checks_with_exit_three(
code, out, err = run(capsys, "merge", "--wait=0")

assert (code, err) == (3, "")
assert f"timed out waiting for required checks on {head[:12]}" in out
assert f"timed out waiting for required checks on {head[:12]}. Run `loopzero merge --wait` to resume on this head." in out
assert wt.exists() and all(c["argv"][:2] != ["pr", "merge"] for c in gh.calls)


Expand Down Expand Up @@ -3392,7 +3392,7 @@ def slow_check(argv, *, timeout, **kwargs):

assert (code, err) == (3, "")
assert budgets == pytest.approx([8.0])
assert f"timed out waiting for required checks on {head[:12]}" in out
assert f"timed out waiting for required checks on {head[:12]}. Run `loopzero merge --wait` to resume on this head." in out
assert all(c["argv"][:2] != ["pr", "merge"] for c in gh.calls)


Expand Down
Loading