From b26d1ede691d55b81cc4521bc3a1f4d7613ac508 Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Wed, 28 Oct 2026 14:56:01 +0000 Subject: [PATCH 1/6] fix(streams): DescribeStream refuses a Limit below 1 or above 100 The handler validates Limit before storage is reached. The backends index the shard list at Limit minus one, so a Limit of 0 was an integer underflow in the request task. The range, 1 to 100, is the one the DescribeStream API Reference gives, and the constant cites it. The two refusals carry the messages the service sent on 2026-10-22 in us-east-1, for DescribeStream on an existing stream with the SDK's parameter validation off so the requests reached the service: Limit 0 and Limit -1: 400 {"__type":"com.amazon.coral.validate#ValidationException","message":"1 validation error detected: Value at 'limit' failed to satisfy constraint: Member must have value greater than or equal to 1"} Limit 101 and Limit 1000: 400 {"__type":"com.amazon.coral.validate#ValidationException","message":"One or more parameter values were invalid: Limit cannot be greater than the maximum: 100"} The test module quotes both responses. The handler refuses the Limit before it looks the stream up. The service's order for a bad Limit on a missing stream is unmeasured, because the measurement ran on an existing stream only, and the test comment says so. The stream handler tests run over a storage double that counts describe_stream calls: Limit 0, -3, 101 and 1000 are refused with these messages and never reach storage, while Limit 1 and Limit 100 reach it. --- crates/engine/src/streams.rs | 34 +- .../src/streams/describe_limit_tests.rs | 74 +++ crates/engine/src/streams/test_storage.rs | 509 ++++++++++++++++++ 3 files changed, 616 insertions(+), 1 deletion(-) create mode 100644 crates/engine/src/streams/describe_limit_tests.rs create mode 100644 crates/engine/src/streams/test_storage.rs diff --git a/crates/engine/src/streams.rs b/crates/engine/src/streams.rs index 83b297253..dc2ec0bcb 100755 --- a/crates/engine/src/streams.rs +++ b/crates/engine/src/streams.rs @@ -15,12 +15,19 @@ use serde_json::Value; use crate::OperationContext; use crate::serialize_output; +/// Largest `Limit` `DescribeStream` accepts. The API Reference gives the +/// range 1 to 100 ("The upper limit is 100", minimum value 1, +/// ); +/// the service's refusals are quoted in `streams/describe_limit_tests.rs`. +const DESCRIBE_STREAM_LIMIT_MAX: i64 = 100; + /// Handle `DescribeStream`. /// /// # Errors /// /// Returns [`DynamoDbError::ResourceNotFoundException`] if the stream does not exist. -/// Returns [`DynamoDbError::ValidationException`] on invalid input. +/// Returns [`DynamoDbError::ValidationException`] on invalid input, including +/// a `Limit` below 1 or above 100. pub async fn handle_describe_stream( body: Value, ctx: &OperationContext, @@ -28,6 +35,25 @@ pub async fn handle_describe_stream( let input: DescribeStreamInput = serde_json::from_value(body) .map_err(|e| DynamoDbError::SerializationException(e.to_string()))?; + // Limit bounds as the service enforces them (measured 2026-10-22, + // DescribeStream with Limit 0, -1, 101 and 1000 against us-east-1; the + // raw responses are quoted in streams/describe_limit_tests.rs). + if let Some(limit) = input.limit { + if limit < 1 { + return Err(DynamoDbError::ValidationException( + "1 validation error detected: Value at 'limit' failed to satisfy \ + constraint: Member must have value greater than or equal to 1" + .to_owned(), + )); + } + if limit > DESCRIBE_STREAM_LIMIT_MAX { + return Err(DynamoDbError::ValidationException(format!( + "One or more parameter values were invalid: Limit cannot be greater than \ + the maximum: {DESCRIBE_STREAM_LIMIT_MAX}" + ))); + } + } + let desc = ctx .storage .describe_stream(&ctx.account_id, &input) @@ -461,3 +487,9 @@ mod tests { )); } } + +#[cfg(test)] +mod test_storage; + +#[cfg(test)] +mod describe_limit_tests; diff --git a/crates/engine/src/streams/describe_limit_tests.rs b/crates/engine/src/streams/describe_limit_tests.rs new file mode 100644 index 000000000..c6f12fff1 --- /dev/null +++ b/crates/engine/src/streams/describe_limit_tests.rs @@ -0,0 +1,74 @@ +// Copyright 2026 ExtendDB contributors +// SPDX-License-Identifier: Apache-2.0 + +//! `DescribeStream` refuses a `Limit` below 1 or above 100 with the service's +//! messages before storage is reached, and passes the bounds themselves +//! through. +//! +//! The messages were measured on 2026-10-22 in us-east-1 with +//! `DescribeStream` on an existing stream, the SDK's own parameter +//! validation switched off so the requests reached the service: +//! +//! ```text +//! Limit 0 and Limit -1: +//! 400 {"__type":"com.amazon.coral.validate#ValidationException","message":"1 validation error detected: Value at 'limit' failed to satisfy constraint: Member must have value greater than or equal to 1"} +//! Limit 101 and Limit 1000: +//! 400 {"__type":"com.amazon.coral.validate#ValidationException","message":"One or more parameter values were invalid: Limit cannot be greater than the maximum: 100"} +//! ``` +//! +//! Limit 1 returned one shard and `LastEvaluatedShardId`. The below-one text +//! leaves out the value, where this crate's `ListTables` and `Scan` messages +//! for the same constraint include it. +//! +//! The order of the checks against a missing stream is unmeasured: the +//! measurement ran on an existing stream only, so whether the service +//! answers a bad `Limit` on a missing stream with `ValidationException` or +//! `ResourceNotFoundException` is unknown. The handler refuses the `Limit` +//! before it looks the stream up. + +use serde_json::json; + +use extenddb_core::error::DynamoDbError; + +use super::handle_describe_stream; +use super::test_storage::{STREAM_ARN, StreamStorage, context}; + +const BELOW_ONE: &str = "1 validation error detected: Value at 'limit' failed to satisfy \ + constraint: Member must have value greater than or equal to 1"; +const ABOVE_MAX: &str = + "One or more parameter values were invalid: Limit cannot be greater than the maximum: 100"; + +#[tokio::test] +async fn describe_stream_refuses_a_limit_outside_1_to_100_before_storage() { + let storage = StreamStorage::new(); + let ctx = context(&storage); + for (limit, expected) in [ + (0, BELOW_ONE), + (-3, BELOW_ONE), + (101, ABOVE_MAX), + (1000, ABOVE_MAX), + ] { + let body = json!({"StreamArn": STREAM_ARN, "Limit": limit}); + match handle_describe_stream(body, &ctx).await { + Err(DynamoDbError::ValidationException(m)) => assert_eq!(m, expected, "Limit {limit}"), + other => panic!("Limit {limit}: expected ValidationException, got {other:?}"), + } + } + assert_eq!( + storage.describe_calls(), + 0, + "no refused Limit reached storage" + ); +} + +#[tokio::test] +async fn describe_stream_passes_limits_1_and_100_to_storage() { + let storage = StreamStorage::new(); + let ctx = context(&storage); + for limit in [1, 100] { + let body = json!({"StreamArn": STREAM_ARN, "Limit": limit}); + let described = handle_describe_stream(body, &ctx).await; + assert!(described.is_ok(), "Limit {limit}: {described:?}"); + } + assert_eq!(storage.describe_calls(), 2); +} diff --git a/crates/engine/src/streams/test_storage.rs b/crates/engine/src/streams/test_storage.rs new file mode 100644 index 000000000..297d98a12 --- /dev/null +++ b/crates/engine/src/streams/test_storage.rs @@ -0,0 +1,509 @@ +// Copyright 2026 ExtendDB contributors +// SPDX-License-Identifier: Apache-2.0 + +//! A storage double for the stream handler tests. `validate_shard` accepts +//! every shard, `get_stream_records` answers an empty page and +//! `describe_stream` answers a description with no shards, counting its +//! calls. Every other method is unreachable from the stream handlers under +//! test and panics if called. + +use std::collections::HashMap; +use std::path::PathBuf; +use std::sync::Arc; +use std::sync::atomic::{AtomicUsize, Ordering}; + +use extenddb_core::expression::{Expr, ExpressionMaps, KeyCondition, UpdateAction}; +use extenddb_core::limits::LimitsConfig; +use extenddb_core::types::{ + BackupDescription, BackupDetails, BackupSummary, ContinuousBackupsDescription, + CreateTableInput, DeleteTableInput, DescribeStreamInput, DescribeTableInput, IndexInfo, Item, + ListTablesInput, ListTablesOutput, StreamDescription, StreamRecord, StreamStatus, + StreamViewType, TableDescription, TableKeyInfo, Tag, TimeToLiveDescription, UpdateTableInput, +}; +use extenddb_storage::BoxedFuture as BoxFuture; +use extenddb_storage::error::StorageError; +use extenddb_storage::{ + BackupEngine, BackupRestoreSource, DataEngine, IdempotencyKey, ItemPairResult, MetadataEngine, + QueryResult, RestoreRequest, StreamCapture, StreamEngine, StreamListResult, + StreamRecordsResult, TableEngine, TransactGetOp, TransactWriteOp, TtlTableInfo, WorkerStore, +}; + +use crate::OperationContext; + +/// The account the context's requests run as. +pub(super) const ACCOUNT: &str = "000000000000"; + +/// A stream ARN in [`ACCOUNT`]; the double accepts any shard of it. +pub(super) const STREAM_ARN: &str = + "arn:aws:dynamodb:us-east-1:000000000000:table/Orders/stream/2026-10-22T00:00:00.000"; + +/// A storage engine with just enough stream behaviour for the handlers. +pub(super) struct StreamStorage { + /// How many `describe_stream` calls reached the double. + describe_calls: AtomicUsize, +} + +impl StreamStorage { + pub(super) fn new() -> Arc { + Arc::new(Self { + describe_calls: AtomicUsize::new(0), + }) + } + + /// How many `describe_stream` calls reached storage. + pub(super) fn describe_calls(&self) -> usize { + self.describe_calls.load(Ordering::Relaxed) + } +} + +/// An operation context over `storage` for [`ACCOUNT`]. +pub(super) fn context(storage: &Arc) -> OperationContext { + let empty: Vec> = Vec::new(); + OperationContext { + storage: Arc::clone(storage) as Arc, + limits: Arc::new(LimitsConfig::default()), + region: Arc::from("us-east-1"), + account_id: Arc::from(ACCOUNT), + import_paths: Arc::from(empty.clone()), + export_paths: Arc::from(empty), + authorized_key_info: HashMap::new(), + auth_cache: extenddb_auth::AuthCacheRegistry::empty(), + table_key_info_lookup: None, + } +} + +impl TableEngine for StreamStorage { + fn create_table( + &self, + _account_id: &str, + _input: CreateTableInput, + ) -> BoxFuture<'_, Result> { + unimplemented!("not reached by the stream handlers") + } + + fn delete_table( + &self, + _account_id: &str, + _input: DeleteTableInput, + ) -> BoxFuture<'_, Result> { + unimplemented!("not reached by the stream handlers") + } + + fn describe_table( + &self, + _account_id: &str, + _input: DescribeTableInput, + ) -> BoxFuture<'_, Result> { + unimplemented!("not reached by the stream handlers") + } + + fn list_tables( + &self, + _account_id: &str, + _input: ListTablesInput, + ) -> BoxFuture<'_, Result> { + unimplemented!("not reached by the stream handlers") + } + + fn update_table( + &self, + _account_id: &str, + _input: UpdateTableInput, + ) -> BoxFuture<'_, Result> { + unimplemented!("not reached by the stream handlers") + } + + fn table_key_info( + &self, + _account_id: &str, + _table_name: &str, + ) -> BoxFuture<'_, Result> { + unimplemented!("not reached by the stream handlers") + } + + fn index_info( + &self, + _account_id: &str, + _table_name: &str, + _index_name: &str, + ) -> BoxFuture<'_, Result> { + unimplemented!("not reached by the stream handlers") + } + + fn index_info_by_table_id( + &self, + _table_id: &str, + _index_name: &str, + ) -> BoxFuture<'_, Result> { + unimplemented!("not reached by the stream handlers") + } +} + +impl DataEngine for StreamStorage { + fn put_item( + &self, + _key_info: &TableKeyInfo, + _item: Item, + _return_old: bool, + _condition: Option<&Expr>, + _maps: &ExpressionMaps, + _stream: Option<&StreamCapture>, + ) -> BoxFuture<'_, Result, StorageError>> { + unimplemented!("not reached by the stream handlers") + } + + fn get_item( + &self, + _key_info: &TableKeyInfo, + _key: &Item, + ) -> BoxFuture<'_, Result, StorageError>> { + unimplemented!("not reached by the stream handlers") + } + + fn delete_item( + &self, + _key_info: &TableKeyInfo, + _key: &Item, + _return_old: bool, + _condition: Option<&Expr>, + _maps: &ExpressionMaps, + _stream: Option<&StreamCapture>, + ) -> BoxFuture<'_, Result, StorageError>> { + unimplemented!("not reached by the stream handlers") + } + + fn update_item( + &self, + _key_info: &TableKeyInfo, + _key: &Item, + _actions: &[UpdateAction], + _return_old: bool, + _return_new: bool, + _condition: Option<&Expr>, + _maps: &ExpressionMaps, + _stream: Option<&StreamCapture>, + ) -> BoxFuture<'_, ItemPairResult> { + unimplemented!("not reached by the stream handlers") + } + + fn query( + &self, + _key_info: &TableKeyInfo, + _key_condition: &KeyCondition, + _maps: &ExpressionMaps, + _forward: bool, + _limit: Option, + _exclusive_start_key: Option<&Item>, + _index_name: Option<&str>, + ) -> BoxFuture<'_, QueryResult> { + unimplemented!("not reached by the stream handlers") + } + + fn scan( + &self, + _key_info: &TableKeyInfo, + _limit: Option, + _exclusive_start_key: Option<&Item>, + _segment: Option, + _total_segments: Option, + _index_name: Option<&str>, + ) -> BoxFuture<'_, QueryResult> { + unimplemented!("not reached by the stream handlers") + } + + fn scan_key_in_segment( + &self, + _key_info: &TableKeyInfo, + _key: &Item, + _segment: i64, + _total_segments: i64, + _index_name: Option<&str>, + ) -> BoxFuture<'_, Result> { + unimplemented!("not reached by the stream handlers") + } + + fn transact_get_items( + &self, + _ops: &[TransactGetOp<'_>], + ) -> BoxFuture<'_, Result>, StorageError>> { + unimplemented!("not reached by the stream handlers") + } + + fn transact_write_items( + &self, + _ops: &[TransactWriteOp<'_>], + _idempotency: Option>, + ) -> BoxFuture<'_, Result<(), StorageError>> { + unimplemented!("not reached by the stream handlers") + } + + fn cleanup_expired_idempotency_tokens( + &self, + _max_age_seconds: i64, + ) -> BoxFuture<'_, Result> { + unimplemented!("not reached by the stream handlers") + } +} + +impl MetadataEngine for StreamStorage { + fn describe_ttl( + &self, + _account_id: &str, + _table_name: &str, + ) -> BoxFuture<'_, Result> { + unimplemented!("not reached by the stream handlers") + } + + fn update_ttl( + &self, + _account_id: &str, + _table_name: &str, + _attribute_name: &str, + _enabled: bool, + ) -> BoxFuture<'_, Result<(), StorageError>> { + unimplemented!("not reached by the stream handlers") + } + + fn tag_resource(&self, _arn: &str, _tags: &[Tag]) -> BoxFuture<'_, Result<(), StorageError>> { + unimplemented!("not reached by the stream handlers") + } + + fn untag_resource( + &self, + _arn: &str, + _tag_keys: &[String], + ) -> BoxFuture<'_, Result<(), StorageError>> { + unimplemented!("not reached by the stream handlers") + } + + fn list_tags(&self, _arn: &str) -> BoxFuture<'_, Result, StorageError>> { + unimplemented!("not reached by the stream handlers") + } + + fn tables_with_ttl( + &self, + _account_id: &str, + ) -> BoxFuture<'_, Result, StorageError>> { + unimplemented!("not reached by the stream handlers") + } + + fn all_tables_with_ttl(&self) -> BoxFuture<'_, Result, StorageError>> { + unimplemented!("not reached by the stream handlers") + } + + fn all_tables_with_ttl_index_ready( + &self, + ) -> BoxFuture<'_, Result, StorageError>> { + unimplemented!("not reached by the stream handlers") + } + + fn create_ttl_index( + &self, + _account_id: &str, + _table_name: &str, + _ttl_attribute: &str, + ) -> BoxFuture<'_, Result<(), StorageError>> { + unimplemented!("not reached by the stream handlers") + } + + fn drop_ttl_index( + &self, + _account_id: &str, + _table_name: &str, + _ttl_attribute: &str, + ) -> BoxFuture<'_, Result<(), StorageError>> { + unimplemented!("not reached by the stream handlers") + } + + fn find_expired_items_indexed( + &self, + _account_id: &str, + _table_name: &str, + _ttl_attribute: &str, + _limit: usize, + ) -> BoxFuture<'_, Result, StorageError>> { + unimplemented!("not reached by the stream handlers") + } + + fn refresh_table_size( + &self, + _account_id: &str, + _table_name: &str, + ) -> BoxFuture<'_, Result<(), StorageError>> { + unimplemented!("not reached by the stream handlers") + } + + fn list_active_table_names( + &self, + _account_id: &str, + ) -> BoxFuture<'_, Result, StorageError>> { + unimplemented!("not reached by the stream handlers") + } + + fn all_active_tables(&self) -> BoxFuture<'_, Result, StorageError>> { + unimplemented!("not reached by the stream handlers") + } +} + +impl StreamEngine for StreamStorage { + fn write_stream_record( + &self, + _account_id: &str, + _record: &StreamRecord, + _shard_id: &str, + _table_name: &str, + ) -> BoxFuture<'_, Result<(), StorageError>> { + unimplemented!("not reached by the stream handlers") + } + + fn get_stream_records( + &self, + _account_id: &str, + _shard_id: &str, + _after_sequence: Option<&str>, + _limit: i64, + ) -> BoxFuture<'_, StreamRecordsResult> { + Box::pin(async { Ok((Vec::new(), None)) }) + } + + fn describe_stream( + &self, + _account_id: &str, + input: &DescribeStreamInput, + ) -> BoxFuture<'_, Result> { + self.describe_calls.fetch_add(1, Ordering::Relaxed); + let description = StreamDescription { + stream_arn: input.stream_arn.clone(), + stream_label: String::new(), + stream_status: StreamStatus::Enabled, + stream_view_type: StreamViewType::NewImage, + table_name: "Orders".to_owned(), + key_schema: Vec::new(), + shards: Vec::new(), + last_evaluated_shard_id: None, + }; + Box::pin(async move { Ok(description) }) + } + + fn list_streams( + &self, + _account_id: &str, + _table_name: Option<&str>, + _limit: i64, + _exclusive_start_stream_arn: Option<&str>, + ) -> BoxFuture<'_, StreamListResult> { + unimplemented!("not reached by the stream handlers") + } + + fn cleanup_expired_stream_records( + &self, + _retention_hours: i64, + ) -> BoxFuture<'_, Result> { + unimplemented!("not reached by the stream handlers") + } + + fn assign_shard( + &self, + _account_id: &str, + _table_name: &str, + _partition_key: &str, + ) -> BoxFuture<'_, Result> { + unimplemented!("not reached by the stream handlers") + } + + fn next_sequence_number(&self, _shard_id: &str) -> BoxFuture<'_, Result> { + unimplemented!("not reached by the stream handlers") + } + + fn validate_shard( + &self, + _account_id: &str, + _stream_arn: &str, + _shard_id: &str, + ) -> BoxFuture<'_, Result<(), StorageError>> { + Box::pin(async { Ok(()) }) + } + + fn latest_sequence_number( + &self, + _shard_id: &str, + ) -> BoxFuture<'_, Result, StorageError>> { + unimplemented!("not reached by the stream handlers") + } +} + +impl WorkerStore for StreamStorage { + fn process_control_plane_transitions( + &self, + ) -> BoxFuture<'_, Result, StorageError>> { + unimplemented!("not reached by the stream handlers") + } +} + +impl BackupEngine for StreamStorage { + fn create_backup( + &self, + _account_id: &str, + _table_name: &str, + _backup_name: &str, + ) -> BoxFuture<'_, Result> { + unimplemented!("not reached by the stream handlers") + } + + fn describe_backup( + &self, + _account_id: &str, + _backup_arn: &str, + ) -> BoxFuture<'_, Result> { + unimplemented!("not reached by the stream handlers") + } + + fn list_backups( + &self, + _account_id: &str, + _table_name: Option<&str>, + ) -> BoxFuture<'_, Result, StorageError>> { + unimplemented!("not reached by the stream handlers") + } + + fn delete_backup( + &self, + _account_id: &str, + _backup_arn: &str, + ) -> BoxFuture<'_, Result> { + unimplemented!("not reached by the stream handlers") + } + + fn backup_restore_source( + &self, + _account_id: &str, + _backup_arn: &str, + ) -> BoxFuture<'_, Result> { + unimplemented!("not reached by the stream handlers") + } + + fn restore_table_from_backup( + &self, + _account_id: &str, + _request: RestoreRequest, + ) -> BoxFuture<'_, Result> { + unimplemented!("not reached by the stream handlers") + } + + fn describe_continuous_backups( + &self, + _account_id: &str, + _table_name: &str, + ) -> BoxFuture<'_, Result> { + unimplemented!("not reached by the stream handlers") + } + + fn update_continuous_backups( + &self, + _account_id: &str, + _table_name: &str, + _pitr_enabled: bool, + ) -> BoxFuture<'_, Result> { + unimplemented!("not reached by the stream handlers") + } +} From e41b5c6fdc0a9cb67cacad0d0b8c5d5b350cc1f2 Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Sat, 14 Nov 2026 15:01:18 +0000 Subject: [PATCH 2/6] test(streams): run the DescribeStream Limit tests on the engine's SQLite test context The tests ran on a storage double in crates/engine/src/streams/test_storage.rs that implemented every storage trait. Main changed those traits after this branch was cut, so the double no longer compiled. The crate already builds an OperationContext on an in-memory SQLite engine for its unit tests, in crates/engine/src/partiql/test_context.rs. The tests now use that context, and this commit deletes the double. partiql::test_context and its context function become pub(crate) so the streams tests can reach them. The context's database holds no stream. A refused Limit still carries its measured message, which shows the check ran before storage. For Limit 1 and Limit 100 the test asserts that neither Limit message comes back, in place of counting the storage calls. No helper in the crate opens a migrated in-memory engine, so there is no stream to describe, and the module doc says so. --- crates/engine/src/partiql/mod.rs | 2 +- crates/engine/src/partiql/test_context.rs | 2 +- crates/engine/src/streams.rs | 3 - .../src/streams/describe_limit_tests.rs | 37 +- crates/engine/src/streams/test_storage.rs | 509 ------------------ 5 files changed, 25 insertions(+), 528 deletions(-) delete mode 100644 crates/engine/src/streams/test_storage.rs diff --git a/crates/engine/src/partiql/mod.rs b/crates/engine/src/partiql/mod.rs index fb5e21044..dd7d0b0d9 100644 --- a/crates/engine/src/partiql/mod.rs +++ b/crates/engine/src/partiql/mod.rs @@ -57,7 +57,7 @@ mod returning; mod select; mod snapshot; #[cfg(test)] -mod test_context; +pub(crate) mod test_context; mod transaction; mod write; diff --git a/crates/engine/src/partiql/test_context.rs b/crates/engine/src/partiql/test_context.rs index 443514af0..bf44de0f9 100644 --- a/crates/engine/src/partiql/test_context.rs +++ b/crates/engine/src/partiql/test_context.rs @@ -30,7 +30,7 @@ pub(super) fn block_on(future: F) -> F::Output { } /// A context whose item authorizer is `authorizer`. -pub(super) async fn context(authorizer: Option>) -> OperationContext { +pub(crate) async fn context(authorizer: Option>) -> OperationContext { let storage = SqliteEngine::new(":memory:", 1, "us-east-1", 409_600) .await .expect("an in-memory database opens"); diff --git a/crates/engine/src/streams.rs b/crates/engine/src/streams.rs index fd4309178..c6d907e15 100755 --- a/crates/engine/src/streams.rs +++ b/crates/engine/src/streams.rs @@ -524,8 +524,5 @@ fn storage_to_dynamo(e: StorageError) -> DynamoDbError { #[path = "streams_tests.rs"] mod tests; -#[cfg(test)] -mod test_storage; - #[cfg(test)] mod describe_limit_tests; diff --git a/crates/engine/src/streams/describe_limit_tests.rs b/crates/engine/src/streams/describe_limit_tests.rs index c6f12fff1..2a5e2d27d 100644 --- a/crates/engine/src/streams/describe_limit_tests.rs +++ b/crates/engine/src/streams/describe_limit_tests.rs @@ -25,13 +25,26 @@ //! answers a bad `Limit` on a missing stream with `ValidationException` or //! `ResourceNotFoundException` is unknown. The handler refuses the `Limit` //! before it looks the stream up. +//! +//! The tests run the handler on the engine's in-memory SQLite test context +//! (`partiql::test_context::context`). Its database holds no stream, so a +//! request that reaches storage is answered with an error that is neither +//! `Limit` message. A refused `Limit` carries its exact message, which shows +//! the check ran before storage. For Limit 1 and Limit 100 the tests assert +//! only that neither `Limit` message comes back: the crate has no helper that +//! opens a migrated in-memory engine, so no stream exists to describe. use serde_json::json; use extenddb_core::error::DynamoDbError; use super::handle_describe_stream; -use super::test_storage::{STREAM_ARN, StreamStorage, context}; +use crate::partiql::test_context::context; + +/// A stream ARN in the context's account. Its database holds no table, so a +/// request that reaches storage is not answered with a stream description. +const STREAM_ARN: &str = + "arn:aws:dynamodb:us-east-1:000000000000:table/Orders/stream/2026-10-22T00:00:00.000"; const BELOW_ONE: &str = "1 validation error detected: Value at 'limit' failed to satisfy \ constraint: Member must have value greater than or equal to 1"; @@ -40,8 +53,7 @@ const ABOVE_MAX: &str = #[tokio::test] async fn describe_stream_refuses_a_limit_outside_1_to_100_before_storage() { - let storage = StreamStorage::new(); - let ctx = context(&storage); + let ctx = context(None).await; for (limit, expected) in [ (0, BELOW_ONE), (-3, BELOW_ONE), @@ -54,21 +66,18 @@ async fn describe_stream_refuses_a_limit_outside_1_to_100_before_storage() { other => panic!("Limit {limit}: expected ValidationException, got {other:?}"), } } - assert_eq!( - storage.describe_calls(), - 0, - "no refused Limit reached storage" - ); } #[tokio::test] -async fn describe_stream_passes_limits_1_and_100_to_storage() { - let storage = StreamStorage::new(); - let ctx = context(&storage); +async fn describe_stream_passes_limits_1_and_100() { + let ctx = context(None).await; for limit in [1, 100] { let body = json!({"StreamArn": STREAM_ARN, "Limit": limit}); - let described = handle_describe_stream(body, &ctx).await; - assert!(described.is_ok(), "Limit {limit}: {described:?}"); + let answer = handle_describe_stream(body, &ctx).await; + let refused = matches!( + &answer, + Err(DynamoDbError::ValidationException(m)) if m == BELOW_ONE || m == ABOVE_MAX + ); + assert!(!refused, "Limit {limit} was refused: {answer:?}"); } - assert_eq!(storage.describe_calls(), 2); } diff --git a/crates/engine/src/streams/test_storage.rs b/crates/engine/src/streams/test_storage.rs deleted file mode 100644 index 297d98a12..000000000 --- a/crates/engine/src/streams/test_storage.rs +++ /dev/null @@ -1,509 +0,0 @@ -// Copyright 2026 ExtendDB contributors -// SPDX-License-Identifier: Apache-2.0 - -//! A storage double for the stream handler tests. `validate_shard` accepts -//! every shard, `get_stream_records` answers an empty page and -//! `describe_stream` answers a description with no shards, counting its -//! calls. Every other method is unreachable from the stream handlers under -//! test and panics if called. - -use std::collections::HashMap; -use std::path::PathBuf; -use std::sync::Arc; -use std::sync::atomic::{AtomicUsize, Ordering}; - -use extenddb_core::expression::{Expr, ExpressionMaps, KeyCondition, UpdateAction}; -use extenddb_core::limits::LimitsConfig; -use extenddb_core::types::{ - BackupDescription, BackupDetails, BackupSummary, ContinuousBackupsDescription, - CreateTableInput, DeleteTableInput, DescribeStreamInput, DescribeTableInput, IndexInfo, Item, - ListTablesInput, ListTablesOutput, StreamDescription, StreamRecord, StreamStatus, - StreamViewType, TableDescription, TableKeyInfo, Tag, TimeToLiveDescription, UpdateTableInput, -}; -use extenddb_storage::BoxedFuture as BoxFuture; -use extenddb_storage::error::StorageError; -use extenddb_storage::{ - BackupEngine, BackupRestoreSource, DataEngine, IdempotencyKey, ItemPairResult, MetadataEngine, - QueryResult, RestoreRequest, StreamCapture, StreamEngine, StreamListResult, - StreamRecordsResult, TableEngine, TransactGetOp, TransactWriteOp, TtlTableInfo, WorkerStore, -}; - -use crate::OperationContext; - -/// The account the context's requests run as. -pub(super) const ACCOUNT: &str = "000000000000"; - -/// A stream ARN in [`ACCOUNT`]; the double accepts any shard of it. -pub(super) const STREAM_ARN: &str = - "arn:aws:dynamodb:us-east-1:000000000000:table/Orders/stream/2026-10-22T00:00:00.000"; - -/// A storage engine with just enough stream behaviour for the handlers. -pub(super) struct StreamStorage { - /// How many `describe_stream` calls reached the double. - describe_calls: AtomicUsize, -} - -impl StreamStorage { - pub(super) fn new() -> Arc { - Arc::new(Self { - describe_calls: AtomicUsize::new(0), - }) - } - - /// How many `describe_stream` calls reached storage. - pub(super) fn describe_calls(&self) -> usize { - self.describe_calls.load(Ordering::Relaxed) - } -} - -/// An operation context over `storage` for [`ACCOUNT`]. -pub(super) fn context(storage: &Arc) -> OperationContext { - let empty: Vec> = Vec::new(); - OperationContext { - storage: Arc::clone(storage) as Arc, - limits: Arc::new(LimitsConfig::default()), - region: Arc::from("us-east-1"), - account_id: Arc::from(ACCOUNT), - import_paths: Arc::from(empty.clone()), - export_paths: Arc::from(empty), - authorized_key_info: HashMap::new(), - auth_cache: extenddb_auth::AuthCacheRegistry::empty(), - table_key_info_lookup: None, - } -} - -impl TableEngine for StreamStorage { - fn create_table( - &self, - _account_id: &str, - _input: CreateTableInput, - ) -> BoxFuture<'_, Result> { - unimplemented!("not reached by the stream handlers") - } - - fn delete_table( - &self, - _account_id: &str, - _input: DeleteTableInput, - ) -> BoxFuture<'_, Result> { - unimplemented!("not reached by the stream handlers") - } - - fn describe_table( - &self, - _account_id: &str, - _input: DescribeTableInput, - ) -> BoxFuture<'_, Result> { - unimplemented!("not reached by the stream handlers") - } - - fn list_tables( - &self, - _account_id: &str, - _input: ListTablesInput, - ) -> BoxFuture<'_, Result> { - unimplemented!("not reached by the stream handlers") - } - - fn update_table( - &self, - _account_id: &str, - _input: UpdateTableInput, - ) -> BoxFuture<'_, Result> { - unimplemented!("not reached by the stream handlers") - } - - fn table_key_info( - &self, - _account_id: &str, - _table_name: &str, - ) -> BoxFuture<'_, Result> { - unimplemented!("not reached by the stream handlers") - } - - fn index_info( - &self, - _account_id: &str, - _table_name: &str, - _index_name: &str, - ) -> BoxFuture<'_, Result> { - unimplemented!("not reached by the stream handlers") - } - - fn index_info_by_table_id( - &self, - _table_id: &str, - _index_name: &str, - ) -> BoxFuture<'_, Result> { - unimplemented!("not reached by the stream handlers") - } -} - -impl DataEngine for StreamStorage { - fn put_item( - &self, - _key_info: &TableKeyInfo, - _item: Item, - _return_old: bool, - _condition: Option<&Expr>, - _maps: &ExpressionMaps, - _stream: Option<&StreamCapture>, - ) -> BoxFuture<'_, Result, StorageError>> { - unimplemented!("not reached by the stream handlers") - } - - fn get_item( - &self, - _key_info: &TableKeyInfo, - _key: &Item, - ) -> BoxFuture<'_, Result, StorageError>> { - unimplemented!("not reached by the stream handlers") - } - - fn delete_item( - &self, - _key_info: &TableKeyInfo, - _key: &Item, - _return_old: bool, - _condition: Option<&Expr>, - _maps: &ExpressionMaps, - _stream: Option<&StreamCapture>, - ) -> BoxFuture<'_, Result, StorageError>> { - unimplemented!("not reached by the stream handlers") - } - - fn update_item( - &self, - _key_info: &TableKeyInfo, - _key: &Item, - _actions: &[UpdateAction], - _return_old: bool, - _return_new: bool, - _condition: Option<&Expr>, - _maps: &ExpressionMaps, - _stream: Option<&StreamCapture>, - ) -> BoxFuture<'_, ItemPairResult> { - unimplemented!("not reached by the stream handlers") - } - - fn query( - &self, - _key_info: &TableKeyInfo, - _key_condition: &KeyCondition, - _maps: &ExpressionMaps, - _forward: bool, - _limit: Option, - _exclusive_start_key: Option<&Item>, - _index_name: Option<&str>, - ) -> BoxFuture<'_, QueryResult> { - unimplemented!("not reached by the stream handlers") - } - - fn scan( - &self, - _key_info: &TableKeyInfo, - _limit: Option, - _exclusive_start_key: Option<&Item>, - _segment: Option, - _total_segments: Option, - _index_name: Option<&str>, - ) -> BoxFuture<'_, QueryResult> { - unimplemented!("not reached by the stream handlers") - } - - fn scan_key_in_segment( - &self, - _key_info: &TableKeyInfo, - _key: &Item, - _segment: i64, - _total_segments: i64, - _index_name: Option<&str>, - ) -> BoxFuture<'_, Result> { - unimplemented!("not reached by the stream handlers") - } - - fn transact_get_items( - &self, - _ops: &[TransactGetOp<'_>], - ) -> BoxFuture<'_, Result>, StorageError>> { - unimplemented!("not reached by the stream handlers") - } - - fn transact_write_items( - &self, - _ops: &[TransactWriteOp<'_>], - _idempotency: Option>, - ) -> BoxFuture<'_, Result<(), StorageError>> { - unimplemented!("not reached by the stream handlers") - } - - fn cleanup_expired_idempotency_tokens( - &self, - _max_age_seconds: i64, - ) -> BoxFuture<'_, Result> { - unimplemented!("not reached by the stream handlers") - } -} - -impl MetadataEngine for StreamStorage { - fn describe_ttl( - &self, - _account_id: &str, - _table_name: &str, - ) -> BoxFuture<'_, Result> { - unimplemented!("not reached by the stream handlers") - } - - fn update_ttl( - &self, - _account_id: &str, - _table_name: &str, - _attribute_name: &str, - _enabled: bool, - ) -> BoxFuture<'_, Result<(), StorageError>> { - unimplemented!("not reached by the stream handlers") - } - - fn tag_resource(&self, _arn: &str, _tags: &[Tag]) -> BoxFuture<'_, Result<(), StorageError>> { - unimplemented!("not reached by the stream handlers") - } - - fn untag_resource( - &self, - _arn: &str, - _tag_keys: &[String], - ) -> BoxFuture<'_, Result<(), StorageError>> { - unimplemented!("not reached by the stream handlers") - } - - fn list_tags(&self, _arn: &str) -> BoxFuture<'_, Result, StorageError>> { - unimplemented!("not reached by the stream handlers") - } - - fn tables_with_ttl( - &self, - _account_id: &str, - ) -> BoxFuture<'_, Result, StorageError>> { - unimplemented!("not reached by the stream handlers") - } - - fn all_tables_with_ttl(&self) -> BoxFuture<'_, Result, StorageError>> { - unimplemented!("not reached by the stream handlers") - } - - fn all_tables_with_ttl_index_ready( - &self, - ) -> BoxFuture<'_, Result, StorageError>> { - unimplemented!("not reached by the stream handlers") - } - - fn create_ttl_index( - &self, - _account_id: &str, - _table_name: &str, - _ttl_attribute: &str, - ) -> BoxFuture<'_, Result<(), StorageError>> { - unimplemented!("not reached by the stream handlers") - } - - fn drop_ttl_index( - &self, - _account_id: &str, - _table_name: &str, - _ttl_attribute: &str, - ) -> BoxFuture<'_, Result<(), StorageError>> { - unimplemented!("not reached by the stream handlers") - } - - fn find_expired_items_indexed( - &self, - _account_id: &str, - _table_name: &str, - _ttl_attribute: &str, - _limit: usize, - ) -> BoxFuture<'_, Result, StorageError>> { - unimplemented!("not reached by the stream handlers") - } - - fn refresh_table_size( - &self, - _account_id: &str, - _table_name: &str, - ) -> BoxFuture<'_, Result<(), StorageError>> { - unimplemented!("not reached by the stream handlers") - } - - fn list_active_table_names( - &self, - _account_id: &str, - ) -> BoxFuture<'_, Result, StorageError>> { - unimplemented!("not reached by the stream handlers") - } - - fn all_active_tables(&self) -> BoxFuture<'_, Result, StorageError>> { - unimplemented!("not reached by the stream handlers") - } -} - -impl StreamEngine for StreamStorage { - fn write_stream_record( - &self, - _account_id: &str, - _record: &StreamRecord, - _shard_id: &str, - _table_name: &str, - ) -> BoxFuture<'_, Result<(), StorageError>> { - unimplemented!("not reached by the stream handlers") - } - - fn get_stream_records( - &self, - _account_id: &str, - _shard_id: &str, - _after_sequence: Option<&str>, - _limit: i64, - ) -> BoxFuture<'_, StreamRecordsResult> { - Box::pin(async { Ok((Vec::new(), None)) }) - } - - fn describe_stream( - &self, - _account_id: &str, - input: &DescribeStreamInput, - ) -> BoxFuture<'_, Result> { - self.describe_calls.fetch_add(1, Ordering::Relaxed); - let description = StreamDescription { - stream_arn: input.stream_arn.clone(), - stream_label: String::new(), - stream_status: StreamStatus::Enabled, - stream_view_type: StreamViewType::NewImage, - table_name: "Orders".to_owned(), - key_schema: Vec::new(), - shards: Vec::new(), - last_evaluated_shard_id: None, - }; - Box::pin(async move { Ok(description) }) - } - - fn list_streams( - &self, - _account_id: &str, - _table_name: Option<&str>, - _limit: i64, - _exclusive_start_stream_arn: Option<&str>, - ) -> BoxFuture<'_, StreamListResult> { - unimplemented!("not reached by the stream handlers") - } - - fn cleanup_expired_stream_records( - &self, - _retention_hours: i64, - ) -> BoxFuture<'_, Result> { - unimplemented!("not reached by the stream handlers") - } - - fn assign_shard( - &self, - _account_id: &str, - _table_name: &str, - _partition_key: &str, - ) -> BoxFuture<'_, Result> { - unimplemented!("not reached by the stream handlers") - } - - fn next_sequence_number(&self, _shard_id: &str) -> BoxFuture<'_, Result> { - unimplemented!("not reached by the stream handlers") - } - - fn validate_shard( - &self, - _account_id: &str, - _stream_arn: &str, - _shard_id: &str, - ) -> BoxFuture<'_, Result<(), StorageError>> { - Box::pin(async { Ok(()) }) - } - - fn latest_sequence_number( - &self, - _shard_id: &str, - ) -> BoxFuture<'_, Result, StorageError>> { - unimplemented!("not reached by the stream handlers") - } -} - -impl WorkerStore for StreamStorage { - fn process_control_plane_transitions( - &self, - ) -> BoxFuture<'_, Result, StorageError>> { - unimplemented!("not reached by the stream handlers") - } -} - -impl BackupEngine for StreamStorage { - fn create_backup( - &self, - _account_id: &str, - _table_name: &str, - _backup_name: &str, - ) -> BoxFuture<'_, Result> { - unimplemented!("not reached by the stream handlers") - } - - fn describe_backup( - &self, - _account_id: &str, - _backup_arn: &str, - ) -> BoxFuture<'_, Result> { - unimplemented!("not reached by the stream handlers") - } - - fn list_backups( - &self, - _account_id: &str, - _table_name: Option<&str>, - ) -> BoxFuture<'_, Result, StorageError>> { - unimplemented!("not reached by the stream handlers") - } - - fn delete_backup( - &self, - _account_id: &str, - _backup_arn: &str, - ) -> BoxFuture<'_, Result> { - unimplemented!("not reached by the stream handlers") - } - - fn backup_restore_source( - &self, - _account_id: &str, - _backup_arn: &str, - ) -> BoxFuture<'_, Result> { - unimplemented!("not reached by the stream handlers") - } - - fn restore_table_from_backup( - &self, - _account_id: &str, - _request: RestoreRequest, - ) -> BoxFuture<'_, Result> { - unimplemented!("not reached by the stream handlers") - } - - fn describe_continuous_backups( - &self, - _account_id: &str, - _table_name: &str, - ) -> BoxFuture<'_, Result> { - unimplemented!("not reached by the stream handlers") - } - - fn update_continuous_backups( - &self, - _account_id: &str, - _table_name: &str, - _pitr_enabled: bool, - ) -> BoxFuture<'_, Result> { - unimplemented!("not reached by the stream handlers") - } -} From c2a801fe53a2d094d00df1f32ec956e8b6edddc3 Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Sat, 14 Nov 2026 14:32:20 +0000 Subject: [PATCH 3/6] refactor(streams): build the DescribeStream Limit refusal with constraint() Main added the constraint() helper to crates/engine/src/streams.rs. ListStreams and GetRecords use it for the same Limit sentence that this branch wrote out in full for DescribeStream. handle_describe_stream now calls constraint("limit", "have value greater than or equal to 1"). The message text does not change, and the DescribeStream Limit tests still assert the measured sentence. --- crates/engine/src/streams.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/streams.rs b/crates/engine/src/streams.rs index c6d907e15..38b76d14a 100755 --- a/crates/engine/src/streams.rs +++ b/crates/engine/src/streams.rs @@ -48,11 +48,10 @@ pub async fn handle_describe_stream( // raw responses are quoted in streams/describe_limit_tests.rs). if let Some(limit) = input.limit { if limit < 1 { - return Err(DynamoDbError::ValidationException( - "1 validation error detected: Value at 'limit' failed to satisfy \ - constraint: Member must have value greater than or equal to 1" - .to_owned(), - )); + return Err(DynamoDbError::ValidationException(constraint( + "limit", + "have value greater than or equal to 1", + ))); } if limit > DESCRIBE_STREAM_LIMIT_MAX { return Err(DynamoDbError::ValidationException(format!( From eaba19c8df3a35edcd3ee0020cd21edecd182d80 Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Wed, 25 Nov 2026 07:50:48 +0000 Subject: [PATCH 4/6] fix(streams): DescribeStream refuses a Limit above 100 after the stream lookup The service checks the two Limit bounds at different points. It refuses a Limit below 1 before it looks the stream up, in one message with the other member constraints. It refuses a Limit above 100 only after it has found the stream. Measured 2026-11-25 in us-east-1, each request twice, on a stream of a table that does not exist. Limit 1, 101 and 1000 got ResourceNotFoundException "Requested resource not found: Stream: not found", and so did Limit 101 with a 36-character ExclusiveStartShardId. Limit 0 and -1 got the below-one ValidationException. Limit 0 with a 13-character ExclusiveStartShardId got both clauses in one message: 400 {"__type":"com.amazon.coral.validate#ValidationException","message":"2 validation errors detected: Value at 'exclusiveStartShardId' failed to satisfy constraint: Member must have length greater than or equal to 28; Value at 'limit' failed to satisfy constraint: Member must have value greater than or equal to 1"} Limit 101 with that 13-character id got the ExclusiveStartShardId clause alone. handle_describe_stream now collects the ExclusiveStartShardId clause and the below-one Limit clause in one list, through main's clause() and validation_errors_detected(). When the list is not empty, it refuses before the lookup. It checks the upper bound once describe_stream has answered. Main's lookup answers ResourceNotFoundException for a missing stream, so main's answer to Limit 101 on a missing stream stays. The test module runs the handler on the engine's test context over SqliteEngine::new_in_memory, which migrates the database, with a table Orders that has a stream. One table of 14 rows asserts each answer by equality. The refusals carry their full messages. The missing stream gets the ResourceNotFoundException message. Limit 1 and Limit 100 on the existing stream get the StreamArn echoed. Two earlier messages on this branch no longer describe the code. The first commit says the tests run over a storage double that counts describe_stream calls, and that Limit 101 and 1000 never reach storage. e41b5c6f deleted the double, and with this commit Limit 101 and 1000 reach storage and are refused after the lookup. --- crates/engine/src/streams.rs | 42 ++--- .../src/streams/describe_limit_tests.rs | 155 ++++++++++++------ 2 files changed, 128 insertions(+), 69 deletions(-) diff --git a/crates/engine/src/streams.rs b/crates/engine/src/streams.rs index bde946197..fa5d3da4d 100755 --- a/crates/engine/src/streams.rs +++ b/crates/engine/src/streams.rs @@ -35,31 +35,26 @@ pub async fn handle_describe_stream( ) -> Result { let input: DescribeStreamInput = serde_json::from_value(body) .map_err(|e| DynamoDbError::SerializationException(e.to_string()))?; + // The service names every failed member constraint in one message before + // it looks the stream up, and refuses a Limit above 100 only once it has + // found the stream (measured in us-east-1; the answers are quoted in + // streams/describe_limit_tests.rs). + let mut clauses = Vec::new(); if let Some(start) = &input.exclusive_start_shard_id && start.chars().count() < SHARD_ID_MIN_LEN { - return Err(DynamoDbError::ValidationException(constraint( + clauses.push(clause( "exclusiveStartShardId", "have length greater than or equal to 28", - ))); + )); } - - // Limit bounds as the service enforces them (measured 2026-10-22, - // DescribeStream with Limit 0, -1, 101 and 1000 against us-east-1; the - // raw responses are quoted in streams/describe_limit_tests.rs). - if let Some(limit) = input.limit { - if limit < 1 { - return Err(DynamoDbError::ValidationException(constraint( - "limit", - "have value greater than or equal to 1", - ))); - } - if limit > DESCRIBE_STREAM_LIMIT_MAX { - return Err(DynamoDbError::ValidationException(format!( - "One or more parameter values were invalid: Limit cannot be greater than \ - the maximum: {DESCRIBE_STREAM_LIMIT_MAX}" - ))); - } + if input.limit.is_some_and(|limit| limit < 1) { + clauses.push(clause("limit", "have value greater than or equal to 1")); + } + if !clauses.is_empty() { + return Err(DynamoDbError::ValidationException( + extenddb_core::error::validation_errors_detected(&clauses), + )); } let desc = ctx @@ -67,6 +62,15 @@ pub async fn handle_describe_stream( .describe_stream(&ctx.account_id, &input) .await .map_err(storage_to_dynamo)?; + if input + .limit + .is_some_and(|limit| limit > DESCRIBE_STREAM_LIMIT_MAX) + { + return Err(DynamoDbError::ValidationException(format!( + "One or more parameter values were invalid: Limit cannot be greater than \ + the maximum: {DESCRIBE_STREAM_LIMIT_MAX}" + ))); + } let output = DescribeStreamOutput { stream_description: desc, diff --git a/crates/engine/src/streams/describe_limit_tests.rs b/crates/engine/src/streams/describe_limit_tests.rs index 2a5e2d27d..a171d565d 100644 --- a/crates/engine/src/streams/describe_limit_tests.rs +++ b/crates/engine/src/streams/describe_limit_tests.rs @@ -1,13 +1,13 @@ // Copyright 2026 ExtendDB contributors // SPDX-License-Identifier: Apache-2.0 -//! `DescribeStream` refuses a `Limit` below 1 or above 100 with the service's -//! messages before storage is reached, and passes the bounds themselves -//! through. +//! `DescribeStream` refuses a `Limit` below 1 together with the other member +//! constraints before it looks the stream up, and a `Limit` above 100 only +//! after it has found the stream. //! -//! The messages were measured on 2026-10-22 in us-east-1 with -//! `DescribeStream` on an existing stream, the SDK's own parameter -//! validation switched off so the requests reached the service: +//! Measured in us-east-1 with the SDK's own parameter validation switched +//! off, so the requests reached the service. On 2026-10-22, on an existing +//! stream: //! //! ```text //! Limit 0 and Limit -1: @@ -16,68 +16,123 @@ //! 400 {"__type":"com.amazon.coral.validate#ValidationException","message":"One or more parameter values were invalid: Limit cannot be greater than the maximum: 100"} //! ``` //! -//! Limit 1 returned one shard and `LastEvaluatedShardId`. The below-one text -//! leaves out the value, where this crate's `ListTables` and `Scan` messages -//! for the same constraint include it. +//! On 2026-11-25, each request twice, on a stream of a table that does not +//! exist: Limit 0 and -1 got the first body above; Limit 1, 101 and 1000, and +//! Limit 101 with a 36-character `ExclusiveStartShardId`, got 400 +//! `ResourceNotFoundException` "Requested resource not found: Stream: +//! not found"; Limit 0 with a 13-character `ExclusiveStartShardId` got the +//! two clauses in one message ([`SHORT_START_AND_BELOW_ONE`]); Limit 101 with +//! that start got the start clause alone ([`SHORT_START`]). //! -//! The order of the checks against a missing stream is unmeasured: the -//! measurement ran on an existing stream only, so whether the service -//! answers a bad `Limit` on a missing stream with `ValidationException` or -//! `ResourceNotFoundException` is unknown. The handler refuses the `Limit` -//! before it looks the stream up. -//! -//! The tests run the handler on the engine's in-memory SQLite test context -//! (`partiql::test_context::context`). Its database holds no stream, so a -//! request that reaches storage is answered with an error that is neither -//! `Limit` message. A refused `Limit` carries its exact message, which shows -//! the check ran before storage. For Limit 1 and Limit 100 the tests assert -//! only that neither `Limit` message comes back: the crate has no helper that -//! opens a migrated in-memory engine, so no stream exists to describe. +//! The tests run the handler on the engine's test context over a migrated +//! in-memory engine, so a request that reaches storage for a missing stream +//! gets `ResourceNotFoundException`. + +use std::sync::Arc; use serde_json::json; use extenddb_core::error::DynamoDbError; use super::handle_describe_stream; +use crate::OperationContext; use crate::partiql::test_context::context; -/// A stream ARN in the context's account. Its database holds no table, so a -/// request that reaches storage is not answered with a stream description. -const STREAM_ARN: &str = - "arn:aws:dynamodb:us-east-1:000000000000:table/Orders/stream/2026-10-22T00:00:00.000"; +const MISSING: &str = + "arn:aws:dynamodb:us-east-1:000000000000:table/Missing/stream/2026-10-22T00:00:00.000"; +const SHORT_ID: &str = "shardId-short"; +const VALID_ID: &str = "shardId-00000001700000000000-00000000"; const BELOW_ONE: &str = "1 validation error detected: Value at 'limit' failed to satisfy \ constraint: Member must have value greater than or equal to 1"; const ABOVE_MAX: &str = "One or more parameter values were invalid: Limit cannot be greater than the maximum: 100"; +const SHORT_START: &str = "1 validation error detected: Value at 'exclusiveStartShardId' \ + failed to satisfy constraint: Member must have length greater \ + than or equal to 28"; +const SHORT_START_AND_BELOW_ONE: &str = "2 validation errors detected: Value at \ + 'exclusiveStartShardId' failed to satisfy constraint: Member must have length greater \ + than or equal to 28; Value at 'limit' failed to satisfy constraint: Member must have \ + value greater than or equal to 1"; -#[tokio::test] -async fn describe_stream_refuses_a_limit_outside_1_to_100_before_storage() { - let ctx = context(None).await; - for (limit, expected) in [ - (0, BELOW_ONE), - (-3, BELOW_ONE), - (101, ABOVE_MAX), - (1000, ABOVE_MAX), - ] { - let body = json!({"StreamArn": STREAM_ARN, "Limit": limit}); - match handle_describe_stream(body, &ctx).await { - Err(DynamoDbError::ValidationException(m)) => assert_eq!(m, expected, "Limit {limit}"), - other => panic!("Limit {limit}: expected ValidationException, got {other:?}"), - } - } +/// The answer a row expects. +enum Answer { + Refused(&'static str), + NotFound, + Served, +} + +/// The test context over a migrated in-memory engine holding the table +/// `Orders` with a stream. Returns the context and the stream's ARN. +async fn context_with_stream() -> (OperationContext, String) { + let mut ctx = context(None).await; + let storage = + extenddb_storage_sqlite::SqliteEngine::new_in_memory("us-east-1", &ctx.account_id, 409_600) + .await + .expect("a migrated in-memory engine opens"); + ctx.storage = Arc::new(storage); + let created = crate::handle_create_table( + json!({ + "TableName": "Orders", + "AttributeDefinitions": [{"AttributeName": "pk", "AttributeType": "S"}], + "KeySchema": [{"AttributeName": "pk", "KeyType": "HASH"}], + "BillingMode": "PAY_PER_REQUEST", + "StreamSpecification": {"StreamEnabled": true, "StreamViewType": "KEYS_ONLY"} + }), + &ctx, + ) + .await + .expect("the table is created"); + let arn = created["TableDescription"]["LatestStreamArn"] + .as_str() + .expect("the table has a stream") + .to_owned(); + (ctx, arn) } #[tokio::test] -async fn describe_stream_passes_limits_1_and_100() { - let ctx = context(None).await; - for limit in [1, 100] { - let body = json!({"StreamArn": STREAM_ARN, "Limit": limit}); +async fn describe_stream_checks_limit_where_the_service_does() { + let (ctx, existing) = context_with_stream().await; + let not_found = format!("Requested resource not found: Stream: {MISSING} not found"); + let rows: [(&str, i64, Option<&str>, Answer); 14] = [ + (existing.as_str(), 0, None, Answer::Refused(BELOW_ONE)), + (existing.as_str(), -1, None, Answer::Refused(BELOW_ONE)), + (existing.as_str(), 101, None, Answer::Refused(ABOVE_MAX)), + (existing.as_str(), 1000, None, Answer::Refused(ABOVE_MAX)), + (existing.as_str(), 1, None, Answer::Served), + (existing.as_str(), 100, None, Answer::Served), + (MISSING, 0, None, Answer::Refused(BELOW_ONE)), + (MISSING, -1, None, Answer::Refused(BELOW_ONE)), + (MISSING, 1, None, Answer::NotFound), + (MISSING, 101, None, Answer::NotFound), + (MISSING, 1000, None, Answer::NotFound), + ( + MISSING, + 0, + Some(SHORT_ID), + Answer::Refused(SHORT_START_AND_BELOW_ONE), + ), + (MISSING, 101, Some(SHORT_ID), Answer::Refused(SHORT_START)), + (MISSING, 101, Some(VALID_ID), Answer::NotFound), + ]; + for (arn, limit, start, expected) in rows { + let mut body = json!({"StreamArn": arn, "Limit": limit}); + if let Some(start) = start { + body["ExclusiveStartShardId"] = json!(start); + } + let row = format!("{arn} Limit {limit} start {start:?}"); let answer = handle_describe_stream(body, &ctx).await; - let refused = matches!( - &answer, - Err(DynamoDbError::ValidationException(m)) if m == BELOW_ONE || m == ABOVE_MAX - ); - assert!(!refused, "Limit {limit} was refused: {answer:?}"); + match (answer, expected) { + (Err(DynamoDbError::ValidationException(m)), Answer::Refused(e)) => { + assert_eq!(m, e, "{row}"); + } + (Err(DynamoDbError::ResourceNotFoundException(m)), Answer::NotFound) => { + assert_eq!(m, not_found, "{row}"); + } + (Ok(v), Answer::Served) => { + assert_eq!(v["StreamDescription"]["StreamArn"], json!(arn), "{row}"); + } + (other, _) => panic!("{row}: got {other:?}"), + } } } From 0c97f41ba6c6b45a3f6d9e7b789b49cc67dd8b2f Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Wed, 25 Nov 2026 07:50:48 +0000 Subject: [PATCH 5/6] test(streams): build the DescribeStream Limit tests only with the partiql feature The test module imports partiql::test_context::context, and crates/engine/src/lib.rs declares the partiql module under the partiql feature. With cargo test -p extenddb-engine --no-default-features --lib --no-run the module did not compile: E0433, cannot find partiql in crate. CI builds the engine's tests with default features only, so no job showed it. The module is now declared under cfg(all(test, feature = "partiql")), like the partiql module it reads from. The same command exits 0 with the gate. --- crates/engine/src/streams.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/engine/src/streams.rs b/crates/engine/src/streams.rs index fa5d3da4d..36af7e4b7 100755 --- a/crates/engine/src/streams.rs +++ b/crates/engine/src/streams.rs @@ -584,5 +584,5 @@ fn storage_to_dynamo(e: StorageError) -> DynamoDbError { #[path = "streams_tests.rs"] mod tests; -#[cfg(test)] +#[cfg(all(test, feature = "partiql"))] mod describe_limit_tests; From 4af9d30207e175a2256bc81838b94de34193cded Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Wed, 25 Nov 2026 09:14:55 +0000 Subject: [PATCH 6/6] test(wasm): expect the Limit refusal in the DescribeStream parity case The WebAssembly parity corpus sends DescribeStream with Limit 4294967297 to a table's stream and expected all four shards. That was the answer before this branch. The branch refuses a Limit above 100 once it has found the stream, as the service does for 101 and 1000. The case now expects that refusal by its message. It still catches a build that reads the Limit as 32 bits: 4294967297 is 1 there, and Limit 1 is served. On 25 Nov the service answered ResourceNotFoundException for Limit 4294967297 and for 2147483648, two sends each. The stream was one of a table that does not exist. So the service reads both values as a Limit and looks the stream up first. --- crates/wasm-adapter/parity/corpus.json | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/crates/wasm-adapter/parity/corpus.json b/crates/wasm-adapter/parity/corpus.json index bb8840a7a..131dd30e1 100644 --- a/crates/wasm-adapter/parity/corpus.json +++ b/crates/wasm-adapter/parity/corpus.json @@ -2858,25 +2858,17 @@ } }, { - "name": "DescribeStream with a Limit above 2^32 returns all four shards and no LastEvaluatedShardId", + "name": "DescribeStream with a Limit above 2^32 is refused as a Limit above 100, not read as a Limit of 1", "op": "DescribeStream", "body": { "StreamArn": "${strmArn}", "Limit": 4294967297 }, - "error": null, + "error": "ValidationException", "checks": [ { - "path": "/StreamDescription/Shards/3/ShardId", - "present": true - }, - { - "path": "/StreamDescription/Shards/4", - "absent": true - }, - { - "path": "/StreamDescription/LastEvaluatedShardId", - "absent": true + "path": "/message", + "equals": "One or more parameter values were invalid: Limit cannot be greater than the maximum: 100" } ] },