fix(sfn): support advanced JSONPath expressions (#3398)

Co-authored-by: xujiantop-crypto <265865031+xujiantop-crypto@users.noreply.github.com>
This commit is contained in:
XuJianandxujiantop-crypto authored and GitHub committed 2026-09-11 10:21:19 -04:00
1 parent 485b7c5047
commit 5bf8075d52
4 files changed
+123 -2

No files matched your search

@@ -101,10 +101,49 @@ class AslExecutorPathIntrinsicsTest {
@Test
void bracketQuotedMembersSupportNamesOutsideDotShorthand() throws Exception {
JsonNode root = mapper.readTree("{\"config\":{\"max-limit\":2},\"a.b\":3}");
JsonNode root = mapper.readTree(
"{\"config\":{\"max-limit\":2},\"a.b\":3,\"a..b\":4,\"[?(\":5}");
assertEquals(2, executor.resolvePath("$['config']['max-limit']", root).asInt());
assertEquals(3, executor.resolvePath("$['a.b']", root).asInt());
assertEquals(4, executor.resolvePath("$['a..b']", root).asInt());
assertEquals(5, executor.resolvePath("$['[?(']", root).asInt());
}
@Test
void filterExpressionsSupportExistenceAndComparisonPredicates() throws Exception {
JsonNode root = mapper.readTree("""
{"list":[{"keep":true,"id":1},{"keep":false,"id":2},{"id":3}]}
""");
assertEquals(mapper.readTree("[{\"keep\":true,\"id\":1},{\"keep\":false,\"id\":2}]"),
executor.resolvePath("$.list[?(@.keep)]", root));
assertEquals(mapper.readTree("[{\"keep\":true,\"id\":1}]"),
executor.resolvePath("$.list[?(@.keep == true)]", root));
}
@Test
void recursiveDescentPreservesAndFlattensNestedArrayMatches() throws Exception {
JsonNode root = mapper.readTree("{\"d\":{\"x\":{\"a\":[1,2]}}}");
assertEquals(mapper.readTree("[[1,2]]"), executor.resolvePath("$.d..a", root));
assertEquals(mapper.readTree("[1,2]"), executor.resolvePath("$.d..a[*]", root));
}
@Test
void advancedPathsWorkInPayloadTemplatesAndIntrinsics() throws Exception {
JsonNode root = mapper.readTree("{\"list\":[1,null,2]}");
JsonNode parameters = mapper.readTree("""
{
"filtered.$": "$.list[?(@ != null)]",
"count.$": "States.ArrayLength($.list[?(@ != null)])"
}
""");
JsonNode resolved = executor.resolveParameters(parameters, root, mapper.createObjectNode());
assertEquals(mapper.readTree("[1,2]"), resolved.path("filtered"));
assertEquals(2, resolved.path("count").asInt());
}
@Test
@@ -122,6 +122,16 @@ class AslExecutorStatePathTest {
"{\"kept\":true}");
}
@Test
void passOutputPathSupportsFilterExpressions() throws Exception {
assertOutput("""
{"StartAt":"Pass","States":{
"Pass":{"Type":"Pass","OutputPath":"$.Payload[?(@.title)]","End":true}}}
""",
"{\"Payload\":[{\"title\":\"first\"},{\"title\":false},{\"other\":1}]}",
"[{\"title\":\"first\"},{\"title\":false}]");
}
@Test
void succeedAppliesInputPathBeforeOutputPath() throws Exception {
assertOutput("""