The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
ci(remote-backends): fail on skips from the runner's parsed counts (review)
Tekniumecf7d948e694
diff --git a/.github/workflows/remote-backends.yml b/.github/workflows/remote-backends.ymlindex 60740af3a2e..2ddca83aef0 100644--- a/.github/workflows/remote-backends.yml+++ b/.github/workflows/remote-backends.yml@@ -61,14 +61,13 @@ jobs:OPENROUTER_API_KEY: ""OPENAI_API_KEY: ""NOUS_API_KEY: ""+ # The real tests skip when their host is missing; here that would be a green+ # lane over zero coverage. --fail-on-skip fails the run on any skip, decided+ # from pytest's parsed counts rather than the progress line's display format.run: |- set -o pipefail- scripts/run_tests.sh tests/tools/test_ssh_environment.py tests/tools/test_docker_backend_real.py \- | tee "$RUNNER_TEMP/remote-backends.log"- # The real tests skip when their host is missing; here that would be a green- # lane over zero coverage. The runner prints a file's skip count as "<n>s,".- if grep -E '\((.* )?[0-9]+s,' "$RUNNER_TEMP/remote-backends.log"; then- echo "::error::real-backend tests skipped: the sshd or docker image was not wired through"+ if ! scripts/run_tests.sh --fail-on-skip \+ tests/tools/test_ssh_environment.py tests/tools/test_docker_backend_real.py; then+ echo "::error::real-backend tests failed or skipped (a skip means the sshd or docker image was not wired through)"exit 1fidiff --git a/scripts/run_tests_parallel.py b/scripts/run_tests_parallel.pyindex 343c168be25..521a95eb647 100644--- a/scripts/run_tests_parallel.py+++ b/scripts/run_tests_parallel.py@@ -1093,6 +1093,63 @@ def _pytest_flag_error(tokens: list[str]) -> Optional[str]:return f"unrecognized arguments: {' '.join(unknown)}" if unknown else None+def _report_skips(+ skipped_files: list[tuple[Path, int]], repo_root: Path,+) -> bool:+ """--fail-on-skip: a skip is a failure of the lane, not of a test.++ Decided from pytest's parsed per-file counts, never from the progress+ line's display format. Returns True when the run must fail.+ """+ total = sum(n for _, n in skipped_files)+ if not total:+ return False+ print()+ print(f"=== ✗ {total} test{'s' if total != 1 else ''} SKIPPED under --fail-on-skip. This is NOT a pass. ===")+ for file, n in sorted(skipped_files, key=lambda item: str(item[0])):+ print(f" {_format_file(file, repo_root)} ({n} skipped)")+ return True+++def _print_failure_report(+ failures: list[tuple[Path, str, dict[str, int]]], repo_root: Path,+) -> None:+ """Every failing file's output, then the failures grouped by cause."""+ print()+ print("=== Failure output ===")+ for file, output, _summary in failures:+ print()+ print(f"--- {_format_file(file, repo_root)} ---")+ print(output.rstrip())+ print()+ # Split: files with actual test failures vs non-zero exit for other reasons+ crashed_files = [(f, o, s) for f, o, s in failures if s.get("crashed")]+ rest = [(f, s) for f, _o, s in failures if not s.get("crashed")]+ test_fail_files = [(f, s) for f, s in rest if s.get("failed", 0) > 0]+ all_passed_but_nonzero = [(f, s) for f, s in rest+ if s.get("failed", 0) == 0 and s.get("passed", 0) > 0]+ no_tests_ran = [(f, s) for f, s in rest+ if s.get("failed", 0) == 0 and s.get("passed", 0) == 0]+ if crashed_files:+ print(f"=== {len(crashed_files)} file{'s' if len(crashed_files) != 1 else ''} where the interpreter CRASHED mid-run (native fault — a real bug, not a collection error; the tests that did run are not counted) ===")+ for file, output, _s in crashed_files:+ print(f" {_format_file(file, repo_root)} {output.splitlines()[0]}")+ if test_fail_files:+ total_tf = sum(s.get("failed", 0) for _, s in test_fail_files)+ print(f"=== {len(test_fail_files)} file{'s' if len(test_fail_files) != 1 else ''} with test failures ({total_tf} test{'s' if total_tf != 1 else ''} failed) ===")+ for file, s in test_fail_files:+ nf = s.get("failed", 0)+ print(f" {_format_file(file, repo_root)} ({nf} test{'s' if nf != 1 else ''} failed)")+ if all_passed_but_nonzero:+ print(f"=== {len(all_passed_but_nonzero)} file{'s' if len(all_passed_but_nonzero) != 1 else ''} where all tests passed but pytest exited non-zero (warnings-as-errors, hook failures, etc.) ===")+ for file, s in all_passed_but_nonzero:+ print(f" {_format_file(file, repo_root)} ({s.get('passed', 0)} passed)")+ if no_tests_ran:+ print(f"=== {len(no_tests_ran)} file{'s' if len(no_tests_ran) != 1 else ''} where no tests ran (collection/import error, timeout before collection, etc.) ===")+ for file, s in no_tests_ran:+ print(f" {_format_file(file, repo_root)}")++def main() -> int:_make_stdio_glyph_safe()parser = argparse.ArgumentParser(@@ -1191,6 +1248,15 @@ def main() -> int:"the per-argv-element cap; mutually exclusive with --files."),)+ parser.add_argument(+ "--fail-on-skip",+ action="store_true",+ help=(+ "Fail the run if any test is skipped. For lanes whose whole point "+ "is coverage a skip would hide (e.g. the real SSH/Docker backend "+ "tests, which skip when their host is not wired through)."+ ),+ )parser.add_argument("paths_positional",nargs="*",@@ -1220,7 +1286,7 @@ def main() -> int:OUR_FLAGS = {"-h", "--help", "-j", "--jobs", "--paths", "--include-integration","--file-timeout", "--file-retries", "--slice", "--generate-slices", "--files",- "--files-from",+ "--files-from", "--fail-on-skip",}# pytest short flags that consume the NEXT token as their value.PYTEST_VALUE_FLAGS = {"-k", "-m", "-p", "-o", "-c", "-r", "-W"}@@ -1403,6 +1469,7 @@ def main() -> int:tests_passed = 0tests_failed = 0tests_skipped = 0+ skipped_files: list[tuple[Path, int]] = []# Every collected outcome, not just pass/fail: a legitimately all-skipped# (platform-gated) file reports "2 skipped" and must NOT trip the# nothing-ran guard, whereas a file that died before collection reports@@ -1438,6 +1505,8 @@ def main() -> int:tests_passed += summary.get("passed", 0)tests_failed += summary.get("failed", 0)tests_skipped += summary.get("skipped", 0)+ if summary.get("skipped", 0):+ skipped_files.append((fpath, summary["skipped"]))files_crashed += summary.get("crashed", 0)tests_collected += sum(summary.get(k, 0)@@ -1579,43 +1648,13 @@ def main() -> int:for f, t in slowest:print(f" {t:>6.2f}s {_format_file(f, repo_root)}")+ skips_fail_the_run = bool(args.fail_on_skip) and _report_skips(skipped_files, repo_root)+if failures:- print()- print("=== Failure output ===")- for file, output, _summary in failures:- print()- print(f"--- {_format_file(file, repo_root)} ---")- print(output.rstrip())- print()- # Split: files with actual test failures vs non-zero exit for other reasons- crashed_files = [(f, o, s) for f, o, s in failures if s.get("crashed")]- rest = [(f, s) for f, _o, s in failures if not s.get("crashed")]- test_fail_files = [(f, s) for f, s in rest if s.get("failed", 0) > 0]- all_passed_but_nonzero = [(f, s) for f, s in rest- if s.get("failed", 0) == 0 and s.get("passed", 0) > 0]- no_tests_ran = [(f, s) for f, s in rest- if s.get("failed", 0) == 0 and s.get("passed", 0) == 0]- if crashed_files:- print(f"=== {len(crashed_files)} file{'s' if len(crashed_files) != 1 else ''} where the interpreter CRASHED mid-run (native fault — a real bug, not a collection error; the tests that did run are not counted) ===")- for file, output, _s in crashed_files:- print(f" {_format_file(file, repo_root)} {output.splitlines()[0]}")- if test_fail_files:- total_tf = sum(s.get("failed", 0) for _, s in test_fail_files)- print(f"=== {len(test_fail_files)} file{'s' if len(test_fail_files) != 1 else ''} with test failures ({total_tf} test{'s' if total_tf != 1 else ''} failed) ===")- for file, s in test_fail_files:- nf = s.get("failed", 0)- print(f" {_format_file(file, repo_root)} ({nf} test{'s' if nf != 1 else ''} failed)")- if all_passed_but_nonzero:- print(f"=== {len(all_passed_but_nonzero)} file{'s' if len(all_passed_but_nonzero) != 1 else ''} where all tests passed but pytest exited non-zero (warnings-as-errors, hook failures, etc.) ===")- for file, s in all_passed_but_nonzero:- print(f" {_format_file(file, repo_root)} ({s.get('passed', 0)} passed)")- if no_tests_ran:- print(f"=== {len(no_tests_ran)} file{'s' if len(no_tests_ran) != 1 else ''} where no tests ran (collection/import error, timeout before collection, etc.) ===")- for file, s in no_tests_ran:- print(f" {_format_file(file, repo_root)}")+ _print_failure_report(failures, repo_root)return 1- if no_tests_ran_at_all:+ if no_tests_ran_at_all or skips_fail_the_run:return 1return 0diff --git a/tests/ci/test_classify_changes.py b/tests/ci/test_classify_changes.pyindex 0f490f2d56e..8578f62ff40 100644--- a/tests/ci/test_classify_changes.py+++ b/tests/ci/test_classify_changes.py@@ -609,6 +609,9 @@ def test_remote_backends_lane_runs_test_files_that_exist_and_start_it():assert pathsassert [p for p in paths if not (_REPO / p).is_file()] == []assert [p for p in paths if not classify([p])["remote_backends"]] == []+ # A skip there is a missing host, not a pass; the runner, not a grep over its+ # progress line, decides that.+ assert "scripts/run_tests.sh --fail-on-skip" in textdef test_windows_venv_e2e_runs_only_test_files_that_exist():diff --git a/tests/scripts/test_run_tests_parallel.py b/tests/scripts/test_run_tests_parallel.pyindex a1d9c1bf196..262dcb047ca 100644--- a/tests/scripts/test_run_tests_parallel.py+++ b/tests/scripts/test_run_tests_parallel.py@@ -447,6 +447,36 @@ def test_zero_collected_across_run_fails_and_says_so(tmp_path: Path) -> None:+def test_fail_on_skip_fails_a_run_with_any_skip_even_beside_an_xfail(tmp_path: Path) -> None:+ """--fail-on-skip reads the parsed skip count, not the progress line.++ The remote-backends lane once grepped the line for an ``<n>s,`` suffix,+ which an xfail printed after the skip (``1✓ 1s 1xf, ...``) hid.+ """+ probe_dir = tmp_path / "probe"+ probe_dir.mkdir()+ (probe_dir / "test_skipprobe.py").write_text(+ "import pytest\n\n"+ "def test_runs():\n assert True\n\n"+ "def test_skips():\n pytest.skip('host not wired')\n\n"+ "@pytest.mark.xfail(strict=True)\ndef test_xfails():\n assert False\n"+ )+ plain = _run_runner(probe_dir)+ assert plain.returncode == 0, plain.stdout+ assert "1s 1xf," in plain.stdout, plain.stdout++ gated = _run_runner(probe_dir, "--fail-on-skip")+ assert gated.returncode == 1, gated.stdout+ assert "1 test SKIPPED under --fail-on-skip" in gated.stdout+ assert "test_skipprobe.py (1 skipped)" in gated.stdout+++def test_fail_on_skip_passes_a_run_without_skips(tmp_path: Path) -> None:+ proc = _run_runner(_make_probe_dir(tmp_path), "--fail-on-skip")+ assert proc.returncode == 0, proc.stdout+ assert "SKIPPED" not in proc.stdout++@pytest.mark.parametrize("form,expected", [("positional", ["alpha", "beta"]), ("bare-k", ["alpha"]),("node-id", ["alpha"]), ("explicit-k", ["beta"]),