use semantic_memory::{MemoryConfig, MemoryStore, MockEmbedder};
use tempfile::TempDir;
fn test_store_in(dir: &std::path::Path) -> MemoryStore {
let config = MemoryConfig {
base_dir: dir.to_path_buf(),
..Default::default()
};
let embedder = Box::new(MockEmbedder::new(768));
MemoryStore::open_with_embedder(config, embedder).unwrap()
}
#[tokio::test]
async fn v5_migration_adds_columns() {
let tmp = TempDir::new().unwrap();
let store = test_store_in(tmp.path());
let fact_id = store
.add_fact(
"general",
"v5 migration added quantized embedding columns",
None,
None,
)
.await
.unwrap();
let fact = store.get_fact(&fact_id).await.unwrap();
assert!(fact.is_some(), "Fact should exist after V5 migration");
let results = store
.search("v5 migration quantized", Some(5), None, None)
.await
.unwrap();
assert!(!results.is_empty(), "Search should work after V5 migration");
}
#[tokio::test]
async fn v5_migration_idempotent() {
let tmp = TempDir::new().unwrap();
{
let store = test_store_in(tmp.path());
store
.add_fact("general", "idempotent migration test fact", None, None)
.await
.unwrap();
}
let store = test_store_in(tmp.path());
let results = store
.search("idempotent migration", Some(5), None, None)
.await
.unwrap();
assert!(
!results.is_empty(),
"Data should survive reopen; migration should be idempotent"
);
let fact_id = store
.add_fact(
"general",
"second fact after idempotent migration reopen",
None,
None,
)
.await
.unwrap();
let fact = store.get_fact(&fact_id).await.unwrap();
assert!(
fact.is_some(),
"New fact should be writable after idempotent migration"
);
}