-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_full_validation_suite.py
More file actions
357 lines (315 loc) · 10.9 KB
/
run_full_validation_suite.py
File metadata and controls
357 lines (315 loc) · 10.9 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
#!/usr/bin/env python3
"""Run a consolidated capability + security + performance validation suite."""
from __future__ import annotations
import json
import os
import argparse
import subprocess
import sys
from dataclasses import asdict, dataclass
from datetime import datetime, timezone
from pathlib import Path
from typing import Dict, List, Optional
REPO_ROOT = Path(__file__).resolve().parents[3]
OUT_DIR = REPO_ROOT / "test-results" / "full-validation"
OUT_DIR.mkdir(parents=True, exist_ok=True)
STAMP = datetime.now(timezone.utc).strftime("%Y%m%d_%H%M%S")
JSON_OUT = OUT_DIR / f"full_validation_{STAMP}.json"
MD_OUT = OUT_DIR / f"full_validation_{STAMP}.md"
HISTORY_FILE = OUT_DIR / "history.jsonl"
PYTHON_EXEC = sys.executable or "python"
@dataclass
class CheckResult:
name: str
category: str
command: str
passed: bool
return_code: int
duration_seconds: float
output_file: str
BASE_CHECKS = [
{
"name": "API coverage validator",
"category": "capabilities",
"command": "node scripts/validate-api-coverage.js",
"timeout": 180,
},
{
"name": "Python communication contracts",
"category": "capabilities",
"command": f"{PYTHON_EXEC} tests/scripts/python/test_communication_contracts.py",
"timeout": 180,
},
{
"name": "Live backend HTTP E2E",
"category": "capabilities",
"command": f"{PYTHON_EXEC} tests/scripts/python/test_backend_live_e2e.py",
"timeout": 420,
},
{
"name": "Mobile gradient signature contract",
"category": "capabilities",
"command": f"{PYTHON_EXEC} tests/scripts/python/test_mobile_verify_gradient_contract.py",
"timeout": 240,
},
{
"name": "Marketplace local contracts",
"category": "functions",
"command": f"{PYTHON_EXEC} tests/scripts/python/test_marketplace_local_contracts.py",
"timeout": 300,
},
{
"name": "Marketplace negative-path contracts",
"category": "functions",
"command": f"{PYTHON_EXEC} tests/scripts/python/test_marketplace_negative_paths.py",
"timeout": 300,
},
{
"name": "Backend security controls",
"category": "security",
"command": f"{PYTHON_EXEC} tests/scripts/python/test_security_controls.py",
"timeout": 240,
},
{
"name": "Security fuzz controls",
"category": "security",
"command": f"{PYTHON_EXEC} tests/scripts/python/test_security_fuzz_controls.py",
"timeout": 300,
},
{
"name": "Performance regression thresholds",
"category": "performance",
"command": f"{PYTHON_EXEC} tests/scripts/python/test_performance_regression_thresholds.py",
"timeout": 300,
},
{
"name": "Dependency security audit",
"category": "security",
"command": "npm run security:check",
"timeout": 420,
},
{
"name": "Frontend unit tests",
"category": "functions",
"command": "npm --prefix frontend run test -- --run",
"timeout": 420,
},
{
"name": "SDK package unit tests",
"category": "capabilities",
"command": "npm run test:ci",
"timeout": 900,
},
]
DEEP_ONLY_CHECKS = [
{
"name": "Browser runtime render cadence E2E",
"category": "performance",
"command": f"{PYTHON_EXEC} tests/scripts/python/test_browser_runtime_e2e.py",
"timeout": 1200,
},
{
"name": "Scheduled chaos soak guard",
"category": "performance",
"command": f"{PYTHON_EXEC} tests/scripts/python/test_soak_chaos_guard.py",
"timeout": 1200,
},
]
CHECKS_BY_PROFILE = {
"fast": BASE_CHECKS,
"deep": BASE_CHECKS + DEEP_ONLY_CHECKS,
}
def _safe_write_text(path: Path, content: str) -> None:
"""Write text and recover if a concurrent cleanup removed the parent dir."""
try:
path.write_text(content, encoding="utf-8")
except FileNotFoundError:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(content, encoding="utf-8")
def run_check(name: str, category: str, command: str, timeout: int) -> CheckResult:
started = datetime.now(timezone.utc)
safe_name = (
name.lower()
.replace(" ", "_")
.replace("/", "_")
.replace(":", "")
.replace("-", "_")
)
output_file = OUT_DIR / f"{STAMP}_{safe_name}.log"
output_file.parent.mkdir(parents=True, exist_ok=True)
try:
proc = subprocess.run(
command,
cwd=REPO_ROOT,
shell=True,
text=True,
capture_output=True,
timeout=timeout,
env={**os.environ, "PYTHONUNBUFFERED": "1"},
)
_safe_write_text(output_file, (proc.stdout or "") + "\n" + (proc.stderr or ""))
passed = proc.returncode == 0
return_code = proc.returncode
except subprocess.TimeoutExpired as exc:
_safe_write_text(
output_file, (exc.stdout or "") + "\n" + (exc.stderr or "") + "\n[TIMEOUT]"
)
passed = False
return_code = 124
duration = (datetime.now(timezone.utc) - started).total_seconds()
return CheckResult(
name=name,
category=category,
command=command,
passed=passed,
return_code=return_code,
duration_seconds=round(duration, 2),
output_file=str(output_file.relative_to(REPO_ROOT)),
)
def aggregate_by_category(results: List[CheckResult]) -> Dict[str, Dict[str, int]]:
grouped: Dict[str, Dict[str, int]] = {}
for row in results:
grouped.setdefault(row.category, {"passed": 0, "failed": 0})
grouped[row.category]["passed" if row.passed else "failed"] += 1
return grouped
def load_last_history_record() -> Optional[Dict[str, object]]:
if not HISTORY_FILE.exists():
return None
lines = HISTORY_FILE.read_text(encoding="utf-8").splitlines()
for line in reversed(lines):
line = line.strip()
if not line:
continue
try:
return json.loads(line)
except json.JSONDecodeError:
continue
return None
def append_history_record(payload: Dict[str, object]) -> None:
HISTORY_FILE.parent.mkdir(parents=True, exist_ok=True)
summary = payload.get("summary", {})
duration = sum(
float(item.get("duration_seconds", 0.0)) for item in payload.get("results", [])
)
record = {
"timestamp_utc": payload.get("timestamp_utc"),
"total": int(summary.get("total", 0)),
"passed": int(summary.get("passed", 0)),
"failed": int(summary.get("failed", 0)),
"duration_seconds": round(duration, 2),
"categories": payload.get("categories", {}),
}
with HISTORY_FILE.open("a", encoding="utf-8") as handle:
handle.write(json.dumps(record) + "\n")
def build_markdown(
results: List[CheckResult], previous: Optional[Dict[str, object]]
) -> str:
total = len(results)
passed = sum(1 for r in results if r.passed)
failed = total - passed
by_category = aggregate_by_category(results)
duration = round(sum(r.duration_seconds for r in results), 2)
lines = [
"# Full Validation Suite Summary",
"",
f"- Timestamp (UTC): {datetime.now(timezone.utc).isoformat()}",
f"- Total checks: {total}",
f"- Passed: {passed}",
f"- Failed: {failed}",
f"- Total suite duration (s): {duration}",
"",
"## Trend vs Previous Run",
"",
]
if previous is None:
lines.append("- No previous history record available.")
else:
prev_passed = int(previous.get("passed", 0))
prev_failed = int(previous.get("failed", 0))
prev_duration = float(previous.get("duration_seconds", 0.0))
lines.append(f"- Passed delta: {passed - prev_passed:+d}")
lines.append(f"- Failed delta: {failed - prev_failed:+d}")
lines.append(f"- Duration delta (s): {round(duration - prev_duration, 2):+}")
lines.extend(
[
"",
"## By Category",
"",
]
)
for category in sorted(by_category.keys()):
stats = by_category[category]
lines.append(
f"- {category}: {stats['passed']} passed / {stats['failed']} failed"
)
lines.extend(
[
"",
"## Detailed Results",
"",
"| Check | Category | Status | Exit | Duration (s) | Log |",
"|------|----------|--------|------|--------------|-----|",
]
)
for row in results:
status = "PASS" if row.passed else "FAIL"
lines.append(
f"| {row.name} | {row.category} | {status} | {row.return_code} | {row.duration_seconds} | {row.output_file} |"
)
lines.extend(
[
"",
"## Immediate Gaps To Close",
"",
"1. Fix any failed checks shown above and re-run this suite.",
"2. Keep live HTTP E2E, fuzz, and performance budgets required in CI.",
"3. Track history.jsonl trends and investigate pass-rate or duration regressions.",
"4. Add chaos/soak runs on schedule for long-horizon reliability.",
]
)
return "\n".join(lines) + "\n"
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Run consolidated validation checks")
parser.add_argument(
"--profile",
choices=sorted(CHECKS_BY_PROFILE.keys()),
default=os.getenv("VALIDATION_PROFILE", "fast"),
help="Suite profile to run (default: fast)",
)
return parser.parse_args()
def main() -> int:
args = parse_args()
checks = CHECKS_BY_PROFILE[args.profile]
results: List[CheckResult] = []
for check in checks:
results.append(
run_check(
name=check["name"],
category=check["category"],
command=check["command"],
timeout=check["timeout"],
)
)
categories = aggregate_by_category(results)
payload = {
"timestamp_utc": datetime.now(timezone.utc).isoformat(),
"profile": args.profile,
"results": [asdict(r) for r in results],
"categories": categories,
"summary": {
"total": len(results),
"passed": sum(1 for r in results if r.passed),
"failed": sum(1 for r in results if not r.passed),
},
}
previous = load_last_history_record()
JSON_OUT.parent.mkdir(parents=True, exist_ok=True)
JSON_OUT.write_text(json.dumps(payload, indent=2), encoding="utf-8")
MD_OUT.write_text(build_markdown(results, previous), encoding="utf-8")
append_history_record(payload)
print(f"JSON summary: {JSON_OUT.relative_to(REPO_ROOT)}")
print(f"Markdown summary: {MD_OUT.relative_to(REPO_ROOT)}")
print(f"History file: {HISTORY_FILE.relative_to(REPO_ROOT)}")
return 0 if payload["summary"]["failed"] == 0 else 1
if __name__ == "__main__":
raise SystemExit(main())