lib

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

commit 9100e33c8f9511f9e6ffa13486a89fbefb13c71d
parent 89f1b0f51f0fc38266f31a9a3504755c5834204c
Author: triesap <tyson@radroots.org>
Date:   Tue, 13 Oct 2026 22:50:19 +0000

xtask: reject linked and nonregular conformance inventories

- Validate inventory directories and ancestor components within the workspace.
- Propagate entry errors and inspect file types without following links.
- Preserve lexical JSON discovery with eight retained validator regressions.
- Verify xtask tests, Clippy, contracts and generated DTO freshness.

Diffstat:
Mcontracts/architecture/deviations.toml | 28++++++++++++++++++++++++++++
Mtools/xtask/src/contract.rs | 75++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Atools/xtask/src/contract/conformance_inventory_tests.rs | 167+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 265 insertions(+), 5 deletions(-)

diff --git a/contracts/architecture/deviations.toml b/contracts/architecture/deviations.toml @@ -2,6 +2,34 @@ schema_version = 1 architecture_id = "radroots.crates.release.v1" [[deviation]] +id = "RCRV1-DEV-036" +date = "2026-10-13" +status = "closed" +approval = "The user approved the successor refactor, scoped execution/recovery amendments and all remaining local verified checkpoints; publication and supported consumer qualification remain separate." +affected_steps = ["010", "130"] +spec_anchors = ["contracts/crates/release_v1/radroots_crates_release_v1.toml#repository_policy"] +source_evidence = [ + "Current conformance discovery drops directory-entry errors and follows directory symlinks through Path::is_dir; file suffix matching can also admit linked or nonregular JSON entries.", + "Both the all-vector validator and knowledge-vector inventory call this helper. The freshly fetched public integration revision retains the same source and no newer public correction was observed.", +] +replacement_action = "Bring forward contained conformance discovery admission. First demonstrate unchanged-source failures through the actual vector validator using disposable regular, linked and Unix-socket fixtures. Then reject linked or non-directory root components, admit only real descendant directories and regular JSON files, propagate directory-entry/type errors, and preserve lexical traversal and valid vectors. Preserve public APIs, dependencies, generated bytes, mirrors and existing missing-vector fixture policy." +verification = [ + "Validate this prospective deviation before production edits; each retained regression uses one temporary root, at most six directories including that root, three regular vectors, one ignored regular file and one link or Unix socket, without recursive cycles or application effects.", + "Run byte-identical compiled regressions before and after the correction; assert exact linked target bytes and object types remain intact and valid nested vectors retain deterministic first-error order.", + "Run exact Rust 1.99.0 formatting, locked all-feature/all-target xtask checking/testing, warnings-as-errors Clippy, standalone contract/architecture validation and generated DTO-root freshness.", + "Review exact owned discovery, callers, retained tests and deviation source before a local owner commit; retain unresolved parser, aggregate, descriptor-race, platform and supported adoption obligations separately.", +] +unresolved_risk = "The contained discovery correction is locally qualified on macOS arm64. Static pathname/type admission does not establish descriptor-race immunity, bounded JSON parsing or aggregate inventory limits, complete tooling/platform/resource qualification or supported consumer adoption; the two existing native/WASM producer integration cases remain ignored in the default xtask suite." +normative_architecture_change = false +adr_required = false +closure_evidence = [ + "Prospective standalone architecture validation passed before production edits. The first regression run exposed the platform Unix-socket pathname limit as a fixture setup error; the corrected retained fixture binds a short owned socket and renames it into the inventory. Against unchanged production, the complete second run has six causal failures and two passing regular/order controls, with no ignored cases or application effects.", + "All five linked file/directory/root/parent/dangling fixtures were accepted by unchanged discovery; the nonregular socket reached the file reader. Private discovery now checks the admitted workspace root and directory components, rejects links and nonregular descendants before parsing, propagates directory-entry/type errors and preserves lexical depth-first discovery. Both all-vector and knowledge-vector callers provide the owning root.", + "The byte-identical eight retained regressions pass with the correction, preserve linked target bytes and object types, and leave the dangling target absent. Exact Rust 1.99.0 formatting, locked all-feature/all-target xtask checking and warnings-as-errors Clippy passed. The complete default all-target xtask suite passed 585 cases with zero failures or filtered cases; two pre-existing canonical native/WASM producer cases remained explicitly ignored.", + "Actual standalone contract validation and generated DTO-root freshness passed without changing source or generated bytes. Public APIs, dependency locks, vector/mirror bytes and missing-vector fixture policy are unchanged. Final closed-deviation architecture validation and exact owned source/status review are required before the local owner checkpoint; broader parsing, descriptor races, resources, platforms, generated producer qualification and supported consumer adoption remain separate.", +] + +[[deviation]] id = "RCRV1-DEV-035" date = "2026-10-13" status = "closed" diff --git a/tools/xtask/src/contract.rs b/tools/xtask/src/contract.rs @@ -3,6 +3,8 @@ mod admission_authority; pub(crate) mod artifact_bundle; mod comment_authority; +#[cfg(test)] +mod conformance_inventory_tests; mod deletion_authority; mod registry_v7; pub(crate) use registry_v7::{ @@ -4497,17 +4499,79 @@ fn validate_version_governance( validate_conformance_vector_mirrors(workspace_root) } -fn collect_conformance_vector_paths(dir: &Path, paths: &mut Vec<PathBuf>) -> Result<(), String> { +fn validate_conformance_directory(workspace_root: &Path, dir: &Path) -> Result<(), String> { + let relative = dir.strip_prefix(workspace_root).map_err(|error| { + format!( + "conformance inventory directory {} is outside workspace root {}: {error}", + dir.display(), + workspace_root.display() + ) + })?; + let mut current = workspace_root.to_path_buf(); + validate_real_conformance_directory(&current)?; + for component in relative.components() { + let std::path::Component::Normal(segment) = component else { + return Err(format!( + "conformance inventory directory must be workspace-relative and normalized: {}", + dir.display() + )); + }; + current.push(segment); + validate_real_conformance_directory(&current)?; + } + Ok(()) +} + +fn validate_real_conformance_directory(path: &Path) -> Result<(), String> { + let metadata = fs::symlink_metadata(path) + .map_err(|error| format!("inspect conformance inventory {}: {error}", path.display()))?; + if metadata.file_type().is_symlink() { + return Err(format!( + "conformance inventory directory contains a symlink: {}", + path.display() + )); + } + if !metadata.is_dir() { + return Err(format!( + "conformance inventory path must be a directory: {}", + path.display() + )); + } + Ok(()) +} + +fn collect_conformance_vector_paths( + workspace_root: &Path, + dir: &Path, + paths: &mut Vec<PathBuf>, +) -> Result<(), String> { + validate_conformance_directory(workspace_root, dir)?; let read_dir = match fs::read_dir(dir) { Ok(read_dir) => read_dir, Err(e) => return Err(format!("read dir {}: {e}", dir.display())), }; - let mut entries = read_dir.filter_map(Result::ok).collect::<Vec<_>>(); + let mut entries = read_dir + .collect::<Result<Vec<_>, _>>() + .map_err(|error| format!("read dir {}: {error}", dir.display()))?; entries.sort_by_key(|entry| entry.file_name()); for entry in entries { let path = entry.path(); - if path.is_dir() { - collect_conformance_vector_paths(&path, paths)?; + let file_type = entry + .file_type() + .map_err(|error| format!("inspect conformance entry {}: {error}", path.display()))?; + if file_type.is_symlink() { + return Err(format!( + "conformance inventory entry must not be a symlink: {}", + path.display() + )); + } + if file_type.is_dir() { + collect_conformance_vector_paths(workspace_root, &path, paths)?; + } else if !file_type.is_file() { + return Err(format!( + "conformance inventory entry must be a regular file or a directory: {}", + path.display() + )); } else if path.extension().and_then(|ext| ext.to_str()) == Some("json") { paths.push(path); } @@ -4586,7 +4650,7 @@ fn validate_all_conformance_vectors( return validate_missing_conformance_vectors(workspace_root, &vectors_dir); } let mut paths = Vec::new(); - collect_conformance_vector_paths(&vectors_dir, &mut paths)?; + collect_conformance_vector_paths(workspace_root, &vectors_dir, &mut paths)?; if paths.is_empty() { return Err(format!( "conformance vectors directory {} must contain JSON vectors", @@ -4861,6 +4925,7 @@ fn validate_knowledge_conformance_vector_inventory(workspace_root: &Path) -> Res ]); let mut paths = Vec::new(); collect_conformance_vector_paths( + workspace_root, &workspace_root.join("contracts/conformance/vectors/knowledge"), &mut paths, )?; diff --git a/tools/xtask/src/contract/conformance_inventory_tests.rs b/tools/xtask/src/contract/conformance_inventory_tests.rs @@ -0,0 +1,167 @@ +use super::validate_all_conformance_vectors; +use std::{fs, path::Path}; + +const VECTOR: &str = r#"{"suite":"inventory-control","contract_version":"1.0.0","vectors":[{"id":"inventory-control-001","kind":"synthetic.operation","input":{},"expected":{}}]}"#; + +fn vectors_root(root: &Path) -> std::path::PathBuf { + root.join("contracts/conformance/vectors") +} + +fn fixture() -> tempfile::TempDir { + let root = tempfile::tempdir().expect("disposable inventory root"); + fs::create_dir_all(vectors_root(root.path())).expect("fixed vector scaffold"); + root +} + +fn write_vector(path: &Path) { + fs::write(path, VECTOR).expect("synthetic vector"); +} + +#[test] +fn valid_nested_regular_vectors_and_ignored_files_validate() { + let root = fixture(); + let vectors = vectors_root(root.path()); + fs::create_dir(vectors.join("a")).expect("first vector directory"); + fs::create_dir(vectors.join("z")).expect("last vector directory"); + write_vector(&vectors.join("a/first.json")); + write_vector(&vectors.join("middle.json")); + write_vector(&vectors.join("z/last.json")); + fs::write(vectors.join("README.txt"), "ordinary ignored file").expect("ignored file"); + + validate_all_conformance_vectors(root.path(), "1.0.0").expect("valid nested inventory"); + + assert_eq!( + fs::read_to_string(vectors.join("middle.json")).unwrap(), + VECTOR + ); +} + +#[test] +fn lexical_depth_first_error_order_is_preserved() { + let root = fixture(); + let vectors = vectors_root(root.path()); + fs::create_dir(vectors.join("a")).expect("first vector directory"); + for relative in ["z.json", "b.json", "a/first.json"] { + fs::write( + vectors.join(relative), + VECTOR.replace("inventory-control", ""), + ) + .expect("invalid synthetic vector"); + } + + let error = validate_all_conformance_vectors(root.path(), "1.0.0") + .expect_err("invalid inventory must fail"); + assert!(error.contains("a/first.json"), "{error}"); + assert!(error.contains("suite must not be empty"), "{error}"); +} + +#[cfg(unix)] +fn assert_link_rejected(root: &Path, link: &Path) { + let error = validate_all_conformance_vectors(root, "1.0.0") + .expect_err("linked conformance inventory must be rejected"); + assert!(error.contains("symlink"), "{error}"); + assert!(fs::symlink_metadata(link).unwrap().file_type().is_symlink()); +} + +#[cfg(unix)] +#[test] +fn linked_vector_file_is_rejected_without_changing_its_target() { + let root = fixture(); + let foreign = root.path().join("foreign.json"); + write_vector(&foreign); + let link = vectors_root(root.path()).join("linked.json"); + std::os::unix::fs::symlink(&foreign, &link).expect("fixture file link"); + + assert_link_rejected(root.path(), &link); + assert_eq!(fs::read_to_string(&foreign).unwrap(), VECTOR); + assert!(fs::symlink_metadata(&foreign).unwrap().is_file()); +} + +#[cfg(unix)] +#[test] +fn linked_vector_directory_is_rejected_without_entering_its_target() { + let root = fixture(); + let foreign = root.path().join("foreign"); + fs::create_dir(&foreign).expect("foreign fixture directory"); + write_vector(&foreign.join("vector.json")); + let link = vectors_root(root.path()).join("linked"); + std::os::unix::fs::symlink(&foreign, &link).expect("fixture directory link"); + + assert_link_rejected(root.path(), &link); + assert_eq!( + fs::read_to_string(foreign.join("vector.json")).unwrap(), + VECTOR + ); + assert!(fs::symlink_metadata(&foreign).unwrap().is_dir()); +} + +#[cfg(unix)] +#[test] +fn linked_inventory_root_is_rejected_without_changing_its_target() { + let root = fixture(); + let foreign = root.path().join("foreign"); + fs::create_dir(&foreign).expect("foreign fixture directory"); + write_vector(&foreign.join("vector.json")); + let link = vectors_root(root.path()); + fs::remove_dir(&link).expect("empty fixture vector directory"); + std::os::unix::fs::symlink(&foreign, &link).expect("fixture root link"); + + assert_link_rejected(root.path(), &link); + assert_eq!( + fs::read_to_string(foreign.join("vector.json")).unwrap(), + VECTOR + ); +} + +#[cfg(unix)] +#[test] +fn linked_inventory_parent_is_rejected_without_changing_its_target() { + let root = fixture(); + write_vector(&vectors_root(root.path()).join("vector.json")); + let link = root.path().join("contracts"); + let foreign = root.path().join("foreign"); + fs::rename(&link, &foreign).expect("move owned fixture scaffold"); + std::os::unix::fs::symlink(&foreign, &link).expect("fixture parent link"); + + assert_link_rejected(root.path(), &link); + assert_eq!( + fs::read_to_string(foreign.join("conformance/vectors/vector.json")).unwrap(), + VECTOR + ); +} + +#[cfg(unix)] +#[test] +fn dangling_ignored_suffix_link_is_rejected_without_repairing_it() { + let root = fixture(); + write_vector(&vectors_root(root.path()).join("vector.json")); + let missing = root.path().join("absent"); + let link = vectors_root(root.path()).join("ignored.txt"); + std::os::unix::fs::symlink(&missing, &link).expect("dangling fixture link"); + + assert_link_rejected(root.path(), &link); + assert!(!missing.exists()); + assert_eq!(fs::read_link(&link).unwrap(), missing); +} + +#[cfg(unix)] +#[test] +fn nonregular_vector_is_rejected_before_reading_it() { + let root = fixture(); + let socket = vectors_root(root.path()).join("socket.json"); + let short_socket = root.path().join("s"); + let _listener = + std::os::unix::net::UnixListener::bind(&short_socket).expect("disposable socket fixture"); + fs::rename(&short_socket, &socket).expect("move owned socket into vector inventory"); + + let error = validate_all_conformance_vectors(root.path(), "1.0.0") + .expect_err("nonregular vector must fail admission"); + assert!(error.contains("regular file"), "{error}"); + use std::os::unix::fs::FileTypeExt; + assert!( + fs::symlink_metadata(&socket) + .unwrap() + .file_type() + .is_socket() + ); +}