mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 17:33:03 -05:00
fix(sfn): apply ItemSelector/Parameters transformation in Map state (#683)
Map state was passing each item raw to the branch executor, ignoring ItemSelector (current AWS syntax) and Parameters (legacy syntax). Now resolves the transform against the Map state's effective input (after InputPath) and enriches the context with $$.Map.Item.Index and $$.Map.Item.Value per iteration before calling executeBranch.
This commit is contained in:
1 parent
05d89a0810
commit
b56c7ced82
2 files changed
+105
-1
No files matched your search
+82
@@ -107,6 +107,88 @@ class StepFunctionsJsonataIntegrationTest {
|
||||
assertTrue(output.contains("default"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapStateWithItemSelector_appliesTransformationAndContextVars() throws Exception {
|
||||
// ItemSelector (JSONPath Map state) should transform each item using parent-state
|
||||
// data and $$.Map.Item.Value / $$.Map.Item.Index context variables.
|
||||
// Regression test for: Map state ignores Parameters/ItemSelector (issue #675)
|
||||
String definition = """
|
||||
{
|
||||
"StartAt": "ProcessItems",
|
||||
"States": {
|
||||
"ProcessItems": {
|
||||
"Type": "Map",
|
||||
"ItemsPath": "$.items",
|
||||
"ItemSelector": {
|
||||
"bucket.$": "$.bucket",
|
||||
"item.$": "$$.Map.Item.Value",
|
||||
"index.$": "$$.Map.Item.Index"
|
||||
},
|
||||
"ItemProcessor": {
|
||||
"StartAt": "Pass",
|
||||
"States": {
|
||||
"Pass": {
|
||||
"Type": "Pass",
|
||||
"End": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"End": true
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
String smArn = createStateMachine("map-itemselector-test", definition);
|
||||
String execArn = startExecution(smArn, "{\"bucket\": \"my-bucket\", \"items\": [\"a\", \"b\"]}");
|
||||
String output = waitForExecution(execArn);
|
||||
|
||||
assertTrue(output.contains("my-bucket"), "bucket from parent input should be injected");
|
||||
assertTrue(output.contains("\"item\":\"a\"") || output.contains("\"item\": \"a\""),
|
||||
"item value should be the raw item");
|
||||
assertTrue(output.contains("\"index\":0") || output.contains("\"index\": 0"),
|
||||
"index should start at 0");
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapStateWithParameters_legacySyntax_appliesTransformation() throws Exception {
|
||||
// Parameters is the legacy equivalent of ItemSelector; both must be applied.
|
||||
String definition = """
|
||||
{
|
||||
"StartAt": "ProcessItems",
|
||||
"States": {
|
||||
"ProcessItems": {
|
||||
"Type": "Map",
|
||||
"ItemsPath": "$.items",
|
||||
"Parameters": {
|
||||
"key.$": "$.key",
|
||||
"value.$": "$$.Map.Item.Value"
|
||||
},
|
||||
"ItemProcessor": {
|
||||
"StartAt": "Pass",
|
||||
"States": {
|
||||
"Pass": {
|
||||
"Type": "Pass",
|
||||
"End": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"End": true
|
||||
}
|
||||
}
|
||||
}
|
||||
""";
|
||||
|
||||
String smArn = createStateMachine("map-parameters-test", definition);
|
||||
String execArn = startExecution(smArn, "{\"key\": \"env\", \"items\": [1, 2]}");
|
||||
String output = waitForExecution(execArn);
|
||||
|
||||
assertTrue(output.contains("\"key\":\"env\"") || output.contains("\"key\": \"env\""),
|
||||
"key from parent input should be injected via Parameters");
|
||||
assertTrue(output.contains("\"value\":1") || output.contains("\"value\": 1"),
|
||||
"value should be the raw item");
|
||||
}
|
||||
|
||||
@Test
|
||||
void mapStateWithJsonataItems() throws Exception {
|
||||
// Map state using JSONata Items field instead of ItemsPath
|
||||
|
||||
Reference in new issue
Block a user