lib

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

public_surface.rs (5152B)


      1 #[test]
      2 fn approved_module_skeleton_is_public() {
      3     #[allow(unused_imports)]
      4     use radroots::{
      5         client, event, farm, identity, knowledge, listing, signing, storage, sync, trade, transport,
      6     };
      7 }
      8 
      9 #[test]
     10 fn root_exports_only_the_client_boundary() {
     11     fn assert_client<T: Clone>() {}
     12     #[cfg(not(target_arch = "wasm32"))]
     13     fn assert_native_client<T: Send + Sync>() {}
     14     fn assert_error<T: std::error::Error + Send + Sync + 'static>() {}
     15 
     16     assert_client::<radroots::Client>();
     17     #[cfg(not(target_arch = "wasm32"))]
     18     assert_native_client::<radroots::Client>();
     19     assert_error::<radroots::Error>();
     20     let result: radroots::Result<()> = Ok(());
     21     assert!(result.is_ok());
     22 }
     23 
     24 #[test]
     25 fn canonical_domain_paths_compile() {
     26     #[allow(unused_imports)]
     27     use radroots::{
     28         event::{Event, EventId, GenericEventDraft},
     29         farm::{Farm, FarmPublicLocation, Plan as FarmPlan, PrepareRequest as FarmRequest},
     30         identity::{AccountId, PublicKey, Username},
     31         listing::{EditV1, OperationalListing, Plan as ListingPlan},
     32         signing::{Mode, Provider},
     33         storage::{IntegrityStatus, Operations as StorageOperations, Status},
     34         trade::{Money, MutationV1, Plan as TradePlan, Projection},
     35         transport::{Profile, SatisfactionPolicy, Target, TargetSet, TransportId},
     36     };
     37 }
     38 
     39 #[cfg(feature = "client")]
     40 #[test]
     41 fn ordinary_memory_and_local_only_construction_is_inert() {
     42     let client = radroots::Client::preview();
     43     assert_eq!(
     44         client.state(),
     45         radroots_execution::session::SessionState::Ready
     46     );
     47     assert!(radroots::client::local_only().is_local_only());
     48 }
     49 
     50 #[cfg(any(feature = "nostr", feature = "full"))]
     51 #[test]
     52 fn retained_advanced_transport_composition_is_inert() {
     53     use std::sync::Arc;
     54 
     55     use radroots::transport::{EventSink, EventSource};
     56     use radroots_transport::{
     57         DeliveryReceipt, DeliveryRequest, Error, FetchPage, FetchRequest, SinkFailure, SinkStatus,
     58         SourceStatus, outcome::Retryability, source::BoxFuture,
     59     };
     60 
     61     struct Source;
     62     struct Sink;
     63 
     64     impl EventSource for Source {
     65         fn status(&self) -> BoxFuture<'_, Result<SourceStatus, Error>> {
     66             Box::pin(async { Err(Error::UnsupportedOperation) })
     67         }
     68 
     69         fn fetch(&self, _request: FetchRequest) -> BoxFuture<'_, Result<FetchPage, Error>> {
     70             Box::pin(async { Err(Error::UnsupportedOperation) })
     71         }
     72     }
     73 
     74     impl EventSink for Sink {
     75         fn status(&self) -> BoxFuture<'_, Result<SinkStatus, Error>> {
     76             Box::pin(async { Err(Error::UnsupportedOperation) })
     77         }
     78 
     79         fn deliver(
     80             &self,
     81             request: DeliveryRequest,
     82         ) -> BoxFuture<'_, Result<DeliveryReceipt, SinkFailure>> {
     83             Box::pin(async move {
     84                 Err(SinkFailure::for_request(
     85                     &request,
     86                     "test_sink_unavailable",
     87                     Retryability::Terminal,
     88                     None,
     89                     None,
     90                     Vec::new(),
     91                 )
     92                 .expect("test sink failure"))
     93             })
     94         }
     95     }
     96 
     97     // The retained advanced SDK owns this source/sink composition until its
     98     // concrete ordinary network host is qualified. This does not claim the
     99     // new preview/native Client implements a network worker.
    100     let client = radroots_sdk::ClientBuilder::memory_default()
    101         .source(Arc::new(Source))
    102         .sink(Arc::new(Sink))
    103         .build()
    104         .expect("explicit advanced transport client");
    105     assert!(client.source().expect("source").is_some());
    106     assert!(client.sink().expect("sink").is_some());
    107 }
    108 
    109 #[cfg(any(feature = "geonames", feature = "full"))]
    110 #[test]
    111 fn geonames_selection_is_explicit() {
    112     assert!(radroots::client::geonames_enabled());
    113 }
    114 
    115 #[cfg(any(feature = "knowledge", feature = "full"))]
    116 #[test]
    117 fn knowledge_selection_is_explicit() {
    118     assert!(radroots::client::knowledge_enabled());
    119 }
    120 
    121 #[cfg(any(feature = "knowledge", feature = "full"))]
    122 #[test]
    123 fn canonical_knowledge_paths_compile() {
    124     #[allow(unused_imports)]
    125     use radroots::knowledge::{KnowledgeClaim, WikiArticle, normalize_wiki_d_tag};
    126 }
    127 
    128 #[cfg(feature = "client")]
    129 #[test]
    130 fn preview_handles_share_explicit_start_and_actual_memory_close() {
    131     use radroots::{Client, StartMode};
    132     use radroots_execution::session::SessionState;
    133     use radroots_storage::status::{ShutdownState, StorageBackend};
    134     let client = Client::preview();
    135     let clone = client.clone();
    136     let status = futures::executor::block_on(client.storage_status()).unwrap();
    137     assert_eq!(status.backend(), StorageBackend::Memory);
    138     assert_eq!(status.shutdown(), ShutdownState::Open);
    139     assert!(client.signer_session().is_none());
    140     let started = futures::executor::block_on(client.start(StartMode::LocalOnly)).unwrap();
    141     assert_eq!(started.state(), SessionState::Running);
    142     assert_eq!(clone.state(), SessionState::Running);
    143     let receipt = futures::executor::block_on(clone.close()).unwrap();
    144     assert_eq!(receipt.storage().shutdown(), ShutdownState::Closed);
    145     assert_eq!(client.state(), SessionState::Closed);
    146 }