-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(stepfunctions): Add support for variables as TestState parameter #13827
Changes from all commits
ae6c2a1
4985ece
0c393fb
b80b5ea
06e17a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |
| ProgramRetriable, | ||
| ) | ||
| from localstack.services.stepfunctions.asl.eval.variable_store import VariableStore | ||
| from localstack.services.stepfunctions.asl.utils.encoding import to_json_str | ||
| from localstack.services.stepfunctions.backend.activity import Activity | ||
| from localstack.services.stepfunctions.backend.test_state.test_state_mock import TestStateMock | ||
|
|
||
|
|
@@ -50,6 +51,9 @@ def __init__( | |
| variable_store=variable_store, | ||
| ) | ||
| self.inspection_data = InspectionData() | ||
| variables = variable_store.to_dict() | ||
| if variables: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| self.inspection_data["variables"] = to_json_str(variables) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| self.mock = mock | ||
|
|
||
| def is_test_state_mocked_mode(self) -> bool: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -54,13 +54,17 @@ class VariableStore: | |
| _outer_variable_declaration_cache: VariableDeclarations | None | ||
| _variable_declarations_cache: VariableDeclarations | None | ||
|
|
||
| def __init__(self): | ||
| def __init__(self, variables: dict | None = None): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| self._outer_scope = {} | ||
| self._inner_scope = {} | ||
| self._declaration_tracing = set() | ||
| self._outer_variable_declaration_cache = None | ||
| self._variable_declarations_cache = None | ||
|
|
||
| if variables: | ||
| for key, value in variables.items(): | ||
| self.set(key, value) | ||
|
Comment on lines
+65
to
+66
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Q: should we be doing a deep copy here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, since |
||
|
|
||
| @classmethod | ||
| def as_inner_scope_of(cls, outer_variable_store: VariableStore) -> VariableStore: | ||
| inner_variable_store = cls() | ||
|
|
@@ -85,6 +89,14 @@ def get_assigned_variables(self) -> dict[str, str]: | |
| assigned_variables[traced_declaration_identifier] = traced_declaration_value_json_str | ||
| return assigned_variables | ||
|
|
||
| def to_dict(self) -> dict[str, str]: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This new function is similar to |
||
| assigned_variables: dict[str, str] = {} | ||
| for traced_declaration_identifier in self._declaration_tracing: | ||
| assigned_variables[traced_declaration_identifier] = self.get( | ||
| traced_declaration_identifier | ||
| ) | ||
| return assigned_variables | ||
|
|
||
| def get(self, variable_identifier: VariableIdentifier) -> VariableValue: | ||
| if variable_identifier in self._inner_scope: | ||
| return self._inner_scope[variable_identifier] | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "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", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| "recorded-content": { | ||
| "get_execution_history": { | ||
| "events": [ | ||
|
|
@@ -78,7 +78,7 @@ | |
| } | ||
| }, | ||
| "tests/aws/services/stepfunctions/v2/outputdecl/test_output.py::TestArgumentsBase::test_base_cases[BASE_LITERALS]": { | ||
| "recorded-date": "04-11-2024, 13:16:06", | ||
| "recorded-date": "19-02-2026, 14:47:49", | ||
| "recorded-content": { | ||
| "get_execution_history": { | ||
| "events": [ | ||
|
|
@@ -266,7 +266,7 @@ | |
| } | ||
| }, | ||
| "tests/aws/services/stepfunctions/v2/outputdecl/test_output.py::TestArgumentsBase::test_base_cases[BASE_EXPR]": { | ||
| "recorded-date": "04-11-2024, 13:16:22", | ||
| "recorded-date": "19-02-2026, 14:48:04", | ||
| "recorded-content": { | ||
| "get_execution_history": { | ||
| "events": [ | ||
|
|
@@ -463,7 +463,7 @@ | |
| } | ||
| }, | ||
| "tests/aws/services/stepfunctions/v2/outputdecl/test_output.py::TestArgumentsBase::test_base_cases[BASE_DIRECT_EXPR]": { | ||
| "recorded-date": "04-11-2024, 13:16:38", | ||
| "recorded-date": "19-02-2026, 14:48:17", | ||
| "recorded-content": { | ||
| "get_execution_history": { | ||
| "events": [ | ||
|
|
@@ -587,7 +587,7 @@ | |
| } | ||
| }, | ||
| "tests/aws/services/stepfunctions/v2/outputdecl/test_output.py::TestArgumentsBase::test_base_lambda[BASE_LAMBDA]": { | ||
| "recorded-date": "04-11-2024, 14:01:00", | ||
| "recorded-date": "19-02-2026, 14:48:36", | ||
| "recorded-content": { | ||
| "get_execution_history": { | ||
| "events": [ | ||
|
|
@@ -813,7 +813,7 @@ | |
| } | ||
| }, | ||
| "tests/aws/services/stepfunctions/v2/outputdecl/test_output.py::TestArgumentsBase::test_base_task_lambda[BASE_TASK_LAMBDA]": { | ||
| "recorded-date": "04-11-2024, 14:15:19", | ||
| "recorded-date": "19-02-2026, 14:48:54", | ||
| "recorded-content": { | ||
| "get_execution_history": { | ||
| "events": [ | ||
|
|
@@ -920,9 +920,7 @@ | |
| "Connection": [ | ||
| "keep-alive" | ||
| ], | ||
| "x-amzn-RequestId": [ | ||
| "<uuid:1>" | ||
| ], | ||
| "x-amzn-RequestId": "x-amzn-RequestId", | ||
| "Content-Length": [ | ||
| "60" | ||
| ], | ||
|
|
@@ -939,13 +937,13 @@ | |
| "Date": "date", | ||
| "X-Amz-Executed-Version": "$LATEST", | ||
| "x-amzn-Remapped-Content-Length": "0", | ||
| "x-amzn-RequestId": "<uuid:1>", | ||
| "x-amzn-RequestId": "x-amzn-RequestId", | ||
| "X-Amzn-Trace-Id": "X-Amzn-Trace-Id" | ||
| }, | ||
| "HttpStatusCode": 200 | ||
| }, | ||
| "SdkResponseMetadata": { | ||
| "RequestId": "<uuid:1>" | ||
| "RequestId": "RequestId" | ||
| }, | ||
| "StatusCode": 200 | ||
| }, | ||
|
|
@@ -996,9 +994,7 @@ | |
| "Connection": [ | ||
| "keep-alive" | ||
| ], | ||
| "x-amzn-RequestId": [ | ||
| "<uuid:1>" | ||
| ], | ||
| "x-amzn-RequestId": "x-amzn-RequestId", | ||
| "Content-Length": [ | ||
| "60" | ||
| ], | ||
|
|
@@ -1015,13 +1011,13 @@ | |
| "Date": "date", | ||
| "X-Amz-Executed-Version": "$LATEST", | ||
| "x-amzn-Remapped-Content-Length": "0", | ||
| "x-amzn-RequestId": "<uuid:1>", | ||
| "x-amzn-RequestId": "x-amzn-RequestId", | ||
| "X-Amzn-Trace-Id": "X-Amzn-Trace-Id" | ||
| }, | ||
| "HttpStatusCode": 200 | ||
| }, | ||
| "SdkResponseMetadata": { | ||
| "RequestId": "<uuid:1>" | ||
| "RequestId": "RequestId" | ||
| }, | ||
| "StatusCode": 200 | ||
| } | ||
|
|
@@ -1068,9 +1064,7 @@ | |
| "Connection": [ | ||
| "keep-alive" | ||
| ], | ||
| "x-amzn-RequestId": [ | ||
| "<uuid:1>" | ||
| ], | ||
| "x-amzn-RequestId": "x-amzn-RequestId", | ||
| "Content-Length": [ | ||
| "60" | ||
| ], | ||
|
|
@@ -1087,13 +1081,13 @@ | |
| "Date": "date", | ||
| "X-Amz-Executed-Version": "$LATEST", | ||
| "x-amzn-Remapped-Content-Length": "0", | ||
| "x-amzn-RequestId": "<uuid:1>", | ||
| "x-amzn-RequestId": "x-amzn-RequestId", | ||
| "X-Amzn-Trace-Id": "X-Amzn-Trace-Id" | ||
| }, | ||
| "HttpStatusCode": 200 | ||
| }, | ||
| "SdkResponseMetadata": { | ||
| "RequestId": "<uuid:1>" | ||
| "RequestId": "RequestId" | ||
| }, | ||
| "StatusCode": 200 | ||
| } | ||
|
|
@@ -1116,7 +1110,7 @@ | |
| } | ||
| }, | ||
| "tests/aws/services/stepfunctions/v2/outputdecl/test_output.py::TestArgumentsBase::test_base_output_any_non_dict[NULL]": { | ||
| "recorded-date": "20-11-2024, 18:24:00", | ||
| "recorded-date": "19-02-2026, 14:49:08", | ||
| "recorded-content": { | ||
| "get_execution_history": { | ||
| "events": [ | ||
|
|
@@ -1184,7 +1178,7 @@ | |
| } | ||
| }, | ||
| "tests/aws/services/stepfunctions/v2/outputdecl/test_output.py::TestArgumentsBase::test_base_output_any_non_dict[INT]": { | ||
| "recorded-date": "20-11-2024, 18:24:15", | ||
| "recorded-date": "19-02-2026, 14:49:23", | ||
| "recorded-content": { | ||
| "get_execution_history": { | ||
| "events": [ | ||
|
|
@@ -1252,7 +1246,7 @@ | |
| } | ||
| }, | ||
| "tests/aws/services/stepfunctions/v2/outputdecl/test_output.py::TestArgumentsBase::test_base_output_any_non_dict[FLOAT]": { | ||
| "recorded-date": "20-11-2024, 18:24:31", | ||
| "recorded-date": "19-02-2026, 14:49:37", | ||
| "recorded-content": { | ||
| "get_execution_history": { | ||
| "events": [ | ||
|
|
@@ -1320,7 +1314,7 @@ | |
| } | ||
| }, | ||
| "tests/aws/services/stepfunctions/v2/outputdecl/test_output.py::TestArgumentsBase::test_base_output_any_non_dict[BOOL]": { | ||
| "recorded-date": "20-11-2024, 18:24:46", | ||
| "recorded-date": "19-02-2026, 14:49:51", | ||
| "recorded-content": { | ||
| "get_execution_history": { | ||
| "events": [ | ||
|
|
@@ -1388,7 +1382,7 @@ | |
| } | ||
| }, | ||
| "tests/aws/services/stepfunctions/v2/outputdecl/test_output.py::TestArgumentsBase::test_base_output_any_non_dict[STR_LIT]": { | ||
| "recorded-date": "20-11-2024, 18:25:01", | ||
| "recorded-date": "19-02-2026, 14:50:05", | ||
| "recorded-content": { | ||
| "get_execution_history": { | ||
| "events": [ | ||
|
|
@@ -1456,7 +1450,7 @@ | |
| } | ||
| }, | ||
| "tests/aws/services/stepfunctions/v2/outputdecl/test_output.py::TestArgumentsBase::test_base_output_any_non_dict[JSONATA_EXPR]": { | ||
| "recorded-date": "20-11-2024, 18:25:16", | ||
| "recorded-date": "19-02-2026, 14:50:20", | ||
| "recorded-content": { | ||
| "get_execution_history": { | ||
| "events": [ | ||
|
|
@@ -1528,7 +1522,7 @@ | |
| } | ||
| }, | ||
| "tests/aws/services/stepfunctions/v2/outputdecl/test_output.py::TestArgumentsBase::test_base_output_any_non_dict[LIST_EMPY]": { | ||
| "recorded-date": "20-11-2024, 18:25:31", | ||
| "recorded-date": "19-02-2026, 14:50:35", | ||
| "recorded-content": { | ||
| "get_execution_history": { | ||
| "events": [ | ||
|
|
@@ -1596,7 +1590,7 @@ | |
| } | ||
| }, | ||
| "tests/aws/services/stepfunctions/v2/outputdecl/test_output.py::TestArgumentsBase::test_base_output_any_non_dict[LIST_RICH]": { | ||
| "recorded-date": "20-11-2024, 18:25:47", | ||
| "recorded-date": "19-02-2026, 14:50:49", | ||
| "recorded-content": { | ||
| "get_execution_history": { | ||
| "events": [ | ||
|
|
@@ -1664,7 +1658,7 @@ | |
| } | ||
| }, | ||
| "tests/aws/services/stepfunctions/v2/outputdecl/test_output.py::TestArgumentsBase::test_output_in_choice[CONDITION_TRUE]": { | ||
| "recorded-date": "27-12-2024, 14:50:09", | ||
| "recorded-date": "19-02-2026, 14:51:09", | ||
| "recorded-content": { | ||
| "get_execution_history": { | ||
| "events": [ | ||
|
|
@@ -1758,7 +1752,7 @@ | |
| } | ||
| }, | ||
| "tests/aws/services/stepfunctions/v2/outputdecl/test_output.py::TestArgumentsBase::test_output_in_choice[CONDITION_FALSE]": { | ||
| "recorded-date": "27-12-2024, 14:50:24", | ||
| "recorded-date": "19-02-2026, 14:51:23", | ||
| "recorded-content": { | ||
| "get_execution_history": { | ||
| "events": [ | ||
|
|
||
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.
New test uncovered that JSONPath-related inspection data were added to states that use JSONata.