Repository navigation
Show how to act on terminal required-check failures #1507
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 |
|---|---|---|
|
|
@@ -1207,7 +1207,7 @@ def cmd_ready(args: argparse.Namespace) -> int: | |
| return 3 | ||
| pr, readiness, kicked = waited | ||
| assert readiness is not None | ||
| for reason in readiness.reasons: | ||
| for reason in _readiness_messages(pr, readiness): | ||
| print(f"not ready: {reason}") | ||
| if not readiness.ready: | ||
| if args.wait is None and _pending_checks(config, pr, readiness): | ||
|
|
@@ -1248,6 +1248,17 @@ def _pending_checks( | |
| return reasons if reasons and all(r in waitable for r in reasons) else () | ||
|
|
||
|
|
||
| def _readiness_messages(pr: github.PR, readiness: github.Readiness) -> Iterator[str]: | ||
| for reason in readiness.reasons: | ||
| check, separator, conclusion = reason.rpartition("' is ") | ||
| if (separator and check.startswith("required check '") and conclusion not in {"pending", "skipped"} | ||
| and reason not in readiness.waitable_failures): | ||
| yield (f"{reason}. Inspect {pr.url}/checks. Fix reproducible failures before retrying. " | ||
|
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: The recovery paragraph repeats once per failed check The four-sentence guidance is added to every failing required check. With two or more terminal failures, |
||
| "Rerun the failed job only for a transient failure. Once green, run `loopzero ready --wait`.") | ||
|
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: Merge refusals tell the builder to run Both merge paths use |
||
| else: | ||
| yield reason | ||
|
|
||
|
|
||
| def _merge_check_hint(config: Config, pr: github.PR, readiness: github.Readiness) -> str: | ||
| if _pending_checks(config, pr, readiness): | ||
| return "; next: loopzero merge --wait" | ||
|
|
@@ -1531,7 +1542,7 @@ def _merge_with_mergify( | |
| """Request Mergify after readiness verifies the source gates and queue configuration.""" | ||
| if not readiness.ready: | ||
| hint = _merge_check_hint(config, pr, readiness) | ||
| raise CliError("not ready to request Mergify: " + "; ".join(readiness.reasons) + hint) | ||
| raise CliError("not ready to request Mergify: " + "; ".join(_readiness_messages(pr, readiness)) + hint) | ||
| queue = config.mergify_queue | ||
| assert queue is not None | ||
| requested, confirmed_marker = mergify.markers( | ||
|
|
@@ -1612,7 +1623,7 @@ def cmd_merge(args: argparse.Namespace) -> int: | |
| else: | ||
| if not readiness.ready: | ||
| hint = _merge_check_hint(config, pr, readiness) | ||
| raise CliError("not ready to merge: " + "; ".join(readiness.reasons) + hint) | ||
| raise CliError("not ready to merge: " + "; ".join(_readiness_messages(pr, readiness)) + hint) | ||
| if admit_by is not None and time.monotonic() > admit_by: | ||
| print(f"timed out before merging PR #{pr.number}") | ||
| return 3 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,7 @@ | |
|
|
||
| REPO = "acme/widgets" | ||
| URL = f"https://github.com/{REPO}/pull/7" | ||
| FAILED_CHECK_HINT = f". Inspect {URL}/checks. Fix reproducible failures before retrying. Rerun the failed job only for a transient failure. Once green, run `loopzero ready --wait`." | ||
| MERGIFY_QUEUE_FIXTURE = json.loads((Path(__file__).with_name("fixtures") / "mergify-queue.json").read_text()) | ||
| BRANCH_READ = branch_head_key().split() | ||
| PR_LIST_READ = pr_list_key().split() | ||
|
|
@@ -2319,6 +2320,7 @@ def test_ready_not_ready_lists_reasons(wt: Path, gh: FakeGh, capsys, head) -> No | |
| "name": "checks", "status": "completed", "conclusion": "failure", | ||
| "check_suite": {"id": 10}}]) | ||
| code, out, _ = run(capsys, "ready") | ||
| out = out.replace(FAILED_CHECK_HINT, "") | ||
|
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: No test checks that a waitable failure keeps its plain message Acceptance requires waitable failures to stay unchanged, and the code handles this with |
||
| assert code == 1 | ||
| assert without_accepted_receipt(out).splitlines() == [ | ||
| "not ready: no review recorded for the current head", | ||
|
|
@@ -2330,7 +2332,7 @@ def test_ready_not_ready_lists_reasons(wt: Path, gh: FakeGh, capsys, head) -> No | |
|
|
||
| @pytest.mark.parametrize("retargeted,reason", [ | ||
| (True, "PR targets release, configured base is main"), | ||
| (False, "required check 'checks' is failure"), | ||
| (False, f"required check 'checks' is failure{FAILED_CHECK_HINT}"), | ||
| ], ids=["retargeted", "trust-base-required-ci"]) | ||
| def test_ready_explains_trusted_policy_blocker(wt, gh, capsys, head, retargeted, reason): | ||
| if retargeted: | ||
|
|
@@ -2341,8 +2343,7 @@ def test_ready_explains_trusted_policy_blocker(wt, gh, capsys, head, retargeted, | |
|
|
||
| code, out, err = run(capsys, "ready") | ||
|
|
||
| assert (code, err) == (1, "") | ||
| assert without_accepted_receipt(out) == f"not ready: {reason}\n" | ||
| assert (code, err, without_accepted_receipt(out)) == (1, "", f"not ready: {reason}\n") | ||
|
|
||
|
|
||
| def test_pending_required_check_names_the_wait(wt: Path, gh: FakeGh, capsys, head) -> None: | ||
|
|
@@ -2645,7 +2646,7 @@ def sleep(seconds): | |
|
|
||
| assert (code, err) == (expected, "") | ||
| assert out.endswith({ | ||
| 0: f"ready: {URL}\n", 1: "not ready: required check 'checks' is failure\n", | ||
| 0: f"ready: {URL}\n", 1: f"not ready: required check 'checks' is failure{FAILED_CHECK_HINT}\n", | ||
| 3: f"timed out waiting for required checks on {head[:12]}\n", | ||
| }[expected]) | ||
|
|
||
|
|
@@ -2682,7 +2683,7 @@ def sleep(seconds: float) -> None: | |
| assert "timed out waiting for required checks" in out | ||
| else: | ||
| assert out.endswith(f"ready: {URL}\n" if expected == 0 else | ||
| "not ready: required check 'checks' is failure\n") | ||
| f"not ready: required check 'checks' is failure{FAILED_CHECK_HINT}\n") | ||
|
|
||
|
|
||
| @pytest.mark.usefixtures("replay_gh") | ||
|
|
@@ -2730,7 +2731,7 @@ def advance(seconds): | |
| assert sleeps == ([30.0, 5.0, 5.0] if replacement == "pending" else | ||
| [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"not ready: required check 'checks' is failure{FAILED_CHECK_HINT}\n" if expected == 1 else | ||
| f"timed out waiting for required checks on {head[:12]}\n") | ||
| assert sum(c["argv"][:2] == ["pr", "ready"] for c in gh.calls) == 1 | ||
|
|
||
|
|
@@ -2929,7 +2930,7 @@ def advance(seconds): | |
| ) | ||
| assert (code, err, bool(sleeps)) == (expected, "", waited) | ||
| assert out.endswith(f"ready: {URL}\n" if expected == 0 else | ||
| f"not ready: required check '{name}' is failure\n") | ||
| f"not ready: required check '{name}' is failure{FAILED_CHECK_HINT}\n") | ||
| assert (f"waiting: required check '{name}' is failure" in out) == waited | ||
| assert out.count("predates the review; awaiting refresh") == int( | ||
| waited and (age < 0 or age >= 120) and not pending | ||
|
|
@@ -3197,14 +3198,13 @@ def test_ready_respects_latest_review_state(wt: Path, gh: FakeGh, capsys, state, | |
| def test_merge_refuses_when_not_ready(wt: Path, gh: FakeGh, capsys, head) -> None: | ||
| arm_pr(gh, head, isDraft=False) | ||
| gh.respond(reviews_key(), [rev(head, "primary")]) | ||
| arm_readiness(gh, head, wt, threads=( | ||
| arm_readiness(gh, head, wt, conclusion="failure", threads=( | ||
| {"isResolved": False, "isOutdated": False, "path": "feature.py", "line": 1, | ||
| "comments": {"nodes": [{"body": f"<!-- loopzero:finding severity=critical head={head} -->" | ||
| "\n**critical: Bad**"}]}},)) | ||
| code, out, err = run(capsys, "merge") | ||
| out = without_accepted_receipt(out) | ||
| assert code == 1 and out == "" | ||
| assert "not ready to merge: open critical finding at feature.py:1: Bad" in err | ||
| assert code == 1 and without_accepted_receipt(out) == "" | ||
| assert f"not ready to merge: open critical finding at feature.py:1: Bad; required check 'checks' is failure{FAILED_CHECK_HINT}" in err | ||
| assert wt.exists() | ||
|
|
||
|
|
||
|
|
||
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: Terminal failures are found by parsing a message string built in another module
_readiness_messagesusesrpartition("' is ")and astartswithtest to take apart thef"required check '{name}' is {conclusion}"text built atgithub.py:1309. If someone rewords that text ingithub.readiness, the guidance silently stops appearing, and no type check catches it._pending_checksalready relies on string matching, butReadinessexposeswaitable_failuresandstale_verdictsas structured fields. A sturdier fix is a parallel field, for exampleterminal_failures, computed where the reason is built._readiness_messagescould then check membership instead of parsing text.