myc

Self-custodial remote signer for Radroots apps
git clone https://radroots.dev/git/myc.git
Log | Files | Refs | README | LICENSE

build_policy.rs (4945B)


      1 #![forbid(unsafe_code)]
      2 
      3 use sha2::{Digest, Sha256};
      4 
      5 const MANIFEST: &str = include_str!("../Cargo.toml");
      6 const RELEASE_ACCEPTANCE: &str = include_str!("../scripts/release-acceptance.sh");
      7 const SOURCE_LOCK: &str = include_str!("../radroots.service.source_lock.v4.toml");
      8 const FLAKE_LOCK: &[u8] = include_bytes!("../flake.lock");
      9 
     10 #[test]
     11 fn manifest_freezes_the_final_rust_policy() {
     12     assert!(MANIFEST.contains("[workspace]\nresolver = \"3\""));
     13     assert!(MANIFEST.contains("[workspace.lints.rust]\nunsafe_code = \"deny\""));
     14     assert!(MANIFEST.contains("[workspace.lints.rustdoc]\nbroken_intra_doc_links = \"deny\""));
     15     assert!(MANIFEST.contains(
     16         "[workspace.lints.clippy]\ndbg_macro = \"deny\"\ntodo = \"deny\"\nunimplemented = \"deny\""
     17     ));
     18     assert!(MANIFEST.contains("[lints]\nworkspace = true"));
     19 }
     20 
     21 #[test]
     22 fn service_host_is_the_exact_default_feature_profile() {
     23     assert!(MANIFEST.contains("[features]\ndefault = [\"service-host\"]\nservice-host = []"));
     24     assert!(!MANIFEST.contains("getrandom = \"0.2\""));
     25     assert!(MANIFEST.contains(
     26         "tokio = { version = \"1.53.3\", default-features = false, features = [\"io-util\", \"macros\", \"net\", \"rt-multi-thread\", \"signal\", \"sync\", \"time\"] }"
     27     ));
     28 }
     29 
     30 #[test]
     31 fn shared_runtime_paths_is_exactly_pinned_to_the_source_locked_lib() {
     32     assert!(MANIFEST.contains(
     33         "radroots_runtime_paths = { git = \"https://github.com/radrootslabs/lib\", rev = \"e55c1749902811732167a2ce5c099e22e964624f\", version = \"=0.1.0-alpha\" }"
     34     ));
     35 }
     36 
     37 #[test]
     38 fn shared_identity_is_exactly_pinned_to_the_source_locked_lib() {
     39     assert!(MANIFEST.contains(
     40         "radroots_identity = { git = \"https://github.com/radrootslabs/lib\", rev = \"e55c1749902811732167a2ce5c099e22e964624f\", version = \"=0.1.0-alpha\" }"
     41     ));
     42 }
     43 
     44 #[test]
     45 fn shared_service_host_is_exactly_pinned_to_the_source_locked_lib() {
     46     assert!(MANIFEST.contains(
     47         "radroots_service_host = { git = \"https://github.com/radrootslabs/lib\", rev = \"e55c1749902811732167a2ce5c099e22e964624f\", version = \"=0.1.0-alpha\" }"
     48     ));
     49 }
     50 
     51 #[test]
     52 fn shared_service_sqlite_is_exactly_pinned_to_the_source_locked_lib() {
     53     assert!(MANIFEST.contains(
     54         "radroots_service_sqlite = { git = \"https://github.com/radrootslabs/lib\", rev = \"e55c1749902811732167a2ce5c099e22e964624f\", version = \"=0.1.0-alpha\" }"
     55     ));
     56 }
     57 
     58 #[test]
     59 fn shared_storage_evidence_is_exactly_pinned_to_the_source_locked_lib() {
     60     assert!(MANIFEST.contains(
     61         "radroots_storage = { git = \"https://github.com/radrootslabs/lib\", rev = \"e55c1749902811732167a2ce5c099e22e964624f\", version = \"=0.1.0-alpha\", default-features = false }"
     62     ));
     63 }
     64 
     65 #[test]
     66 fn delivery_dependencies_are_exactly_source_locked() {
     67     for dependency in [
     68         "radroots_event_codec",
     69         "radroots_transport",
     70         "radroots_transport_nostr",
     71         "radroots_transport_nostr_native",
     72     ] {
     73         assert!(
     74             MANIFEST.contains(&format!(
     75                 "{dependency} = {{ git = \"https://github.com/radrootslabs/lib\", rev = \"e55c1749902811732167a2ce5c099e22e964624f\", version = \"=0.1.0-alpha\""
     76             )),
     77             "{dependency} is not pinned to the exact source lock"
     78         );
     79     }
     80 }
     81 
     82 #[test]
     83 fn release_acceptance_checks_both_feature_profiles() {
     84     assert!(
     85         RELEASE_ACCEPTANCE.contains("cargo check --locked --all-targets --no-default-features\n")
     86     );
     87     assert!(RELEASE_ACCEPTANCE.contains(
     88         "cargo check --locked --all-targets --no-default-features --features service-host\n"
     89     ));
     90     assert!(RELEASE_ACCEPTANCE.contains("cargo test --locked -p myc_xtask\n"));
     91     assert!(!RELEASE_ACCEPTANCE.contains("nix "));
     92 }
     93 
     94 #[test]
     95 fn source_lock_binds_the_current_cargo_lock() {
     96     let digest = hex::encode(Sha256::digest(include_bytes!("../Cargo.lock")));
     97     let flake_digest = hex::encode(Sha256::digest(FLAKE_LOCK));
     98     assert!(SOURCE_LOCK.starts_with(
     99         "schema = \"radroots.service.source_lock.v4\"\ncontract_version = 4\nservice = \"myc\"\n"
    100     ));
    101     assert!(SOURCE_LOCK.contains(&format!("cargo_lock_sha256 = \"{digest}\"")));
    102     assert!(SOURCE_LOCK.contains(&format!("sha256 = \"{flake_digest}\"")));
    103     assert!(SOURCE_LOCK.contains("revision = \"e55c1749902811732167a2ce5c099e22e964624f\""));
    104     assert!(SOURCE_LOCK.contains(
    105         "[nix]\nmaterial = \"bound\"\nlib_revision = \"e55c1749902811732167a2ce5c099e22e964624f\"\nsupported_systems = [\"aarch64-darwin\", \"x86_64-linux\"]\n"
    106     ));
    107     assert!(SOURCE_LOCK.contains(
    108         "workspace_catalog_sha256 = \"424909855b2af1ffc8fa6bbfd5aa0e6d17642662c18212fef4660e71700fbfc8\""
    109     ));
    110     assert!(SOURCE_LOCK.contains(
    111         "source_archive_sha256 = \"5e6005a01402ed60225ec5207cb0db465a0d1cd4c8107e0505d2af0762dc57c0\""
    112     ));
    113     assert!(SOURCE_LOCK.ends_with(
    114         "[contract_versions]\nconfig = 1\nstate = 12\nadmin = 1\nstatus = 1\nprovider = 1\n"
    115     ));
    116 }