diff --git a/api/README.md b/api/README.md index ca88fca..e4bb458 100644 --- a/api/README.md +++ b/api/README.md @@ -154,8 +154,8 @@ treated as stable merely because they are publicly reachable. The `api/` directory contains the evidence used by CI: -- `stability.json` records package tiers, source commits, snapshot hashes, and - the current review decision; +- `stability.json` records package tiers, compatibility baselines, and snapshot + hashes; - `snapshots/` records the explicit all-feature Apple ARM64 Rust API and the manifest, feature, dependency, target, and MSRV contract; and - `fixtures/` compiles recommended and retained import paths as an external @@ -176,6 +176,7 @@ cargo check --manifest-path api/fixtures/Cargo.toml --locked cargo check --manifest-path api/fixtures/Cargo.toml --all-features --locked ``` -Snapshot updates require a clean source commit and an explicit review recorded -in `api/stability.json`. Additions, removals, deprecations, platform impact, and -version consequences must be reviewed before accepting new evidence. +After reviewing an API change, run +`python3 tools/check-api-baseline.py --update` and commit the source and snapshot +changes together. CI compares snapshots with the current source; compatibility +checks retain the historical baseline. diff --git a/api/stability.json b/api/stability.json index e9a1891..c17f206 100644 --- a/api/stability.json +++ b/api/stability.json @@ -1,5 +1,5 @@ { - "schemaVersion": 1, + "schemaVersion": 2, "tool": { "name": "cargo-public-api", "version": "0.52.0", @@ -11,41 +11,12 @@ ] }, "baseline": { - "commit": "47dbbf1febc0a9d3259f179a0512d9b56bb2320d", - "capturedOn": "2026-08-17" + "commit": "47dbbf1febc0a9d3259f179a0512d9b56bb2320d" }, "compatibilityFloor": { "evidenceCommit": "c9b210a52b139ac9754b46c5c2639c4113e7ae53", "sourceCommit": "47dbbf1febc0a9d3259f179a0512d9b56bb2320d" }, - "snapshotSource": { - "commit": "56c7a6e5d80d66b9e95a63d2780cf23456e06746", - "capturedOn": "2026-09-24", - "review": { - "areas": [ - "RET-09 bounded multi-requester discovery observations and cancellation", - "RET-13 advanced actor control with exact operation/interface registration ownership", - "Retained previously reviewed Link dispatch, failed-attempt recovery and finite protocol-wait additions", - "RET-05/07/10 compatible bind readiness and BLE packet flow control (September 24)" - ], - "canonicalPath": "rns_transport::actor::TransportActor::discovery_path_request", - "classification": "deliberate discovery API break; one private canonical ledger, detached snapshots and generation-specific requester cancellation; other capability paths retained", - "publicApiDiff": { - "added": 155, - "removed": 3 - }, - "semver": "Owner-approved project version 1.3.0 for a breaking API release. Cargo caret compatibility differs; first-party RNS requirements select ~1.3.0. Package tiers unchanged.", - "deprecations": "The actor::DiscoveryPathRequest import is retained, but public fields/Copy and the mutable actor map are removed. Exact approved removals have a public 1.3 migration guide; no blanket compatibility waiver.", - "wirePersistenceRuntimeImpact": "No encoding, signatures, persisted formats, shared RPC, JNI, UI, AutoInterface ports or radio defaults change. Discovery deadlines, bounded coalescing and same-radio/Roaming/IPC response policy remain. Tokens cannot cancel other requesters, replacement channels, later operations or foreign actors. Last-owner retirement immediately removes related unadmitted bytes. Normal runtime lookup and recovery remain unchanged.", - "platformEvidence": [ - "Reviewed generated Apple ARM64 all-feature discovery delta: 32 unique additions, exactly three public field/map removals; cumulative floor diff +154/-3. Historical floor retained. Copy removal additionally protected by a compile-fail consumer.", - "Working-source focused gates: all 510 transport tests including one unrelated retained test passed; five new public-only private consumer tests passed; stable/MSRV transport all-target/all-feature strict lint and external fixtures passed.", - "Ratspeak, rsLXMF and rsLXST host workspace checks passed against 1.3.0; only RNS workspace versions/requirements changed in the manifest contract. Full clean-source, native and live interop receipts belong to the release handoff.", - "Exact final-source remote CI, Nix/source-consumer, signed packages and physical acceptance remain separate step-5-and-later gates. No hardware or fully green NomadNet claim.", - "September 24: one added provisional bind-readiness method, zero new removals; focused BLE/endpoint tests, strict host checks, and iOS/Android target checks pass; physical throughput remains unqualified." - ] - } - }, "packages": [ { "name": "rns-crypto", @@ -148,17 +119,5 @@ "pub rns_transport::actor::TransportActor::discovery_path_requests: std::collections::hash::map::HashMap<[u8; 16], rns_transport::actor::DiscoveryPathRequest>" ] } - }, - "bleThroughputReview": { - "reviewedOn": "2026-09-24", - "capabilities": [ - "RET-05", - "RET-07", - "RET-10" - ], - "classification": "Compatible additive provisional bind-readiness method; existing APIs retained. BLE implementation correction; no version, feature, MSRV, wire, or persistence change.", - "ownership": "Readiness retains the bind result without publishing ownership; cancellation before consumption still retires the unpublished generation.", - "behavior": "Bounded complete-packet Apple native queues preserve FIFO under backpressure, refuse whole new packets on overflow, use negotiated per-operation payload capacity and callback pacing, and isolate receive roles. Android unknown MTU falls back to 20 bytes.", - "validation": "Focused BLE/endpoint tests, encrypted Resource scheduling probes, strict host Clippy, and iOS/Android target checks. Hardware speed, PHY tuning, and role-selection optimizations remain separately qualified." } } diff --git a/tools/check-api-baseline.py b/tools/check-api-baseline.py index 85f6bb4..935a409 100644 --- a/tools/check-api-baseline.py +++ b/tools/check-api-baseline.py @@ -4,7 +4,6 @@ from __future__ import annotations import argparse -from datetime import date import hashlib import json import os @@ -55,46 +54,21 @@ def load_config() -> dict[str, object]: config = json.loads(CONFIG_PATH.read_text(encoding="utf-8")) except (OSError, json.JSONDecodeError) as error: fail(f"cannot read {CONFIG_PATH.name}: {error}") - if config.get("schemaVersion") != 1: + if not isinstance(config, dict) or config.get("schemaVersion") != 2: fail("unsupported api-stability schema") return config -def validate_snapshot_review(record: object) -> None: +def require_keys( + record: object, required: set[str], label: str, + optional: set[str] | None = None, +) -> None: if not isinstance(record, dict): - fail("snapshot review is missing") - required = { - "areas", - "canonicalPath", - "classification", - "publicApiDiff", - "semver", - "deprecations", - "wirePersistenceRuntimeImpact", - "platformEvidence", - } - if not required.issubset(record): - fail("snapshot review is incomplete") - if not isinstance(record.get("areas"), list) or not record["areas"]: - fail("snapshot review must name the affected API areas") - if not all(isinstance(area, str) and area for area in record["areas"]): - fail("snapshot review API areas must be non-empty strings") - diff = record.get("publicApiDiff") - if not isinstance(diff, dict) or set(diff) != {"added", "removed"}: - fail("snapshot review must classify added and removed API lines") - if not all(isinstance(diff[key], int) and diff[key] >= 0 for key in diff): - fail("snapshot review API counts must be non-negative integers") - if not isinstance(record.get("platformEvidence"), list) or not record["platformEvidence"]: - fail("snapshot review must name platform evidence") - for key in ( - "canonicalPath", - "classification", - "semver", - "deprecations", - "wirePersistenceRuntimeImpact", - ): - if not isinstance(record.get(key), str) or not record[key]: - fail(f"snapshot review must name {key}") + fail(f"{label} must be an object") + missing = required - set(record) + unknown = set(record) - required - (optional or set()) + if missing or unknown: + fail(f"{label}: missing fields {sorted(missing)}, unknown fields {sorted(unknown)}") def public_packages(manifest_path: str) -> set[str]: @@ -121,6 +95,25 @@ def public_packages(manifest_path: str) -> set[str]: def validate_metadata( config: dict[str, object], *, updating: bool = False ) -> list[dict[str, object]]: + require_keys( + config, {"schemaVersion", "tool", "baseline", "compatibilityFloor", "packages"}, + "metadata", {"approvedBreakingChanges"}, + ) + if config["schemaVersion"] != 2: + fail("unsupported api-stability schema") + require_keys( + config["tool"], {"name", "version", "rustdocToolchain", "target", "arguments"}, + "tool", + ) + require_keys(config["baseline"], {"commit"}, "baseline") + require_keys( + config["compatibilityFloor"], {"evidenceCommit", "sourceCommit"}, + "compatibility floor", + ) + if "approvedBreakingChanges" in config: + require_keys(config["approvedBreakingChanges"], + {"releaseLine", "migrationGuide", "removed"}, "approved break") + tool = config.get("tool") if not isinstance(tool, dict): fail("tool contract is missing") @@ -174,26 +167,6 @@ def validate_metadata( if floor_ancestor.returncode != 0: fail(f"compatibility floor {label} commit is not an ancestor of HEAD") - snapshot_source = config.get("snapshotSource") - if not isinstance(snapshot_source, dict): - fail("snapshot source identity is missing") - snapshot_commit = snapshot_source.get("commit") - if not isinstance(snapshot_commit, str) or not SHA_PATTERN.fullmatch( - snapshot_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 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 commit {snapshot_commit} is not an ancestor of HEAD") - validate_snapshot_review(snapshot_source.get("review")) - packages = config.get("packages") if not isinstance(packages, list) or not packages: fail("package ledger is empty") @@ -203,6 +176,10 @@ def validate_metadata( for package in packages: if not isinstance(package, dict): fail("package ledger entry is not an object") + require_keys(package, {"name", "manifestPath", "tier", "compatibility", + "snapshot", "itemCount", "sha256"}, "package") + if type(package["itemCount"]) is not int or package["itemCount"] < 0: + fail("package item count must be a non-negative integer") name = package.get("name") manifest = package.get("manifestPath") snapshot = package.get("snapshot") @@ -217,7 +194,9 @@ def validate_metadata( fail(f"{name} must use the reviewed-snapshot compatibility policy") if not isinstance(snapshot, str) or not snapshot.startswith("api/snapshots/"): fail(f"{name} has an invalid snapshot path") - snapshot_path = ROOT / snapshot + snapshot_path = (ROOT / snapshot).resolve() + if not snapshot_path.is_relative_to(ROOT / "api/snapshots"): + fail(f"{name} snapshot must stay inside api/snapshots") if not snapshot_path.is_file() and not updating: fail(f"{name} snapshot is missing: {snapshot}") if not updating: @@ -296,28 +275,21 @@ def render_snapshot( 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("--update", action="store_true", + help="refresh snapshots from the working tree to commit alongside source changes") + parser.add_argument("--snapshot-source-commit", + help="optional HEAD guard for --update; includes uncommitted source changes") 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: - fail("--update requires --snapshot-source-commit") + if args.snapshot_source_commit is not None: + if not args.update: + fail("--snapshot-source-commit requires --update") head = run(["git", "rev-parse", "HEAD"]).strip() if args.snapshot_source_commit != head: - fail("snapshot source must be the clean source commit at HEAD") - status = run(["git", "status", "--porcelain=v1", "--untracked-files=all"]) - dirty_paths = {line[3:] for line in status.splitlines() if len(line) > 3} - if dirty_paths - {"api/stability.json"}: - fail("snapshot source has uncommitted changes outside api/stability.json") - snapshot_source = config.get("snapshotSource") - if not isinstance(snapshot_source, dict): - fail("snapshot source identity is missing") - snapshot_source["commit"] = args.snapshot_source_commit - snapshot_source["capturedOn"] = date.today().isoformat() + fail("snapshot source guard must match HEAD") 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 08836a5..f342215 100644 --- a/tools/check-api-compatibility.py +++ b/tools/check-api-compatibility.py @@ -93,7 +93,7 @@ def main() -> None: [sys.executable, "tools/check-api-baseline.py", "--metadata-only"], cwd=ROOT ) if metadata.returncode != 0: - fail("snapshot metadata or reviewed change record is invalid") + fail("snapshot metadata is invalid") ledger = json.loads(LEDGER_PATH.read_text(encoding="utf-8")) metadata_result = subprocess.run( ["cargo", "metadata", "--locked", "--no-deps", "--format-version", "1"], @@ -112,6 +112,9 @@ def main() -> None: floor_snapshots = { package["name"]: package["snapshot"] for package in floor_ledger["packages"] } + removed_packages = set(floor_snapshots) - {package["name"] for package in ledger["packages"]} + if removed_packages: + fail(f"compatibility-floor packages removed: {sorted(removed_packages)}") total_added = 0 total_removed = 0 for package in ledger["packages"]: @@ -130,13 +133,7 @@ def main() -> None: for line in removed: print(f"- {line}", file=sys.stderr) validate_removed(package["name"], set(removed), approved) - review = ledger["snapshotSource"]["review"] - if review["publicApiDiff"] != { - "added": total_added, - "removed": total_removed, - }: - fail("snapshot review does not match the measured API diff") - print(f"api compatibility: reviewed (+{total_added}, -{total_removed}); " + print(f"api compatibility: checked (+{total_added}, -{total_removed}); " "unapproved removals forbidden")