diff --git a/scripts/run_quality_gate.py b/scripts/run_quality_gate.py index ce3800e93..e85be5178 100644 --- a/scripts/run_quality_gate.py +++ b/scripts/run_quality_gate.py @@ -47,6 +47,8 @@ EXTRA_COMPILE_TARGETS = [ CORE_PYTEST_TARGETS = [ "tests/test_cli_smoke.py", "tests/test_api_server_security.py", + # Keeps the in-pytest fragment audit from disappearing (the gate no longer runs it separately). + "tests/test_quality_gate_fragment_audit_once.py", "tests/test_jaimini.py", "tests/test_shadbala_complete.py", "tests/test_transit_trigger.py", @@ -767,7 +769,10 @@ def main() -> int: compile_targets() validate_json_files() run([PYTHON, "scripts/audit_capabilities.py", "--mode", "validate"]) - run([PYTHON, "scripts/audit_fragments.py", "--strict"]) + # `audit_fragments.py --strict` only fails when audit()["valid"] is false. + # The pytest run below always includes tests/test_api_server_security.py, + # whose test_fragment_audit_blocks_registry_surface_drift runs the same + # audit() and asserts valid plus more; running both cost ~52 s twice. run([PYTHON, "scripts/interpretation_source_inventory_gate.py"]) run([PYTHON, "scripts/character_level_inventory_manifest.py", "--scope", "project", "--no-write", "--summary-only"]) if profile["check_release_hygiene"]: diff --git a/tests/test_quality_gate_fragment_audit_once.py b/tests/test_quality_gate_fragment_audit_once.py new file mode 100644 index 000000000..1d0321254 --- /dev/null +++ b/tests/test_quality_gate_fragment_audit_once.py @@ -0,0 +1,34 @@ +"""The fragment audit runs once per quality gate, inside pytest (CI speed-up, 2026-11-03). + +The gate used to run `scripts/audit_fragments.py --strict` and then pytest ran +the same `audit()` again in tests/test_api_server_security.py. The separate step +is gone; these checks keep the pytest copy from silently disappearing. +""" + +from __future__ import annotations + +import ast +import sys +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / "scripts")) + +import run_quality_gate # noqa: E402 + + +def test_the_core_pytest_targets_run_the_whole_security_file() -> None: + assert "tests/test_api_server_security.py" in run_quality_gate.CORE_PYTEST_TARGETS + + +def test_the_security_file_still_asserts_the_fragment_audit_is_valid() -> None: + source = (ROOT / "tests" / "test_api_server_security.py").read_text(encoding="utf-8") + tree = ast.parse(source) + names = {node.name for node in tree.body if isinstance(node, ast.FunctionDef)} + assert "test_fragment_audit_blocks_registry_surface_drift" in names + assert "result['valid'] is True" in source + + +def test_the_gate_does_not_run_the_fragment_audit_a_second_time() -> None: + gate = (ROOT / "scripts" / "run_quality_gate.py").read_text(encoding="utf-8") + assert '"scripts/audit_fragments.py", "--strict"' not in gate