lib

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

workspace_consumers.rs (2583B)


      1 use std::fs;
      2 use std::path::{Path, PathBuf};
      3 
      4 const REMOVED_CLIENT_NAMES: [&str; 5] = [
      5     "RadrootsNostrClient",
      6     "RadrootsNostrClientKey",
      7     "RadrootsNostrMonitor",
      8     "RadrootsNostrMonitorNotification",
      9     "RadrootsNostrRelayStatus",
     10 ];
     11 
     12 #[test]
     13 fn ready_workspace_consumers_do_not_import_the_removed_client_surface() {
     14     let workspace = workspace_root();
     15     for source in rust_sources(workspace.join("crates")) {
     16         let contents = fs::read_to_string(&source).expect("read workspace source");
     17         for removed in REMOVED_CLIENT_NAMES {
     18             assert!(
     19                 !contents.contains(removed),
     20                 "ready consumer {} imports removed `{removed}`",
     21                 source.display()
     22             );
     23         }
     24     }
     25 }
     26 
     27 #[test]
     28 fn superseded_transport_packages_and_nostrdb_adapter_are_removed() {
     29     let workspace = workspace_root();
     30     assert!(!workspace.join("crates/nostr_runtime/Cargo.toml").exists());
     31     assert!(!workspace.join("crates/net/Cargo.toml").exists());
     32     let workspace_manifest =
     33         fs::read_to_string(workspace.join("Cargo.toml")).expect("workspace manifest");
     34     let nostrdb_manifest =
     35         fs::read_to_string(workspace.join("crates/nostrdb/Cargo.toml")).expect("nostrdb manifest");
     36     let deviations = fs::read_to_string(workspace.join("contracts/architecture/deviations.toml"))
     37         .expect("deviation authority");
     38 
     39     assert!(!workspace_manifest.contains("radroots_nostr_runtime"));
     40     assert!(!workspace_manifest.contains("radroots_net"));
     41     assert!(!nostrdb_manifest.contains("runtime-adapter"));
     42     assert!(deviations.contains(
     43         "Delete radroots_nostr_runtime, its NostrDB runtime adapter, and radroots_net during Step 301 qualification"
     44     ));
     45 }
     46 
     47 fn workspace_root() -> PathBuf {
     48     Path::new(env!("CARGO_MANIFEST_DIR"))
     49         .join("../..")
     50         .canonicalize()
     51         .expect("workspace root")
     52 }
     53 
     54 fn rust_sources(root: PathBuf) -> Vec<PathBuf> {
     55     let mut pending = vec![root];
     56     let mut sources = Vec::new();
     57     while let Some(path) = pending.pop() {
     58         for entry in fs::read_dir(path).expect("read source directory") {
     59             let path = entry.expect("source entry").path();
     60             if path.is_dir() {
     61                 pending.push(path);
     62             } else if path.extension().is_some_and(|extension| extension == "rs")
     63                 && path
     64                     .components()
     65                     .any(|component| component.as_os_str() == "src")
     66             {
     67                 sources.push(path);
     68             }
     69         }
     70     }
     71     sources.sort();
     72     sources
     73 }