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(tests): stop debug cargo test stack overflows, and name the missing 127.0.0.2 alias (#2910)
Cristian Groza702b8d3d20ca
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6cc5ed51f..a7785ea2b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -139,6 +139,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Fixed+- A plain debug `cargo test --workspace` no longer aborts on a stack overflow,+ and the `127.0.0.2` loopback test names the missing macOS alias (#2903). Five+ tests that run the ES-compat router on multi-thread workers overflowed tokio's+ 2 MiB worker stack in a debug build, killing their whole test binary: one in+ `xerj-mcp`'s `local_def`, one in `xerj-api`'s+ `autoindex_changed_file_drops_stale_symbols`, and three in `hub_api`. They now+ use the server's 4 MiB, as the other in-process router tests do. On a host without `127.0.0.2`,+ `loopback_proxy` fails up front with+ `sudo ifconfig lo0 alias 127.0.0.2 up` instead of a bare connection error,+ through the new `xerj_common::loopback_test::require_loopback_alias`.+ CONTRIBUTING documents both, and that CI runs `--profile ci-test`.- Data-stream `_rollover` honours `dry_run` and its `conditions` instead ofignoring the body: `max_docs`/`max_age` are ORed and reported in`conditions`, and a dry run or an unmet condition creates no backing index.diff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex 65cb7c7e8..e5d1e11de 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -47,6 +47,17 @@ sandbox that denies binding `127.0.0.1`, those tests fail with a message that saso. A new test that binds an ephemeral loopback port should wrap the bind in`xerj_common::loopback_test::expect_loopback`.+CI runs the tests with `cargo test --profile ci-test` (optimised, with unwinding+panics). A plain debug `cargo test` passes too. In a debug build, the ES-compat+handlers need more than tokio's 2 MiB default worker stack, so a test that+serves the router in process builds its runtime with+`thread_stack_size(4 * 1024 * 1024)`, the server's own size, instead of using+`#[tokio::test]`.++One test, `xerj-mcp`'s `loopback_proxy`, connects to `127.0.0.2`. Linux routes+all of `127.0.0.0/8` to loopback. Stock macOS configures only `127.0.0.1`, so the+test fails and names the fix: `sudo ifconfig lo0 alias 127.0.0.2 up`.+### ES-YAML conformance suite (required)XERJ's compatibility contract is the Elasticsearch REST API YAML test suite based on ES 8.13. **CI requires 0 failed cases — there is no "known failures" list.** The runner reports passed, failed, and skipped cases separately; skipped cases do not fail the gate, and the total changes as cases are added. If a test expects one response and XERJ returns another, XERJ is wrong; fix the engine, not the test.diff --git a/engine/crates/xerj-api/tests/autoindex_changed_file_drops_stale_symbols.rs b/engine/crates/xerj-api/tests/autoindex_changed_file_drops_stale_symbols.rsindex 3024ca9b7..84eaf263b 100644--- a/engine/crates/xerj-api/tests/autoindex_changed_file_drops_stale_symbols.rs+++ b/engine/crates/xerj-api/tests/autoindex_changed_file_drops_stale_symbols.rs@@ -348,8 +348,21 @@ async fn reindex_changed_code(app: &axum::Router, url: &str, no_graph: bool) {assert_only_current(&format!("{mode} incremental reindex"), &live, &fresh);}-#[tokio::test(flavor = "multi_thread", worker_threads = 2)]-async fn changed_code_file_reindex_drops_shifted_and_removed_symbols_on_the_engine() {+#[test]+fn changed_code_file_reindex_drops_shifted_and_removed_symbols_on_the_engine() {+ // The router is served in process, and its handlers do not fit tokio's+ // 2 MiB default worker stack in a debug build (#2903). The server runtime+ // is 4 MiB (`xerj-server`'s `RT_THREAD_STACK_SIZE`); match it.+ let rt = tokio::runtime::Builder::new_multi_thread()+ .worker_threads(2)+ .thread_stack_size(4 * 1024 * 1024)+ .enable_all()+ .build()+ .expect("runtime");+ rt.block_on(changed_code_file_reindex_drops_shifted_and_removed_symbols_inner());+}++async fn changed_code_file_reindex_drops_shifted_and_removed_symbols_inner() {let app = app().await;let listener = xerj_common::loopback_test::expect_loopback(tokio::net::TcpListener::bind("127.0.0.1:0").await,diff --git a/engine/crates/xerj-api/tests/hub_api.rs b/engine/crates/xerj-api/tests/hub_api.rsindex d8c85f512..923e4f856 100644--- a/engine/crates/xerj-api/tests/hub_api.rs+++ b/engine/crates/xerj-api/tests/hub_api.rs@@ -366,6 +366,20 @@ fn bare(o: &Opts) -> Hub {}}+/// Runs `test` on four workers with the server's 4 MiB stack. The hub's Ask+/// and Def paths do not fit tokio's 2 MiB default worker stack in a debug+/// build (#2903); the server runtime is 4 MiB (`xerj-server`'s+/// `RT_THREAD_STACK_SIZE`).+fn on_server_stack<F: std::future::Future>(test: F) -> F::Output {+ tokio::runtime::Builder::new_multi_thread()+ .worker_threads(4)+ .thread_stack_size(4 * 1024 * 1024)+ .enable_all()+ .build()+ .expect("runtime")+ .block_on(test)+}+/// A node with the fixture indices seeded.async fn hub(o: Opts) -> Hub {let hub = bare(&o);@@ -908,8 +922,12 @@ async fn catalogue_follows_the_file_when_it_changes() {assert_ne!(etag1, etag2, "and under a new ETag");}-#[tokio::test(flavor = "multi_thread", worker_threads = 4)]-async fn def_answers_with_the_fixture_value_the_pin_and_a_hosted_origin() {+#[test]+fn def_answers_with_the_fixture_value_the_pin_and_a_hosted_origin() {+ on_server_stack(def_answers_with_the_fixture_value_the_pin_and_a_hosted_origin_inner());+}++async fn def_answers_with_the_fixture_value_the_pin_and_a_hosted_origin_inner() {let h = hub(Opts::new(false, false)).await;let r = h.get("/_hub/v1/def/mini-c/MINI_LIMIT").await;assert_eq!(r.status, StatusCode::OK, "{:?}", r.json());@@ -1303,8 +1321,12 @@ async fn k_is_clamped_to_fifty_and_garbage_k_is_400() {assert!(hub_api::parse_k(Some("0"), 5).is_err());}-#[tokio::test(flavor = "multi_thread", worker_threads = 4)]-async fn oversized_blank_missing_and_stray_inputs_are_400() {+#[test]+fn oversized_blank_missing_and_stray_inputs_are_400() {+ on_server_stack(oversized_blank_missing_and_stray_inputs_are_400_inner());+}++async fn oversized_blank_missing_and_stray_inputs_are_400_inner() {let h = hub(Opts::new(false, false)).await;let big = "a".repeat(600);let edge = "a".repeat(512);@@ -3103,8 +3125,12 @@ fn the_fixture_dir_is_the_shared_one() {/// index's store is `<data_dir>/<index name>` — so it must carry a name no/// index can take. It used to be `hub-routing`, a legal index name: an `Ask`/// wrote `.git` into a user's `hub-routing` index on every request.-#[tokio::test(flavor = "multi_thread", worker_threads = 4)]-async fn ask_never_writes_into_a_user_index_named_like_its_routing_dir() {+#[test]+fn ask_never_writes_into_a_user_index_named_like_its_routing_dir() {+ on_server_stack(ask_never_writes_into_a_user_index_named_like_its_routing_dir_inner());+}++async fn ask_never_writes_into_a_user_index_named_like_its_routing_dir_inner() {let h = hub(Opts::new(false, false)).await;let data = PathBuf::from(&h.state.config.server.data_dir);// The old name, and the shape of the new one: an index may take the first,diff --git a/engine/crates/xerj-common/src/loopback_test.rs b/engine/crates/xerj-common/src/loopback_test.rsindex f19f38753..b6ae9c2f0 100644--- a/engine/crates/xerj-common/src/loopback_test.rs+++ b/engine/crates/xerj-common/src/loopback_test.rs@@ -40,6 +40,34 @@ pub fn bind_failure(e: &io::Error) -> String {}}+/// Fails the test, naming the fix, unless `addr` (a loopback address other+/// than 127.0.0.1, such as 127.0.0.2) is usable on this host. Linux routes all+/// of 127.0.0.0/8 to loopback; stock macOS configures only 127.0.0.1, and a+/// connection to another address fails with an error that does not say why+/// (#2903). Call it at the top of a test that connects to such an address.+#[track_caller]+pub fn require_loopback_alias(addr: std::net::Ipv4Addr) {+ if let Err(e) = std::net::TcpListener::bind((addr, 0)) {+ panic!("{}", alias_failure(addr, &e));+ }+}++/// The panic message for a loopback address the host cannot bind.+pub fn alias_failure(addr: std::net::Ipv4Addr, e: &io::Error) -> String {+ match e.kind() {+ io::ErrorKind::AddrNotAvailable => format!(+ "loopback address {addr} is not configured on this host ({e}): this test \+ connects to {addr} as a second loopback address. Linux has it by default; \+ on macOS add it with `sudo ifconfig lo0 alias {addr} up`."+ ),+ io::ErrorKind::PermissionDenied => format!(+ "loopback bind to {addr} failed ({e}): this test needs loopback networking. \+ Run the tests where binding {addr} is allowed."+ ),+ _ => format!("bind {addr}: {e}"),+ }+}+#[cfg(test)]mod tests {use super::*;@@ -69,4 +97,30 @@ mod tests {fn expect_loopback_passes_a_listener_through() {assert_eq!(expect_loopback(Ok::<u16, io::Error>(7)), 7);}++ #[test]+ fn a_missing_loopback_alias_names_the_address_and_the_fix() {+ let addr = std::net::Ipv4Addr::new(127, 0, 0, 2);+ let msg = alias_failure(addr, &io::Error::from(io::ErrorKind::AddrNotAvailable));+ assert!(msg.contains("127.0.0.2 is not configured"), "{msg}");+ assert!(msg.contains("ifconfig lo0 alias 127.0.0.2"), "{msg}");+ let denied = alias_failure(addr, &io::Error::from(io::ErrorKind::PermissionDenied));+ assert!(denied.contains("needs loopback networking"), "{denied}");+ assert!(!denied.contains("ifconfig"), "{denied}");+ let other = alias_failure(addr, &io::Error::from(io::ErrorKind::Other));+ assert!(!other.contains("ifconfig"), "{other}");+ }++ #[test]+ fn require_loopback_alias_accepts_127_0_0_1() {+ require_loopback_alias(std::net::Ipv4Addr::LOCALHOST);+ }++ /// A non-loopback documentation address (TEST-NET-1) is never configured,+ /// so it stands in for macOS's missing 127.0.0.2.+ #[test]+ #[should_panic(expected = "is not configured on this host")]+ fn require_loopback_alias_panics_for_an_unconfigured_address() {+ require_loopback_alias(std::net::Ipv4Addr::new(192, 0, 2, 1));+ }}diff --git a/engine/crates/xerj-mcp/tests/local_def.rs b/engine/crates/xerj-mcp/tests/local_def.rsindex 966fa58bd..e8152ed6b 100644--- a/engine/crates/xerj-mcp/tests/local_def.rs+++ b/engine/crates/xerj-mcp/tests/local_def.rs@@ -221,8 +221,22 @@ async fn lookup(url: &str, arguments: Value) -> Value {serde_json::from_str(response["result"]["content"][0]["text"].as_str().unwrap()).unwrap()}-#[tokio::test(flavor = "multi_thread", worker_threads = 2)]-async fn local_def_returns_ranked_unique_declarations_in_the_requested_scope() {+#[test]+fn local_def_returns_ranked_unique_declarations_in_the_requested_scope() {+ // This test serves the ES-compat router in process. Its handlers do not fit+ // tokio's 2 MiB default worker stack in a debug build, which overflowed a+ // plain `cargo test` (#2903). The server runtime is 4 MiB+ // (`xerj-server`'s `RT_THREAD_STACK_SIZE`); match it.+ let rt = tokio::runtime::Builder::new_multi_thread()+ .worker_threads(2)+ .thread_stack_size(4 * 1024 * 1024)+ .enable_all()+ .build()+ .expect("runtime");+ rt.block_on(local_def_returns_ranked_unique_declarations_in_the_requested_scope_inner());+}++async fn local_def_returns_ranked_unique_declarations_in_the_requested_scope_inner() {let tmp = tempfile::tempdir().unwrap();let mut config = xerj_common::config::Config::default();config.server.data_dir = tmp.path().join("data").to_string_lossy().into_owned();diff --git a/engine/crates/xerj-mcp/tests/loopback_proxy.rs b/engine/crates/xerj-mcp/tests/loopback_proxy.rsindex b877e4368..8c6d2b458 100644--- a/engine/crates/xerj-mcp/tests/loopback_proxy.rs+++ b/engine/crates/xerj-mcp/tests/loopback_proxy.rs@@ -145,6 +145,9 @@ async fn tool(url: &str, msg: Value) -> (bool, String) {#[tokio::test]async fn loopback_ignores_an_unreachable_proxy_and_a_proxied_503_names_the_proxy() {+ // Phase 3 connects to 127.0.0.2 directly. Stock macOS has no such alias,+ // and the connection error alone does not say so (#2903).+ xerj_common::loopback_test::require_loopback_alias(std::net::Ipv4Addr::new(127, 0, 0, 2));let _guard = EnvGuard::capture();let node_hits = Arc::new(AtomicUsize::new(0));