about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorAlexander_Kabui <alexanderkabui@proton.me>2026-11-17 12:11:19 +0300
committerAlexander_Kabui <alexanderkabui@proton.me>2026-11-17 14:06:50 +0300
commitf76043bf82b6c86b5e844b27b53e957d770aeb33 (patch)
tree5b4257c2523410f077e9fbc4f71f3fd797360b9f /tests
parente13bbd27d0b7addd277d0f50d9e90fee2a936211 (diff)
downloadgenenetwork4-search/extract-engine.tar.gz
* src/search (engine): no default arm, so a wrong name is refused. search/extract-engine
An unrecognised SEARCH_ENGINE used to fall through to the gn3 proxy, which
turned a typo into a silently different engine. The arms are now explicit -
"crate"/"native" for the in-process engine, "forward" for the proxy - and
anything else returns the value it was given. src/search/native.rs is deleted;
the former name resolves through the same arm.
Diffstat (limited to 'tests')
-rw-r--r--tests/search_crate_engine.rs16
-rw-r--r--tests/search_native.rs18
-rw-r--r--tests/search_native_dev_corpus.rs4
-rw-r--r--tests/search_native_shapes.rs4
4 files changed, 29 insertions, 13 deletions
diff --git a/tests/search_crate_engine.rs b/tests/search_crate_engine.rs
index 446bbf5..5273d9c 100644
--- a/tests/search_crate_engine.rs
+++ b/tests/search_crate_engine.rs
@@ -124,3 +124,19 @@ fn a_crate_hit_deserialises_into_the_route_hit_without_losing_keys() {
     // twin that could drift from it.
     let _: Option<SearchError> = None;
 }
+
+#[tokio::test]
+async fn an_unknown_engine_name_is_refused_by_name() {
+    // A misconfiguration must not fall through to whichever engine sits last in
+    // the match, so the dispatcher has no default arm and names the value.
+    unsafe { std::env::set_var("SEARCH_ENGINE", "cratee") };
+    let error = genenetwork4::search::search("alcohol", "phenotype", 5, 1)
+        .await
+        .expect_err("an unknown engine name is refused");
+    let text = format!("{error:?}");
+    assert!(
+        text.contains("SEARCH_ENGINE") && text.contains("cratee"),
+        "the refusal names the setting and the value it was given: {text}"
+    );
+    unsafe { std::env::set_var("SEARCH_ENGINE", "crate") };
+}
diff --git a/tests/search_native.rs b/tests/search_native.rs
index 6c8f58e..3b75687 100644
--- a/tests/search_native.rs
+++ b/tests/search_native.rs
@@ -14,7 +14,7 @@
 //! development index is never a recorded-count source, per
 //! AMENDMENT B — counts are printed as reference data only).
 
-use genenetwork4::search::{self as seam, Engine, SearchError, SearchHit, native::Native};
+use genenetwork4::search::{self as seam, Engine, SearchError, SearchHit, gnindex::CrateEngine};
 
 /// The name of a result's variant, so a failed assertion can name what
 /// it got without requiring `SearchHit: Debug`.
