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
test(search): prove ambiguous passage requests fail cleanly
buger53362391fd49
diff --git a/engine/crates/xerj-api/src/es_compat.rs b/engine/crates/xerj-api/src/es_compat.rsindex d6234e1cc..335830bcb 100644--- a/engine/crates/xerj-api/src/es_compat.rs+++ b/engine/crates/xerj-api/src/es_compat.rs@@ -15482,6 +15482,109 @@ mod passage_scroll_tests {);}}++ async fn assert_ambiguous_passage_query_is_actionable_400(app: &axum::Router, body: Value) {+ let response = app+ .clone()+ .oneshot(+ Request::post("/passage-composition/_search")+ .header("content-type", "application/json")+ .body(Body::from(body.to_string()))+ .unwrap(),+ )+ .await+ .unwrap();+ assert_eq!(+ response.status(),+ StatusCode::BAD_REQUEST,+ "ambiguous passage ownership must be a caller-fixable 400, not a 500"+ );+ let bytes = axum::body::to_bytes(response.into_body(), usize::MAX)+ .await+ .unwrap();+ let body: Value = serde_json::from_slice(&bytes).unwrap();+ assert_eq!(body["status"], 400, "{body}");+ let reason = body["error"]["reason"].as_str().unwrap_or_default();+ assert!(+ reason.contains("one unambiguous winning passage"),+ "error must explain why provenance is ambiguous: {body}"+ );+ assert!(+ reason.contains("request `_passage` only with a single semantic/kNN clause")+ && reason.contains("omit `_passage` for fusion"),+ "error must tell the caller how to fix the request: {body}"+ );+ }++ #[tokio::test]+ async fn ambiguous_multi_knn_passage_requests_are_http_400_in_both_orders() {+ let state = test_state();+ state+ .engine+ .create_index("passage-composition", Schema::empty())+ .unwrap();+ let app = crate::router::build_es_compat_router(state);+ let knn_a = json!({+ "field": "embedding_a",+ "query_vector": [1.0, 0.0],+ "k": 10+ });+ let knn_b = json!({+ "field": "embedding_b",+ "query_vector": [0.0, 1.0],+ "k": 10+ });++ for knn in [+ json!([knn_a.clone(), knn_b.clone()]),+ json!([knn_b.clone(), knn_a.clone()]),+ ] {+ assert_ambiguous_passage_query_is_actionable_400(+ &app,+ json!({"fields": ["_passage"], "knn": knn}),+ )+ .await;+ }+ }++ #[tokio::test]+ async fn ambiguous_hybrid_passage_requests_are_http_400_in_both_orders() {+ let state = test_state();+ state+ .engine+ .create_index("passage-composition", Schema::empty())+ .unwrap();+ let app = crate::router::build_es_compat_router(state);+ let semantic = json!({+ "query": {+ "semantic": {+ "field": "content",+ "query": "quarterly evidence",+ "k": 10+ }+ }+ });+ let lexical = json!({"query": {"match_all": {}}});++ for queries in [+ json!([semantic.clone(), lexical.clone()]),+ json!([lexical.clone(), semantic.clone()]),+ ] {+ assert_ambiguous_passage_query_is_actionable_400(+ &app,+ json!({+ "fields": ["_passage"],+ "query": {+ "hybrid": {+ "queries": queries,+ "fusion": "rrf"+ }+ }+ }),+ )+ .await;+ }+ }}#[derive(Debug, Deserialize, Default)]