diff --git a/.changeset/mcp-offset-refusal-before-store.md b/.changeset/mcp-offset-refusal-before-store.md new file mode 100644 index 000000000..5cce0949f --- /dev/null +++ b/.changeset/mcp-offset-refusal-before-store.md @@ -0,0 +1,4 @@ +--- +--- + +test(mcp): pin that the offset refusal happens before any store call (#1268) diff --git a/crates/nostream-mcp/tests/tool_payloads.rs b/crates/nostream-mcp/tests/tool_payloads.rs index bea7a5acb..3e23499f1 100644 --- a/crates/nostream-mcp/tests/tool_payloads.rs +++ b/crates/nostream-mcp/tests/tool_payloads.rs @@ -20,7 +20,7 @@ //! | `an_unknown_argument_is_an_argument_error` | a mistyped key is an argument error naming the accepted fields, not an unfiltered page | //! | `an_uppercase_id_finds_its_row` | a stored id pasted in uppercase is the same id, not a confident `null` | //! | `a_criterion_the_wire_would_refuse_is_an_argument_error` | a non-hex, short, oversized or over-counted criterion is refused, naming its field | -//! | `a_refused_criterion_never_reaches_the_store` | the refusal comes before the store: over the unwired store the argument error answers, not `NotImplemented` | +//! | `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` | //! | `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 | //! | `a_full_default_page_is_marked_truncated` | a page the store's own bound cut says so | //! | `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; use std::collections::BTreeSet; use common::{Fixture, Stores, TestMcp, event, id_of, payload, text}; -use nostream_mcp::{TOOL_GET_EVENT, TOOL_LIST_EVENTS, TOOL_SETTINGS_GET, TOOL_SETTINGS_SET}; +use nostream_mcp::{ + MAX_ROWS_PER_SKIP, TOOL_GET_EVENT, TOOL_INVOICES_LIST, TOOL_LIST_EVENTS, TOOL_SETTINGS_GET, + TOOL_SETTINGS_SET, +}; use nostream_storage::repositories::EventRepository; use serde_json::{Value, json}; @@ -523,6 +526,35 @@ async fn a_refused_criterion_never_reaches_the_store() { "a criterion the wire takes reaches the store: {}", text(&reached) ); + + // The invoice walk's offset ceiling answers before the store is reached: + // 5001 and u64::MAX are refused at the door, 5000 reaches the store (#1268). + for given in [MAX_ROWS_PER_SKIP + 1, u64::MAX] { + let refused = client + .call(TOOL_INVOICES_LIST, json!({ "offset": given })) + .await; + assert_eq!(refused.is_error, Some(true), "{given}: {}", text(&refused)); + assert!( + text(&refused).starts_with("offset:"), + "{given}: {}", + text(&refused) + ); + assert!( + !text(&refused).contains("storage::backend::wiring"), + "the refusal is not the store's: {}", + text(&refused) + ); + } + + let reached = client + .call(TOOL_INVOICES_LIST, json!({ "offset": MAX_ROWS_PER_SKIP })) + .await; + assert_eq!(reached.is_error, Some(true), "{}", text(&reached)); + assert!( + text(&reached).contains("not implemented in Phase 1 (job 005): storage::backend::wiring"), + "an allowed offset reaches the store: {}", + text(&reached) + ); } #[tokio::test]