use topodb::*;
#[test]
#[ignore]
fn regenerate_fixture() {
let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/v1.redb");
let _ = std::fs::remove_file(&path);
let spec = IndexSpec {
equality: vec![PropIndex {
label: "Entity".into(),
prop: "name".into(),
}],
text: vec![PropIndex {
label: "Memory".into(),
prop: "content".into(),
}],
};
{
let db = Db::open_with(&path, spec).unwrap();
let s = ScopeId::from_u128(1);
let n1 = NodeId::from_u128(10);
let n2 = NodeId::from_u128(11);
let mut p1 = Props::new();
p1.insert("name".into(), PropValue::Str("ada".into()));
let mut p2 = Props::new();
p2.insert(
"content".into(),
PropValue::Str("fixture memory about databases".into()),
);
db.submit(vec![
Op::CreateNode {
id: n1,
scope: Scope::Id(s),
label: "Entity".into(),
props: p1,
},
Op::CreateNode {
id: n2,
scope: Scope::Id(s),
label: "Memory".into(),
props: p2,
},
])
.unwrap();
db.submit(vec![Op::SetEmbedding {
id: n2,
model: "m1".into(),
vector: vec![1.0, 0.0],
}])
.unwrap();
}
{
let mut raw = redb::Database::open(&path).unwrap();
raw.compact().unwrap();
}
assert!(
path.exists(),
"regenerate_fixture: fixture file was not created at {path:?}"
);
}
#[test]
fn v1_fixture_opens_and_reads() {
let src = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/v1.redb");
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("v1.redb");
std::fs::copy(&src, &path).unwrap(); let spec = IndexSpec {
equality: vec![PropIndex {
label: "Entity".into(),
prop: "name".into(),
}],
text: vec![PropIndex {
label: "Memory".into(),
prop: "content".into(),
}],
};
let db = Db::open_with(&path, spec).unwrap();
let s = ScopeId::from_u128(1);
let scopes = ScopeSet::of(&[s]);
assert_eq!(
db.nodes_by_prop(&scopes, "Entity", "name", &PropValue::Str("ada".into()))
.unwrap()
.len(),
1
);
assert_eq!(db.search_text(&scopes, "databases", 10).unwrap().len(), 1);
assert_eq!(
db.search_vector(&VectorQuery {
scopes: scopes.clone(),
model: "m1".into(),
vector: vec![1.0, 0.0],
k: 1,
candidates: None,
})
.unwrap()
.len(),
1
);
assert_eq!(db.current_seq().unwrap(), 3);
}