From 7d0285f46d06391e017d478d76a69ef15fa4301f Mon Sep 17 00:00:00 2001 From: DeFiDude <59237470+DeFiDude@users.noreply.github.com> Date: Mon, 17 Aug 2026 12:36:12 -0600 Subject: [PATCH] api: bind snapshots to reviewed source --- api-reviews/wave-c-message-api.json | 1 + api-stability.json | 2 +- tools/check-api-baseline.py | 55 +++++++++++++++++++++++++---- tools/check-api-compatibility.py | 13 +++++++ 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/api-reviews/wave-c-message-api.json b/api-reviews/wave-c-message-api.json index 0d0a1ae..bccd9de 100644 --- a/api-reviews/wave-c-message-api.json +++ b/api-reviews/wave-c-message-api.json @@ -1,5 +1,6 @@ { "schemaVersion": 1, + "snapshotSourceCommit": "c934ccc5feaaddb55461404094ed6bb514aae2cc", "capabilities": ["LXMF-01"], "canonicalPath": "lxmf_core::message_api", "retainedPaths": [ diff --git a/api-stability.json b/api-stability.json index f9095b6..854a81d 100644 --- a/api-stability.json +++ b/api-stability.json @@ -19,7 +19,7 @@ "sourceCommit": "b8d7afce73f7f098706029361568e63f22888ea3" }, "snapshotSource": { - "basisCommit": "a8f74d2aed815d5508f40e3732e473b126f06aa8", + "commit": "c934ccc5feaaddb55461404094ed6bb514aae2cc", "capturedOn": "2026-08-17", "changeRecord": "api-reviews/wave-c-message-api.json" }, diff --git a/tools/check-api-baseline.py b/tools/check-api-baseline.py index 37f1c64..6ebf974 100644 --- a/tools/check-api-baseline.py +++ b/tools/check-api-baseline.py @@ -4,6 +4,7 @@ from __future__ import annotations import argparse +from datetime import date import hashlib import json import os @@ -59,6 +60,34 @@ def load_config() -> dict[str, object]: return config +def validate_change_record(path: str, snapshot_commit: str) -> None: + record_path = ROOT / path + try: + record = json.loads(record_path.read_text(encoding="utf-8")) + except (OSError, json.JSONDecodeError) as error: + fail(f"cannot read snapshot change record {path}: {error}") + required = { + "schemaVersion", "snapshotSourceCommit", "capabilities", "classification", + "publicApiDiff", "semver", "deprecations", "platformEvidence", + } + if not required.issubset(record) or record.get("schemaVersion") != 1: + fail("snapshot change record is incomplete") + if record.get("snapshotSourceCommit") != snapshot_commit: + fail("snapshot change record does not match the snapshot source commit") + if not isinstance(record.get("capabilities"), list) or not record["capabilities"]: + fail("snapshot change record must name capability IDs") + diff = record.get("publicApiDiff") + if not isinstance(diff, dict) or set(diff) != {"added", "removed"}: + fail("snapshot change record must classify added and removed API lines") + if not all(isinstance(diff[key], int) and diff[key] >= 0 for key in diff): + fail("snapshot change record API counts must be non-negative integers") + if not isinstance(record.get("platformEvidence"), list) or not record["platformEvidence"]: + fail("snapshot change record must name platform evidence") + for key in ("classification", "semver", "deprecations"): + if not isinstance(record.get(key), str) or not record[key]: + fail(f"snapshot change record must name {key}") + + def public_packages(manifest_path: str) -> set[str]: metadata = json.loads( run( @@ -139,26 +168,25 @@ def validate_metadata( snapshot_source = config.get("snapshotSource") if not isinstance(snapshot_source, dict): fail("snapshot source identity is missing") - snapshot_commit = snapshot_source.get("basisCommit") + snapshot_commit = snapshot_source.get("commit") if not isinstance(snapshot_commit, str) or not SHA_PATTERN.fullmatch( snapshot_commit ): - fail("snapshot source basis commit must be a full Git commit") + fail("snapshot source commit must be a full Git commit") snapshot_check = subprocess.run( ["git", "cat-file", "-e", f"{snapshot_commit}^{{commit}}"], cwd=ROOT ) if snapshot_check.returncode != 0: - fail(f"snapshot source basis commit {snapshot_commit} is unavailable") + fail(f"snapshot source commit {snapshot_commit} is unavailable") snapshot_ancestor = subprocess.run( ["git", "merge-base", "--is-ancestor", snapshot_commit, "HEAD"], cwd=ROOT ) if snapshot_ancestor.returncode != 0: - fail(f"snapshot source basis commit {snapshot_commit} is not an ancestor of HEAD") + fail(f"snapshot source commit {snapshot_commit} is not an ancestor of HEAD") change_record = snapshot_source.get("changeRecord") if not isinstance(change_record, str) or not change_record.startswith("api-reviews/"): fail("snapshot source must name a reviewed change record") - if not (ROOT / change_record).is_file(): - fail(f"snapshot source change record is missing: {change_record}") + validate_change_record(change_record, snapshot_commit) packages = config.get("packages") if not isinstance(packages, list) or not packages: @@ -263,11 +291,26 @@ def main() -> None: parser = argparse.ArgumentParser() parser.add_argument("--metadata-only", action="store_true") parser.add_argument("--update", action="store_true") + parser.add_argument("--snapshot-source-commit") + parser.add_argument("--change-record") args = parser.parse_args() if args.metadata_only and args.update: fail("--metadata-only and --update are mutually exclusive") config = load_config() + if args.update: + if not args.snapshot_source_commit or not args.change_record: + fail("--update requires --snapshot-source-commit and --change-record") + head = run(["git", "rev-parse", "HEAD"]).strip() + if args.snapshot_source_commit != head: + fail("snapshot source must be the clean source commit at HEAD") + if not args.change_record.startswith("api-reviews/"): + fail("change record must be stored below api-reviews/") + config["snapshotSource"] = { + "commit": args.snapshot_source_commit, + "capturedOn": date.today().isoformat(), + "changeRecord": args.change_record, + } packages = validate_metadata(config, updating=args.update) if args.metadata_only: print("api baseline metadata: ok") diff --git a/tools/check-api-compatibility.py b/tools/check-api-compatibility.py index 1f91ba7..946a7d4 100644 --- a/tools/check-api-compatibility.py +++ b/tools/check-api-compatibility.py @@ -33,6 +33,11 @@ def git_show(commit: str, path: str) -> str: def main() -> None: + metadata = subprocess.run( + [sys.executable, "tools/check-api-baseline.py", "--metadata-only"], cwd=ROOT + ) + if metadata.returncode != 0: + fail("snapshot metadata or reviewed change record is invalid") ledger = json.loads(LEDGER_PATH.read_text(encoding="utf-8")) floor = ledger.get("compatibilityFloor", {}).get("evidenceCommit") if not isinstance(floor, str): @@ -56,6 +61,14 @@ def main() -> None: f"{total_removed} public API lines were removed from the Wave C floor; " "the current policy permits additions only" ) + change_record = json.loads( + (ROOT / ledger["snapshotSource"]["changeRecord"]).read_text(encoding="utf-8") + ) + if change_record["publicApiDiff"] != { + "added": total_added, + "removed": total_removed, + }: + fail("reviewed change record does not match the measured API diff") print(f"api compatibility: additive-only (+{total_added}, -0)")