lib

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

package_boundary.rs (2384B)


      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             "radroots_event",
     28             "radroots_event_codec",
     29             "radroots_secrets",
     30             "radroots_storage",
     31             "radroots_transport",
     32             "serde",
     33             "serde_json",
     34             "sha2",
     35             "sqlx",
     36         ])
     37     );
     38     assert!(!ROOT.contains("SqlitePool"));
     39     assert!(!ROOT.contains("sqlx"));
     40     for forbidden in [
     41         "radroots_event_store",
     42         "radroots_outbox",
     43         "radroots_runtime_store",
     44         "radroots_protected_store",
     45         "radroots_secret_vault",
     46         "radroots_nostr_accounts",
     47     ] {
     48         assert!(!MANIFEST.contains(forbidden));
     49         assert!(!ROOT.contains(forbidden));
     50     }
     51 
     52     assert_eq!(
     53         public_modules(ROOT),
     54         BTreeSet::from([
     55             "backup",
     56             "config",
     57             "integrity",
     58             "legacy",
     59             "lock",
     60             "migration",
     61             "open",
     62             "status",
     63         ])
     64     );
     65 }
     66 
     67 fn public_modules(source: &str) -> BTreeSet<&str> {
     68     source
     69         .lines()
     70         .filter_map(|line| line.trim().strip_prefix("pub mod "))
     71         .filter_map(|module| module.strip_suffix(';'))
     72         .collect()
     73 }
     74 
     75 fn dependency_keys(manifest: &str) -> BTreeSet<&str> {
     76     manifest
     77         .split_once("[dependencies]")
     78         .map(|(_, dependencies)| dependencies)
     79         .unwrap_or_default()
     80         .lines()
     81         .skip(1)
     82         .take_while(|line| !line.starts_with('['))
     83         .filter_map(|line| line.split_once('=').map(|(key, _)| key.trim()))
     84         .filter(|key| !key.is_empty())
     85         .collect()
     86 }