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

Commit fd25c20

Browse files
committed
Add test for invalid state machine definition in test state call
Ignoring the exact validation message for now
1 parent cb8043c commit fd25c20

5 files changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Comment": "Base state machine with a state that is not a valid state definition.",
3+
"StartAt": "ExistingButInvalidState",
4+
"States": {
5+
"ExistingButInvalidState": {
6+
"Type": "TypeThatDoesNotExist",
7+
"End": true
8+
}
9+
}
10+
}

tests/aws/services/stepfunctions/templates/test_state/test_state_templates.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,7 @@ class TestStateMachineTemplate(TemplateLoader):
124124
LOCALSTACK_BLOGPOST_SCENARIO_STATE_MACHINE: Final[str] = os.path.join(
125125
_THIS_FOLDER, "statemachines/localstack_blogpost_scenario_state_machine.json5"
126126
)
127+
128+
BASE_INVALID_STATE_DEFINITION: Final[str] = os.path.join(
129+
_THIS_FOLDER, "statemachines/base_invalid_state_definition.json5"
130+
)

tests/aws/services/stepfunctions/v2/test_state/test_test_state_machine_scenarios.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,28 @@ def test_base_state_name_validation_failures(
105105
sfn_snapshot.match(
106106
"exception", {"exception_typename": ex.typename, "exception_value": ex.value}
107107
)
108+
109+
@markers.aws.validated
110+
@markers.snapshot.skip_snapshot_verify(paths=["$..Error.Message", "$..message"])
111+
# ANTLR parser message has different wording but the same meaning as AWS response. Not investing time now to convert to the exact same wording - relying on error code for test.
112+
# TODO match wording and hide implementation details (ANTLR)
113+
# expected:
114+
# /Error/Message "Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: The field 'Type' should have one of these values: [Task, Wait, Pass, Succeed, Fail, Choice, Parallel, Map] at /States/ExistingButInvalidState/Type'"
115+
# actual:
116+
# 'ASLParserException line 1:170, at "TypeThatDoesNotExist", mismatched input \'"TypeThatDoesNotExist"\' expecting {\'"Task"\', \'"Choice"\', \'"Fail"\', \'"Succeed"\', \'"Pass"\', \'"Wait"\', \'"Parallel"\', \'"Map"\'}'
117+
def test_state_name_invalid_state_definition(
118+
self,
119+
aws_client_no_sync_prefix,
120+
sfn_snapshot,
121+
):
122+
template = TSMT.load_sfn_template(TSMT.BASE_INVALID_STATE_DEFINITION)
123+
definition = json.dumps(template)
124+
125+
with pytest.raises(Exception) as e:
126+
aws_client_no_sync_prefix.stepfunctions.test_state(
127+
stateName="ExistingButInvalidState",
128+
definition=definition,
129+
input=HELLO_WORLD_INPUT,
130+
inspectionLevel=InspectionLevel.INFO,
131+
)
132+
sfn_snapshot.match("validation_exception", e.value.response)

tests/aws/services/stepfunctions/v2/test_state/test_test_state_machine_scenarios.snapshot.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,5 +345,21 @@
345345
}
346346
}
347347
}
348+
},
349+
"tests/aws/services/stepfunctions/v2/test_state/test_test_state_machine_scenarios.py::TestStateMachineScenarios::test_state_name_invalid_state_definition": {
350+
"recorded-date": "04-12-2025, 12:16:39",
351+
"recorded-content": {
352+
"validation_exception": {
353+
"Error": {
354+
"Code": "InvalidDefinition",
355+
"Message": "Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: The field 'Type' should have one of these values: [Task, Wait, Pass, Succeed, Fail, Choice, Parallel, Map] at /States/ExistingButInvalidState/Type'"
356+
},
357+
"message": "Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: The field 'Type' should have one of these values: [Task, Wait, Pass, Succeed, Fail, Choice, Parallel, Map] at /States/ExistingButInvalidState/Type'",
358+
"ResponseMetadata": {
359+
"HTTPHeaders": {},
360+
"HTTPStatusCode": 400
361+
}
362+
}
363+
}
348364
}
349365
}

tests/aws/services/stepfunctions/v2/test_state/test_test_state_machine_scenarios.validation.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,5 +160,14 @@
160160
"teardown": 0.0,
161161
"total": 0.59
162162
}
163+
},
164+
"tests/aws/services/stepfunctions/v2/test_state/test_test_state_machine_scenarios.py::TestStateMachineScenarios::test_state_name_invalid_state_definition": {
165+
"last_validated_date": "2025-12-04T12:16:39+00:00",
166+
"durations_in_seconds": {
167+
"setup": 0.55,
168+
"call": 0.67,
169+
"teardown": 0.0,
170+
"total": 1.22
171+
}
163172
}
164173
}

0 commit comments

Comments
 (0)