From bf5ce007dd113208a36e3d804cd06ebe21d31a3e Mon Sep 17 00:00:00 2001 From: Test Date: Wed, 25 Nov 2026 18:22:11 -0500 Subject: [PATCH] fix(loop): name the exit code for a failing gate with no recognised summary MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #3603. A gate that exits non-zero without a pass/fail summary the driver recognises (an oracle printing `RED: ...` lines, say) got the NO VERDICT note, which says the shown lines "may be unrelated to the failure". `extract_failure_excerpt` keeps keyword lines only; the note matches ("pass/fail") and the command's own lines do not, so the excerpt carried the note and the gate header and none of the output. `select_gate_report_lines` now takes the command's return code. When it is non-zero and no verdict line is found, the report ends in "exit code N: ... the lines above are the last lines of its own output" instead, and `extract_failure_excerpt` keeps the lines above that note up to the command echo. The NO VERDICT note is unchanged for a zero exit and for callers that pass no return code (prerun capture). Pass/fail, failure_class and failure_signature are unchanged: the new note carries no failure keyword, so the signature still keys off the command's output. Tests: - tests/test_nonzero_exit_no_verdict.py — report names the exit code, excerpt carries the command's own lines, class/signature unchanged, zero-exit and no-return-code paths keep the NO VERDICT note, a recognised verdict gets no exit note. Verification: - scripts/smoke-test.sh: 5108 tests OK, lint/security/coverage green. Co-Authored-By: Claude Opus 5.5 --- ...-gate-that-exits-non-zero-without-a-rec.md | 5 + specfuse/loop/loop.py | 49 ++++++++- tests/test_nonzero_exit_no_verdict.py | 103 ++++++++++++++++++ 3 files changed, 152 insertions(+), 5 deletions(-) create mode 100644 changelog.d/3603-a-gate-that-exits-non-zero-without-a-rec.md create mode 100644 tests/test_nonzero_exit_no_verdict.py diff --git a/changelog.d/3603-a-gate-that-exits-non-zero-without-a-rec.md b/changelog.d/3603-a-gate-that-exits-non-zero-without-a-rec.md new file mode 100644 index 00000000..2a1b83d7 --- /dev/null +++ b/changelog.d/3603-a-gate-that-exits-non-zero-without-a-rec.md @@ -0,0 +1,5 @@ +--- +class: fixed +trace: #3603 +--- +A gate that exits non-zero without a recognised pass/fail summary is now reported with its exit code, and failure_excerpt carries the command's own last lines instead of a "NO VERDICT FOUND ... may be unrelated" note. diff --git a/specfuse/loop/loop.py b/specfuse/loop/loop.py index 021674ad..54a9128d 100644 --- a/specfuse/loop/loop.py +++ b/specfuse/loop/loop.py @@ -2760,8 +2760,24 @@ def extract_failure_excerpt(stdout: str, max_chars: int = 500) -> str: # The report echoes the gate's own command as `$ `; a command # that mentions FAIL in its text (a surefire grep fallback, say) would # otherwise be the excerpt's head and eat half its budget (#3293). - relevant = [ln for ln in stdout.splitlines() - if _KW.search(ln) and not ln.lstrip().startswith("$ ")] + lines = stdout.splitlines() + keep: set[int] = set() + for i, ln in enumerate(lines): + if _KW.search(ln) and not ln.lstrip().startswith("$ "): + keep.add(i) + # A gate that exited non-zero with no recognisable summary (#3603): + # its own last lines, which `select_gate_report_lines` put just above + # this note, are the failure reason even when no keyword matches them + # (an oracle's `RED: ...` lines). Walk back to the command echo. + if _NONZERO_EXIT_NOTE_RE.match(ln.strip()): + j = i - 1 + while j >= 0: + prev = lines[j].strip() + if prev.startswith(("$ ", "### ")) or _FENCE_RE.match(prev): + break + keep.add(j) + j -= 1 + relevant = [lines[i] for i in sorted(keep)] # Hoist surefire failing-test lines to the front (#207): Maven emits # dozens of boilerplate [ERROR] wrapper lines that all pass the keyword # filter, so the head+tail budget reliably crowded out the actual @@ -6600,8 +6616,26 @@ def resolve_bash() -> str | None: "only, and may be unrelated to the failure. Run the command directly." ) +#: Note for a command that exited non-zero with no recognisable summary +#: (#3603). The exit code is the verdict, and the lines above it are the +#: command's own last lines, so they are the failure reason, not noise. Worded +#: without any `_FAILURE_KEYWORD_RE` keyword so the failure signature still +#: keys off the command's own output, exactly as before. +_NONZERO_EXIT_NOTE_PREFIX = "exit code " +_NONZERO_EXIT_NOTE_RE = re.compile(r"^exit code -?\d+: ") + + +def _nonzero_exit_note(returncode: int) -> str: + return ( + f"{_NONZERO_EXIT_NOTE_PREFIX}{returncode}: the command exited non-zero " + "without a recognisable pass/fail summary — the lines above are the last " + "lines of its own output." + ) + -def select_gate_report_lines(out: "str | None", window: int = 15) -> list[str]: +def select_gate_report_lines( + out: "str | None", window: int = 15, returncode: "int | None" = None, +) -> list[str]: """Return the lines to show in a gate's report — verdict first, tail always. A positional tail is not enough (FEAT-2026-0068). `unittest` writes its @@ -6616,7 +6650,9 @@ def select_gate_report_lines(out: "str | None", window: int = 15) -> list[str]: (see `_VERDICT_RE`) found *before* the tail, with an explicit elision marker between the two so nothing is dropped silently. When no verdict is found anywhere, say so rather than presenting unrelated trailing output as though - it were the failure. + it were the failure — unless *returncode* is non-zero (#3603): then the exit + code is the verdict and the tail is the command's own account of it, so + the note names the exit code instead. """ lines = (out or "").strip().splitlines() if not lines: @@ -6649,6 +6685,8 @@ def select_gate_report_lines(out: "str | None", window: int = 15) -> list[str]: tail_verdict_re = _MAVEN_VERDICT_RE if maven else _VERDICT_RE if any(tail_verdict_re.search(ln.strip()) for ln in tail): return tail + if returncode: + return tail + [_nonzero_exit_note(returncode)] return tail + [_NO_VERDICT_NOTE] @@ -6894,7 +6932,8 @@ def _run_gate_set( ok = proc.returncode == 0 if _capture_returncodes is not None: _capture_returncodes[gate["name"]] = proc.returncode - tail = select_gate_report_lines(out, window=15) + tail = select_gate_report_lines( + out, window=15, returncode=proc.returncode) # A green gate whose oracle silently degraded is a hollow pass # (issue #134): force FAIL and name the degradation honestly so the # log reads as "oracle couldn't measure it," not "code is clean." diff --git a/tests/test_nonzero_exit_no_verdict.py b/tests/test_nonzero_exit_no_verdict.py new file mode 100644 index 00000000..4d4e1da1 --- /dev/null +++ b/tests/test_nonzero_exit_no_verdict.py @@ -0,0 +1,103 @@ +# Copyright 2026 Specfuse Contributors +# Licensed under the Apache License, Version 2.0. See LICENSE. +"""Issue #3603 — a gate that exits non-zero without a recognised summary. + +A `feature_oracle` script printed `RED: lacks: ` lines and exited +1. Its report ended in the NO VERDICT note ("may be unrelated to the failure. +Run the command directly."), and `failure_excerpt` carried that note and the +`### feature_oracle: FAIL` header but none of the oracle's own lines: the +excerpt keeps keyword lines only, `RED:` matches none of the keywords, and the +note does ("pass/fail"). The signature, meanwhile, was the first `RED:` line. + +A non-zero exit IS the verdict. The report must say so with the exit code, the +excerpt must carry the command's own last lines, and the no-verdict wording is +kept for a command that exited zero with nothing recognisable. Pass/fail, +failure_class and failure_signature are unchanged. +""" +from __future__ import annotations + +import os +import tempfile +import unittest +from pathlib import Path + +from tests._loop_loader import load_loop + +loop = load_loop() + +_RED_ORACLE = ( + "echo 'checking 3 files'; " + "echo 'RED: docs/guide.md lacks: the new flag'; " + "echo 'RED: README.md lacks: the install line'; " + "exit 1" +) + + +class _InTempDir(unittest.TestCase): + def setUp(self): + self._cwd = os.getcwd() + self._tmp = tempfile.TemporaryDirectory() + os.chdir(self._tmp.name) + self.feature_dir = Path("feat") + self.feature_dir.mkdir() + + def tearDown(self): + os.chdir(self._cwd) + self._tmp.cleanup() + + def _payload(self, command: str, name: str = "feature_oracle") -> tuple[bool, str]: + results = loop._run_gate_set([{"name": name, "command": command}], self.feature_dir) + return results[0]["ok"], "\n\n".join(r["report"] for r in results) + + +class TestNonZeroExitWithoutSummary(_InTempDir): + def test_report_names_the_exit_code_not_no_verdict(self): + ok, payload = self._payload(_RED_ORACLE) + self.assertFalse(ok) + self.assertNotIn("NO VERDICT FOUND", payload) + self.assertNotIn("may be unrelated to the failure", payload) + self.assertIn("exit code 1", payload) + + def test_excerpt_carries_the_commands_own_last_lines(self): + _, payload = self._payload(_RED_ORACLE) + excerpt = loop.extract_failure_excerpt(payload) + self.assertIn("RED: docs/guide.md lacks: the new flag", excerpt) + self.assertIn("RED: README.md lacks: the install line", excerpt) + self.assertIn("exit code 1", excerpt) + self.assertNotIn("NO VERDICT FOUND", excerpt) + self.assertNotIn("$ echo", excerpt, "the command echo is not the command's output") + + def test_class_and_signature_are_unchanged(self): + _, payload = self._payload(_RED_ORACLE) + self.assertEqual( + loop.parse_gate_failure_signature(payload), + ("other", "checking 3 files"), + ) + + def test_other_exit_codes_are_named(self): + _, payload = self._payload("echo 'RED: x'; exit 3") + self.assertIn("exit code 3", payload) + self.assertIn("exit code 3", loop.extract_failure_excerpt(payload)) + + +class TestZeroExitWithoutSummaryKeepsTheNote(_InTempDir): + def test_a_passing_command_with_nothing_recognisable_still_reads_no_verdict(self): + ok, payload = self._payload("echo 'abc0001 subject'; exit 0", name="recent-commits") + self.assertTrue(ok) + self.assertIn(loop._NO_VERDICT_NOTE, payload) + + def test_selector_without_a_return_code_is_unchanged(self): + # prerun_capture and older callers pass no return code. + lines = loop.select_gate_report_lines("plain line\n", window=15) + self.assertEqual(lines, ["plain line", loop._NO_VERDICT_NOTE]) + + +class TestRecognisedSummaryIsUnaffected(_InTempDir): + def test_a_nonzero_exit_with_a_verdict_line_gets_no_exit_note(self): + _, payload = self._payload("echo 'FAILED (failures=1)'; exit 1", name="tests") + self.assertNotIn("exit code 1", payload) + self.assertNotIn("NO VERDICT FOUND", payload) + + +if __name__ == "__main__": + unittest.main()