-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrun_core_python_checks.py
More file actions
169 lines (147 loc) · 6.05 KB
/
Copy pathrun_core_python_checks.py
File metadata and controls
169 lines (147 loc) · 6.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
from __future__ import annotations
import argparse
import json
import os
import subprocess
import sys
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parents[2]
ARTIFACT_DIR = REPO_ROOT / "artifacts" / "system-audit"
# Fast, deterministic smoke lane for PR gating. This should finish quickly on
# GitHub-hosted runners and avoid pulling in long-running "everything tests".
#
# When you add a new product surface, add the test path here so regressions
# get caught on PR rather than discovered post-merge. The PR #1700
# `_public_dispatch_payload` regression that stripped `bus_event.version`
# from the public free-llm response sat undetected on main for two days
# because `tests/api/test_free_llm_routes.py` wasn't in this list.
CORE_SMOKE_PATHS: tuple[str, ...] = (
"tests/test_src_harmonic_contract.py",
"tests/test_api_header_compat.py",
"tests/test_geoseal_v2.py",
"tests/test_notarize.py",
"tests/test_phi_ternary.py",
"tests/test_runtime_gate.py",
# Security contracts must run on every PR, including both Python trees.
"tests/test_patent_security_regressions.py",
"tests/governance/test_patent_decision_repairs.py",
"tests/governance/test_full_system_decision_precedence.py",
"tests/security/test_breathing_and_backend_contracts.py",
"tests/security/test_braid_signature_integrity.py",
"tests/security/test_rwp2_authentication_contract.py",
"tests/test_sacred_eggs.py",
"tests/test_sacred_egg_registry.py",
"tests/test_semantic_projector_deep.py",
"tests/test_triangulated_lattice.py",
"tests/crypto",
# Active product surfaces — keep these in PR-gated CI.
"tests/api/test_free_llm_routes.py",
"tests/system/test_agent_bus_workspace_cli.py",
"tests/system/test_trap_redirect_cli.py",
"tests/system/test_trap_dispatch_cli.py",
"tests/system/test_trap_dispatch_workspace_cli.py",
# Reaction-state spine + chemistry verifier lanes (signed receipts,
# exact units, balancer, geometry view). rdkit-dependent geometry
# tests importorskip cleanly where rdkit is absent.
"tests/test_reaction_state_packet.py",
"tests/test_reaction_ledger_checkpoint.py",
"tests/test_jcs_canonicalization.py",
"tests/test_acta_receipt_export.py",
"tests/test_units.py",
"tests/test_units_pathology.py",
"tests/test_reaction_balance.py",
"tests/test_geometry_view.py",
"tests/test_controlled_substance_screen.py",
"tests/test_reaction_language.py",
)
# Optional or experimental lanes that currently pull in extra services,
# unpublished modules, or heavyweight third-party stacks. Keep them out of the
# default merge path and triage them in dedicated workflows instead.
OPTIONAL_TEST_IGNORES: tuple[str, ...] = (
"tests/api/test_billing_public_checkout.py",
"tests/industry_standard/test_byzantine_consensus.py",
"tests/test_aethermoore_patents.py",
"tests/test_api_key_hashing.py",
"tests/test_hallpass.py",
"tests/test_mcp_servers.py",
"tests/test_mobile_goal_api.py",
"tests/test_orchestrator.py",
"tests/test_paper_aggregator.py",
"tests/test_sacred_tongue_integration.py",
"tests/test_spectral_langgraph.py",
"tests/test_system_script_security.py",
)
DEFAULT_MARKER_EXPR = "not slow"
def build_pytest_command(
test_targets: tuple[str, ...],
maxfail: int | None = None,
extra_args: list[str] | None = None,
) -> list[str]:
command = [
sys.executable,
"-m",
"pytest",
"-v",
"-m",
DEFAULT_MARKER_EXPR,
"--ignore=tests/node_modules",
]
command.extend(test_targets)
if maxfail is not None:
command.append(f"--maxfail={maxfail}")
command.extend(f"--ignore={path}" for path in OPTIONAL_TEST_IGNORES)
if extra_args:
command.extend(extra_args)
return command
def build_environment() -> dict[str, str]:
env = os.environ.copy()
env["PYTHONPATH"] = str(REPO_ROOT)
return env
def summary_payload(command: list[str]) -> dict[str, object]:
return {
"repo_root": str(REPO_ROOT),
"command": command,
"optional_ignores": list(OPTIONAL_TEST_IGNORES),
"marker": DEFAULT_MARKER_EXPR,
"env": {
"PYTHONPATH": str(REPO_ROOT),
},
}
def write_summary(payload: dict[str, object]) -> Path:
ARTIFACT_DIR.mkdir(parents=True, exist_ok=True)
destination = ARTIFACT_DIR / "core_python_suite.json"
destination.write_text(json.dumps(payload, indent=2), encoding="utf-8")
return destination
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Run the curated core Python test lane for merge readiness.")
parser.add_argument("--dry-run", action="store_true", help="Print the command and exit without running pytest.")
parser.add_argument("--json", action="store_true", help="Print machine-readable command summary.")
parser.add_argument(
"--full",
action="store_true",
help="Run the full tests/ tree (still excluding known-heavy optional lanes).",
)
parser.add_argument("--maxfail", type=int, default=1, help="Maximum failures before stopping pytest.")
parser.add_argument("pytest_args", nargs="*", help="Extra pytest args appended after the curated defaults.")
return parser.parse_args()
def main() -> int:
args = parse_args()
targets = ("tests",) if args.full else CORE_SMOKE_PATHS
command = build_pytest_command(test_targets=targets, maxfail=args.maxfail, extra_args=list(args.pytest_args))
payload = summary_payload(command)
summary_path = write_summary(payload)
if args.json:
print(json.dumps(payload, indent=2))
else:
print("Core Python merge lane")
print(f"repo_root={REPO_ROOT}")
print(f"summary={summary_path}")
for item in OPTIONAL_TEST_IGNORES:
print(f"ignore={item}")
print("command=" + " ".join(command))
if args.dry_run:
return 0
completed = subprocess.run(command, cwd=REPO_ROOT, env=build_environment())
return completed.returncode
if __name__ == "__main__":
raise SystemExit(main())