feat(stepfunctions): implement States.JsonMerge intrinsic (#1662)

* feat(stepfunctions): implement States.JsonMerge intrinsic

The DPS provisioning state machine uses States.JsonMerge, which AslExecutor rejected with "Unsupported intrinsic function: States.JsonMerge". Implement the shallow merge (second object's top-level fields win on conflict); reject the deep-merge form (third argument true) and non-object arguments, as AWS does. Also resolve boolean/null literal intrinsic arguments so the third argument evaluates correctly. Covered by AslExecutorJsonMergeTest.

* fix(stepfunctions): reject a non-boolean States.JsonMerge third argument

The third (deep) argument was read with JsonNode.asBoolean(), which silently
coerces null/number/string/object nodes to false, so States.JsonMerge($.a,$.b,$.x)
with a non-boolean $.x quietly performed a shallow merge instead of failing.
Validate that the resolved third argument is a boolean and raise States.Runtime
otherwise. Covered by AslExecutorJsonMergeTest.nonBooleanThirdArgumentRejected.

* fix(stepfunctions): validate JsonMerge argument types before the deep-merge flag

AWS validates the argument types of States.JsonMerge before evaluating the deep-merge
flag, so two non-objects passed with true should report "requires two JSON objects"
rather than "shallow merge only". Reorder the object-type check ahead of the deep-flag
rejection and add a precedence test.

* test(stepfunctions): adapt JsonMerge test to main's AslExecutor constructor

main's AslExecutor constructor now takes EcsService and EcsJsonHandler; pass the
two new mocks. Also generalize a comment that named a specific downstream system.

* docs: regenerate action tables

* fix(stepfunctions): thread context into States.JsonMerge intrinsic args

The intrinsic pipeline gained a context argument on main (resolveIntrinsicArg /
evaluateIntrinsic now take three parameters). Thread the surrounding case's
root/context through the three States.JsonMerge argument resolutions so the branch
compiles against current main.

* fix: align JsonMerge intrinsic failures

* fix(athena): harden compatibility query polling
This commit is contained in:
Alex Banna authored and GitHub committed 2026-07-21 12:14:35 -04:00
1 parent 024d74e5c4
commit b245632a2e
5 files changed
+192 -32

No files matched your search

@@ -2052,6 +2052,39 @@ public class AslExecutor {
case "States.UUID" -> {
yield objectMapper.getNodeFactory().textNode(java.util.UUID.randomUUID().toString());
}
case "States.JsonMerge" -> {
List<String> parts = splitIntrinsicArgs(argsStr);
if (parts.size() != 3 || argsStr.stripTrailing().endsWith(",")) {
throw new FailStateException("States.IntrinsicFailure",
"States.JsonMerge requires exactly 3 arguments");
}
JsonNode a = resolveIntrinsicArg(parts.get(0).trim(), root, context);
JsonNode b = resolveIntrinsicArg(parts.get(1).trim(), root, context);
JsonNode deepArg = resolveIntrinsicArg(parts.get(2).trim(), root, context);
if (!deepArg.isBoolean()) {
// AWS rejects a non-boolean third argument rather than coercing it to false.
throw new FailStateException("States.IntrinsicFailure",
"States.JsonMerge third argument must be a boolean");
}
boolean deep = deepArg.asBoolean();
// Validate argument types before rejecting the deep-merge flag, matching AWS error
// ordering: two non-objects passed with true yield "requires two JSON objects", not
// "shallow merge only".
if (!a.isObject() || !b.isObject()) {
throw new FailStateException("States.IntrinsicFailure",
"States.JsonMerge requires two JSON objects");
}
if (deep) {
// AWS Step Functions only supports the shallow merge (third argument false).
throw new FailStateException("States.IntrinsicFailure",
"States.JsonMerge supports only shallow merge (third argument must be false)");
}
// Shallow merge: second object's top-level fields override the first's.
var merged = objectMapper.createObjectNode();
a.fields().forEachRemaining(e -> merged.set(e.getKey(), e.getValue()));
b.fields().forEachRemaining(e -> merged.set(e.getKey(), e.getValue()));
yield merged;
}
default -> throw new FailStateException("States.Runtime",
"Unsupported intrinsic function: " + fnName);
};
@@ -2085,6 +2118,12 @@ public class AslExecutor {
if (arg.startsWith("\"") && arg.endsWith("\"")) {
return objectMapper.getNodeFactory().textNode(arg.substring(1, arg.length() - 1));
}
if ("true".equals(arg) || "false".equals(arg)) {
return objectMapper.getNodeFactory().booleanNode(Boolean.parseBoolean(arg));
}
if ("null".equals(arg)) {
return objectMapper.getNodeFactory().nullNode();
}
try {
return objectMapper.getNodeFactory().numberNode(Long.parseLong(arg));
} catch (NumberFormatException e1) {