fix(stepfunctions): return the PascalCase execution envelope from states:startExecution, .sync and .sync:2 (#4737)

AWS returns, as the Task result of the optimized states:startExecution
integration (measured in ap-northeast-1 on 2026-09-30):

- request-response: the StartExecution response, {ExecutionArn, StartDate},
  StartDate in epoch milliseconds
- .sync: the child's DescribeExecution response, PascalCase with its keys
  in alphabetical order, dates in epoch milliseconds, Input and Output as
  JSON strings
- .sync:2: the same envelope with Input and Output as JSON values

Floci returned camelCase with dates in seconds for the first two and the
child's output alone for .sync:2, so a state machine written against AWS
found nothing at $.Output, $.ExecutionArn or $.Status.

The failure cause of the two .sync modes already built this envelope
(#4675). It now builds the success result too: a SUCCEEDED child carries
Output, OutputDetails and RedriveStatusReason and reports NOT_REDRIVABLE.
Request-response returns the response TaskSubmitted already records.

This changes the result shape for state machines written against Floci's
earlier one: the child output of .sync:2 moves from $ to $.Output.

Closes #4723

Co-authored-by: mitsukado-shinagawa <mitsukado-shinagawa@users.noreply.github.com>
This commit is contained in:
mitsukado-shinagawaandmitsukado-shinagawa authored and GitHub committed 2026-09-30 10:14:12 -04:00
1 parent d267ba3a9d
commit fd094aee05
6 files changed
+348 -110

No files matched your search

@@ -272,31 +272,72 @@ class AslExecutorNestedStartExecutionTest {
assertEquals("StepFunctions.StateMachineDoesNotExistException", exec.getError());
}
@ParameterizedTest
@ValueSource(strings = {".sync", ".sync:2"})
void syncChildSuccessIsUndisturbedByTheWrap(String mode) throws Exception {
// Regression guard: wrapping the start call in try/catch must not disturb the .sync/.sync:2
// success branches. The child starts RUNNING (setUp) then the poll observes it SUCCEEDED.
Execution done = new Execution();
done.setExecutionArn("arn:aws:states:us-east-1:000000000000:execution:child:e1");
done.setStateMachineArn(CHILD_ARN);
done.setName("e1");
done.setStatus("SUCCEEDED");
done.setStartDate(1.0);
done.setStopDate(2.0);
done.setOutput("{\"ok\":true}");
when(childSfn.describeExecution(any())).thenReturn(done);
/**
* Measured on AWS: .sync returns the child's DescribeExecution response in PascalCase, keys in
* alphabetical order, dates in epoch milliseconds, Input and Output as JSON strings.
*/
@Test
void syncReturnsTheExecutionEnvelopeWithPayloadsAsJsonStrings() {
childSucceeds();
Execution exec = runParent(parentMode(mode), "{}");
assertEquals("SUCCEEDED", exec.getStatus());
var output = mapper.readTree(exec.getOutput());
if (".sync:2".equals(mode)) {
assertTrue(output.path("ok").asBoolean(), "sync:2 returns the parsed child output");
} else {
assertEquals("SUCCEEDED", output.path("status").asText(), "sync returns the execution envelope");
assertEquals("{\"ok\":true}", output.path("output").asText(), "envelope output is the child output JSON string");
}
Execution exec = runParent(parentMode(".sync"), "{}");
assertEquals("SUCCEEDED", exec.getStatus(), exec.getCause());
assertEquals("{\"ExecutionArn\":\"arn:aws:states:us-east-1:000000000000:execution:child:e1\","
+ "\"Input\":\"{\\\"k\\\":1}\",\"InputDetails\":{\"Included\":true},\"Name\":\"e1\","
+ "\"Output\":\"{\\\"ok\\\":true}\",\"OutputDetails\":{\"Included\":true},"
+ "\"RedriveCount\":0,\"RedriveStatus\":\"NOT_REDRIVABLE\","
+ "\"RedriveStatusReason\":\"Execution is SUCCEEDED and cannot be redriven\","
+ "\"StartDate\":1000,\"StateMachineArn\":\"" + CHILD_ARN + "\","
+ "\"Status\":\"SUCCEEDED\",\"StopDate\":2000}", exec.getOutput());
}
/** Measured on AWS: .sync:2 returns the same envelope with Input and Output as JSON values. */
@Test
void sync2ReturnsTheExecutionEnvelopeWithPayloadsAsJsonValues() {
childSucceeds();
Execution exec = runParent(parentMode(".sync:2"), "{}");
assertEquals("SUCCEEDED", exec.getStatus(), exec.getCause());
assertEquals("{\"ExecutionArn\":\"arn:aws:states:us-east-1:000000000000:execution:child:e1\","
+ "\"Input\":{\"k\":1},\"InputDetails\":{\"Included\":true},\"Name\":\"e1\","
+ "\"Output\":{\"ok\":true},\"OutputDetails\":{\"Included\":true},"
+ "\"RedriveCount\":0,\"RedriveStatus\":\"NOT_REDRIVABLE\","
+ "\"RedriveStatusReason\":\"Execution is SUCCEEDED and cannot be redriven\","
+ "\"StartDate\":1000,\"StateMachineArn\":\"" + CHILD_ARN + "\","
+ "\"Status\":\"SUCCEEDED\",\"StopDate\":2000}", exec.getOutput());
}
/** Measured on AWS: a child started through an alias carries the alias and its version. */
@Test
void syncEnvelopeCarriesTheAliasAndVersionTheChildWasStartedThrough() throws Exception {
Execution done = childSucceeds();
done.setStateMachineAliasArn(CHILD_ARN + ":live");
done.setStateMachineVersionArn(CHILD_ARN + ":1");
Execution exec = runParent(parentMode(".sync:2"), "{}");
List<String> keys = new ArrayList<>();
mapper.readTree(exec.getOutput()).fieldNames().forEachRemaining(keys::add);
assertEquals(List.of("ExecutionArn", "Input", "InputDetails", "Name", "Output", "OutputDetails",
"RedriveCount", "RedriveStatus", "RedriveStatusReason", "StartDate", "StateMachineAliasArn",
"StateMachineArn", "StateMachineVersionArn", "Status", "StopDate"), keys);
}
/**
* Measured on AWS: request-response returns the StartExecution response in PascalCase with
* StartDate in epoch milliseconds (and the SDK metadata, which Floci omits).
*/
@Test
void requestResponseReturnsTheStartExecutionResponseInPascalCase() {
Execution exec = runParent(parentMode(""), "{}");
assertEquals("SUCCEEDED", exec.getStatus(), exec.getCause());
assertEquals("{\"ExecutionArn\":\"arn:aws:states:us-east-1:000000000000:execution:child:e1\","
+ "\"StartDate\":1000}", exec.getOutput());
}
/**
* AWS records TaskSubmitted once StartExecution has returned and before it waits on the child
* (measured: resourceType states, resource startExecution.sync:2, the response in PascalCase with
@@ -360,7 +401,7 @@ class AslExecutorNestedStartExecutionTest {
assertFalse(types().contains("TaskSubmitted"), types().toString());
}
private void childSucceeds() {
private Execution childSucceeds() {
Execution done = new Execution();
done.setExecutionArn("arn:aws:states:us-east-1:000000000000:execution:child:e1");
done.setStateMachineArn(CHILD_ARN);
@@ -368,8 +409,10 @@ class AslExecutorNestedStartExecutionTest {
done.setStatus("SUCCEEDED");
done.setStartDate(1.0);
done.setStopDate(2.0);
done.setInput("{\"k\":1}");
done.setOutput("{\"ok\":true}");
when(childSfn.describeExecution(any())).thenReturn(done);
return done;
}
private List<String> types() {
@@ -118,7 +118,7 @@ class AslExecutorNestedSyncTimeoutTest {
assertEquals("SUCCEEDED", execution.getStatus(), execution.getCause());
assertEquals(700, polls.get());
assertTrue(objectMapper.readTree(execution.getOutput()).path("output").asText().contains("42"));
assertTrue(objectMapper.readTree(execution.getOutput()).path("Output").asText().contains("42"));
verify(sfnService, never()).stopExecution(any(), any(), any());
}
@@ -0,0 +1,182 @@
package io.github.hectorvent.floci.services.stepfunctions;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import static io.restassured.RestAssured.given;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
/**
* The Task result of {@code states:startExecution} in its three modes, the way AWS returns it
* (measured in ap-northeast-1 on 2026-09-30): the StartExecution response for request-response and
* the child's DescribeExecution response for {@code .sync} and {@code .sync:2}, all PascalCase with
* dates in epoch milliseconds, {@code .sync:2} carrying {@code Input} and {@code Output} as JSON
* values where {@code .sync} carries JSON strings.
*/
@QuarkusTest
class StepFunctionsNestedStartExecutionResultIntegrationTest {
private static final String SFN_CONTENT_TYPE = "application/x-amz-json-1.0";
private static final String ROLE_ARN = "arn:aws:iam::000000000000:role/test-role";
private static final List<String> ENVELOPE_KEYS = List.of("ExecutionArn", "Input", "InputDetails", "Name",
"Output", "OutputDetails", "RedriveCount", "RedriveStatus", "RedriveStatusReason", "StartDate",
"StateMachineArn", "Status", "StopDate");
private static final ObjectMapper mapper = new ObjectMapper();
@BeforeAll
static void configureRestAssured() {
RestAssuredJsonUtils.configureAwsContentTypes();
}
@Test
void eachModeReturnsItsPascalCaseResult() throws Exception {
String childArn = createStateMachine("nested-result-child", """
{"StartAt": "D", "States": {"D": {"Type": "Pass", "Result": {"ok": true}, "End": true}}}
""");
String parentArn = createStateMachine("nested-result-parent", """
{
"StartAt": "RR",
"States": {
"RR": {
"Type": "Task",
"Resource": "arn:aws:states:::states:startExecution",
"Parameters": {"StateMachineArn": "%1$s", "Input": {"k": 1}},
"ResultPath": "$.rr",
"Next": "Sync"
},
"Sync": {
"Type": "Task",
"Resource": "arn:aws:states:::states:startExecution.sync",
"Parameters": {"StateMachineArn": "%1$s", "Input": {"k": 1}},
"ResultPath": "$.sync",
"Next": "Sync2"
},
"Sync2": {
"Type": "Task",
"Resource": "arn:aws:states:::states:startExecution.sync:2",
"Parameters": {"StateMachineArn": "%1$s", "Input": {"k": 1}},
"ResultPath": "$.sync2",
"Next": "Unwrap"
},
"Unwrap": {
"Type": "Pass",
"Parameters": {"ok.$": "$.sync2.Output.ok"},
"ResultPath": "$.unwrapped",
"End": true
}
}
}
""".formatted(childArn));
Response done = waitForTerminalExecution(startExecution(parentArn, "{}"));
assertEquals("SUCCEEDED", done.jsonPath().getString("status"), done.body().asString());
JsonNode output = mapper.readTree(done.jsonPath().getString("output"));
JsonNode requestResponse = output.path("rr");
assertEquals(List.of("ExecutionArn", "StartDate"), fieldNames(requestResponse));
assertTrue(requestResponse.path("ExecutionArn").asText().contains(":execution:nested-result-child"),
requestResponse.toString());
assertTrue(requestResponse.path("StartDate").isIntegralNumber(), "epoch milliseconds: " + requestResponse);
JsonNode sync = output.path("sync");
assertEquals(ENVELOPE_KEYS, fieldNames(sync));
assertEquals("{\"k\":1}", sync.path("Input").asText());
assertEquals("{\"ok\":true}", sync.path("Output").asText());
assertEquals(childArn, sync.path("StateMachineArn").asText());
assertEquals("SUCCEEDED", sync.path("Status").asText());
assertEquals("NOT_REDRIVABLE", sync.path("RedriveStatus").asText());
assertEquals("Execution is SUCCEEDED and cannot be redriven", sync.path("RedriveStatusReason").asText());
assertTrue(sync.path("InputDetails").path("Included").asBoolean(), sync.toString());
assertTrue(sync.path("OutputDetails").path("Included").asBoolean(), sync.toString());
assertTrue(sync.path("StartDate").isIntegralNumber(), "epoch milliseconds: " + sync);
assertTrue(sync.path("StopDate").isIntegralNumber(), "epoch milliseconds: " + sync);
JsonNode sync2 = output.path("sync2");
assertEquals(ENVELOPE_KEYS, fieldNames(sync2));
assertEquals(mapper.readTree("{\"k\":1}"), sync2.path("Input"));
assertEquals(mapper.readTree("{\"ok\":true}"), sync2.path("Output"));
assertEquals("SUCCEEDED", sync2.path("Status").asText());
assertTrue(output.path("unwrapped").path("ok").asBoolean(), "$.Output of .sync:2 is addressable: " + output);
}
private static List<String> fieldNames(JsonNode node) {
List<String> names = new ArrayList<>();
Iterator<String> it = node.fieldNames();
while (it.hasNext()) {
names.add(it.next());
}
return names;
}
private static String createStateMachine(String name, String definition) {
Response resp = given()
.header("X-Amz-Target", "AWSStepFunctions.CreateStateMachine")
.contentType(SFN_CONTENT_TYPE)
.body("""
{"name": "%s-%d", "definition": %s, "roleArn": "%s"}
""".formatted(name, System.currentTimeMillis(), quote(definition), ROLE_ARN))
.when()
.post("/");
resp.then().statusCode(200);
return resp.jsonPath().getString("stateMachineArn");
}
private static String startExecution(String smArn, String input) {
Response resp = given()
.header("X-Amz-Target", "AWSStepFunctions.StartExecution")
.contentType(SFN_CONTENT_TYPE)
.body("""
{"stateMachineArn": "%s", "input": %s}
""".formatted(smArn, quote(input)))
.when()
.post("/");
resp.then().statusCode(200);
return resp.jsonPath().getString("executionArn");
}
private static Response describeExecution(String execArn) {
return given()
.header("X-Amz-Target", "AWSStepFunctions.DescribeExecution")
.contentType(SFN_CONTENT_TYPE)
.body("""
{"executionArn": "%s"}
""".formatted(execArn))
.when()
.post("/");
}
private static Response waitForTerminalExecution(String execArn) throws InterruptedException {
for (int poll = 0; poll < 200; poll++) {
Response resp = describeExecution(execArn);
if (!"RUNNING".equals(resp.jsonPath().getString("status"))) {
return resp;
}
Thread.sleep(100);
}
fail("Execution " + execArn + " was still RUNNING after 20 seconds");
return null;
}
private static String quote(String raw) {
return "\"" + raw
.replace("\\", "\\\\")
.replace("\"", "\\\"")
.replace("\n", "\\n")
.replace("\r", "\\r")
.replace("\t", "\\t")
+ "\"";
}
}