@@ -47,7 +47,7 @@ async fn native_engine_error_contract_and_per_page_invariant() {
     //    carries the parser's own classification.
     set("XAPIAN_DB_PATH", "");
     set("SEARCH_ENGINE", "native");
-    let result = Native.search("alcohol AND", "phenotype", 5, 1).await;
+    let result = CrateEngine::from_config().search("alcohol AND", "phenotype", 5, 1).await;
     assert_eq!(variant_name(&result), "InvalidQuery");
     let Err(SearchError::InvalidQuery {
         message,
@@ -65,12 +65,12 @@ async fn native_engine_error_contract_and_per_page_invariant() {
     assert_eq!(variant_name(&result), "InvalidQuery");
 
     // 3. An unset index path is a local misconfiguration: Internal.
-    let result = Native.search("alcohol", "phenotype", 5, 1).await;
+    let result = CrateEngine::from_config().search("alcohol", "phenotype", 5, 1).await;
     assert_eq!(variant_name(&result), "Internal");
 
     // 4. An index path that cannot be opened: Unreachable.
     set("XAPIAN_DB_PATH", "/nonexistent/gn4-native-test-index");
-    let result = Native.search("alcohol", "phenotype", 5, 1).await;
+    let result = CrateEngine::from_config().search("alcohol", "phenotype", 5, 1).await;
     assert_eq!(variant_name(&result), "Unreachable");
 
     // 5. The default engine stays the gn3 forwarder: with
@@ -110,13 +110,13 @@ async fn native_engine_error_contract_and_per_page_invariant() {
     // Forward limit=10: the engine must ignore it and return the FULL
     // match set (PORT-DESIGN §5 — the recording compared complete
     // match sets; Q02's is 57 632 hits).
-    let small = Native.search("alcohol", "phenotype", 10, 1).await;
+    let small = CrateEngine::from_config().search("alcohol", "phenotype", 10, 1).await;
     let small = match small {
         Ok(hits) => hits,
         Err(e) => panic!("dev-index search failed: {e:?}"),
     };
     // ... and the same query at a different limit returns the same set.
-    let large = Native
+    let large = CrateEngine::from_config()
         .search("alcohol", "phenotype", 100, 1)
         .await
         .expect("dev-index search with limit=100");
@@ -151,7 +151,7 @@ async fn native_engine_error_contract_and_per_page_invariant() {
     // 7. The typed search hits decode through the doc-data mapping:
     //    a typed query through a type the index documents (gene) must
     //    also come back Ok (the XT filter maps to real XT terms).
-    let genes = Native
+    let genes = CrateEngine::from_config()
         .search("insulin", "gene", 20, 1)
         .await
         .expect("dev-index insulin/gene search");
@@ -175,7 +175,7 @@ async fn native_engine_error_contract_and_per_page_invariant() {
             h.name.clone().unwrap_or_default(),
         )
     };
-    let page2 = Native
+    let page2 = CrateEngine::from_config()
         .search("alcohol", "phenotype", 10, 2)
         .await
         .expect("dev-index page-2 search");
@@ -195,7 +195,7 @@ async fn native_engine_error_contract_and_per_page_invariant() {
         page2.iter().all(|h| !head.contains(&hit_key(h))),
         "page 1 and page 2 must be disjoint"
     );
-    let far = Native
+    let far = CrateEngine::from_config()
         .search("alcohol", "phenotype", 10, 100_000)
         .await
         .expect("dev-index far-page search");
diff --git a/tests/search_native_dev_corpus.rs b/tests/search_native_dev_corpus.rs
index 66ed86a..de118fc 100644
--- a/tests/search_native_dev_corpus.rs
+++ b/tests/search_native_dev_corpus.rs
@@ -28,7 +28,7 @@
 //!   - `XAPIAN_DB_PATH` — the dev index directory;
 //!   - `GN4_DEV_CORPUS_DIR` — output directory for the full corpus.
 
-use genenetwork4::search::{Engine, SearchError, SearchHit, native::Native};
+use genenetwork4::search::{Engine, SearchError, SearchHit, gnindex::CrateEngine};
 
 /// One row of the harness's shape table, parsed from its source.
 struct RecordedShape {
@@ -172,7 +172,7 @@ async fn record_dev_corpus() {
     let mut recorded = 0usize;
     for shape in &shapes {
         let path = std::path::Path::new(&out_dir).join(format!("{}.json", shape.id));
-        let search = Native
+        let search = CrateEngine::from_config()
             .search(&shape.raw_query, &shape.kind, RECORD_FETCH_LIMIT, 1)
             .await;
         match shape.class.as_str() {
diff --git a/tests/search_native_shapes.rs b/tests/search_native_shapes.rs
index 7358ed3..c0bcae7 100644
--- a/tests/search_native_shapes.rs
+++ b/tests/search_native_shapes.rs
@@ -47,7 +47,7 @@
 //! set it to ~/spikes/index-self-build/xapian-index); the test skips
 //! loudly when unset so the hermetic suites stay green.
 
-use genenetwork4::search::{Engine, SearchError, SearchHit, native::Native};
+use genenetwork4::search::{Engine, SearchError, SearchHit, gnindex::CrateEngine};
 
 /// The recorded behavior class this gate asserts (see module doc).
 #[derive(Clone, Copy, PartialEq, Eq)]
@@ -224,7 +224,7 @@ async fn native_engine_shape_class_gate() {
     let mut passed = 0usize;
     let mut failed = Vec::new();
     for (id, query, type_, expected) in SHAPES {
-        let result = Native.search(query, type_, 100, 1).await;
+        let result = CrateEngine::from_config().search(query, type_, 100, 1).await;
         match (expected, &result) {
             (Class::Match200, Ok(hits)) => {
                 // Dev-index counts are REFERENCE DATA ONLY (AMENDMENT B):