lib

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

package_boundary.rs (3405B)


      1 use std::collections::BTreeSet;
      2 
      3 const MANIFEST: &str = include_str!("../Cargo.toml");
      4 const ROOT: &str = include_str!("../src/lib.rs");
      5 
      6 #[test]
      7 fn sqlite_storage_declares_the_final_backend_boundaries() {
      8     fn assert_complete_storage<T: radroots_storage::Storage>() {}
      9     assert_complete_storage::<radroots_storage_sqlite::SqliteStorage>();
     10 
     11     for required in [
     12         "name = \"radroots_storage_sqlite\"",
     13         "version = \"0.1.0-alpha\"",
     14         "publish = [\"crates-io\"]",
     15         "[lib]\nname = \"radroots_storage_sqlite\"",
     16     ] {
     17         assert!(
     18             MANIFEST.contains(required),
     19             "manifest is missing `{required}`"
     20         );
     21     }
     22     assert!(!MANIFEST.contains("[features]"));
     23     assert_eq!(
     24         dependency_keys(MANIFEST),
     25         BTreeSet::from([
     26             "fs2",
     27             "getrandom",
     28             "nostr",
     29             "radroots_domain",
     30             "radroots_event",
     31             "radroots_event_codec",
     32             "radroots_nostr",
     33             "radroots_protocol",
     34             "radroots_secrets",
     35             "radroots_signing",
     36             "radroots_storage",
     37             "radroots_transport",
     38             "serde",
     39             "serde_json",
     40             "sha2",
     41             "rustix",
     42             "subtle",
     43             "sqlx",
     44             "tokio",
     45             "zeroize",
     46         ])
     47     );
     48     let manifest: toml::Value = toml::from_str(MANIFEST).expect("checked manifest");
     49     let crypto = manifest["dependencies"]["nostr"]
     50         .as_table()
     51         .expect("explicit crypto dependency");
     52     assert_eq!(
     53         crypto.keys().map(String::as_str).collect::<BTreeSet<_>>(),
     54         BTreeSet::from(["workspace", "default-features", "features"])
     55     );
     56     assert_eq!(crypto["workspace"].as_bool(), Some(true));
     57     assert_eq!(crypto["default-features"].as_bool(), Some(false));
     58     assert_eq!(
     59         crypto["features"]
     60             .as_array()
     61             .unwrap()
     62             .iter()
     63             .map(|value| value.as_str().unwrap())
     64             .collect::<BTreeSet<_>>(),
     65         BTreeSet::from(["std", "nip44"])
     66     );
     67     assert!(!ROOT.contains("SqlitePool"));
     68     assert!(!ROOT.contains("sqlx"));
     69     for forbidden in [
     70         "radroots_event_store",
     71         "radroots_outbox",
     72         "radroots_runtime_store",
     73         "radroots_protected_store",
     74         "radroots_secret_vault",
     75         "radroots_nostr_accounts",
     76     ] {
     77         assert!(!MANIFEST.contains(forbidden));
     78         assert!(!ROOT.contains(forbidden));
     79     }
     80 
     81     assert_eq!(
     82         public_modules(ROOT),
     83         BTreeSet::from([
     84             "backup",
     85             "config",
     86             "integrity",
     87             "legacy",
     88             "lock",
     89             "migration",
     90             "open",
     91             "status",
     92             "workspace",
     93         ])
     94     );
     95 }
     96 
     97 fn public_modules(source: &str) -> BTreeSet<&str> {
     98     source
     99         .lines()
    100         .filter_map(|line| line.trim().strip_prefix("pub mod "))
    101         .filter_map(|module| module.strip_suffix(';'))
    102         .collect()
    103 }
    104 
    105 fn dependency_keys(manifest: &str) -> BTreeSet<&str> {
    106     manifest
    107         .split_once("[dependencies]")
    108         .map(|(_, dependencies)| dependencies)
    109         .unwrap_or_default()
    110         .lines()
    111         .skip(1)
    112         .take_while(|line| !line.starts_with('['))
    113         .filter_map(|line| line.split_once('=').map(|(key, _)| key.trim()))
    114         .filter(|key| !key.is_empty())
    115         .collect()
    116 }