Test coverage and headless nvim bug fixes

This commit is contained in:
Riz Ashraf committed 2026-09-27 08:10:09 +01:00
1 parent bffc8896f1
commit 4bae4e9c08
9 files changed
+316 -58

No files matched your search

+42 -29
View File
@@ -128,37 +128,40 @@ impl MemoryState {
}
pub async fn rebuild_index(self: &Arc<Self>) {
if let Ok(new_idx) = MemoryIndex::new(&self.base_dir) {
let idx = new_idx.clone();
let idx = self.search_index.read().unwrap().clone();
idx.delete_all();
let entities: Vec<_> = self.graph.read_with(|g| g.entities.values().cloned().collect());
let tasks = self.tasks.read_with(|t| t.clone());
let snippets = self.snippets.read_with(|s| s.clone());
let adrs = self.adrs.read_with(|a| a.clone());
let entities: Vec<_> = self.graph.read_with(|g| g.entities.values().cloned().collect());
let tasks = self.tasks.read_with(|t| t.clone());
let snippets = self.snippets.read_with(|s| s.clone());
let adrs = self.adrs.read_with(|a| a.clone());
tokio::task::spawn_blocking(move || {
for e in entities {
idx.add_entity_sync(&e);
}
for task in tasks {
idx.add_task_sync(&task);
}
for snippet in snippets {
idx.add_snippet_sync(&snippet);
}
for adr in adrs {
idx.add_adr_sync(&adr);
}
})
.await
.unwrap_or_else(|e| {
tracing::error!("Failed to join tantivy index rebuild thread: {}", e);
});
println!("rebuild_index: found {} entities, {} tasks", entities.len(), tasks.len());
let _ = new_idx.commit().await;
if let Ok(mut w) = self.search_index.write() {
*w = new_idx;
let idx_clone = idx.clone();
tokio::task::spawn_blocking(move || {
println!("spawn_blocking started in rebuild_index");
for e in entities {
idx_clone.add_entity_sync(&e);
}
for task in tasks {
idx_clone.add_task_sync(&task);
}
for snippet in snippets {
idx_clone.add_snippet_sync(&snippet);
}
for adr in adrs {
idx_clone.add_adr_sync(&adr);
}
})
.await
.unwrap_or_else(|e| {
tracing::error!("Failed to join tantivy index rebuild thread: {}", e);
});
let _ = idx.commit().await;
if let Ok(mut w) = self.search_index.write() {
*w = idx;
}
}
}
@@ -204,7 +207,17 @@ mod tests {
// Check search index initialization
let idx = arc_state.search_index.read().unwrap();
// Just verify we can read it without panic
assert!(idx.search("Test", None).is_ok());
// Force reload reader to ensure it sees the commit made by rebuild_index
idx.reader.reload().unwrap();
println!("Index reader doc count: {}", idx.reader.searcher().num_docs());
let all_docs = idx.search("Test", None).expect("Search failed");
println!("All docs for 'Test': {:?}", all_docs);
// Verify the task added synchronously is actually searchable
let results = idx.search("Test", None).expect("Search failed");
assert_eq!(results.len(), 1, "Expected exactly 1 search result");
assert_eq!(results[0].0, "123", "Expected the result to be the task we just added");
assert_eq!(results[0].1, "task", "Expected document type to be task");
}
}