mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(stepfunctions): resolve payload-template .$ inside arrays and $$ context in intrinsic args (#1691)
* feat(stepfunctions): resolve payload-template .$ inside arrays and $$ context in intrinsic args
Two AWS States Language parity fixes in the payload-template / intrinsic path:
- resolveParameters now recurses into arrays, not just objects. A Parameters / ItemSelector /
ResultSelector template resolves .$ references at any nesting depth, including inside arrays
(e.g. an ECS Overrides.ContainerOverrides[].Environment[].Value.$). Previously array elements
passed through verbatim, so those references were never substituted.
- Intrinsic-function arguments can now reference the Context Object ($$). resolvePath /
evaluateIntrinsic / resolveIntrinsicArg thread the Context Object through, so an argument like
States.Format('{}', $$.Map.Item.Value.x) or a bare $$.Execution.Id resolves against the
context. Ordinary $. / input-only resolution is unchanged (context is null there).
Adds AslExecutorArrayParamsTest and AslExecutorIntrinsicContextTest.
* docs: regenerate action tables
This commit is contained in:
1 parent
4a16266f48
commit
54b378ed6c
3 files changed
+226
-21
No files matched your search
+56
@@ -0,0 +1,56 @@
|
||||
package io.github.hectorvent.floci.services.stepfunctions;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* A Parameters / ItemSelector payload template must resolve {@code .$} references at ANY nesting
|
||||
* depth, including inside arrays — e.g. the {@code Environment} array of an ECS
|
||||
* {@code Overrides.ContainerOverrides[]}. Without array recursion those {@code Value.$} entries pass
|
||||
* through verbatim and the launched container receives empty environment variables.
|
||||
*/
|
||||
class AslExecutorArrayParamsTest {
|
||||
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
private AslExecutor newExecutor() {
|
||||
return new AslExecutor(null, null, null, null, null, null, null, null,
|
||||
null, null, mapper, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolvesDotDollarReferencesInsideArrays() throws Exception {
|
||||
JsonNode parameters = mapper.readTree("""
|
||||
{
|
||||
"Overrides": {
|
||||
"ContainerOverrides": [
|
||||
{
|
||||
"Name": "runner",
|
||||
"Environment": [
|
||||
{"Name": "ACTION_TYPE", "Value.$": "$.solution.operation"},
|
||||
{"Name": "PROVISION_TYPE", "Value.$": "$.solution.primaryProvisionType"},
|
||||
{"Name": "STATIC", "Value": "CREATE_UPDATE"}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
""");
|
||||
JsonNode input = mapper.readTree("""
|
||||
{ "solution": { "operation": "create", "primaryProvisionType": "awscdk" } }
|
||||
""");
|
||||
|
||||
JsonNode resolved = newExecutor().resolveParameters(parameters, input, mapper.createObjectNode());
|
||||
|
||||
JsonNode env = resolved.path("Overrides").path("ContainerOverrides").path(0).path("Environment");
|
||||
assertEquals("create", env.path(0).path("Value").asText());
|
||||
assertEquals("awscdk", env.path(1).path("Value").asText());
|
||||
assertEquals("CREATE_UPDATE", env.path(2).path("Value").asText());
|
||||
// The unresolved ".$" key must be gone.
|
||||
assertTrue(env.path(0).path("Value.$").isMissingNode(), "Value.$ should have been resolved away");
|
||||
}
|
||||
}
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
package io.github.hectorvent.floci.services.stepfunctions;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* Unit tests for Context Object ($$) resolution inside JSONPath-mode intrinsic functions.
|
||||
*
|
||||
* <p>A whole-value {@code "x.$": "$$.Map.Item.Value"} Parameters field already resolved against
|
||||
* the Context Object, but a {@code $$.} reference nested inside an intrinsic argument — e.g.
|
||||
* {@code States.Format('.../{}', $$.Map.Item.Value.solutionId)} — used to fall through to an
|
||||
* input-only lookup and resolve to null, because the context was never threaded from
|
||||
* {@code resolveParameters} into {@code evaluateIntrinsic}/{@code resolveIntrinsicArg}. These
|
||||
* tests pin the fix and guard the no-context (input-only) path against regression.
|
||||
*/
|
||||
class AslExecutorIntrinsicContextTest {
|
||||
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
/** Only ObjectMapper is exercised by the path/intrinsic resolution methods under test. */
|
||||
private AslExecutor newExecutor() {
|
||||
return new AslExecutor(null, null, null, null, null, null, null, null,
|
||||
null, null, mapper, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void statesFormat_resolvesContextArgInsideParameters() throws Exception {
|
||||
AslExecutor executor = newExecutor();
|
||||
// Shaped like a Map ItemSelector: $. args come from the Map state's effective input,
|
||||
// $$.Map.Item.Value.* comes from the per-iteration Context Object.
|
||||
JsonNode parameters = mapper.readTree("""
|
||||
{
|
||||
"provisionerFolder.$": "States.Format('/mnt/efs/{}/{}/{}/provisioner', $.systemId, $.systemConfigVersion, $$.Map.Item.Value.solutionId)"
|
||||
}
|
||||
""");
|
||||
JsonNode input = mapper.readTree("""
|
||||
{ "systemId": "SYS1", "systemConfigVersion": "v3" }
|
||||
""");
|
||||
JsonNode context = mapper.readTree("""
|
||||
{ "Map": { "Item": { "Index": 0, "Value": { "solutionId": "SOLUTION_A" } } } }
|
||||
""");
|
||||
|
||||
JsonNode resolved = executor.resolveParameters(parameters, input, context);
|
||||
|
||||
assertEquals("/mnt/efs/SYS1/v3/SOLUTION_A/provisioner",
|
||||
resolved.path("provisionerFolder").asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void statesFormat_resolvesContextArgViaResolvePath() {
|
||||
AslExecutor executor = newExecutor();
|
||||
JsonNode input = mapper.createObjectNode();
|
||||
JsonNode context = mapper.createObjectNode();
|
||||
((com.fasterxml.jackson.databind.node.ObjectNode) context).putObject("Map")
|
||||
.putObject("Item").putObject("Value").put("solutionId", "SOLUTION_B");
|
||||
|
||||
JsonNode result = executor.resolvePath(
|
||||
"States.Format('id={}', $$.Map.Item.Value.solutionId)", input, context);
|
||||
|
||||
assertEquals("id=SOLUTION_B", result.asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void wholeContext_resolvesInsideIntrinsic() {
|
||||
AslExecutor executor = newExecutor();
|
||||
JsonNode input = mapper.createObjectNode();
|
||||
JsonNode context = mapper.createObjectNode();
|
||||
((com.fasterxml.jackson.databind.node.ObjectNode) context).put("token", "abc");
|
||||
|
||||
// States.JsonToString($$) serializes the whole Context Object.
|
||||
JsonNode result = executor.resolvePath("States.JsonToString($$)", input, context);
|
||||
|
||||
assertEquals("{\"token\":\"abc\"}", result.asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void inputArgsStillResolveWithContextPresent() {
|
||||
AslExecutor executor = newExecutor();
|
||||
JsonNode input = mapper.createObjectNode();
|
||||
((com.fasterxml.jackson.databind.node.ObjectNode) input).put("a", "X").put("b", "Y");
|
||||
JsonNode context = mapper.createObjectNode();
|
||||
|
||||
JsonNode result = executor.resolvePath("States.Format('{}-{}', $.a, $.b)", input, context);
|
||||
|
||||
assertEquals("X-Y", result.asText());
|
||||
}
|
||||
|
||||
@Test
|
||||
void noContext_intrinsicResolutionUnchanged() {
|
||||
AslExecutor executor = newExecutor();
|
||||
JsonNode input = mapper.createObjectNode();
|
||||
((com.fasterxml.jackson.databind.node.ObjectNode) input).put("name", "widget");
|
||||
|
||||
// The 2-arg form (context == null) must behave exactly as before: $. args resolve,
|
||||
// and a stray $$. arg — which has no context to resolve against — yields "null".
|
||||
// The "null" here pins Floci-internal transitional behavior, NOT AWS semantics (on real
|
||||
// AWS the Context Object always exists); see resolveIntrinsicArg. It only holds until
|
||||
// context is threaded into the remaining resolvePath callers, at which point this
|
||||
// assertion should be updated rather than treated as a contract.
|
||||
assertEquals("widget", executor.resolvePath("States.Format('{}', $.name)", input).asText());
|
||||
assertEquals("null", executor.resolvePath(
|
||||
"States.Format('{}', $$.Map.Item.Value.solutionId)", input).asText());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user