mod alias_lane;
use std::time::Duration;
use serde_json::json;
use trusty_memory::bm25_lane::Bm25Lane;
use trusty_memory::tools::dispatch_tool;
async fn poll_corpus_for(lane: &Bm25Lane, palace: &str, query: &str) -> Vec<String> {
for _ in 0..100 {
if let Ok(hits) = lane.search(palace, query, 10).await {
if !hits.is_empty() {
return hits.into_iter().map(|h| h.doc_id).collect();
}
}
tokio::time::sleep(Duration::from_millis(50)).await;
}
Vec::new()
}
#[tokio::test(flavor = "multi_thread")]
async fn an_aliased_write_indexes_into_the_resolved_palaces_corpus() {
trusty_common::memory_core::retrieval::seed_shared_embedder_with_mock();
let fx = alias_lane::Aliased::new("w");
let token = "zqxjrollback";
let payload = dispatch_tool(
&fx.state,
"memory_remember",
json!({
"palace": fx.alias,
"text": format!("{token} procedure for the staged deployment plan"),
"force": true,
}),
)
.await
.expect("memory_remember through the alias");
let drawer_id = payload["drawer_id"]
.as_str()
.unwrap_or_else(|| panic!("the write was skipped, not stored: {payload}"))
.to_string();
let lane = fx.state.bm25_lane().expect("the lane is armed");
let indexed = poll_corpus_for(lane, &fx.canonical, token).await;
assert!(
indexed.contains(&drawer_id),
"#5036: a write through alias '{}' must be indexed into '{}'s corpus. Got {indexed:?}",
fx.alias,
fx.canonical,
);
assert!(
!fx.state.data_root.join(&fx.alias).join("bm25").exists(),
"#5036: no BM25 index may be created for the alias slug on the write path"
);
fx.shutdown().await;
}