lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

commit 565cce2a08751e3dd55cf761736e049397e914c7
parent f552be2c411340e59b7308b0e1bce256324659b1
Author: triesap <tyson@radroots.org>
Date:   Thu, 15 Oct 2026 21:07:12 +0000

radroots: validate optional capability owners in source guards

- Replace vocabulary bans with explicit optional package activation checks.
- Preserve existing facade boundaries and add thirteen fixture cases.
- Keep runtime features unchanged with two cached test-only parser edges.
- Pass all 26 facade tests, strict Clippy and standalone contract checks.

Diffstat:
MCargo.lock | 2++
Mcontracts/architecture/deviations.toml | 27+++++++++++++++++++++++++++
Mcrates/radroots/Cargo.toml | 4++++
Mcrates/radroots/tests/package_boundary.rs | 287+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
4 files changed, 314 insertions(+), 6 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock @@ -2916,6 +2916,8 @@ dependencies = [ "radroots_sdk", "radroots_trade", "radroots_transport", + "serde_json", + "toml 0.8.23", ] [[package]] diff --git a/contracts/architecture/deviations.toml b/contracts/architecture/deviations.toml @@ -2,6 +2,33 @@ schema_version = 1 architecture_id = "radroots.crates.release.v1" [[deviation]] +id = "RCRV1-DEV-039" +date = "2026-10-15" +status = "closed" +approval = "The user approved the complete shared SDK refactor and all remaining local verified checkpoints, including retained ancillary capabilities and direct replacement of incompatible active guards. Publication remains separately unauthorized." +affected_steps = ["020", "040", "130"] +spec_anchors = ["contracts/crates/release_v1/radroots_crates_release_v1.toml#package.radroots"] +source_evidence = [ + "The complete current radroots package-boundary test rejects every manifest occurrence of reticulum, mesh, simplex, nostrdb or replica. The approved shared_sdk_refactor.v1 target explicitly retains those package families as optional advanced capabilities.", + "Current ordinary facade source, normal dependencies and forwarding assertions remain buildable and unchanged. This is an obsolete source-policy restriction, not a reproduced product or network incident. The existing SP1 exclusion and no private dependencies, namespace or wildcard exports remain retained purposes.", +] +replacement_action = "Replace only the blanket ancillary vocabulary ban with bounded fixture-level manifest and approved-package admission. Admit the five approved advanced capability families only through declared optional dependencies and explicit feature activation; reject private or unapproved package targets, missing/nonoptional activation and local default activation. Preserve current production features, all other package/API assertions, SP1 separation and actual no-hidden-role-reduction gates. Add only cached test-parser dev dependencies and prove an exact lock delta with no registry package changes." +verification = [ + "Validate the prospective deviation before source edits. Map the old forbidden-token assertion to approved optional admission and retained denial cases before replacement; keep all other original test functions and assertions.", + "Use disposable in-memory TOML/JSON fixtures only, with no filesystem mutation, network, signer, account, product runtime or meaningful state. Prove the approved optional fixtures fail the faithful old lexical guard and then pass the replacement; malformed/private/nonoptional/default or unapproved cases retain explicit refusal.", + "Run Rust1.99.0 scoped formatting, locked all-feature/all-target facade check/test and strict Clippy, standalone architecture/contract, and exact package/checksum/dependency lock comparison. Full supported native/browser feature/default closure and actual capability execution remain separate required gates.", +] +unresolved_risk = "This unit governs a local source test and fixture manifests only. It does not implement or qualify any ancillary feature, new SDK API, transport, target graph, browser, compiler migration, package publication or consumer adoption. Other exact old API/feature assertions require their retained-purpose binding and atomic updates with actual successor source." +normative_architecture_change = false +adr_required = false +closure_evidence = [ + "Prospective architecture validation passed before the test source or dependency change. A faithful extraction of the original lexical rule plus the initial twelve fixtures yields eight failures and eight passing controls: all five approved optional families are denied, while malformed/private/oversize input is accepted. This is a source-policy mismatch, not a product incident.", + "The manifest-aware guard uses the approved target owner graph, explicit optional activation, private/unapproved owner and alias refusal, local default feature traversal, bounded parsing and retained SP1 separation. Review added an independent owner-admission case, which failed before arbitrary and tooling-only owners were excluded. The twelve initial fixture functions and builder remain byte-identical; the extra review case is also unchanged through its fix. All four original test functions and their other assertions remain retained.", + "Final Rust1.99.0 scoped formatting, locked all-feature/all-target facade checking, all26facade tests with zero failures/ignored/filtered cases, strict Clippy, complete workspace formatting, architecture and standalone contract validation passed locally. All17package-boundary cases pass, including13new fixtures. A final closed-deviation architecture check and exact owned source review remain required before commit.", + "Normal runtime dependencies, feature definitions, exports and targets are unchanged. Exactly two dev-parser edges were added to the facade lock node; all584package identities/checksums and every other package/edge are unchanged. No ancillary capability, public API, compiler migration, browser/full target closure, package publication, generated artifact or supported consumer adoption is implemented or qualified by this contained test-policy correction. Other old guard purposes remain bound to their actual successor source changes.", +] + +[[deviation]] id = "RCRV1-DEV-038" date = "2026-10-15" status = "closed" diff --git a/crates/radroots/Cargo.toml b/crates/radroots/Cargo.toml @@ -55,6 +55,10 @@ geonames = ["client", "radroots_sdk/geonames"] knowledge = ["client", "radroots_sdk/knowledge"] full = ["radroots_sdk/full"] +[dev-dependencies] +serde_json = { workspace = true, features = ["std"] } +toml = { workspace = true } + [[example]] name = "ordinary_memory" path = "examples/ordinary_memory.rs" diff --git a/crates/radroots/tests/package_boundary.rs b/crates/radroots/tests/package_boundary.rs @@ -40,12 +40,7 @@ fn features_forward_the_exact_user_oriented_graph() { ] { assert!(MANIFEST.contains(forwarding), "missing `{forwarding}`"); } - for forbidden in ["reticulum", "mesh", "simplex", "nostrdb", "replica", "sp1"] { - assert!( - !MANIFEST.to_ascii_lowercase().contains(forbidden), - "forbidden feature vocabulary `{forbidden}`" - ); - } + assert!(feature_guard(MANIFEST).is_ok()); } #[test] @@ -91,3 +86,283 @@ fn dependency_names(manifest: &str) -> BTreeSet<&str> { .filter_map(|line| line.split_once(" = ").map(|(name, _)| name.trim())) .collect() } + +fn feature_guard(manifest: &str) -> Result<(), &'static str> { + if manifest.len() > 65_536 { + return Err("manifest byte limit exceeded"); + } + let value: toml::Value = toml::from_str(manifest).map_err(|_| "invalid manifest")?; + let dependencies = value + .get("dependencies") + .and_then(toml::Value::as_table) + .ok_or("missing dependency table")?; + let features = value + .get("features") + .and_then(toml::Value::as_table) + .ok_or("missing feature table")?; + let features = features + .iter() + .map(|(name, values)| { + let values = values.as_array().ok_or("feature must be an array")?; + let tokens = values + .iter() + .map(toml::Value::as_str) + .collect::<Option<Vec<_>>>() + .ok_or("feature values must be strings")?; + Ok((name.as_str(), tokens)) + }) + .collect::<Result<std::collections::BTreeMap<_, _>, &'static str>>()?; + if features.contains_key("sp1") { + return Err("SP1 remains a separate capability"); + } + + let policy: serde_json::Value = serde_json::from_str(include_str!( + "../../../contracts/architecture/decisions/shared_sdk_refactor.v1.json" + )) + .map_err(|_| "invalid approved target contract")?; + let mut approved = policy + .get("packages") + .and_then(serde_json::Value::as_array) + .ok_or("missing approved package graph")? + .iter() + .map(|p| p.get("package").and_then(serde_json::Value::as_str)) + .collect::<Option<BTreeSet<_>>>() + .ok_or("invalid approved package identity")?; + let advanced = BTreeSet::from([ + "radroots_transport_reticulum", + "radroots_mesh", + "radroots_simplex_chat_proto", + "radroots_nostrdb", + "radroots_replica_sync", + ]); + if !advanced.is_subset(&approved) { + return Err("advanced owners must exist in approved graph"); + } + // The original exact-dependency test still governs the current base. New + // optional owners must come from the prospective target, not arbitrary text. + let base: toml::Value = toml::from_str(MANIFEST).map_err(|_| "invalid base manifest")?; + approved.extend( + base.get("dependencies") + .and_then(toml::Value::as_table) + .ok_or("missing base dependencies")? + .keys() + .map(String::as_str), + ); + let mut advanced_aliases = BTreeSet::new(); + for (alias, declaration) in dependencies { + let table = declaration.as_table(); + if table.is_none() && declaration.as_str().is_none() { + return Err("invalid dependency shape"); + } + let package = match table.and_then(|t| t.get("package")) { + Some(p) => p.as_str().ok_or("invalid package alias")?, + None => alias.as_str(), + }; + if !approved.contains(package) || ["xtask", "radroots_test_fixtures"].contains(&package) { + return Err("unapproved runtime dependency owner"); + } + for name in [alias.as_str(), package] { + if ["radroots_ee_", "radroots_ops_", "radroots_platform_"] + .iter() + .any(|prefix| name.starts_with(prefix)) + || (name.starts_with("radroots_") && !approved.contains(name)) + { + return Err("unapproved package owner"); + } + if name.starts_with("sp1") { + return Err("SP1 remains a separate capability"); + } + } + if advanced.contains(package) { + if table + .and_then(|t| t.get("optional")) + .and_then(toml::Value::as_bool) + != Some(true) + { + return Err("advanced dependency must be optional"); + } + let explicit = format!("dep:{alias}"); + if !features + .values() + .any(|tokens| tokens.iter().any(|token| *token == explicit)) + { + return Err("advanced dependency needs explicit activation"); + } + advanced_aliases.insert(alias.as_str()); + } + } + for tokens in features.values() { + for token in tokens { + if let Some(alias) = token.strip_prefix("dep:") + && !dependencies.contains_key(alias) + { + return Err("feature activates an undeclared dependency"); + } + } + } + let mut pending = features.get("default").cloned().unwrap_or_default(); + let mut visited = BTreeSet::new(); + while let Some(token) = pending.pop() { + let (dependency, activates) = if let Some(alias) = token.strip_prefix("dep:") { + (alias, true) + } else if let Some((alias, _)) = token.split_once('/') { + (alias.trim_end_matches('?'), !alias.ends_with('?')) + } else { + (token, true) + }; + if activates && advanced_aliases.contains(dependency) { + return Err("advanced dependency cannot be enabled by default"); + } + if visited.insert(token) + && let Some(tokens) = features.get(token) + { + pending.extend(tokens); + } + } + Ok(()) +} + +fn advanced_fixture(feature: &str, package: &str, optional: bool) -> String { + let mut value: toml::Value = toml::from_str(MANIFEST).unwrap(); + let dependency = toml::Table::from_iter([ + ("workspace".to_owned(), toml::Value::Boolean(true)), + ("optional".to_owned(), toml::Value::Boolean(optional)), + ]); + value["dependencies"] + .as_table_mut() + .unwrap() + .insert(package.to_owned(), toml::Value::Table(dependency)); + value["features"].as_table_mut().unwrap().insert( + feature.to_owned(), + toml::Value::Array(vec![toml::Value::String(format!("dep:{package}"))]), + ); + let text = toml::to_string(&value).unwrap(); + assert!(text.len() < 65_536); + text +} + +#[test] +fn approved_optional_reticulum_is_not_rejected_by_vocabulary() { + assert!( + feature_guard(&advanced_fixture( + "reticulum", + "radroots_transport_reticulum", + true + )) + .is_ok() + ); +} + +#[test] +fn approved_optional_mesh_is_not_rejected_by_vocabulary() { + assert!(feature_guard(&advanced_fixture("mesh", "radroots_mesh", true)).is_ok()); +} + +#[test] +fn approved_optional_simplex_is_not_rejected_by_vocabulary() { + assert!( + feature_guard(&advanced_fixture( + "simplex", + "radroots_simplex_chat_proto", + true + )) + .is_ok() + ); +} + +#[test] +fn approved_optional_nostrdb_is_not_rejected_by_vocabulary() { + assert!(feature_guard(&advanced_fixture("nostrdb", "radroots_nostrdb", true)).is_ok()); +} + +#[test] +fn approved_optional_replica_is_not_rejected_by_vocabulary() { + assert!(feature_guard(&advanced_fixture("replica", "radroots_replica_sync", true)).is_ok()); +} + +#[test] +fn advanced_dependency_must_be_optional() { + assert!(feature_guard(&advanced_fixture("mesh", "radroots_mesh", false)).is_err()); +} + +#[test] +fn advanced_dependency_needs_explicit_activation() { + let mut value: toml::Value = + toml::from_str(&advanced_fixture("mesh", "radroots_mesh", true)).unwrap(); + value["features"].as_table_mut().unwrap().remove("mesh"); + assert!(feature_guard(&toml::to_string(&value).unwrap()).is_err()); +} + +#[test] +fn advanced_dependency_cannot_be_enabled_by_default() { + for route in ["direct", "feature", "transitive_feature"] { + let mut value: toml::Value = + toml::from_str(&advanced_fixture("mesh", "radroots_mesh", true)).unwrap(); + let token = match route { + "direct" => "dep:radroots_mesh", + "feature" => "mesh", + _ => { + value["features"].as_table_mut().unwrap().insert( + "feature_hop".to_owned(), + toml::Value::Array(vec![toml::Value::String("mesh".to_owned())]), + ); + "feature_hop" + } + }; + value["features"]["default"] + .as_array_mut() + .unwrap() + .push(toml::Value::String(token.to_owned())); + assert!(feature_guard(&toml::to_string(&value).unwrap()).is_err()); + } +} + +#[test] +fn private_package_cannot_hide_behind_a_feature_alias() { + assert!( + feature_guard(&advanced_fixture( + "innocent_feature", + "radroots_ee_hidden", + true + )) + .is_err() + ); + let mut value: toml::Value = toml::from_str(&advanced_fixture( + "innocent_feature", + "ordinary_alias", + true, + )) + .unwrap(); + value["dependencies"]["ordinary_alias"] + .as_table_mut() + .unwrap() + .insert( + "package".to_owned(), + toml::Value::String("radroots_ee_hidden".to_owned()), + ); + assert!(feature_guard(&toml::to_string(&value).unwrap()).is_err()); +} + +#[test] +fn malformed_or_wrong_shape_manifest_cannot_pass_as_harmless_text() { + for value in ["not TOML input", "a = 1", "[features]\ndefault = 7\n"] { + assert!(feature_guard(value).is_err()); + } +} + +#[test] +fn oversized_manifest_is_rejected_before_parsing() { + assert!(feature_guard(&" ".repeat(65_537)).is_err()); +} + +#[test] +fn sp1_remains_separate_from_the_ordinary_facade() { + assert!(feature_guard(&advanced_fixture("sp1", "sp1_sdk", true)).is_err()); +} + +#[test] +fn only_approved_dependency_owners_are_admitted() { + for package in ["unapproved_owner", "xtask", "radroots_test_fixtures"] { + assert!(feature_guard(&advanced_fixture("innocent_feature", package, true)).is_err()); + } +}