diff options
| author | Alexander_Kabui <alexanderkabua@gmail.com> | 2026-10-07 05:50:48 +0300 |
|---|---|---|
| committer | Alexander_Kabui <alexanderkabua@gmail.com> | 2026-10-07 05:50:48 +0300 |
| commit | ccfa1b02dc29571ac74602479d1798d17abb9239 (patch) | |
| tree | a243ae2b54306122e182217dcea59a9b0c7d6d67 /src | |
| parent | 228bedf08631704a2f884d58f9a70d26783fb1a7 (diff) | |
| download | genenetwork4-ccfa1b02dc29571ac74602479d1798d17abb9239.tar.gz | |
src/config.rs (Config): add xapian_db_path and search_engine keys.
New configuration for the native search engine (PORT-DESIGN C1.2 / AMENDMENT D pre-decided mechanical naming): - xapian_db_path (env XAPIAN_DB_PATH): directory of the xapian index the native engine queries. Mirrors gn3's own key at gn3/api/search.py:295 so the two services share one convention. Empty default: forwarding needs no index; the native engine reports the missing key as a local misconfiguration rather than guessing a path. - search_engine (env SEARCH_ENGINE): "forward" (default, the existing gn3 proxy) or "native" (query the xapian index directly). Opt-in, so the default behavior of every deployment is unchanged and flipping is a one-line config change. Both follow the existing layering (defaults -> GN4_CONF/GN4_SECRETS -> environment) exactly like gn3_url / gn3_timeout_secs; unit tests cover the defaults and the env-over-default layering. Evidence: ~/spikes/port-execution/logs/c1-2.log (config unit tests 12 passed; full suite EXIT=0, parity floor still 54/54 through the forwarding engine).
Diffstat (limited to 'src')
| -rw-r--r-- | src/config.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs index 707bff6..f8dbb50 100644 --- a/src/config.rs +++ b/src/config.rs @@ -24,6 +24,18 @@ pub struct Config { /// timeout of its own (flask app.run()), so this is the only /// guard against a stalled upstream. pub gn3_timeout_secs: u64, + /// Directory of the xapian search index queried by the native + /// search engine. Same XAPIAN_DB_PATH config key GeneNetwork3 uses + /// (gn3 reads it at gn3/api/search.py:295), so the two services can + /// share configuration. Empty by default: the forwarding engine + /// needs no index, and the native engine reports a local + /// misconfiguration if it is asked to search without one. + pub xapian_db_path: String, + /// Which engine backs /search: "forward" (default, proxy gn3) or + /// "native" (query the xapian index directly). Set via the + /// SEARCH_ENGINE key; opt-in so flipping is a one-line config + /// change and never a deployment. + pub search_engine: String, /// TCP port to bind. pub port: u16, /// Base URL of the gn-auth server, e.g. "http://127.0.0.1:8081/". @@ -104,6 +116,8 @@ impl Config { "http://127.0.0.1:5003/api/".to_string(), ); values.insert("GN3_TIMEOUT_SECS".to_string(), "30".to_string()); + values.insert("XAPIAN_DB_PATH".to_string(), String::new()); + values.insert("SEARCH_ENGINE".to_string(), "forward".to_string()); // Layers 2 and 3: config files, in increasing priority. for env_key in ["GN4_CONF", "GN4_SECRETS"] { @@ -127,6 +141,8 @@ impl Config { "GN_AUTH_DEV_PASSWORD", "GN3_URL", "GN3_TIMEOUT_SECS", + "XAPIAN_DB_PATH", + "SEARCH_ENGINE", ] { if let Ok(value) = std::env::var(key) { values.insert(key.to_string(), value); @@ -141,6 +157,8 @@ impl Config { gn3_timeout_secs: values["GN3_TIMEOUT_SECS"] .parse() .expect("GN3_TIMEOUT_SECS must be a number"), + xapian_db_path: values["XAPIAN_DB_PATH"].clone(), + search_engine: values["SEARCH_ENGINE"].clone(), port: values["GENENETWORK4_PORT"] .parse() .expect("GENENETWORK4_PORT must be a number"), @@ -207,6 +225,8 @@ mod tests { "GN_AUTH_DEV_PASSWORD", "GN3_URL", "GN3_TIMEOUT_SECS", + "XAPIAN_DB_PATH", + "SEARCH_ENGINE", ] { if std::env::var(key).is_ok() { eprintln!("skipping: {key} is set in the environment"); @@ -220,6 +240,10 @@ mod tests { assert_eq!(config.bind, "0.0.0.0"); assert!(!config.dev_mode); assert_eq!(config.dev_token_username, "test@development.user"); + // Search-engine wiring defaults: forwarding stays the default + // engine and no index path is configured out of the box. + assert_eq!(config.search_engine, "forward"); + assert_eq!(config.xapian_db_path, ""); } #[test] @@ -230,6 +254,8 @@ mod tests { auth_server_url: String::new(), gn3_url: String::new(), gn3_timeout_secs: 30, + xapian_db_path: String::new(), + search_engine: "forward".to_string(), bind: "127.0.0.1".to_string(), dev_mode: true, dev_token_client_id: String::new(), @@ -296,4 +322,39 @@ mod tests { "http://h:5003/api/" ); } + + /// The new search-engine keys follow the same layering as the gn3 + /// keys they sit next to: environment beats the built-in default. + /// One sequential test function mutating the process environment, + /// per the rule documented in tests/search_engine.rs. + #[test] + fn search_engine_keys_follow_env_over_default_layering() { + let restore = |key: &str, previous: Option<String>| unsafe { + match previous { + Some(value) => std::env::set_var(key, value), + None => std::env::remove_var(key), + } + }; + let prior_path = std::env::var("XAPIAN_DB_PATH").ok(); + let prior_engine = std::env::var("SEARCH_ENGINE").ok(); + + unsafe { + std::env::remove_var("XAPIAN_DB_PATH"); + std::env::remove_var("SEARCH_ENGINE"); + } + let config = Config::load(); + assert_eq!(config.xapian_db_path, ""); + assert_eq!(config.search_engine, "forward"); + + unsafe { + std::env::set_var("XAPIAN_DB_PATH", "/srv/xapian-index"); + std::env::set_var("SEARCH_ENGINE", "native"); + } + let config = Config::load(); + assert_eq!(config.xapian_db_path, "/srv/xapian-index"); + assert_eq!(config.search_engine, "native"); + + restore("XAPIAN_DB_PATH", prior_path); + restore("SEARCH_ENGINE", prior_engine); + } } |
