From b4ecf67e3525fb53f9233cbb665567d903c6c72b Mon Sep 17 00:00:00 2001 From: Shay Date: Fri, 15 May 2026 06:25:37 -0700 Subject: [PATCH] Fix CLI test suite pytest flags - allow pytest flags after core test --suite without requiring separator - preserve strict unknown-argument rejection for non-test commands - add regression coverage for core test --suite packs -q --- core/cli.py | 9 +++++++-- tests/test_cli_test_suites.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/core/cli.py b/core/cli.py index 502594b8..1be54228 100644 --- a/core/cli.py +++ b/core/cli.py @@ -23,7 +23,7 @@ _CORE_RS_DIR = _REPO_ROOT / "core-rs" _CORE_RS_MANIFEST = _CORE_RS_DIR / "Cargo.toml" DESCRIPTION = "CORE versor engine command suite." -EPILOG = "Examples:\n core chat\n core trace \"word beginning truth\"\n core trace --output-language grc --frame-pack grc --json \"logos\"\n core rust status\n core rust build\n core oov covenant\n core pack list\n core pack verify en_minimal_v1\n core test --suite smoke\n core test --suite cognition\n core test -- tests/test_alignment_graph.py -q" +EPILOG = "Examples:\n core chat\n core trace \"word beginning truth\"\n core trace --output-language grc --frame-pack grc --json \"logos\"\n core rust status\n core rust build\n core oov covenant\n core pack list\n core pack verify en_minimal_v1\n core test --suite smoke -q\n core test --suite cognition -q\n core test -- tests/test_alignment_graph.py -q" _TEST_SUITES: dict[str, tuple[str, ...]] = { "smoke": ( @@ -556,7 +556,12 @@ def _print_version() -> None: def main(argv: Sequence[str] | None = None) -> int: parser = build_parser() - args = parser.parse_args(list(argv) if argv is not None else None) + raw_args = list(argv) if argv is not None else sys.argv[1:] + args, unknown = parser.parse_known_args(raw_args) + if unknown: + if getattr(args, "command", None) != "test": + parser.error(f"unrecognized arguments: {' '.join(unknown)}") + args.args = [*(getattr(args, "args", None) or ()), *unknown] if args.version: _print_version() return 0 diff --git a/tests/test_cli_test_suites.py b/tests/test_cli_test_suites.py index 4b117e2a..e7467245 100644 --- a/tests/test_cli_test_suites.py +++ b/tests/test_cli_test_suites.py @@ -2,6 +2,8 @@ from __future__ import annotations +import pytest + from core import cli @@ -38,6 +40,27 @@ def test_core_test_suite_expands_to_expected_pytest_paths(monkeypatch) -> None: assert "-q" in command +def test_core_test_suite_accepts_pytest_flags_without_separator(monkeypatch) -> None: + calls: list[tuple[str, ...]] = [] + + def fake_run(*args: str, check: bool = False, cwd=None) -> int: + calls.append(args) + return 0 + + monkeypatch.setattr(cli, "_run", fake_run) + + rc = cli.main(["test", "--suite", "packs", "-q"]) + + assert rc == 0 + assert calls[0] == ( + cli.sys.executable, + "-m", + "pytest", + "tests/test_core_semantic_seed_pack.py", + "-q", + ) + + def test_core_test_passthrough_still_accepts_arbitrary_pytest_args(monkeypatch) -> None: calls: list[tuple[str, ...]] = [] @@ -57,3 +80,8 @@ def test_core_test_passthrough_still_accepts_arbitrary_pytest_args(monkeypatch) "tests/test_core_semantic_seed_pack.py", "-q", ) + + +def test_non_test_commands_still_reject_unknown_args() -> None: + with pytest.raises(SystemExit): + cli.main(["pack", "list", "-q"])