Skip to content

Commit 64916a6

Browse files
authored
test(mcp): pin that the offset refusal happens before any store call (#1268) (#1288)
## Description Adds regression assertions in `crates/nostream-mcp/tests/tool_payloads.rs` under `a_refused_criterion_never_reaches_the_store` verifying that for `TOOL_INVOICES_LIST`, `offset` values greater than `MAX_ROWS_PER_SKIP` (such as `5001` and `u64::MAX`) are rejected at the door before any store call is dispatched. Also pins that the boundary offset `5000` (`MAX_ROWS_PER_SKIP`) successfully passes door validation and proceeds to the store. ## Related Issue Closes #1268 ## Motivation and Context The issue notes that `offset: 5001` and `offset: u64::MAX` were already guarded by handler validation, but were not explicitly pinned in the test suite against the store boundary seam. `crates/nostream-mcp/tests/tool_payloads.rs` is the only test file configured with `Stores::Unavailable`, where all storage repositories return `StorageError::NotImplemented { module: "storage::backend::wiring" }`. By testing these offset values here: - Values above `MAX_ROWS_PER_SKIP` (`5001` and `u64::MAX`) return an argument error (`offset: <value> exceeds the per-skip maximum of 5000`) without ever touching the store seam (no `storage::backend::wiring` error). - Boundary value `MAX_ROWS_PER_SKIP` (`5000`) passes door validation and reaches the store, failing with the store seam's `NotImplemented` error. This cleanly verifies that the offset refusal happens strictly before any storage call is made. ## How Has This Been Tested? - Ran the modified test suite: - `cargo test -p nostream-mcp --test tool_payloads` (23/23 passed) - Ran all other MCP test suites: - `cargo test -p nostream-mcp --test store_families` (19/19 passed) - `cargo test -p nostream-mcp --test audit` (6/6 passed) - `cargo test -p nostream-mcp --test tools_list` (5/5 passed) - Ran formatting and linter checks: - `cargo fmt --check --package nostream-mcp` - `cargo clippy -p nostream-mcp --all-targets --all-features -- -D warnings` - Strict workspace clippy checks with `-D clippy::unwrap_used -D clippy::expect_used` ## Types of changes - [x] Non-functional change (docs, style, minor refactor) - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Checklist: - [x] My code follows the code style of this project. - [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly. - [x] I have read the **CONTRIBUTING** document. - [x] I have added tests to cover my code changes. - [x] I added a changeset, or this is docs-only and I added an empty changeset. - [x] All new and existing tests passed.
2 parents e582d20 + c552fb3 commit 64916a6

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
---
3+
4+
test(mcp): pin that the offset refusal happens before any store call (#1268)

‎crates/nostream-mcp/tests/tool_payloads.rs‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
//! | `an_unknown_argument_is_an_argument_error` | a mistyped key is an argument error naming the accepted fields, not an unfiltered page |
2121
//! | `an_uppercase_id_finds_its_row` | a stored id pasted in uppercase is the same id, not a confident `null` |
2222
//! | `a_criterion_the_wire_would_refuse_is_an_argument_error` | a non-hex, short, oversized or over-counted criterion is refused, naming its field |
23-
//! | `a_refused_criterion_never_reaches_the_store` | the refusal comes before the store: over the unwired store the argument error answers, not `NotImplemented` |
23+
//! | `a_refused_criterion_never_reaches_the_store` | the refusal comes before the store: over the unwired store the argument error and offset ceiling answer, not `NotImplemented` |
2424
//! | `a_page_is_the_first_rows_oldest_first` | the payload is one order, and `limit` is its first N, with `truncated` marking a full page |
2525
//! | `a_full_default_page_is_marked_truncated` | a page the store's own bound cut says so |
2626
//! | `a_success_carries_one_copy_of_the_payload` | a success is in `structuredContent` only, never also as a text block |
@@ -33,7 +33,10 @@ mod common;
3333
use std::collections::BTreeSet;
3434

3535
use common::{Fixture, Stores, TestMcp, event, id_of, payload, text};
36-
use nostream_mcp::{TOOL_GET_EVENT, TOOL_LIST_EVENTS, TOOL_SETTINGS_GET, TOOL_SETTINGS_SET};
36+
use nostream_mcp::{
37+
MAX_ROWS_PER_SKIP, TOOL_GET_EVENT, TOOL_INVOICES_LIST, TOOL_LIST_EVENTS, TOOL_SETTINGS_GET,
38+
TOOL_SETTINGS_SET,
39+
};
3740
use nostream_storage::repositories::EventRepository;
3841
use serde_json::{Value, json};
3942

@@ -523,6 +526,35 @@ async fn a_refused_criterion_never_reaches_the_store() {
523526
"a criterion the wire takes reaches the store: {}",
524527
text(&reached)
525528
);
529+
530+
// The invoice walk's offset ceiling answers before the store is reached:
531+
// 5001 and u64::MAX are refused at the door, 5000 reaches the store (#1268).
532+
for given in [MAX_ROWS_PER_SKIP + 1, u64::MAX] {
533+
let refused = client
534+
.call(TOOL_INVOICES_LIST, json!({ "offset": given }))
535+
.await;
536+
assert_eq!(refused.is_error, Some(true), "{given}: {}", text(&refused));
537+
assert!(
538+
text(&refused).starts_with("offset:"),
539+
"{given}: {}",
540+
text(&refused)
541+
);
542+
assert!(
543+
!text(&refused).contains("storage::backend::wiring"),
544+
"the refusal is not the store's: {}",
545+
text(&refused)
546+
);
547+
}
548+
549+
let reached = client
550+
.call(TOOL_INVOICES_LIST, json!({ "offset": MAX_ROWS_PER_SKIP }))
551+
.await;
552+
assert_eq!(reached.is_error, Some(true), "{}", text(&reached));
553+
assert!(
554+
text(&reached).contains("not implemented in Phase 1 (job 005): storage::backend::wiring"),
555+
"an allowed offset reaches the store: {}",
556+
text(&reached)
557+
);
526558
}
527559

528560
#[tokio::test]

0 commit comments

Comments
 (0)