AI search engine and MCP server for bots and agents. One Rust binary indexes code, docs, logs, JSONL/CSV and PDFs for BM25 full-text, vector and hybrid search, code search without grep, agent memory and RAG. Elasticsearch-compatible API; Corpus Hub serves hundreds of reference memory corpora.
Rust agent-memoryai-agentsbm25claude-codeclicode-searchcursordatabaseelasticsearchfull-text-searchhybrid-searchjsonllocal-firstmcpmcp-servermodel-context-protocolragrustsearch-enginevector-search
fix(autoindex): #589 sweep exact dataset indices + mock-ES integration test
xerj-org350c0f4ea907
diff --git a/engine/crates/xerj-autoindex/src/incremental_reconcile_http_tests.rs b/engine/crates/xerj-autoindex/src/incremental_reconcile_http_tests.rsindex 04b201ce7..d3dd0f084 100644--- a/engine/crates/xerj-autoindex/src/incremental_reconcile_http_tests.rs+++ b/engine/crates/xerj-autoindex/src/incremental_reconcile_http_tests.rs@@ -2016,3 +2016,87 @@ fn a_journal_that_fails_its_own_revalidation_names_the_rebuild_route() {"the refusal must name the recovery route, not just the invariant: {rendered}");}++/// #589: `sweep_excluded_groups` actually deletes an excluded file's published+/// documents (by `ax_file`, across the plan's dataset indices) and its catalog+/// document (by `path`), while leaving every OTHER file's documents intact.+/// Exercised over the real mock HTTP backend so the delete-by-query truly runs.+#[test]+fn sweep_excluded_groups_deletes_only_the_excluded_files_documents() {+ let ep = HttpEndpoint::start();++ // Seed two files' records in one dataset index, plus their catalog docs.+ {+ let mut st = ep.state.lock().unwrap();+ let ds = "incremental-http-ds".to_string();+ st.docs.insert(+ (ds.clone(), "d1".into()),+ json!({"ax_file": "key-excluded", "body": "secret"}),+ );+ st.docs.insert(+ (ds.clone(), "d2".into()),+ json!({"ax_file": "key-kept", "body": "kept"}),+ );+ st.docs.insert(+ (catalog::CATALOG_INDEX.to_string(), "file:excluded".into()),+ json!({"doc_kind": "file", "path": "secret.csv"}),+ );+ st.docs.insert(+ (catalog::CATALOG_INDEX.to_string(), "file:kept".into()),+ json!({"doc_kind": "file", "path": "kept.csv"}),+ );+ }++ let es = Es::with_bulk_timeout(&ep.url, None, 30).expect("es client");++ let mut plan = Plan::default();+ plan.datasets.push(crate::state::PlanDataset {+ slug: "ds".into(),+ index: "incremental-http-ds".into(),+ family: "csv".into(),+ group: None,+ specs: Vec::new(),+ time_field: None,+ semantic_field: None,+ sampled_records: 1,+ file_count: 1,+ });++ let excluded = vec![InventoryDeltaEntry {+ file_key: "key-excluded".into(),+ path: "secret.csv".into(),+ }];++ sweep_excluded_groups(&es, &plan, &excluded).expect("sweep");++ let st = ep.state.lock().unwrap();+ // The excluded file's dataset record is gone.+ assert!(+ !st.docs+ .values()+ .any(|d| d.get("ax_file").and_then(Value::as_str) == Some("key-excluded")),+ "#589: the excluded file's indexed records must be swept"+ );+ // Its catalog document is gone.+ assert!(+ !st.docs+ .iter()+ .any(|((idx, _), d)| idx == catalog::CATALOG_INDEX+ && d.get("path").and_then(Value::as_str) == Some("secret.csv")),+ "#589: the excluded file's catalog document must be swept"+ );+ // Every other file is untouched (no over-deletion).+ assert!(+ st.docs+ .values()+ .any(|d| d.get("ax_file").and_then(Value::as_str) == Some("key-kept")),+ "#589: a different file's records must NOT be swept"+ );+ assert!(+ st.docs+ .iter()+ .any(|((idx, _), d)| idx == catalog::CATALOG_INDEX+ && d.get("path").and_then(Value::as_str) == Some("kept.csv")),+ "#589: a different file's catalog document must NOT be swept"+ );+}diff --git a/engine/crates/xerj-autoindex/src/lib.rs b/engine/crates/xerj-autoindex/src/lib.rsindex 6ce465c29..6001f2893 100644--- a/engine/crates/xerj-autoindex/src/lib.rs+++ b/engine/crates/xerj-autoindex/src/lib.rs@@ -3068,11 +3068,23 @@ fn finish_generated_run(es: &Es, journal: &mut state::Journal, cfg: &IndexCfg) -/// KNOWN GAP (#589, next hunk): graph edges taught by the file remain in the/// edges index until it is swept too — the same limitation the refusal message/// already documents in `edges_note`.-fn sweep_excluded_groups(es: &Es, prefix: &str, excluded: &[InventoryDeltaEntry]) -> Result<()> {- let corpus = format!("{prefix}-*");+fn sweep_excluded_groups(es: &Es, plan: &Plan, excluded: &[InventoryDeltaEntry]) -> Result<()> {+ // Exact dataset indices from the plan — the same resolution the replacement+ // delete path uses (`ds_rt` → `rt.index`); a `{prefix}-*` wildcard would be+ // untestable and could reach indices this corpus does not own.+ let mut indices: Vec<&str> = plan.datasets.iter().map(|d| d.index.as_str()).collect();+ indices.sort_unstable();+ indices.dedup();for entry in excluded {- es.delete_by_query(&corpus, &json!({"term": {"ax_file": entry.file_key}}))- .with_context(|| format!("sweep indexed records for newly-excluded {}", entry.path))?;+ for index in &indices {+ es.delete_by_query(index, &json!({"term": {"ax_file": entry.file_key}}))+ .with_context(|| {+ format!(+ "sweep indexed records for newly-excluded {} in {index}",+ entry.path+ )+ })?;+ }es.delete_by_query(catalog::CATALOG_INDEX,&json!({"term": {"path": entry.path}}),@@ -3554,7 +3566,7 @@ pub fn run_index_report(cfg: IndexCfg) -> Result<(i32, Option<Value>)> {// continue, rather than leaving them live in the destination. Genuine// deletions above still refuse; never mutate under --dry-run.if !delta.excluded_content_groups.is_empty() && !cfg.dry_run {- sweep_excluded_groups(&es, &cfg.prefix, &delta.excluded_content_groups)+ sweep_excluded_groups(&es, prior_plan, &delta.excluded_content_groups).context("sweep newly-excluded content groups")?;}}@@ -3814,7 +3826,7 @@ pub fn run_index_report(cfg: IndexCfg) -> Result<(i32, Option<Value>)> {// #589: sweep documents left behind by a widened exclusion (see gate// above). Genuine deletions still refuse; never mutate under --dry-run.if !delta.excluded_content_groups.is_empty() && !cfg.dry_run {- sweep_excluded_groups(&es, &cfg.prefix, &delta.excluded_content_groups)+ sweep_excluded_groups(&es, &plan, &delta.excluded_content_groups).context("sweep newly-excluded content groups")?;}}