Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/aws-lambda/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ Resources:
SelectPlanProtocol:
Type: Choice
Choices:
# A comparison on a missing path is a States.Runtime error, not a non-match, so an
# omitted PlanProtocol has to be caught before any StringEquals rule.
- Variable: $.PlanProtocol
IsPresent: false
Next: !If [HasVideoFunction, WarmRender, PlanV2]
# Only a stack with the arm64 video function has a cold x86 function to warm.
# Without one the compared value can never match.
- Variable: $.PlanProtocol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,26 @@ describe("HyperframesRenderStack — snapshot", () => {
}
});

// Step Functions raises States.Runtime for a comparison on a missing path instead of moving on,
// so the Default branch is unreachable unless presence is checked before any comparison.
it("routes an omitted plan protocol before any rule compares it", () => {
for (const [name, definition] of [
["CDK", SYNTHED.definition],
["SAM", readSamDefinition()],
] as const) {
const choices = requireRecord(definition.States.SelectPlanProtocol, "SelectPlanProtocol")
.Choices as Record<string, unknown>[];
expect({ name, first: { ...choices[0], Next: undefined } }).toEqual({
name,
first: { Variable: "$.PlanProtocol", IsPresent: false, Next: undefined },
});
}
expect(SYNTHED.definition.States.SelectPlanProtocol.Choices[0].Next).toBe("PlanV2");
const samFirst = (readSamDefinition().States.SelectPlanProtocol as Record<string, unknown>)
.Choices as Record<string, unknown>[];
expect(samFirst[0].Next).toEqual(["HasVideoFunction", "WarmRender", "PlanV2"]);
});

it("preserves every typed non-retryable error name across the three Lambda tasks", () => {
const { definition } = SYNTHED;
const collected = new Set<string>();
Expand Down
3 changes: 3 additions & 0 deletions packages/aws-lambda/src/cdk/HyperframesRenderStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,10 @@ export class HyperframesRenderStack extends Construct {
error: "PLAN_PROTOCOL_UNSUPPORTED",
cause: 'PlanProtocol must be "v2" or absent (defaults to v2).',
});
// A comparison on a missing path is a States.Runtime error, not a non-match, so an omitted
// PlanProtocol has to be caught before the stringEquals rule.

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.

important: these 2 lines turn the Comments ratchet red: "RAISED comment share … 11.1% (52/468), at the base 10.8% (50/465)". It's not a required check, but it's an easy fix. The SAM comment and the new snapshot test already carry this explanation, so the CDK copy can go.

return new sfn.Choice(this, "SelectPlanProtocol")
.when(sfn.Condition.isNotPresent("$.PlanProtocol"), planV2)
.when(sfn.Condition.stringEquals("$.PlanProtocol", "v2"), planV2)
.when(sfn.Condition.isPresent("$.PlanProtocol"), unsupportedPlanProtocol)
.otherwise(planV2);
Expand Down
Loading