|
| 1 | +//! `tinymemory-core`'s own store, held to the driver contract (#18 §A3/§E1). |
| 2 | +//! |
| 3 | +//! The TinyCortex adapter and the three hosted adapters each have a |
| 4 | +//! `conformance_test.rs` asserting they uphold `MemoryProvider`. This crate's |
| 5 | +//! own store had no such file, because until `create_memory_provider` there was |
| 6 | +//! no way to express it as a driver at all — which is precisely the gap §A3 |
| 7 | +//! describes. These are the missing equivalents. |
| 8 | +
|
| 9 | +// `expect` is the assertion mechanism here, and its message is the failure |
| 10 | +// diagnostic — `expect_used` is `warn` workspace-wide (Cargo.toml) and CI runs |
| 11 | +// clippy with `-D warnings`. Scoped to that one lint: unlike the sibling |
| 12 | +// conformance tests this file has no explicit `panic!`, so it does not need |
| 13 | +// `clippy::panic` too. |
| 14 | +#![allow(clippy::expect_used)] |
| 15 | + |
| 16 | +use std::sync::Arc; |
| 17 | + |
| 18 | +use tinymemory_api::host::MemoryConfig; |
| 19 | +use tinymemory_api::provider::{audit_provider, MemoryProvider}; |
| 20 | + |
| 21 | +use super::factories::create_memory_provider; |
| 22 | + |
| 23 | +/// Builds a provider over a real store in a throwaway directory. |
| 24 | +/// |
| 25 | +/// A temp dir rather than an in-memory backend on purpose: `UnifiedMemory` is a |
| 26 | +/// SQLite store, and a driver that only ever answered from memory would not be |
| 27 | +/// the thing hosts actually bind. |
| 28 | +fn provider(dir: &std::path::Path) -> Arc<dyn MemoryProvider> { |
| 29 | + // The store resolves its embedder through the process-global `EmbeddingHost` |
| 30 | + // and refuses to open without one. `init` is the crate's idempotent stub |
| 31 | + // installer, so this is the same seam every other core test uses rather |
| 32 | + // than a second setup path. |
| 33 | + crate::test_seams::init(); |
| 34 | + create_memory_provider(&MemoryConfig::default(), dir).expect("the bundled store opens") |
| 35 | +} |
| 36 | + |
| 37 | +#[tokio::test] |
| 38 | +async fn the_core_store_upholds_the_contract() { |
| 39 | + let dir = tempfile::tempdir().expect("temp dir"); |
| 40 | + tinymemory_conformance::assert_provider(provider(dir.path())).await; |
| 41 | +} |
| 42 | + |
| 43 | +#[tokio::test] |
| 44 | +async fn the_core_store_actually_retains() { |
| 45 | + // The conformance suite tolerates a driver that refuses a write; without |
| 46 | + // this probe a store that silently retained nothing could pass it |
| 47 | + // vacuously. That is not hypothetical — it is how a broken double slipped |
| 48 | + // through review once already. |
| 49 | + let dir = tempfile::tempdir().expect("temp dir"); |
| 50 | + assert!( |
| 51 | + tinymemory_conformance::retains_writes(provider(dir.path()).as_ref()).await, |
| 52 | + "the bundled store reported success and kept nothing" |
| 53 | + ); |
| 54 | +} |
| 55 | + |
| 56 | +#[tokio::test] |
| 57 | +async fn it_binds_under_the_reserved_namespace_id() { |
| 58 | + let dir = tempfile::tempdir().expect("temp dir"); |
| 59 | + assert_eq!( |
| 60 | + provider(dir.path()).driver_id(), |
| 61 | + tinymemory::registry::NAMESPACE_DRIVER_ID, |
| 62 | + "the bundled store must not bind under another engine's id" |
| 63 | + ); |
| 64 | +} |
| 65 | + |
| 66 | +#[tokio::test] |
| 67 | +async fn its_advertised_capabilities_match_what_it_exposes() { |
| 68 | + // `audit_provider` is the honesty check: advertised families must equal |
| 69 | + // reachable accessors. Wrapping through `MemoryTraitProvider` derives the |
| 70 | + // advertisement from the accessors, so this should hold by construction — |
| 71 | + // it runs because that construction lives in another crate. |
| 72 | + let dir = tempfile::tempdir().expect("temp dir"); |
| 73 | + audit_provider(provider(dir.path()).as_ref()).expect("the bundled store is honest"); |
| 74 | +} |
| 75 | + |
| 76 | +#[tokio::test] |
| 77 | +async fn the_registry_admits_it_as_an_embedded_driver() { |
| 78 | + use tinymemory::registry::{DriverClass, DriverRegistry, NAMESPACE_DRIVER_ID}; |
| 79 | + |
| 80 | + // A reserved id with no admission path would be a driver nothing can bind. |
| 81 | + let admitted = DriverRegistry::builtin() |
| 82 | + .admit(NAMESPACE_DRIVER_ID, None, Default::default()) |
| 83 | + .expect("the bundled store is admissible"); |
| 84 | + assert_eq!(admitted.class, DriverClass::Embedded); |
| 85 | +} |
0 commit comments