fix(sfn): merge ResultPath at a bracket-index reference path (#3483)

Support [n] bracket-index segments in ResultPath so a path such as
$[1].payload merges into the addressed array element instead of
discarding the array input; an out-of-bounds index raises
States.ResultPathMatchFailure. Also support the single-quoted bracket
field name form ($.abc.['def ghi']) AWS documents for a field name a
dotted segment cannot carry.

* Fix #3479

Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
Matheus Oliveira authored and GitHub committed 2026-09-12 13:22:28 -04:00
1 parent 1b83ef323e
commit 99c19d03d2
3 files changed
+237 -42

No files matched your search

@@ -28,7 +28,9 @@ import static org.mockito.Mockito.mock;
/**
* End-to-end coverage for the ResultPath fix: a non-applicable ResultPath fails the execution with
* {@code States.ResultPathMatchFailure} (was a silent input discard), the error is catchable via a
* Parallel state's {@code Catch}, and object inputs merge unchanged.
* Parallel state's {@code Catch}, object inputs merge unchanged, and a bracket-index ResultPath
* (e.g. {@code $[1].payload}) merges into the addressed array element instead of discarding the
* array input.
*
* <p>CI-only: constructing {@link AslExecutor} pulls in Vert.x (absent in the offline sandbox). The merge
* logic is covered locally by {@link ResultPathMergeTest}.
@@ -111,6 +113,27 @@ class AslExecutorResultPathTest {
assertEquals("SUCCEEDED", exec.getStatus());
}
@Test
void arrayIndexResultPathMergesIntoIndexedElementAndKeepsArrayInput() throws Exception {
Execution exec = run(
"{\"StartAt\":\"P\",\"States\":{\"P\":{\"Type\":\"Pass\",\"Result\":{\"subject_status\":1},"
+ "\"ResultPath\":\"$[1].payload\",\"End\":true}}}",
"[{\"a\":1},{\"id\":7},{\"c\":3},4]");
assertEquals("SUCCEEDED", exec.getStatus());
assertEquals(mapper.readTree("[{\"a\":1},{\"id\":7,\"payload\":{\"subject_status\":1}},{\"c\":3},4]"),
mapper.readTree(exec.getOutput()));
}
@Test
void arrayIndexOutOfBoundsResultPathFailsExecution() {
Execution exec = run(
"{\"StartAt\":\"P\",\"States\":{\"P\":{\"Type\":\"Pass\",\"Result\":{\"x\":1},"
+ "\"ResultPath\":\"$[10].payload\",\"End\":true}}}",
"[{\"a\":1},{\"id\":7},{\"c\":3},4]");
assertEquals("FAILED", exec.getStatus());
assertEquals("States.ResultPathMatchFailure", exec.getError());
}
@Test
void catcherResultPathFailureReportsResultPathMatchFailureNotRuntime() {
// A matched Catcher whose own ResultPath cannot apply to the (non-object) input must terminate
@@ -9,8 +9,9 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Unit tests for {@link ResultPathMerge}: the extracted ResultPath merge, including the AWS
* {@code States.ResultPathMatchFailure} case (previously a silent input-discard) and the documented
* residuals. Plain JUnit5 + Jackson, so it runs in the offline sandbox.
* {@code States.ResultPathMatchFailure} case (previously a silent input-discard), bracket-index
* ResultPaths (previously an unimplemented residual), and the remaining documented residual.
* Plain JUnit5 + Jackson, so it runs in the offline sandbox.
*/
class ResultPathMergeTest {
@@ -65,6 +66,52 @@ class ResultPathMergeTest {
() -> ResultPathMerge.merge(n("5"), "$.x", n(j("'r'")), OM));
}
// Note: the $[...] and scalar-intermediate residuals are intentionally NOT asserted here (per the
// scope decision they are documented in ResultPathMerge, not encoded as correct behavior).
@Test
void arrayIndexResultPathMergesIntoIndexedElement() {
JsonNode input = n(j("[{'a':1},{'id':7},{'c':3},4]"));
JsonNode out = ResultPathMerge.merge(input, "$[1].payload", n(j("{'subject_status':1}")), OM);
assertEquals(n(j("[{'a':1},{'id':7,'payload':{'subject_status':1}},{'c':3},4]")), out);
}
@Test
void bracketIndexMidPathMergesIntoNestedElement() {
JsonNode input = n(j("{'a':[{'other':1}]}"));
JsonNode out = ResultPathMerge.merge(input, "$.a[0].b", n("5"), OM);
assertEquals(5, out.get("a").get(0).get("b").asInt());
assertEquals(1, out.get("a").get(0).get("other").asInt());
}
@Test
void arrayIndexOutOfBoundsRaisesResultPathMatchFailure() {
JsonNode input = n(j("[{'a':1},{'id':7},{'c':3},4]"));
assertThrows(ResultPathMerge.ResultPathMatchException.class,
() -> ResultPathMerge.merge(input, "$[10].payload", n(j("{'x':1}")), OM));
}
@Test
void arrayIndexResultPathAgainstNonArrayInputRaisesResultPathMatchFailure() {
assertThrows(ResultPathMerge.ResultPathMatchException.class,
() -> ResultPathMerge.merge(n(j("{'a':1}")), "$[0].x", n(j("{'x':1}")), OM));
}
@Test
void quotedBracketFieldNameMergesLikeADottedField() {
JsonNode out = ResultPathMerge.merge(n(j("{'abc':{}}")), "$.abc.['def ghi']", n("5"), OM);
assertEquals(5, out.get("abc").get("def ghi").asInt());
}
@Test
void quotedBracketFieldNameAsRootSegmentRequiresObjectInput() {
assertThrows(ResultPathMerge.ResultPathMatchException.class,
() -> ResultPathMerge.merge(n("[1,2]"), "$.['def ghi']", n("5"), OM));
}
@Test
void unterminatedQuotedBracketSegmentRaisesResultPathMatchFailure() {
assertThrows(ResultPathMerge.ResultPathMatchException.class,
() -> ResultPathMerge.merge(n(j("{'a':1}")), "$.['unterminated", n("5"), OM));
}
// Note: a $.a.b path whose $.a is a scalar (the pre-existing, documented residual) is
// intentionally NOT asserted here; it is unchanged by this fix and remains a silent overwrite.
}