The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tests): parallel runner rejects unknown bare flags with usage instead of sweeping
teknium1d7bedcee1e67
diff --git a/scripts/run_tests_parallel.py b/scripts/run_tests_parallel.pyindex c95b8f4501c..8438833132b 100755--- a/scripts/run_tests_parallel.py+++ b/scripts/run_tests_parallel.py@@ -29,6 +29,9 @@ Usage:(e.g. ``-q``, ``-v``, ``-x``, ``--tb=long``, ``-k 'pattern'``, ``--lf``)with no special separator — a bare ``-q`` "just works". Anything aftera literal ``--`` is also passed through, and stacks with bare flags.+ ``-h``/``--help`` prints this usage; a bare flag pytest does not know+ (a typo like ``--jbs``) is a usage error here rather than a per-file+ pytest failure. Tokens after ``--`` are never validated.Environment:HERMES_TEST_WORKERS Override worker count (default: os.cpu_count())@@ -821,6 +824,30 @@ def _make_stdio_glyph_safe() -> None:pass+def _unknown_pytest_flags(tokens: List[str]) -> List[str]:+ """Return the bare passthrough tokens pytest itself would reject.++ A mistyped flag (``--jbs``) that is not one of OUR options used to be+ forwarded to every per-file pytest, so the run discovered the whole suite+ and each file died with ``unrecognized arguments`` — an hours-long way to+ learn about a typo. Ask pytest's own argparse parser (with the installed+ plugins loaded, so ``-n``/``--timeout`` count) which tokens it does not+ know; argparse handles the attached-value (``-rA``), combined-flag+ (``-xvs``) and ``-k expr`` forms for us. If the parser cannot be built+ the check is skipped and tokens are forwarded as before.+ """+ try:+ from _pytest.config import get_config++ config = get_config()+ config.pluginmanager.load_setuptools_entrypoints("pytest11")+ parser = config._parser.optparser+ _, unknown = parser.parse_known_args(tokens)+ except Exception:+ return []+ return [tok for tok in unknown if tok.startswith("-")]++def main() -> int:_make_stdio_glyph_safe()parser = argparse.ArgumentParser(@@ -977,6 +1004,14 @@ def main() -> int:args = parser.parse_args(our_args)+ # Bare tokens are validated against pytest's option set so a typo fails+ # here with usage instead of once per discovered file. Anything after a+ # literal ``--`` is the caller's explicit choice and is forwarded as-is.+ if bare_passthrough:+ unknown = _unknown_pytest_flags(bare_passthrough)+ if unknown:+ parser.error(f"unrecognized arguments: {' '.join(unknown)}")+# ── Node-id selectors → file + ``-k`` filter ────────────────────────────# This runner is FILE-granular: it spawns one ``pytest <file>`` per test# file. A pytest node id (``tests/foo.py::TestBar::test_baz``) is not andiff --git a/tests/scripts/test_run_tests_parallel.py b/tests/scripts/test_run_tests_parallel.pyindex f1e96d250ee..4f30d3ade8b 100644--- a/tests/scripts/test_run_tests_parallel.py+++ b/tests/scripts/test_run_tests_parallel.py@@ -293,6 +293,25 @@ def test_help_prints_usage_without_discovering_or_running_tests(assert "Discovered" not in proc.stdout+def test_unknown_bare_flag_errors_with_usage_instead_of_sweeping(tmp_path: Path) -> None:+ """A typo'd flag fails once, up front, and never reaches a per-file pytest.++ Bare tokens are checked against pytest's own option set, so real pytest+ forms (attached short value ``-rA``, bare ``-x``) still pass through and+ run, while ``--jbs`` is rejected with this runner's usage before discovery.+ """+ probe_dir = _make_probe_dir(tmp_path)++ proc = _run_runner(probe_dir, "--jbs")+ assert proc.returncode == 2, proc.stdout+ assert "usage:" in proc.stdout and "unrecognized arguments: --jbs" in proc.stdout+ assert "Discovered" not in proc.stdout++ proc = _run_runner(probe_dir, "-rA", "-x")+ assert proc.returncode == 0, proc.stdout+ assert "2✓" in proc.stdout or "2 passed" in proc.stdout, proc.stdout++def test_bare_value_flag_keeps_its_value(tmp_path: Path) -> None: