From 34687774a198bb023399c83ef3a51b4f2295378e Mon Sep 17 00:00:00 2001 From: "developing-today[bot]" <5454422+developing-today[bot]@users.noreply.github.com> Date: Thu, 5 Nov 2026 11:12:19 -0600 Subject: [PATCH 1/2] fix(atlas-search): cap get-chunk neighbors (#5600) --- .../crates/atlas-search/src/main.rs | 28 +++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/pkgs/atlas-search/crates/atlas-search/src/main.rs b/pkgs/atlas-search/crates/atlas-search/src/main.rs index b37deb3c1d..c7a12f3bea 100644 --- a/pkgs/atlas-search/crates/atlas-search/src/main.rs +++ b/pkgs/atlas-search/crates/atlas-search/src/main.rs @@ -580,13 +580,17 @@ fn u(v: i64) -> usize { /// Validate one CLI count flag against the service's request /// contract (design section 2; `validate_request` in server.rs): /// `--k` at least 1, `--pool` between 1 and 400, and the -/// zero-is-valid counts (`--expand`, `--trunc`, `--neighbors`) -/// merely non-negative. Out-of-range values are a fatal (exit 2), -/// never a silent clamp to 0 (#5407). +/// zero-is-valid counts (`--expand`, `--trunc`, `--neighbors`) are +/// non-negative; `--neighbors` is also capped at the service's limit. +/// Out-of-range values are fatal (exit 2), never silently clamped to 0 +/// (#5407). fn count(flag: &str, v: i64, min: i64, max: Option) -> Result { if v >= min && max.is_none_or(|m| v <= m) { return Ok(usize::try_from(v).expect("range-checked count converts")); } + if v < min && min == 0 { + return Err((2, format!("{flag} must not be negative"))); + } let msg = match (min, max) { (_, Some(m)) => format!("{flag} must be between {min} and {m} (design section 2)"), (1, None) => format!("{flag} must be at least 1"), @@ -661,7 +665,7 @@ fn cmd_search(args: SearchArgs) -> Result<(), CliError> { } fn cmd_get_chunk(args: GetChunkArgs) -> Result<(), CliError> { - let neighbors = count("--neighbors", args.neighbors, 0, None)?; + let neighbors = count("--neighbors", args.neighbors, 0, Some(100))?; let note = via_service_note_get_chunk(&args.backend); // The Python's get-chunk takes no vector args: pick_backend // sees the defaults (getattr fallbacks in its main()). @@ -766,7 +770,7 @@ mod tests { assert!(count("--pool", 0, 1, Some(400)).is_err()); assert!(count("--pool", -5, 1, Some(400)).is_err()); // zero-is-valid counts: 0 stays valid, negatives do not - for flag in ["--expand", "--trunc", "--neighbors"] { + for flag in ["--expand", "--trunc"] { assert_eq!(count(flag, 0, 0, None), Ok(0), "{flag}"); assert_eq!( count(flag, -1, 0, None).unwrap_err(), @@ -774,5 +778,19 @@ mod tests { "{flag}" ); } + // --neighbors has a 100 upper bound (service cap) + assert_eq!(count("--neighbors", 0, 0, Some(100)), Ok(0)); + assert_eq!(count("--neighbors", 100, 0, Some(100)), Ok(100)); + assert_eq!( + count("--neighbors", 101, 0, Some(100)).unwrap_err(), + ( + 2, + "--neighbors must be between 0 and 100 (design section 2)".to_string() + ) + ); + assert_eq!( + count("--neighbors", -1, 0, Some(100)).unwrap_err(), + (2, "--neighbors must not be negative".to_string()) + ); } } From 0ccd562df0743612afb4b60b28127116b82358a9 Mon Sep 17 00:00:00 2001 From: "developing-today[bot]" <5454422+developing-today[bot]@users.noreply.github.com> Date: Fri, 6 Nov 2026 21:06:22 -0600 Subject: [PATCH 2/2] test(atlas-search): command-level coverage for the get-chunk --neighbors cap Issue #6594 (CodeRabbit finding on this PR): the cap at the cmd_get_chunk call site was covered only by unit tests calling count() directly, so removing Some(100) at main.rs:668 failed nothing. Add cli_get_chunk_neighbors_above_cap_exits_2 to cli_parity.rs: run the binary with get-chunk 2 --neighbors 101 --backend local and assert exit 2 plus the bound message on stderr. Verified on the laptop: full atlas-search suite passes (26 unit + 5 cli_parity), and the new test fails when the call-site cap is temporarily removed. --- .../crates/atlas-search/tests/cli_parity.rs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/pkgs/atlas-search/crates/atlas-search/tests/cli_parity.rs b/pkgs/atlas-search/crates/atlas-search/tests/cli_parity.rs index 648ed737f3..6e7a751350 100644 --- a/pkgs/atlas-search/crates/atlas-search/tests/cli_parity.rs +++ b/pkgs/atlas-search/crates/atlas-search/tests/cli_parity.rs @@ -186,6 +186,26 @@ fn cli_get_chunk_not_found_exits_1() { ); } +#[test] +fn cli_get_chunk_neighbors_above_cap_exits_2() { + // Command-level coverage for the --neighbors cap (#6594): the unit + // tests in main.rs call count() directly, so dropping the cap at + // the cmd_get_chunk call site would fail nothing there. Through + // the binary, 101 must be refused before any lookup, with exit 2 + // and the bound message on stderr. + let db = build_fixture_db("neighborscap"); + let out = run_bin( + &db, + &["get-chunk", "2", "--neighbors", "101", "--backend", "local"], + ); + assert_eq!(out.status.code(), Some(2)); + let stderr = String::from_utf8_lossy(&out.stderr); + assert!( + stderr.contains("--neighbors must be between 0 and 100"), + "stderr: {stderr}" + ); +} + #[test] fn cli_text_goldens_match_python() { let db = build_fixture_db("text");