api: qualify application prelude contract

This commit is contained in:
DeFiDude committed 2026-08-17 11:41:18 -06:00
1 parent c9b210a52b
commit cfb7253f99
14 files changed
+4488

No files matched your search

+8
View File
@@ -29,6 +29,14 @@ jobs:
run: cargo install cargo-public-api --version 0.52.0 --locked
- name: Check reviewed public API baseline
run: python3 tools/check-api-baseline.py
- name: Check manifest and feature contract
run: python3 tools/check-api-manifest.py
- name: Check additions-only compatibility floor
run: python3 tools/check-api-compatibility.py
- name: Check canonical and legacy external consumer
run: |
cargo check --manifest-path api-fixtures/Cargo.toml --locked
cargo check --manifest-path api-fixtures/Cargo.toml --all-features --locked
test:
name: Test (${{ matrix.os }})
+3
View File
@@ -7,3 +7,6 @@ __pycache__/
/rust_artifacts/
proptest-regressions/
/tools/*
!/tools/check-api-manifest.py
!/tools/check-api-compatibility.py
/api-fixtures/target/
+16
View File
@@ -31,6 +31,12 @@ facade (`rns_runtime::prelude`, lifecycle handles, destination resolution, and
Link sessions) with broad actor, RPC, manager, and command modules. `rns-ratkey`
is experimental, and the `rns-tools` library target is tool internal.
The existing [`rns_runtime::prelude`](APPLICATION_API.md) is the canonical
application spine. It re-exports the original type identities, and all current
module-qualified paths remain supported. Actor, mailbox, RPC, transport-table,
concrete-driver, and endpoint-ownership modules remain provisional SPI; their
reachability in a snapshot does not promote them.
No existing module is hidden, moved, or made private by this baseline. That
work requires the next explicit API-boundary checkpoint, downstream migration
evidence from rsLXMF/rsLXST/Ratspeak, and a versioning decision.
@@ -49,8 +55,18 @@ To verify the baseline:
cargo install cargo-public-api --version 0.52.0 --locked
rustup toolchain install nightly-2026-08-01 --profile minimal
python3 tools/check-api-baseline.py
python3 tools/check-api-manifest.py
python3 tools/check-api-compatibility.py
cargo check --manifest-path api-fixtures/Cargo.toml --locked
cargo check --manifest-path api-fixtures/Cargo.toml --all-features --locked
```
The immutable floor and current captured snapshot source are separate
identities in `api-stability.json`. The compatibility check currently enforces
an additions-only Wave C policy. Snapshot equality remains only one layer of
SemVer evidence: feature/cfg contracts, external fixtures, platform builds,
and behavioral tests remain mandatory.
Use `--update` only after reviewing the generated API diff and recording the
compatibility/version decision. Snapshot updates do not by themselves make a
breaking change acceptable.
+50
View File
@@ -0,0 +1,50 @@
# Reticulum application API
`rns_runtime::prelude` is the canonical application-facing import path for an
owned Reticulum runtime. It gathers existing identities from the protocol,
identity, Link, interface, and runtime crates; it does not wrap or replace
them. Module-qualified paths remain supported.
The compiled examples under `crates/rns-runtime/examples/` are the executable
application guide. They cover runtime startup and shutdown, Destinations,
announces, packets and receipts, persistent Links, requests, Channels, Buffer
streams, Resources, and RNode observation.
```rust
use rns_runtime::prelude::*;
# async fn example() -> Result<(), Box<dyn std::error::Error>> {
let runtime = init().await?;
let identity = Identity::new();
// Application work owns `runtime`; shutdown is explicit and awaitable.
runtime.shutdown().await;
# let _ = identity;
# Ok(())
# }
```
Finite destination discovery uses `resolve_destination_on_transport` with one
deadline and validated identity recall. Long-lived observation uses
`ReticulumHandle::subscribe_announces`, whose returned
`AnnounceSubscription` owns exactly one registration. A finite lookup never
installs or removes an announce handler.
The prelude is intentionally not a blanket stability promise. Low-level actor,
mailbox, RPC, transport-table, concrete-driver, and Link endpoint ownership
paths remain provisional SPI. Advanced integrations may continue using those
module-qualified paths, but application code should start with the prelude and
the compiled examples.
Compatibility is checked in layers:
- `api-baseline/*.txt` records the explicit all-feature Apple ARM64 surface;
- `api-baseline/manifest-contract.json` records features, targets, MSRV, and
non-development dependencies;
- `api-fixtures` compiles canonical and retained legacy imports as an external
consumer; and
- `tools/check-api-compatibility.py` rejects removals from the immutable Wave C
floor.
These checks complement platform builds and protocol/interoperability tests;
they do not replace them.
+4
View File
@@ -2,6 +2,10 @@
## Unreleased
- Designated the existing `rns_runtime::prelude` and compiled examples as the
canonical application spine while retaining every module-qualified path,
and added external-consumer, manifest/feature, and additions-only API
compatibility gates without changing runtime behavior or public signatures.
- Classified every library package and added pinned, CI-enforced public API
snapshots so compatibility drift is reviewed before any boundary change;
no visibility or signature changed in this baseline.
+1
View File
@@ -30,6 +30,7 @@ rsReticulum can live beside other Reticulum tools on `PATH` without worry.
## Contents
- [Build It](#build-it)
- [Application API](APPLICATION_API.md)
- [Tool Usage](#tool-usage)
- [Configuration](#configuration)
- [Interface Support](#interface-support)
File diff suppressed because it is too large. Load diff
+2118
View File
File diff suppressed because it is too large. Load diff
+14
View File
@@ -0,0 +1,14 @@
[package]
name = "rns-application-api-fixture"
version = "0.0.0"
edition = "2024"
publish = false
[workspace]
[features]
default = []
all = ["rns-runtime/ble", "rns-runtime/rnode-tcp", "rns-runtime/serial"]
[dependencies]
rns-runtime = { path = "../crates/rns-runtime", default-features = false }
+41
View File
@@ -0,0 +1,41 @@
//! External-consumer compile contract for canonical and retained Reticulum paths.
pub mod canonical {
use rns_runtime::prelude::{
AnnounceSubscription, DestinationResolveError, DestinationResolveOptions,
LinkSessionHandle, PacketReceiptHandle, RecalledDestination, ReticulumHandle,
resolve_destination_on_transport,
};
pub fn compile_surface() {
let _ = resolve_destination_on_transport;
let _ = std::mem::size_of::<DestinationResolveOptions>();
let _ = std::mem::size_of::<DestinationResolveError>();
let _ = std::mem::size_of::<ReticulumHandle>();
let _ = std::mem::size_of::<RecalledDestination>();
let _ = std::mem::size_of::<AnnounceSubscription>();
let _ = std::mem::size_of::<PacketReceiptHandle>();
let _ = std::mem::size_of::<LinkSessionHandle>();
}
}
pub mod legacy {
use rns_runtime::destination_resolver::{
DestinationResolveError, DestinationResolveOptions, resolve_destination_on_transport,
};
use rns_runtime::link_session::LinkSessionHandle;
use rns_runtime::reticulum::{
AnnounceSubscription, PacketReceiptHandle, RecalledDestination, ReticulumHandle,
};
pub fn compile_surface() {
let _ = resolve_destination_on_transport;
let _ = std::mem::size_of::<DestinationResolveOptions>();
let _ = std::mem::size_of::<DestinationResolveError>();
let _ = std::mem::size_of::<ReticulumHandle>();
let _ = std::mem::size_of::<RecalledDestination>();
let _ = std::mem::size_of::<AnnounceSubscription>();
let _ = std::mem::size_of::<PacketReceiptHandle>();
let _ = std::mem::size_of::<LinkSessionHandle>();
}
}
+9
View File
@@ -14,6 +14,15 @@
"commit": "47dbbf1febc0a9d3259f179a0512d9b56bb2320d",
"capturedOn": "2026-08-17"
},
"compatibilityFloor": {
"evidenceCommit": "c9b210a52b139ac9754b46c5c2639c4113e7ae53",
"sourceCommit": "47dbbf1febc0a9d3259f179a0512d9b56bb2320d"
},
"snapshotSource": {
"commit": "47dbbf1febc0a9d3259f179a0512d9b56bb2320d",
"capturedOn": "2026-08-17",
"changeRecord": null
},
"packages": [
{
"name": "rns-crypto",
+43
View File
@@ -112,6 +112,49 @@ def validate_metadata(
if ancestor_check.returncode != 0:
fail(f"baseline commit {commit} is not an ancestor of HEAD")
compatibility_floor = config.get("compatibilityFloor")
if not isinstance(compatibility_floor, dict):
fail("compatibility floor identity is missing")
floor_evidence = compatibility_floor.get("evidenceCommit")
floor_source = compatibility_floor.get("sourceCommit")
for label, floor_commit in (
("evidence", floor_evidence),
("source", floor_source),
):
if not isinstance(floor_commit, str) or not SHA_PATTERN.fullmatch(
floor_commit
):
fail(f"compatibility floor {label} commit must be a full Git commit")
floor_check = subprocess.run(
["git", "cat-file", "-e", f"{floor_commit}^{{commit}}"], cwd=ROOT
)
if floor_check.returncode != 0:
fail(f"compatibility floor {label} commit {floor_commit} is unavailable")
floor_ancestor = subprocess.run(
["git", "merge-base", "--is-ancestor", floor_commit, "HEAD"], cwd=ROOT
)
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")
packages = config.get("packages")
if not isinstance(packages, list) or not packages:
fail("package ledger is empty")
+63
View File
@@ -0,0 +1,63 @@
#!/usr/bin/env python3
"""Reject removals from the immutable Wave C public-API compatibility floor."""
from __future__ import annotations
import json
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
LEDGER_PATH = ROOT / "api-stability.json"
def fail(message: str) -> None:
print(f"api compatibility: {message}", file=sys.stderr)
raise SystemExit(1)
def git_show(commit: str, path: str) -> str:
result = subprocess.run(
["git", "show", f"{commit}:{path}"],
cwd=ROOT,
capture_output=True,
text=True,
)
if result.returncode != 0:
if result.stderr:
print(result.stderr, file=sys.stderr, end="")
fail(f"cannot read compatibility floor {commit}:{path}")
return result.stdout
def main() -> None:
ledger = json.loads(LEDGER_PATH.read_text(encoding="utf-8"))
floor = ledger.get("compatibilityFloor", {}).get("evidenceCommit")
if not isinstance(floor, str):
fail("api-stability.json has no compatibility-floor commit")
total_added = 0
total_removed = 0
for package in ledger["packages"]:
path = package["snapshot"]
before = set(git_show(floor, path).splitlines())
after = set((ROOT / path).read_text(encoding="utf-8").splitlines())
added = sorted(after - before)
removed = sorted(before - after)
total_added += len(added)
total_removed += len(removed)
print(f"{package['name']}: +{len(added)} -{len(removed)}")
if removed:
for line in removed:
print(f"- {line}", file=sys.stderr)
if total_removed:
fail(
f"{total_removed} public API lines were removed from the Wave C floor; "
"the current policy permits additions only"
)
print(f"api compatibility: additive-only (+{total_added}, -0)")
if __name__ == "__main__":
main()
+158
View File
@@ -0,0 +1,158 @@
#!/usr/bin/env python3
"""Verify the reviewed Cargo manifest and feature contract for library packages."""
from __future__ import annotations
import argparse
import difflib
import json
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
LEDGER_PATH = ROOT / "api-stability.json"
CONTRACT_PATH = ROOT / "api-baseline" / "manifest-contract.json"
def fail(message: str) -> None:
print(f"api manifest contract: {message}", file=sys.stderr)
raise SystemExit(1)
def metadata(manifest_path: str) -> dict[str, object]:
result = subprocess.run(
[
"cargo",
"metadata",
"--format-version",
"1",
"--no-deps",
"--manifest-path",
manifest_path,
],
cwd=ROOT,
capture_output=True,
text=True,
)
if result.returncode != 0:
if result.stderr:
print(result.stderr, file=sys.stderr, end="")
fail(f"cargo metadata failed for {manifest_path}")
return json.loads(result.stdout)
def dependency_contract(dependency: dict[str, object]) -> dict[str, object]:
source = dependency.get("source")
return {
"name": dependency["name"],
"rename": dependency.get("rename"),
"kind": dependency.get("kind"),
"target": dependency.get("target"),
"requirement": dependency["req"],
"optional": dependency["optional"],
"defaultFeatures": dependency["uses_default_features"],
"features": sorted(dependency["features"]),
"sourceKind": "registry" if source else "path",
}
def package_contract(package: dict[str, object]) -> dict[str, object]:
targets = []
for target in package["targets"]:
if "lib" not in target["kind"]:
continue
targets.append(
{
"name": target["name"],
"kind": sorted(target["kind"]),
"crateTypes": sorted(target["crate_types"]),
"requiredFeatures": sorted(target.get("required-features", [])),
}
)
dependencies = [
dependency_contract(dependency)
for dependency in package["dependencies"]
if dependency.get("kind") != "dev"
]
dependencies.sort(
key=lambda item: (
str(item["kind"]),
str(item["target"]),
str(item["rename"]),
str(item["name"]),
)
)
return {
"name": package["name"],
"version": package["version"],
"rustVersion": package.get("rust_version"),
"edition": package["edition"],
"features": {
name: sorted(values)
for name, values in sorted(package["features"].items())
},
"targets": sorted(targets, key=lambda item: str(item["name"])),
"dependencies": dependencies,
}
def render_contract() -> str:
ledger = json.loads(LEDGER_PATH.read_text(encoding="utf-8"))
manifests = sorted({entry["manifestPath"] for entry in ledger["packages"]})
recorded_names = {entry["name"] for entry in ledger["packages"]}
packages: list[dict[str, object]] = []
for manifest in manifests:
for package in metadata(manifest)["packages"]:
if package["name"] in recorded_names:
packages.append(package_contract(package))
actual_names = {entry["name"] for entry in packages}
if actual_names != recorded_names:
fail(
f"package inventory differs: expected={sorted(recorded_names)}, "
f"actual={sorted(actual_names)}"
)
contract = {
"schemaVersion": 1,
"scope": "library Cargo manifests, public features, targets, and non-dev dependencies",
"packages": sorted(packages, key=lambda item: str(item["name"])),
}
return json.dumps(contract, indent=2) + "\n"
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument(
"--print",
action="store_true",
dest="print_contract",
help="print the current canonical contract for reviewed application",
)
args = parser.parse_args()
rendered = render_contract()
if args.print_contract:
print(rendered, end="")
return
if not CONTRACT_PATH.is_file():
fail(f"missing {CONTRACT_PATH.relative_to(ROOT)}")
expected = CONTRACT_PATH.read_text(encoding="utf-8")
if expected != rendered:
print(
"".join(
difflib.unified_diff(
expected.splitlines(keepends=True),
rendered.splitlines(keepends=True),
fromfile=str(CONTRACT_PATH.relative_to(ROOT)),
tofile="current Cargo metadata",
)
),
file=sys.stderr,
end="",
)
fail("manifest, feature, target, or dependency contract drift")
print("api manifest contract: ok")
if __name__ == "__main__":
main()