Light, fluffy, and always free - The AWS Local Emulator alternative
fix(stepfunctions): preserve object details in PutEvents (#4022)
vamsiak4c64f2e397b1
diff --git a/docs/services/step-functions.md b/docs/services/step-functions.mdindex d76ac93bda..97e6f7b405 100644--- a/docs/services/step-functions.md+++ b/docs/services/step-functions.md@@ -472,6 +472,10 @@ cause is the response serialized as a string, so a `Catch` can read which entry{"FailedEntryCount":1,"Entries":[{"EventId":"08cbdc46-…"},{"ErrorCode":"InvalidArgument","ErrorMessage":"EventBus not found: no-such-bus"}]}```+The optimized integration accepts `Detail` as a JSON object in JSONPath and JSONata workflows. It+serializes that object once for the EventBridge request, preserving nested values and escaped text.+The direct EventBridge API continues to accept its native string-valued `Detail` field.+One deviation, and it belongs to EventBridge rather than to the integration: Floci rejects an entryaddressed to an event bus that does not exist, while AWS accepts it and returns an `EventId`.diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.javaindex ab8d10a58e..4f7651cf01 100644--- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java+++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java@@ -41,6 +41,7 @@ import io.github.hectorvent.floci.services.stepfunctions.model.MockedResponseSteimport io.github.hectorvent.floci.services.stepfunctions.model.MockedTestCase;import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine;import com.fasterxml.jackson.annotation.JsonProperty;+import com.fasterxml.jackson.core.JsonProcessingException;import com.fasterxml.jackson.databind.JsonNode;import com.fasterxml.jackson.databind.ObjectMapper;import com.fasterxml.jackson.databind.node.ArrayNode;@@ -1413,7 +1414,7 @@ public class AslExecutor {private JsonNode invokeOptimizedPutEvents(JsonNode input, String region) throws Exception {Response response;try {- response = eventBridgeHandler.handle("PutEvents", input, region);+ response = eventBridgeHandler.handle("PutEvents", normalizeOptimizedPutEventsInput(input), region);} catch (AwsException e) {throw new FailStateException(sdkExceptionName("EventBridge", e.getErrorCode()), e.getMessage());}@@ -1426,6 +1427,20 @@ public class AslExecutor {return result;}+ private JsonNode normalizeOptimizedPutEventsInput(JsonNode input) throws JsonProcessingException {+ JsonNode normalized = input.deepCopy();+ JsonNode entries = normalized.path("Entries");+ if (entries.isArray()) {+ for (JsonNode entry : entries) {+ JsonNode detail = entry.get("Detail");+ if (entry.isObject() && detail != null && detail.isObject()) {+ ((ObjectNode) entry).put("Detail", objectMapper.writeValueAsString(detail));+ }+ }+ }+ return normalized;+ }+/*** AWS SDK integration for {@code sfn:startSyncExecution}, the way an EXPRESS child workflow is* called. It differs from the optimized {@code states:startExecution.sync} integration in threediff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsPutEventsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsPutEventsIntegrationTest.javaindex 603b790670..083f6c618c 100644--- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsPutEventsIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsPutEventsIntegrationTest.java@@ -87,6 +87,73 @@ class StepFunctionsPutEventsIntegrationTest {@Test@Order(2)+ void jsonataObjectDetailPreservesNestedJsonAndEscapedStrings() throws Exception {+ String smArn = createStateMachine("put-events-jsonata-object-detail", """+ {+ "QueryLanguage": "JSONata",+ "StartAt": "Publish",+ "States": {+ "Publish": {+ "Type": "Task",+ "Resource": "RESOURCE_ARN",+ "Arguments": {+ "Entries": [{+ "Source": "SOURCE_NAME",+ "DetailType": "jsonata object",+ "Detail": {+ "payment": {"amount": 1200, "currency": "USD"},+ "message": "line one\\nline two"+ }+ }]+ },+ "End": true+ }+ }+ }+ """.replace("RESOURCE_ARN", RESOURCE).replace("SOURCE_NAME", SOURCE));++ JsonNode result = mapper.readTree(succeedingOutputOf(smArn));+ assertEquals(0, result.path("FailedEntryCount").asInt());++ JsonNode delivered = mapper.readTree(receiveSingleMessage(sinkQueueUrl).path("Body").asText());+ assertEquals(1200, delivered.path("detail").path("payment").path("amount").asInt());+ assertEquals("USD", delivered.path("detail").path("payment").path("currency").asText());+ assertEquals("line one\nline two", delivered.path("detail").path("message").asText());+ }++ @Test+ @Order(3)+ void jsonPathObjectDetailPreservesNestedJson() throws Exception {+ String smArn = createStateMachine("put-events-jsonpath-object-detail", """+ {+ "StartAt": "Publish",+ "States": {+ "Publish": {+ "Type": "Task",+ "Resource": "RESOURCE_ARN",+ "Parameters": {+ "Entries": [{+ "Source": "SOURCE_NAME",+ "DetailType": "jsonpath object",+ "Detail": {"order": {"id": "order-42", "items": 3}}+ }]+ },+ "End": true+ }+ }+ }+ """.replace("RESOURCE_ARN", RESOURCE).replace("SOURCE_NAME", SOURCE));++ JsonNode result = mapper.readTree(succeedingOutputOf(smArn));+ assertEquals(0, result.path("FailedEntryCount").asInt());++ JsonNode delivered = mapper.readTree(receiveSingleMessage(sinkQueueUrl).path("Body").asText());+ assertEquals("order-42", delivered.path("detail").path("order").path("id").asText());+ assertEquals(3, delivered.path("detail").path("order").path("items").asInt());+ }++ @Test+ @Order(4)void taskResultCarriesTheSameFieldsThePutEventsApiReturns() throws Exception {var smArn = createStateMachine("put-events-same-envelope", """{@@ -123,7 +190,7 @@ class StepFunctionsPutEventsIntegrationTest {}@Test- @Order(3)+ @Order(5)void oneRejectedEntryFailsTheTaskWithFailedEntryAndTheWholeResponseAsCause() throws Exception {var smArn = createStateMachine("put-events-failed-entry", """{@@ -158,7 +225,7 @@ class StepFunctionsPutEventsIntegrationTest {}@Test- @Order(4)+ @Order(6)void aFailedEntryIsCatchableByItsErrorName() throws Exception {var smArn = createStateMachine("put-events-catch", """{