Skip to content
This repository was archived by the owner on Mar 23, 2026. It is now read-only.

feat(stepfunctions): Add support for variables as TestState parameter#13827

Merged
tiurin merged 5 commits intomainfrom
sfn/fix/test-state-jsonata-variables/drg-526
Feb 24, 2026
Merged

feat(stepfunctions): Add support for variables as TestState parameter#13827
tiurin merged 5 commits intomainfrom
sfn/fix/test-state-jsonata-variables/drg-526

Conversation

@tiurin
Copy link
Copy Markdown
Contributor

@tiurin tiurin commented Feb 23, 2026

Motivation

Fixes #13215

variables parameter of TestState API call was not processed. This PR adds support for it.

Changes

Set variables from API call parameter to test state execution environment.

Tests

Related

@tiurin tiurin added aws:stepfunctions AWS Step Functions semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases docs: skip Pull request does not require documentation changes notes: skip Pull request does not have to be mentioned in the release notes labels Feb 23, 2026
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 23, 2026

Test Results - Preflight, Unit

23 070 tests  ±0   21 179 ✅ ±0   6m 11s ⏱️ -16s
     1 suites ±0    1 891 💤 ±0 
     1 files   ±0        0 ❌ ±0 

Results for commit 06e17a7. ± Comparison against base commit aa8af99.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 23, 2026

LocalStack Community integration with Pro

    2 files      2 suites   22m 33s ⏱️
1 730 tests 1 641 ✅ 89 💤 0 ❌
1 732 runs  1 641 ✅ 91 💤 0 ❌

Results for commit 06e17a7.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 23, 2026

Test Results (amd64) - Acceptance

7 tests  ±0   5 ✅ ±0   2m 55s ⏱️ -7s
1 suites ±0   2 💤 ±0 
1 files   ±0   0 ❌ ±0 

Results for commit 06e17a7. ± Comparison against base commit aa8af99.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 23, 2026

Test Results (amd64) - Integration, Bootstrap

    5 files      5 suites   39m 45s ⏱️
1 754 tests 1 666 ✅ 88 💤 0 ❌
1 760 runs  1 666 ✅ 94 💤 0 ❌

Results for commit 06e17a7.

♻️ This comment has been updated with latest results.

@tiurin tiurin modified the milestone: 4.14 Feb 23, 2026
Copy link
Copy Markdown
Contributor Author

@tiurin tiurin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added self-review notes.

def add_inspection_data(self, env: TestStateEnvironment):
state = self._wrapped

if state._is_language_query_jsonpath():
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New test uncovered that JSONPath-related inspection data were added to states that use JSONata.

self.inspection_data = InspectionData()
variables = variable_store.to_dict()
if variables:
self.inspection_data["variables"] = to_json_str(variables)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the key change, the rest is passing variables data through the call stack.

_variable_declarations_cache: VariableDeclarations | None

def __init__(self):
def __init__(self, variables: dict | None = None):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With test state, variables store can now be pre-populated rather than being the result of evaluation.

assigned_variables[traced_declaration_identifier] = traced_declaration_value_json_str
return assigned_variables

def to_dict(self) -> dict[str, str]:
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new function is similar to get_assigned_variables right above, but doesn't add any additional formatting.

{
"tests/aws/services/stepfunctions/v2/outputdecl/test_output.py::TestArgumentsBase::test_base_cases[BASE_EMPTY]": {
"recorded-date": "04-11-2024, 13:15:46",
"recorded-date": "19-02-2026, 14:47:34",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revalidated output tests since initially it looked like output-related problem. Keeping revalidated snapshots, even if they are not strictly related to this PR.

@tiurin tiurin requested a review from gregfurman February 23, 2026 15:39
@tiurin tiurin marked this pull request as ready for review February 23, 2026 15:40
@tiurin tiurin requested a review from joe4dev as a code owner February 23, 2026 15:40
@tiurin tiurin removed the request for review from joe4dev February 23, 2026 15:40
Comment on lines +65 to +66
for key, value in variables.items():
self.set(key, value)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: should we be doing a deep copy here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, since variables is used only once to set up execution environment for the test state. If any variable is modified later in the variable store it won't matter.

)
self.inspection_data = InspectionData()
variables = variable_store.to_dict()
if variables:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we explicitly set variables to an empty dict, would we expect it to come up in inspection data? Suppose I'm wondering if this should be a None check or an is_truthy check

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty dict doesn't come up in inspection data. Good point, thanks! 👍 I've added a validated test for this situation.

Overriding __len__ broke many tests, there might be implicit checks like `if variable_store:` that were breaking with the override, outside of test state functionality.

Changing to a more explicit length check
@tiurin tiurin force-pushed the sfn/fix/test-state-jsonata-variables/drg-526 branch from 8298647 to 06e17a7 Compare February 24, 2026 11:19
@tiurin tiurin merged commit a17c007 into main Feb 24, 2026
35 checks passed
@tiurin tiurin deleted the sfn/fix/test-state-jsonata-variables/drg-526 branch February 24, 2026 11:58
@tiurin tiurin added notes: needed Pull request should be mentioned in the release notes and removed notes: skip Pull request does not have to be mentioned in the release notes labels Feb 25, 2026
@localstack-bot
Copy link
Copy Markdown
Contributor

Currently, only patch changes are allowed on main. Your PR labels (aws:stepfunctions, semver: minor, docs: skip, notes: needed) indicate that it cannot be merged into the main at this time.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

aws:stepfunctions AWS Step Functions docs: skip Pull request does not require documentation changes notes: needed Pull request should be mentioned in the release notes semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: TestState variables not interpolated in Pass state(applies to other supported states as well) with JSONata

3 participants