package_boundary.rs (3287B)
1 use std::collections::BTreeSet; 2 3 const MANIFEST: &str = include_str!("../Cargo.toml"); 4 const WORKSPACE: &str = include_str!("../../../Cargo.toml"); 5 const ROOT: &str = include_str!("../src/lib.rs"); 6 const README: &str = include_str!("../README.md"); 7 8 #[test] 9 fn package_has_final_identity_and_exact_dependencies() { 10 assert!(MANIFEST.contains("name = \"radroots\"")); 11 assert!(MANIFEST.contains("publish = [\"crates-io\"]")); 12 assert_eq!( 13 dependency_names(MANIFEST), 14 BTreeSet::from([ 15 "radroots_core", 16 "radroots_event", 17 "radroots_identity", 18 "radroots_sdk", 19 "radroots_trade", 20 "radroots_transport", 21 ]) 22 ); 23 assert!(WORKSPACE.contains( 24 "radroots_sdk = { path = \"crates/sdk\", version = \"=0.1.0-alpha\", default-features = false }" 25 )); 26 } 27 28 #[test] 29 fn features_forward_the_exact_user_oriented_graph() { 30 for forwarding in [ 31 "default = [\"client\"]", 32 "client = [\"radroots_sdk/default\"]", 33 "native = [\"client\", \"radroots_sdk/native\"]", 34 "nostr = [\"client\", \"radroots_sdk/nostr\"]", 35 "nip46 = [\"nostr\", \"radroots_sdk/nip46\"]", 36 "radrootsd = [\"client\", \"radroots_sdk/radrootsd\"]", 37 "geonames = [\"client\", \"radroots_sdk/geonames\"]", 38 "knowledge = [\"client\", \"radroots_sdk/knowledge\"]", 39 "full = [\"radroots_sdk/full\"]", 40 ] { 41 assert!(MANIFEST.contains(forwarding), "missing `{forwarding}`"); 42 } 43 for forbidden in ["reticulum", "mesh", "simplex", "nostrdb", "replica", "sp1"] { 44 assert!( 45 !MANIFEST.to_ascii_lowercase().contains(forbidden), 46 "forbidden feature vocabulary `{forbidden}`" 47 ); 48 } 49 } 50 51 #[test] 52 fn root_has_exact_exports_and_no_sdk_namespace() { 53 assert!(ROOT.contains("pub use radroots_sdk::{Client, ClientBuilder, Error, Result};")); 54 assert!(!ROOT.contains("pub mod sdk")); 55 assert!(!ROOT.contains("pub use radroots_sdk::*")); 56 assert_eq!(ROOT.matches("pub use ").count(), 1); 57 assert!(README.contains("```compile_fail\nuse radroots::sdk;\n```")); 58 } 59 60 #[test] 61 fn modules_use_deliberate_reexports_without_wildcards() { 62 let source_root = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("src"); 63 for entry in std::fs::read_dir(source_root).expect("read facade source") { 64 let path = entry.expect("read facade source entry").path(); 65 if path.extension().and_then(|value| value.to_str()) != Some("rs") { 66 continue; 67 } 68 let source = std::fs::read_to_string(&path).expect("read facade module"); 69 assert!( 70 !source.contains("::*"), 71 "{} contains a wildcard reexport", 72 path.display() 73 ); 74 assert!( 75 !source.contains("pub mod sdk"), 76 "{} exposes the forbidden SDK namespace", 77 path.display() 78 ); 79 } 80 } 81 82 fn dependency_names(manifest: &str) -> BTreeSet<&str> { 83 manifest 84 .split_once("[dependencies]") 85 .expect("dependency section") 86 .1 87 .split_once("\n[") 88 .expect("section after dependencies") 89 .0 90 .lines() 91 .filter_map(|line| line.split_once(" = ").map(|(name, _)| name.trim())) 92 .collect() 93 }