mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
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:
1 parent
024d74e5c4
commit
b245632a2e
5 files changed
+192
-32
No files matched your search
+113
@@ -0,0 +1,113 @@
|
||||
package io.github.hectorvent.floci.services.stepfunctions;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.hectorvent.floci.services.cloudformation.CloudFormationQueryHandler;
|
||||
import io.github.hectorvent.floci.services.dynamodb.DynamoDbJsonHandler;
|
||||
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
|
||||
import io.github.hectorvent.floci.services.ec2.Ec2Service;
|
||||
import io.github.hectorvent.floci.services.ecs.EcsJsonHandler;
|
||||
import io.github.hectorvent.floci.services.ecs.EcsService;
|
||||
import io.github.hectorvent.floci.services.lambda.LambdaExecutorService;
|
||||
import io.github.hectorvent.floci.services.lambda.LambdaFunctionStore;
|
||||
import io.github.hectorvent.floci.services.s3.S3Service;
|
||||
import io.github.hectorvent.floci.services.sqs.SqsJsonHandler;
|
||||
import jakarta.enterprise.inject.Instance;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Regression + functionality coverage for the {@code States.JsonMerge} intrinsic. AWS Step Functions
|
||||
* supports only the shallow merge form {@code States.JsonMerge($.a, $.b, false)} where the second
|
||||
* object's top-level fields win on a key conflict; deep-merge ({@code true}) and non-object arguments
|
||||
* are rejected. A state machine using this intrinsic previously failed with
|
||||
* "Unsupported intrinsic function: States.JsonMerge".
|
||||
*/
|
||||
class AslExecutorJsonMergeTest {
|
||||
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
private AslExecutor executor;
|
||||
|
||||
@BeforeEach
|
||||
@SuppressWarnings("unchecked")
|
||||
void setUp() {
|
||||
executor = new AslExecutor(
|
||||
mock(LambdaExecutorService.class),
|
||||
mock(LambdaFunctionStore.class),
|
||||
mock(DynamoDbService.class),
|
||||
mock(DynamoDbJsonHandler.class),
|
||||
mock(SqsJsonHandler.class),
|
||||
mock(CloudFormationQueryHandler.class),
|
||||
mock(Ec2Service.class),
|
||||
mock(S3Service.class),
|
||||
mock(EcsService.class),
|
||||
mock(EcsJsonHandler.class),
|
||||
mapper,
|
||||
new JsonataEvaluator(mapper),
|
||||
mock(Instance.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void shallowMergeSecondObjectWins() throws Exception {
|
||||
JsonNode root = mapper.readTree("{\"a\":{\"x\":1,\"y\":2},\"b\":{\"y\":9,\"z\":3}}");
|
||||
JsonNode out = executor.resolvePath("States.JsonMerge($.a, $.b, false)", root);
|
||||
assertTrue(out.isObject());
|
||||
assertEquals(1, out.path("x").asInt());
|
||||
assertEquals(9, out.path("y").asInt(), "second object's value should win on key conflict");
|
||||
assertEquals(3, out.path("z").asInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deepMergeTrueIsRejected() throws Exception {
|
||||
JsonNode root = mapper.readTree("{\"a\":{\"x\":1},\"b\":{\"y\":2}}");
|
||||
assertThrows(RuntimeException.class,
|
||||
() -> executor.resolvePath("States.JsonMerge($.a, $.b, true)", root));
|
||||
}
|
||||
|
||||
@Test
|
||||
void nonObjectArgumentsRejected() throws Exception {
|
||||
JsonNode root = mapper.readTree("{\"a\":[1,2],\"b\":{\"y\":2}}");
|
||||
assertThrows(RuntimeException.class,
|
||||
() -> executor.resolvePath("States.JsonMerge($.a, $.b, false)", root));
|
||||
}
|
||||
|
||||
@Test
|
||||
void nonObjectArgumentsAreRejectedBeforeTheDeepMergeFlag() throws Exception {
|
||||
// Two non-objects passed with deep=true must report the object-type error, not the
|
||||
// "shallow merge only" error — AWS validates argument types before the deep-merge flag.
|
||||
JsonNode root = mapper.readTree("{\"a\":[1,2],\"b\":[3,4]}");
|
||||
RuntimeException ex = assertThrows(RuntimeException.class,
|
||||
() -> executor.resolvePath("States.JsonMerge($.a, $.b, true)", root));
|
||||
assertTrue(ex.getMessage().contains("requires two JSON objects"),
|
||||
"expected the object-type error to take precedence, got: " + ex.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
void wrongArgumentCountUsesIntrinsicFailure() throws Exception {
|
||||
JsonNode root = mapper.readTree("{\"a\":{\"x\":1},\"b\":{\"y\":2}}");
|
||||
AslExecutor.FailStateException exception = assertThrows(AslExecutor.FailStateException.class,
|
||||
() -> executor.resolvePath("States.JsonMerge($.a, $.b)", root));
|
||||
assertEquals("States.IntrinsicFailure", exception.error);
|
||||
}
|
||||
|
||||
@Test
|
||||
void trailingCommaUsesIntrinsicFailure() throws Exception {
|
||||
JsonNode root = mapper.readTree("{\"a\":{\"x\":1},\"b\":{\"y\":2}}");
|
||||
AslExecutor.FailStateException exception = assertThrows(AslExecutor.FailStateException.class,
|
||||
() -> executor.resolvePath("States.JsonMerge($.a, $.b, false,)", root));
|
||||
assertEquals("States.IntrinsicFailure", exception.error);
|
||||
}
|
||||
|
||||
@Test
|
||||
void nonBooleanThirdArgumentRejected() throws Exception {
|
||||
// A non-boolean third argument must be rejected, not silently coerced to false (shallow).
|
||||
JsonNode root = mapper.readTree("{\"a\":{\"x\":1},\"b\":{\"y\":2},\"n\":3}");
|
||||
assertThrows(RuntimeException.class,
|
||||
() -> executor.resolvePath("States.JsonMerge($.a, $.b, $.n)", root));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user