85 lines
3.7 KiB
Python
85 lines
3.7 KiB
Python
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: MIT
|
|
"""Summarize research separately from current-run release conformance."""
|
|
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
import re
|
|
|
|
|
|
LEVELS = {"catalogued", "protocol_decoded"}
|
|
DIGEST = re.compile(r"[0-9a-f]{64}\Z")
|
|
|
|
|
|
def summarize(matrix: dict, research: dict) -> dict:
|
|
if matrix.get("schema") != 1 or research.get("schema") != 1:
|
|
raise ValueError("unsupported evidence schema")
|
|
boards = matrix["boards"]
|
|
chips = matrix["chips"]
|
|
vendors = matrix["vendors"]
|
|
expected = {(board, chip) for board in boards for chip in chips
|
|
if vendors[board] == vendors[chip]}
|
|
rows = matrix["targets"]
|
|
actual = [(row["board"], row["chip"]) for row in rows]
|
|
if set(actual) != expected or len(actual) != len(expected) or len(actual) != 64:
|
|
raise ValueError("release target matrix is incomplete or duplicated")
|
|
levels = {"catalogued": set(), "protocol_decoded": set()}
|
|
for claim in research["claims"]:
|
|
cell = claim["board"], claim["chip"]
|
|
level = claim["level"]
|
|
if cell not in expected or level not in LEVELS:
|
|
raise ValueError("research claim is outside target matrix or level")
|
|
if not isinstance(claim.get("scope"), str) or not claim["scope"].strip():
|
|
raise ValueError("research claim lacks scope")
|
|
if not isinstance(claim.get("source"), str) or not claim["source"].strip():
|
|
raise ValueError("research claim lacks provenance")
|
|
if not isinstance(claim.get("sha256"), str) or not DIGEST.fullmatch(claim["sha256"]):
|
|
raise ValueError("research claim lacks a source digest")
|
|
levels[level].add(cell)
|
|
declared = {
|
|
"stock_result": sum(row.get("stock_result") in {"mines", "rejects"} for row in rows),
|
|
"alkane_share_capture": sum(bool(row.get("alkane_share_accept_capture")) for row in rows),
|
|
"bench_validation": sum(bool(row.get("bench_validation")) for row in rows),
|
|
}
|
|
evidence_levels = {
|
|
"catalogued": {"research_claims": len(levels["catalogued"])},
|
|
"protocol_decoded": {"research_claims": len(levels["protocol_decoded"])},
|
|
"stock_simulator_boot": {"manifest_claims_unverified": declared["stock_result"],
|
|
"current_run_verified": None},
|
|
"captured_nonce_pool_accept": {
|
|
"manifest_claims_unverified": declared["alkane_share_capture"],
|
|
"current_run_verified": None},
|
|
"physical_install_update_uninstall_recovery": {
|
|
"manifest_claims_unverified": declared["bench_validation"],
|
|
"current_run_verified": None},
|
|
"full_release_cell": {"current_run_verified": None},
|
|
}
|
|
return {
|
|
"schema": 1,
|
|
"target_cells": len(expected),
|
|
"research_only": {key: len(value) for key, value in levels.items()},
|
|
"evidence_levels": evidence_levels,
|
|
"release_manifest_declarations_unverified": declared,
|
|
"verified_release_cells": None,
|
|
"note": "Only check-conformance.py may verify current-run artifacts; research claims never satisfy a release cell",
|
|
}
|
|
|
|
|
|
def main() -> None:
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--matrix", type=Path, default=Path("ci/conformance.json"))
|
|
parser.add_argument("--research", type=Path, default=Path("ci/research-evidence.json"))
|
|
parser.add_argument("--output", type=Path)
|
|
args = parser.parse_args()
|
|
report = summarize(json.loads(args.matrix.read_text()), json.loads(args.research.read_text()))
|
|
output = json.dumps(report, indent=2, sort_keys=True) + "\n"
|
|
if args.output:
|
|
args.output.write_text(output)
|
|
else:
|
|
print(output, end="")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|