diff --git a/src/loopzero/cli.py b/src/loopzero/cli.py index 48a64159..62673b30 100644 --- a/src/loopzero/cli.py +++ b/src/loopzero/cli.py @@ -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: @@ -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, @@ -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 diff --git a/tests/test_cli.py b/tests/test_cli.py index c09d043c..951dd730 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -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")] @@ -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]) @@ -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 @@ -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 @@ -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) @@ -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)