Unverified Commit 5bbf0a18 authored by Aaron Todd's avatar Aaron Todd Committed by GitHub
Browse files

fix regression in aws-smithy-mocks MatchAny mode and add a new repeatedly()...

fix regression in aws-smithy-mocks MatchAny mode and add a new repeatedly() function for infinite sequences (#4136)

## Motivation and Context
fixes https://github.com/smithy-lang/smithy-rs/issues/4135

## Description
* **Fixed regression in RuleMode::MatchAny**: Simple rules (created with
`.then_output()`, `.then_error()`, etc.) now correctly work repeatedly
in `MatchAny` mode, restoring backward
compatibility
* **Added repeatedly() method**: New API to make the last response in a
sequence repeat indefinitely
* **Improved times(n) implementation**: Now uses repetition counts
instead of cloning generators, improving memory efficiency
* **Added type state pattern**: Prevents adding more responses after
calling `repeatedly()`
* **Added validation**: Better error messages when `times(n)` is misused
* **Fixed overflow handling**: Used saturating_add to safely calculate
total responses
* **Added unit tests**: New tests for simple rules, `repeatedly()`, and
regression
* **Updated documentation**: Added examples and explanations for the new
functionality

## Questions

1. I've added a typestate pattern for `repeatedly()` since adding new
outputs to such a rule would never be used/invalid. Not sure if this is
worth it or not though.

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] For changes to the smithy-rs codegen or runtime crates, I have
created a changelog entry Markdown file in the `.changelog` directory,
specifying "client," "server," or both in the `applies_to` key.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent b9703dce
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
---
applies_to:
- aws-sdk-rust
- client
authors:
- aajtodd
references:
- smithy-rs#4135
breaking: false
new_feature: false
bug_fix: true
---
fix simple rules behavior with `RuleMode::MatchAny`
+27 −0
Original line number Diff line number Diff line
---
applies_to:
- client
- aws-sdk-rust
authors:
- aajtodd
references:
- smithy-rs#4135
breaking: false
new_feature: true
bug_fix: false
---
Introduce a new `repeatedly()` function to `aws-smithy-mocks` sequence builder to build mock rules that behave as an
infinite sequence.

```rust
let rule = mock!(aws_sdk_s3::Client::get_object)
    .sequence()
    .http_status(503, None)
    .times(2)        // repeat the last output twice before moving onto the next response in the sequence
    .output(|| GetObjectOutput::builder()
        .body(ByteStream::from_static(b"success"))
        .build()
    )
    .repeatedly()    // repeat the last output forever
    .build();
```
+1 −1
Original line number Diff line number Diff line
@@ -189,7 +189,7 @@ version = "0.60.3"

[[package]]
name = "aws-sigv4"
version = "1.3.1"
version = "1.3.2"
dependencies = [
 "aws-credential-types",
 "aws-smithy-eventstream",
+2 −2
Original line number Diff line number Diff line
@@ -51,7 +51,7 @@ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"

[[package]]
name = "aws-config"
version = "1.6.2"
version = "1.6.3"
dependencies = [
 "aws-credential-types",
 "aws-runtime",
@@ -202,7 +202,7 @@ dependencies = [

[[package]]
name = "aws-sigv4"
version = "1.3.1"
version = "1.3.2"
dependencies = [
 "aws-credential-types",
 "aws-smithy-http",
+1 −1
Original line number Diff line number Diff line
@@ -543,7 +543,7 @@ dependencies = [

[[package]]
name = "aws-smithy-mocks"
version = "0.1.0"
version = "0.1.1"
dependencies = [
 "aws-smithy-async",
 "aws-smithy-http-client",
Loading