The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tests): runner applies passthrough --ignore-glob; windows marker test stops sitting out 150s
teknium184692b7d7499
diff --git a/scripts/run_tests_parallel.py b/scripts/run_tests_parallel.pyindex fee6fd19e5e..0819a4ad455 100644--- a/scripts/run_tests_parallel.py+++ b/scripts/run_tests_parallel.py@@ -45,6 +45,7 @@ Exit code: 0 if every file's pytest exited 0; 1 otherwise.from __future__ import annotationsimport argparse+import fnmatchimport jsonimport osimport re@@ -199,6 +200,86 @@ def _split_pathspec(value: str) -> List[str]:# behaviour, and names the CI lane where those tests actually execute.+def _apply_pytest_ignores(+ files: List[Path], pytest_args: List[str], repo_root: Path+) -> List[Path]:+ """Drop the files a passthrough ``--ignore``/``--ignore-glob`` names.++ Each file is handed to its own pytest as an explicit argument, and pytest+ applies ``--ignore``/``--ignore-glob`` only while recursing directories,+ never to an explicit file argument. Forwarded as-is, the flags are no-ops:+ the CI lane's ``--ignore-glob='*test_desktop_update_windows_*.py'`` gate+ ran every one of those files on PRs it was meant to spare. Apply them here+ with pytest's own matching (``fnmatch`` on the absolute path, relative+ patterns anchored at the invocation directory, the repo root here).+ """+ paths: List[Path] = []+ globs: List[str] = []+ i = 0+ while i < len(pytest_args):+ tok = pytest_args[i]+ flag, eq, value = tok.partition("=")+ if flag in ("--ignore", "--ignore-glob"):+ if not eq:+ i += 1+ value = pytest_args[i] if i < len(pytest_args) else ""+ if value:+ anchored = Path(value) if Path(value).is_absolute() else repo_root / value+ if flag == "--ignore":+ paths.append(anchored.resolve())+ else:+ globs.append(str(anchored))+ i += 1+ if not paths and not globs:+ return files++ def _ignored(file: Path) -> bool:+ real = file.resolve()+ if any(real == p or p in real.parents for p in paths):+ return True+ return any(fnmatch.fnmatch(str(file), g) or fnmatch.fnmatch(str(real), g) for g in globs)++ kept = [f for f in files if not _ignored(f)]+ ignored = len(files) - len(kept)+ if ignored:+ print(f"note: --ignore/--ignore-glob excluded {ignored} test "+ f"file{'s' if ignored != 1 else ''} from this run.", flush=True)+ return kept+++def _select_files(+ args: argparse.Namespace, pytest_passthrough: List[str], repo_root: Path+) -> Tuple[List[Path], List[Path]]:+ """Return ``(files, discovery roots)`` for this run, passthrough ignores applied."""+ # --files / --files-from: explicit file list (argv or file-backed) from+ # the CI generate job — skip discovery.+ if args.files and args.files_from:+ print(+ "error: --files and --files-from are mutually exclusive", file=sys.stderr+ )+ sys.exit(2)+ roots: List[Path] = []+ if args.files:+ files = [repo_root / f for f in _split_pathspec(args.files)]+ elif args.files_from:+ files = [repo_root / f for f in _read_files_from(args.files_from)]+ else:+ # Resolve discovery roots: positional path args override --paths if any+ # were supplied, otherwise --paths (which itself defaults to 'tests').+ if args.paths_positional:+ roots = [repo_root / p for p in args.paths_positional]+ else:+ roots = [repo_root / p for p in _split_pathspec(args.paths)]++ if args.include_integration:+ # Caller takes responsibility — typically used via explicit -k filter.+ global _SKIP_PARTS # noqa: PLW0603 — config knob+ _SKIP_PARTS = set()++ files = _discover_files(roots)+ return _apply_pytest_ignores(files, pytest_passthrough, repo_root), roots++def _read_files_from(spec: str) -> List[str]:"""Read an explicit test-file list from *spec* - a path, or ``-`` for stdin.@@ -1227,33 +1308,7 @@ def main() -> int:repo_root = Path(__file__).resolve().parent.parent- # --files / --files-from: explicit file list (argv or file-backed) from- # the CI generate job — skip discovery.- if args.files and args.files_from:- print(- "error: --files and --files-from are mutually exclusive", file=sys.stderr- )- sys.exit(2)- if args.files:- files = [repo_root / f for f in _split_pathspec(args.files)]- roots = []- elif args.files_from:- files = [repo_root / f for f in _read_files_from(args.files_from)]- roots = []- else:- # Resolve discovery roots: positional path args override --paths if any- # were supplied, otherwise --paths (which itself defaults to 'tests').- if args.paths_positional:- roots = [repo_root / p for p in args.paths_positional]- else:- roots = [repo_root / p for p in _split_pathspec(args.paths)]-- if args.include_integration:- # Caller takes responsibility — typically used via explicit -k filter.- global _SKIP_PARTS # noqa: PLW0603 — config knob- _SKIP_PARTS = set()-- files = _discover_files(roots)+ files, roots = _select_files(args, pytest_passthrough, repo_root)if not files:print("No test files to run", file=sys.stderr)diff --git a/tests/scripts/desktop_update/test_desktop_update_windows_marker.py b/tests/scripts/desktop_update/test_desktop_update_windows_marker.pyindex e58a8c39ebe..84154759415 100644--- a/tests/scripts/desktop_update/test_desktop_update_windows_marker.py+++ b/tests/scripts/desktop_update/test_desktop_update_windows_marker.py@@ -234,8 +234,11 @@ def test_dead_owner_marker_is_reclaimed_and_released(tmp_path: Path) -> None:@pytest.mark.platforms('windows')def test_desktop_that_never_exits_is_not_relaunched_over(- tmp_path: Path, sleeper: subprocess.Popen,+ tmp_path: Path, sleeper: subprocess.Popen, monkeypatch: pytest.MonkeyPatch,) -> None:+ # The verdict (refuse with 4, never relaunch) is the same at any ceiling; the production+ # 150 s one alone pushed this file to the runner's 300 s per-file cap on a loaded runner.+ monkeypatch.setenv('HERMES_UPDATE_DESKTOP_EXIT_SECONDS', '5')install = tmp_path / 'checkout'publish_fixture_launcher(install, CLI)home = tmp_path / 'home'; home.mkdir()@@ -243,9 +246,10 @@ def test_desktop_that_never_exits_is_not_relaunched_over((home / MARKER).write_bytes(f'{sleeper.pid}\n{int(time.time())}\nct:{_creation_time(sleeper.pid)}\n'.encode())relaunch = Path(os.environ.get('SystemRoot', r'C:\Windows')) / 'System32' / 'hostname.exe'_, code, out = _run(home, '-DesktopPid', str(sleeper.pid), '-RelaunchExe', str(relaunch),- install=install, timeout=180)+ install=install)assert code == 4, outlog = (home / 'logs/desktop-update-handoff.log').read_text(encoding='utf-8-sig')+ assert 'did not exit within 5s' in log, log # the override reached the script's waitassert 'relaunching desktop' not in log, logdiff --git a/tests/scripts/test_run_tests_parallel.py b/tests/scripts/test_run_tests_parallel.pyindex b9cc90d662b..7e3aaf96f6d 100644--- a/tests/scripts/test_run_tests_parallel.py+++ b/tests/scripts/test_run_tests_parallel.py@@ -437,6 +437,37 @@ def test_runner_selection_records_actual_test_identity(tmp_path, form, expected)assert sorted(path.name for path in receipt.iterdir()) == expected[email protected]("selector", ["files", "discovery"])[email protected]("ignore", ["glob", "glob-spaced", "path"])+def test_passthrough_ignore_drops_files_the_runner_hands_pytest_explicitly(+ tmp_path, selector, ignore,+):+ """Each file reaches its own pytest as an explicit argument, which pytest's+ --ignore/--ignore-glob never filter; the runner must apply them itself. The+ Windows lane's ``--ignore-glob='*test_desktop_update_windows_*.py'`` gate was a+ no-op, so those files ran (and hit the per-file cap) on PRs it meant to spare."""+ root = _probe_root(tmp_path) # relative globs anchor at the repo root (per-file pytest's cwd)+ probe = root / "tests" / "probe"+ probe.mkdir(parents=True)+ receipt = tmp_path / "witnesses"+ receipt.mkdir()+ for name in ("keep", "gated_skipme"):+ (probe / f"test_{name}.py").write_text(+ f"from pathlib import Path\ndef test_{name}():\n Path({str(receipt / name)!r}).touch()\n",+ encoding="utf-8")+ pick = (["--files", os.pathsep.join(f"tests/probe/test_{n}.py" for n in ("keep", "gated_skipme"))]+ if selector == "files" else ["--paths", str(probe)])+ flag = {"glob": ["--ignore-glob=*test_gated_*.py"],+ "glob-spaced": ["--ignore-glob", "*test_gated_*.py"],+ "path": ["--ignore=tests/probe/test_gated_skipme.py"]}[ignore]+ runner = root / "scripts/run_tests_parallel.py"+ result = subprocess.run([sys.executable, str(runner), *pick, "-j", "1", "--file-timeout", "30", "--", *flag],+ cwd=tmp_path, capture_output=True, text=True, encoding="utf-8", timeout=60)+ assert result.returncode == 0, result.stdout + result.stderr+ assert sorted(path.name for path in receipt.iterdir()) == ["keep"], result.stdout+ assert "excluded 1 test file" in result.stdout, result.stdout++@pytest.mark.platforms("posix") # POSIX signal death; Windows has no SIGSEGV exit