mirror of
https://github.com/gadgethd/ukmesh.git
synced 2026-12-06 19:24:41 +00:00
219 lines
14 KiB
Python
219 lines
14 KiB
Python
"""Qualification closure requires actual, complete evidence from every phase."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from common import digest, read_json, safe_error, utc_now, write_json
|
|
from context import phase_context
|
|
|
|
|
|
REQUIRED = ("backups", "inventory", "work-smoke", "access", "reads", "parity",
|
|
"other-operations", "resources", "soak", "steady-runtime-logs", "companion-commits", "core-projection", "recovery", "interfaces", "tests")
|
|
ACCEPTANCE_PROFILES = ("full-stack", "mqtt-first", "production")
|
|
|
|
|
|
def production_public_sockets_pass(receipts: object) -> bool:
|
|
if not isinstance(receipts, list) or len(receipts) != 2:
|
|
return False
|
|
if not all(isinstance(row, dict) for row in receipts):
|
|
return False
|
|
if sorted(str(row.get('format')) for row in receipts) != ['columns-v1', 'legacy']:
|
|
return False
|
|
return all(row.get('received') == 72000 and row.get('snapshots') == 2
|
|
and row.get('auxiliaryExpected') == 160 and row.get('auxiliaryReceived') == 160
|
|
and row.get('interrupted') is True and row.get('passed') is True
|
|
and all(type(row.get(key)) is int and row[key] == 0
|
|
for key in ('missing', 'duplicates', 'auxiliaryDuplicates', 'outOfOrder', 'errors', 'unexpectedCloses'))
|
|
for row in receipts)
|
|
|
|
|
|
def production_reads_pass(value: dict) -> bool:
|
|
from math import ceil, isfinite
|
|
routes = ('map', 'search', 'missing-search', 'observer-map', 'history', 'packet', 'feed', 'links')
|
|
demand = value.get('readDemand', {})
|
|
if demand != {'scheduled': 3840, 'attempted': 3840, 'completed': 3840}:
|
|
return False
|
|
rows = value.get('reads', [])
|
|
if len(rows) != demand['scheduled'] or value.get('readLatency', {}).get('budgetMs') != 1000:
|
|
return False
|
|
slots = set()
|
|
times = {name: [] for name in routes}
|
|
for row in rows:
|
|
burst, slot, name = row.get('burstOrdinal'), row.get('slot'), row.get('name')
|
|
elapsed = row.get('ms')
|
|
if type(burst) is not int or not 1 <= burst <= 480 or type(slot) is not int or not 0 <= slot < 8:
|
|
return False
|
|
expected = 'background-charts' if slot == 7 and burst % 12 == 0 else routes[slot]
|
|
if name != expected or (burst, slot) in slots or row.get('status') != 200 or row.get('failureKind') is not None:
|
|
return False
|
|
if type(elapsed) not in (float, int) or not isfinite(elapsed) or elapsed < 0:
|
|
return False
|
|
slots.add((burst, slot))
|
|
if name in times:
|
|
times[name].append(elapsed)
|
|
return all(values and sorted(values)[ceil(.95 * len(values)) - 1] <= 1000 for values in times.values())
|
|
|
|
|
|
def phase_check(name: str, value: dict, *, acceptance_profile: str = "full-stack") -> tuple[bool, str | None]:
|
|
if acceptance_profile not in ACCEPTANCE_PROFILES:
|
|
raise ValueError("unknown qualification acceptance profile")
|
|
if value.get("passed") is not True:
|
|
return False, "phase failed or has no explicit successful result"
|
|
if name == "resources" and (value.get("duration_seconds", 0) < 2400 * .98
|
|
or value.get("warmup_seconds", 121) > 120):
|
|
return False, "full 40-minute resource window with at most 120s warmup is required"
|
|
if name == "soak":
|
|
settings = value.get("settings", {})
|
|
if settings.get("count") != 72000 or settings.get("rate") != 30 or settings.get("httpConcurrency") != 8:
|
|
return False, "full 72,000-packet, 30/s, C8 soak evidence is required"
|
|
if not value.get("drained") or value.get("wsPackets") != 72000:
|
|
return False, "durable drain and complete live delivery were not proved"
|
|
if value.get('logs_passed') is not True:
|
|
return False,'resident application logs contain failures or were not checked'
|
|
readiness=value.get('socketReadiness',{})
|
|
if readiness.get('initialState') is not True or readiness.get('unexpectedCloses')!=0:
|
|
return False,'authorized live subscription readiness and continuity were not proved'
|
|
cold=value.get('warmupReads',[])
|
|
if settings.get('httpWarmup') is not True or len(cold)!=8 or any(row.get('status')!=200 for row in cold):
|
|
return False,'explicit C8 route warmup with retained successful cold responses is required'
|
|
latency = value.get('readLatency', {})
|
|
if latency.get('advisory') is not (acceptance_profile == 'mqtt-first') \
|
|
or type(latency.get('passed')) is not bool:
|
|
return False, 'mixed-read acceptance mode does not match the requested profile'
|
|
if acceptance_profile != 'mqtt-first' and latency['passed'] is not True:
|
|
return False, 'mixed-read latency failed'
|
|
if acceptance_profile == 'production' and (
|
|
value.get('wsOutOfOrder') != 0 or value.get('wsDuplicates') != 0 or value.get('wsErrors') != 0
|
|
or not 0 <= value.get('drainElapsedMs', -1) <= 120000):
|
|
return False, 'ordered public delivery within the drain deadline is required'
|
|
if acceptance_profile == 'production' and not production_public_sockets_pass(value.get('publicSocketReceipts')):
|
|
return False, 'both unfiltered WebSocket formats must resume and deliver the complete ordered stream'
|
|
if acceptance_profile == 'production' and not production_reads_pass(value):
|
|
return False, 'production read demand, errors or per-route p95 failed'
|
|
if value.get('acceptance_profile') != acceptance_profile:
|
|
return False, 'soak receipt used another acceptance profile'
|
|
if name == "reads":
|
|
from read_protocol import IDENTITY, STEPS
|
|
native_only = acceptance_profile in ('mqtt-first', 'production')
|
|
demand_count = 0 if native_only else len(STEPS)*2
|
|
if value.get('diagnostic_only') is not False or value.get('protocol') != IDENTITY \
|
|
or value.get("missing") or len(value.get("runs", [])) != len(STEPS)*2 \
|
|
or value.get('native_only', False) is not native_only \
|
|
or len(value.get('demand_runs', [])) != demand_count \
|
|
or len(value.get('batches', [])) != 2 or any(item.get('passed') is not True for item in value.get('batches', [])):
|
|
return False, "three complete canonical matched read pairs at both scales are required"
|
|
if name == "access":
|
|
checks = value.get("checks", [])
|
|
if len(checks) < 20 or not all(check.get("passed") is True for check in checks):
|
|
return False, "authenticated permission matrix is incomplete"
|
|
if name == "backups" and (len(value.get("stores", [])) != 4 or not all(
|
|
store.get("verified") is True for store in value.get("stores", []))):
|
|
return False, "four verified original stores are required"
|
|
if name in ("inventory", "work-smoke"):
|
|
records = value.get("services", [])
|
|
if not records or not all(row.get("passed") is True for row in records if row.get("required", True)):
|
|
return False, "required service proofs are incomplete"
|
|
if name in ("other-operations", "parity", "companion-commits", "core-projection", "steady-runtime-logs", "recovery", "interfaces", "tests"):
|
|
checks = value.get("checks", [])
|
|
if not checks or not all(row.get("passed") is True and not row.get("skipped") for row in checks):
|
|
return False, "required checks are missing, skipped or failed"
|
|
if name == "companion-commits" and value.get("count") != 72000:
|
|
return False, "complete companion commit evidence for 72,000 ACKs is required"
|
|
if name=='recovery':
|
|
from recovery import REQUIRED_CHECKS
|
|
if not REQUIRED_CHECKS.issubset({row.get('name') for row in value.get('checks',[])}):
|
|
return False,'concrete required recovery faults or native persistence proofs are missing'
|
|
return True, None
|
|
|
|
|
|
def report(run: Path, *, acceptance_profile: str = "full-stack") -> dict:
|
|
if acceptance_profile not in ACCEPTANCE_PROFILES:
|
|
raise ValueError("unknown qualification acceptance profile")
|
|
native_only = acceptance_profile in ('mqtt-first', 'production')
|
|
if (run / "corescope-public-pg.json").exists() and (run / "corescope-public-ram.json").exists():
|
|
try:
|
|
from core_projection import core_projection
|
|
core_projection(run)
|
|
except Exception as error:
|
|
write_json(run / "core-projection.json", {"passed": False, "error": safe_error(error)})
|
|
phases = []
|
|
advisory_evidence = []
|
|
try:
|
|
current = phase_context(run)
|
|
except Exception:
|
|
current = None
|
|
contexts = {}
|
|
for name in REQUIRED:
|
|
path = run / (("reads-native" if name == 'reads' and native_only else name) + ".json")
|
|
try:
|
|
value = read_json(path)
|
|
passed, error = phase_check(name, value, acceptance_profile=acceptance_profile)
|
|
if name == 'soak' and acceptance_profile == 'mqtt-first':
|
|
advisory_evidence.append({'name': 'mixed-read-latency', 'path': str(path),
|
|
'result': value.get('readLatency'), 'sha256': digest(path)})
|
|
context = value.get("context")
|
|
if name != "backups":
|
|
contexts[name] = context
|
|
if not current or not context or context.get("run_id") != run.name:
|
|
passed, error = False, "phase is not bound to this evidence run"
|
|
elif context.get("profile_sha256") != current["profile_sha256"]:
|
|
passed, error = False, "phase used another runtime profile"
|
|
elif any(context.get("source", {}).get(key) != current["source"][key]
|
|
for key in ("root_content_sha256", "submodules_sha256")):
|
|
passed, error = False, "source changed since this phase"
|
|
if name in ("reads", "other-operations"):
|
|
if name=='reads':
|
|
from source_identity import expected_sources,validate_measurements
|
|
validate_measurements(value.get('runs',[]),expected_sources())
|
|
validate_measurements(value.get('demand_runs',[]),expected_sources())
|
|
from read_measurements import native_read_comparison, read_comparison, validate_read_batches
|
|
validate_read_batches(value, native_only=native_only)
|
|
comparison = (native_read_comparison(value.get('runs', [])) if native_only else
|
|
read_comparison(value.get('runs', []), demand_runs=value.get('demand_runs', [])))
|
|
if not comparison['passed']:
|
|
passed,error=False,'read source, raw companion evidence or regression comparison failed'
|
|
else:
|
|
from source_identity import expected_sources
|
|
from operations import validate_operations,comparison
|
|
expected=expected_sources()
|
|
validate_operations(value.get('runs',[]),expected)
|
|
if not comparison(value.get('runs',[]),expected)['passed']:
|
|
passed,error=False,'statistics/export source, data or regression comparison failed'
|
|
for measurement in value.get("runs", []):
|
|
if measurement.get("context", {}).get("run_id") != run.name or any(
|
|
measurement.get("context", {}).get(key) != context.get(key)
|
|
for key in ("profile_sha256", "source")):
|
|
passed, error = False, "matched read measurements used different source or runtime profiles"
|
|
for scale in ("1x", "10x"):
|
|
tokens = {row.get("fixture_token") for row in value.get("runs", []) if row.get("scale") == scale}
|
|
if len(tokens) != 1 or None in tokens:
|
|
passed, error = False, "matched read measurements used different fixtures"
|
|
phases.append({"phase": name, "passed": passed, "error": error, "path": str(path), "sha256": digest(path)})
|
|
except Exception as error:
|
|
phases.append({"phase": name, "passed": False, "error": safe_error(error)})
|
|
soak_targets = (contexts.get("soak") or {}).get("targets")
|
|
for row in phases:
|
|
if row["phase"] in ("resources", "access", "work-smoke") and row["passed"]:
|
|
if not soak_targets or (contexts.get(row["phase"]) or {}).get("targets") != soak_targets:
|
|
row.update({"passed": False, "error": "phase did not use the qualified soak fixture"})
|
|
if native_only:
|
|
demand_path = run / 'reads.json'
|
|
advisory_evidence.append({'name': 'fixed-demand-80rps', 'path': str(demand_path),
|
|
'available': demand_path.is_file(),
|
|
**({'sha256': digest(demand_path)} if demand_path.is_file() else {})})
|
|
result = {"at": utc_now(), "acceptance_profile": acceptance_profile,
|
|
"advisory": (['fixed-demand-80rps'] if acceptance_profile == 'production' else ['fixed-demand-80rps', 'mixed-read-latency']) if native_only else [],
|
|
'advisory_evidence': advisory_evidence,
|
|
"passed": all(row["passed"] for row in phases), "phases": phases,
|
|
"failed_phases": [row["phase"] for row in phases if not row["passed"]]}
|
|
report_name = 'report-' + acceptance_profile if native_only else 'report'
|
|
write_json(run / (report_name + '.json'), result)
|
|
lines = ["# " + acceptance_profile.capitalize() + " qualification", "", "Acceptance profile: " + acceptance_profile,
|
|
"Passed: " + str(result["passed"]), "",
|
|
"| Phase | Result |", "| --- | --- |"]
|
|
lines.extend(f"| {row['phase']} | {'PASS' if row['passed'] else 'FAIL'} |" for row in phases)
|
|
(run / (report_name + '.md')).write_text("\n".join(lines) + "\n")
|
|
(run / (report_name + '.md')).chmod(0o600)
|
|
return result
|