-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Step Functions: Surface Support for Mocked Responses #12525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Step Functions: Surface Support for Mocked Responses #12525
Conversation
LocalStack Community integration with Pro 2 files 2 suites 1h 51m 54s ⏱️ Results for commit 376a73d. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Some very small nits/questions. Otherwise, I think this is good to go 👍
localstack-core/localstack/services/stepfunctions/mocking/mock_config.py
Show resolved
Hide resolved
range_part_start = definition_parts[0] | ||
range_part_end = definition_parts[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be checking that range_part_start > range_part_end
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We check when trying to construct the mock responses from these values localstack.services.stepfunctions.mocking.mock_config.StateMockedResponses.__init__
|
||
|
||
def _parse_mocked_response_range(string_definition: str) -> tuple[int, int]: | ||
definition_parts = string_definition.strip().split("-") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to validate these values at all? Like are there valid bounds?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes indeed, we do this after parsing the values and constructing the StateMockedResponses object for the runtime later localstack.services.stepfunctions.mocking.mock_config.StateMockedResponses.__init__
localstack-core/localstack/services/stepfunctions/mocking/mock_config_file.py
Show resolved
Hide resolved
Accepts any fields. | ||
""" | ||
|
||
model_config = {"extra": "allow", "frozen": True} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Should we be using a pydantic.dataclass
here instead? It contains a frozen
attribute out-the-box so am wondering about the BaseModel
approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely a good point you raise! In this case we still need a few BaseModel features, I can see:
- extra="allow" on RawReturnResponse
- the root model on RawTestCase
- the model_validator in RawResponseModel
Pydantic’s dataclass doesn’t support any of those as far as I can see, and we'd also lose the model_dump() (although this may not be an issue by itself if we were using records)
@lru_cache(maxsize=1) | ||
def _read_sfn_raw_mock_config(file_path: str, modified_epoch: int) -> Optional[RawMockConfig]: # noqa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: this will only cache a single call. I imagine we wont be reading in multiple mock files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct, for now we'll be loading one file only
Motivation
These changes introduce base support for executing AWS Step Functions state machines in a mock-enabled mode, designed to streamline testing and simulation workflows. The primary motivation is to enable users to execute state machines using mock configuration files, allowing simulated task execution by sampling predefined responses from a mock oracle. This capability is particularly valuable for validating control flow logic and response handling in a deterministic manner without invoking actual downstream services AWS Docs
The changes in this PR surface support for all critical components necessary to enable this workflow. Future changes will refine and expand on each aspect introduced in this PR
Changes