74 lines
3.6 KiB
Python
74 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
|
"""Repeatable native CLI fault matrix; all injected services are localhost fixtures.
|
|
|
|
No production credentials or cloud deployment. Each run keeps its own short
|
|
temporary state/source directory. Do not interpret these results as real BOS,
|
|
system boot, signed installer or production-capacity acceptance.
|
|
"""
|
|
import argparse
|
|
import ast
|
|
import datetime
|
|
import json
|
|
import pathlib
|
|
import os
|
|
import signal
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
|
|
ROOT = pathlib.Path(__file__).resolve().parents[1]
|
|
HARNESS = ROOT / 'scripts/drosync-local-daily-acceptance.py'
|
|
tree = ast.parse(HARNESS.read_text())
|
|
SCENARIOS = next(ast.literal_eval(node.value) for node in tree.body
|
|
if isinstance(node, ast.Assign)
|
|
and any(isinstance(t, ast.Name) and t.id == 'SCENARIOS' for t in node.targets))
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument('--scenario', action='append', choices=SCENARIOS,
|
|
help='Repeat to select cases; default is the complete matrix')
|
|
parser.add_argument('--repeat', type=int, default=1)
|
|
parser.add_argument('--output', type=pathlib.Path)
|
|
args = parser.parse_args()
|
|
if not 1 <= args.repeat <= 20:
|
|
parser.error('--repeat must be in 1..20')
|
|
stamp = datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%SZ')
|
|
out = args.output or ROOT / '.codex-artifacts' / ('local-matrix-' + stamp)
|
|
out.mkdir(parents=True, exist_ok=True)
|
|
rows = []
|
|
for repetition in range(args.repeat):
|
|
for case in args.scenario or SCENARIOS:
|
|
started = time.monotonic()
|
|
try:
|
|
process = subprocess.Popen([sys.executable, str(HARNESS), '--scenario', case],
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
|
text=True, start_new_session=True)
|
|
stdout, stderr = process.communicate(timeout=240)
|
|
result = subprocess.CompletedProcess(process.args, process.returncode, stdout, stderr)
|
|
log = stdout + stderr
|
|
row = {'scenario': case, 'repetition': repetition + 1,
|
|
'status': 'PASS' if result.returncode == 0 else 'FAIL',
|
|
'exitCode': result.returncode}
|
|
if result.returncode == 0:
|
|
payload = json.JSONDecoder().raw_decode(result.stdout[result.stdout.index('{'):])[0]
|
|
row['evidence'] = payload['output']
|
|
except subprocess.TimeoutExpired:
|
|
os.killpg(process.pid, signal.SIGTERM)
|
|
try:
|
|
stdout, stderr = process.communicate(timeout=15)
|
|
except subprocess.TimeoutExpired:
|
|
os.killpg(process.pid, signal.SIGKILL)
|
|
stdout, stderr = process.communicate()
|
|
log = 'Harness exceeded 240 seconds; its dedicated process group was stopped.\n' + stdout + stderr
|
|
row = {'scenario': case, 'repetition': repetition + 1, 'status': 'TIMEOUT'}
|
|
row['seconds'] = round(time.monotonic() - started, 3)
|
|
(out / f'{case}-{repetition + 1}.txt').write_text(log)
|
|
rows.append(row)
|
|
(out / 'matrix.json').write_text(json.dumps(rows, ensure_ascii=False, indent=2) + '\n')
|
|
print(json.dumps(row, ensure_ascii=False), flush=True)
|
|
summary = {'status': 'PASS' if all(r['status'] == 'PASS' for r in rows) else 'FAIL',
|
|
'scope': 'native local CLI/daemon/Web and synthetic HTTP fixtures',
|
|
'cases': len(rows), 'passed': sum(r['status'] == 'PASS' for r in rows),
|
|
'evidence': str(out)}
|
|
(out / 'summary.json').write_text(json.dumps(summary, indent=2) + '\n')
|
|
print(json.dumps(summary), flush=True)
|
|
sys.exit(0 if summary['status'] == 'PASS' else 1)
|