-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat(stepfunctions): resolve payload-template .$ inside arrays and $$ context in intrinsic args #1691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
abanna
wants to merge
1
commit into
floci-io:main
Choose a base branch
from
abanna:feat/stepfunctions-payload-array-and-context
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+206
−16
Open
feat(stepfunctions): resolve payload-template .$ inside arrays and $$ context in intrinsic args #1691
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...st/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutorArrayParamsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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, | ||
| 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"); | ||
| } | ||
| } | ||
103 changes: 103 additions & 0 deletions
103
...va/io/github/hectorvent/floci/services/stepfunctions/AslExecutorIntrinsicContextTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| 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, | ||
| 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". | ||
| assertEquals("widget", executor.resolvePath("States.Format('{}', $.name)", input).asText()); | ||
| assertEquals("null", executor.resolvePath( | ||
| "States.Format('{}', $$.Map.Item.Value.solutionId)", input).asText()); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AGENTS.md specifies that unit tests should follow the
*ServiceTest.javanaming pattern. Both new test files (AslExecutorArrayParamsTestandAslExecutorIntrinsicContextTest) use a different suffix. WhileAslExecutoris not technically a service, establishing an inconsistent test-naming pattern here may cause confusion when locating tests with build tooling or running focused test commands like./mvnw test -Dtest=AslExecutor*.Context Used: AGENTS.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!