Skip to content

Conversation

@tiurin
Copy link
Contributor

@tiurin tiurin commented Nov 26, 2025

Motivation

TestState validates mocked responses against AWS API models with three validation modes: STRICT (this is the default and validates all required fields), PRESENT (validates field types and names), and NONE (no validation).

  • STRICT field validation mode checks the presence of required fields and validates the type and format of the fields in the mock against the respective service shape in AWS API definitions.

  • PRESENT field validation mode doesn't check the presence of required fields. It only validates the type and format of the fields that are present in the user-provided mock.

  • NONE mode means no format validation will be performed. A check that the result is a valid JSON string is still performed even in NONE field validation mode.

    Note: fields that are not present in the API spec but are supplied in the mock will be allowed, because of forward-compatibility.

Closes DRG-220.

Changes

Add mock result validation method to a static analyzer that already contains several other validations.

Limitations:
range/length validation is not implemented yet (added DRG-258 as a follow-up)

Tests

Related

@tiurin tiurin added this to the 4.12 milestone Nov 26, 2025
@tiurin tiurin requested a review from gregfurman November 26, 2025 09:23
@tiurin tiurin added the aws:stepfunctions AWS Step Functions label Nov 26, 2025
@tiurin tiurin added the semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases label Nov 26, 2025
@tiurin tiurin requested a review from joe4dev as a code owner November 26, 2025 09:23
@tiurin tiurin added docs: skip Pull request does not require documentation changes notes: skip Pull request does not have to be mentioned in the release notes labels Nov 26, 2025
@tiurin tiurin changed the title Add mock result validation for strict field validation mode [SFN] [TestState] Add mock result validation for strict field validation mode Nov 26, 2025
@tiurin tiurin changed the title [SFN] [TestState] Add mock result validation for strict field validation mode [SFN] [TestState] Add mock result validation for STRICT field validation mode Nov 26, 2025
@github-actions
Copy link

github-actions bot commented Nov 26, 2025

Test Results - Preflight, Unit

22 669 tests  ±0   20 901 ✅ ±0   6m 17s ⏱️ -5s
     1 suites ±0    1 768 💤 ±0 
     1 files   ±0        0 ❌ ±0 

Results for commit 3952452. ± Comparison against base commit 58f49e9.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Nov 26, 2025

LocalStack Community integration with Pro

    2 files  ±    0      2 suites  ±0   20m 32s ⏱️ - 1h 40m 17s
1 701 tests  - 3 357  1 612 ✅  - 3 062  89 💤  - 295  0 ❌ ±0 
1 703 runs   - 3 357  1 612 ✅  - 3 062  91 💤  - 295  0 ❌ ±0 

Results for commit 3952452. ± Comparison against base commit 58f49e9.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Nov 26, 2025

Test Results (amd64) - Acceptance

7 tests  ±0   5 ✅ ±0   3m 25s ⏱️ +16s
1 suites ±0   2 💤 ±0 
1 files   ±0   0 ❌ ±0 

Results for commit 3952452. ± Comparison against base commit 58f49e9.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Nov 26, 2025

Test Results (amd64) - Integration, Bootstrap

    5 files  ±    0      5 suites  ±0   39m 6s ⏱️ - 2h 2m 8s
1 725 tests  - 3 707  1 637 ✅  - 3 251  88 💤  - 456  0 ❌ ±0 
1 731 runs   - 3 707  1 637 ✅  - 3 251  94 💤  - 456  0 ❌ ±0 

Results for commit 3952452. ± Comparison against base commit 58f49e9.

♻️ This comment has been updated with latest results.

@tiurin tiurin force-pushed the feature/step-functions/test-state-main branch from 7bf7ea6 to c5d5aab Compare November 27, 2025 11:30
@tiurin tiurin requested a review from steffyP as a code owner November 27, 2025 11:30
@tiurin tiurin force-pushed the feature/step-functions/test-state-field-validation-mode-strict branch from 957a2e0 to 08d99fe Compare November 27, 2025 11:35
@tiurin tiurin self-assigned this Nov 27, 2025
Copy link
Contributor

@gregfurman gregfurman left a comment

Choose a reason for hiding this comment

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

LGTM. Nice one addressing these (frankly, extremely) complex validation cases!

Could be worth looking into using a pydantic model to easier validate this JSON like I did in:

def parse_context(context: str, state_type: StateType = None) -> ContextObjectData:
"""Parse and validate context JSON string."""
try:
validation_result = TestStateContextObjectValidator.model_validate_json(context)
return validation_result.model_dump(exclude_unset=True, exclude_none=True)
except ValidationError as e:

return test_program.test_state is not None

@staticmethod
def validate_mock(mock: TestStateMock, definition: Definition, state_name: StateName) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

ok wow. This is gnarly 💀

@tiurin tiurin changed the title [SFN] [TestState] Add mock result validation for STRICT field validation mode [SFN] [TestState] Add mock result validation according to field validation modes Nov 28, 2025
@tiurin tiurin force-pushed the feature/step-functions/test-state-field-validation-mode-strict branch from 48462aa to 3952452 Compare November 28, 2025 14:07
TestState validates mocked responses against AWS API models with three validation modes: STRICT (this is the default and validates all required fields), PRESENT (validates field types and names), and NONE (no validation).

STRICT field validation mode checks the presence of required fields and validates the type and format of the fields in the mock against the respective service shape in AWS API definitions.
PRESENT field validation mode doesn't check the presence of required fields. It only validates the type and format of the fields that are present in the user-provided mock.
NONE mode means no format validation will be performed. A check that the result is a valid JSON string is still performed even in NONE field validation mode.

Note: fields that are not present in the API spec but are supplied in the mock will be allowed, because of forward-compatibility.
@tiurin tiurin force-pushed the feature/step-functions/test-state-field-validation-mode-strict branch from 3952452 to 06902e0 Compare November 28, 2025 14:38
@tiurin tiurin merged commit 5eb1f18 into feature/step-functions/test-state-main Nov 28, 2025
12 checks passed
@tiurin tiurin deleted the feature/step-functions/test-state-field-validation-mode-strict branch November 28, 2025 14:38
tiurin added a commit that referenced this pull request Nov 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aws:stepfunctions AWS Step Functions docs: skip Pull request does not require documentation changes notes: skip Pull request does not have to 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.

3 participants