diff --git a/README.md b/README.md index 19b893c..39a3fd2 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,9 @@ python3 ci/check-conformance.py ``` The last command currently fails because simulator and device evidence are -still pending. It is a release gate, not a unit test. +still pending. It cross-checks the evidence matrix against the built binary's +targets and validates artifact digest fields. It is a release gate, not a +unit test. The badges record measured host-side checks for this initial core. They do not imply that any board image or mining target has passed conformance. diff --git a/ci/check-conformance.py b/ci/check-conformance.py index 33798fa..16b5e5a 100644 --- a/ci/check-conformance.py +++ b/ci/check-conformance.py @@ -1,33 +1,116 @@ #!/usr/bin/env python3 -"""Fail the final release gate until every target has traceable evidence.""" +"""Require the binary target matrix and traceable per-cell release evidence.""" +import argparse import json +import os import pathlib +import re +import subprocess import sys -manifest = json.loads(pathlib.Path("ci/conformance.json").read_text()) -rows = manifest["targets"] -expected = {(board, chip) for board in manifest["boards"] for chip in manifest["chips"] - if manifest["vendors"][board] == manifest["vendors"][chip]} -actual = {(row["board"], row["chip"]) for row in rows} -if actual != expected or len(rows) != len(expected): - sys.exit(f"matrix mismatch: {len(actual)} present, {len(expected)} expected") -required = ("sdk_image_sha256", "stock_image_sha256", "stock_result", - "alkane_share_accept_capture", "simulator_trace_sha256", - "bench_validation") -incomplete = [] -for row in rows: - missing = [field for field in required if not row.get(field)] - if row.get("stock_result") not in (None, "mines", "rejects"): - missing.append("stock_result invalid") - if row.get("stock_result") == "rejects" and not row.get("stock_first_rejection"): - missing.append("stock_first_rejection") - if missing: - incomplete.append((row["board"], row["chip"], missing)) -if incomplete: - print(f"Conformance pending: {len(incomplete)}/{len(rows)} targets") - for board, chip, missing in incomplete[:8]: - print(f" {board} x {chip}: {', '.join(missing)}") - sys.exit(1) -print(f"Conformance complete: {len(rows)} targets") +REQUIRED_BOARDS = { + "am335x-bb": "bitmain", + "zynq-7010": "bitmain", + "cv1835": "bitmain", + "a113d": "bitmain", + "allwinner-h3": "whatsminer", + "allwinner-h6": "whatsminer", + "allwinner-h616": "whatsminer", +} +REQUIRED_CHIPS = { + **{chip: "bitmain" for chip in ( + "BM1384", "BM1387", "BM1360", "BM1362", "BM1366", "BM1368", + "BM1370", "BM1396", "BM1397", "BM1398", "BM1489", "BM1491", "BM1746", + )}, + **{chip: "whatsminer" for chip in ( + "KF1950", "ID-1968", "ID-1980", "ID-1990", + )}, +} +DIGEST = re.compile(r"[0-9a-f]{64}\Z") + + +def binary_targets(path: pathlib.Path) -> set[tuple[str, str]]: + output = subprocess.run( + [str(path), "--list-targets"], + check=True, capture_output=True, text=True, timeout=15, + ).stdout.splitlines() + if not output or output[0] != "control_board,hash_chip,algorithm": + raise ValueError("Alkane OS binary has no target matrix header") + targets = [] + for line in output[1:]: + parts = line.split(",") + if len(parts) != 3 or not all(parts): + raise ValueError(f"invalid binary target row: {line!r}") + targets.append((parts[0], parts[1])) + if len(targets) != len(set(targets)): + raise ValueError("duplicate binary target") + return set(targets) + + +def validate(manifest: dict, built_targets: set[tuple[str, str]]) -> list[str]: + errors = [] + if manifest.get("schema") != 1: + errors.append("unsupported conformance manifest schema") + boards = set(manifest["boards"]) + chips = set(manifest["chips"]) + vendors = manifest["vendors"] + if len(boards) != len(manifest["boards"]) or len(chips) != len(manifest["chips"]): + errors.append("duplicate board or chip in manifest") + for name, vendor in {**REQUIRED_BOARDS, **REQUIRED_CHIPS}.items(): + if name not in boards | chips or vendors.get(name) != vendor: + errors.append(f"required target identity changed: {name}") + if set(vendors) != boards | chips: + errors.append("vendor map differs from board and chip lists") + expected = {(board, chip) for board in boards for chip in chips + if vendors.get(board) == vendors.get(chip)} + rows = manifest["targets"] + actual = {(row["board"], row["chip"]) for row in rows} + if len(expected) < 64 or actual != expected or len(rows) != len(expected): + errors.append(f"manifest matrix mismatch: {len(actual)} present, {len(expected)} expected") + if built_targets != expected: + errors.append(f"binary matrix mismatch: {len(built_targets)} built, {len(expected)} expected") + required = ("sdk_image_sha256", "stock_image_sha256", "stock_result", + "alkane_share_accept_capture", "simulator_trace_sha256", + "bench_validation") + for row in rows: + cell = f"{row['board']} x {row['chip']}" + missing = [field for field in required if not row.get(field)] + if row.get("stock_result") not in (None, "mines", "rejects"): + missing.append("stock_result invalid") + if row.get("stock_result") == "rejects" and not row.get("stock_first_rejection"): + missing.append("stock_first_rejection") + for field in ("sdk_image_sha256", "stock_image_sha256", "simulator_trace_sha256"): + value = row.get(field) + if value and (not isinstance(value, str) or not DIGEST.fullmatch(value)): + missing.append(f"{field} invalid") + if missing: + errors.append(f"{cell}: {', '.join(missing)}") + return errors + + +def main() -> None: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--manifest", type=pathlib.Path, + default=pathlib.Path("ci/conformance.json")) + parser.add_argument("--binary", type=pathlib.Path, + default=pathlib.Path(os.environ.get("CARGO_TARGET_DIR", "target")) + / "release/alkane-os") + args = parser.parse_args() + manifest = json.loads(args.manifest.read_text()) + try: + built_targets = binary_targets(args.binary.resolve()) + except (OSError, subprocess.SubprocessError, ValueError) as error: + sys.exit(f"cannot verify Alkane OS binary target matrix: {error}") + errors = validate(manifest, built_targets) + if errors: + print(f"Conformance pending: {len(errors)} issues across {len(manifest['targets'])} targets") + for error in errors[:8]: + print(f" {error}") + sys.exit(1) + print(f"Conformance complete: {len(manifest['targets'])} targets") + + +if __name__ == "__main__": + main()