-
Notifications
You must be signed in to change notification settings - Fork 3
fix: resolve namespace-qualified references in step-level with parame… #317
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
Merged
Merged
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
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
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
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
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
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
71 changes: 71 additions & 0 deletions
71
src/test/java/io/naftiko/engine/aggregates/AggregateFunctionTest.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,71 @@ | ||
| /** | ||
| * Copyright 2025-2026 Naftiko | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
| * in compliance with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under the License | ||
| * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
| * or implied. See the License for the specific language governing permissions and limitations under | ||
| * the License. | ||
| */ | ||
| package io.naftiko.engine.aggregates; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import org.junit.jupiter.api.Test; | ||
| import io.naftiko.spec.AggregateFunctionSpec; | ||
| import io.naftiko.spec.OutputParameterSpec; | ||
|
|
||
| /** | ||
| * Unit tests for {@link AggregateFunction} — namespace-qualified reference resolution | ||
| * in function-level {@code with} blocks. | ||
| */ | ||
| public class AggregateFunctionTest { | ||
|
|
||
| /** | ||
| * When a mock-mode function has {@code with: {voyage-id: "shipyard.voyage-id"}} and the | ||
| * aggregate namespace is "shipyard", calling execute should resolve the qualified reference | ||
| * to the caller's argument and use it for mock data output. | ||
| * | ||
| * Before the fix: namespace was always {@code null} in mergeWithParameters, so the literal | ||
| * "shipyard.voyage-id" overwrote the caller's "VOY-2026-042" and appeared in the mock output. | ||
| */ | ||
| @Test | ||
| void executeShouldResolveNamespaceQualifiedReferencesInFunctionWith() throws Exception { | ||
| AggregateFunctionSpec spec = new AggregateFunctionSpec(); | ||
| spec.setName("get-voyage"); | ||
| spec.setDescription("Get a voyage manifest."); | ||
| Map<String, Object> withBlock = new HashMap<>(); | ||
| withBlock.put("voyage-id", "shipyard.voyage-id"); | ||
| spec.setWith(withBlock); | ||
|
|
||
| // Add an output parameter using Mustache to echo the resolved value | ||
| OutputParameterSpec outParam = new OutputParameterSpec(); | ||
| outParam.setName("voyage-id"); | ||
| outParam.setType("string"); | ||
| outParam.setValue("{{voyage-id}}"); | ||
| spec.getOutputParameters().add(outParam); | ||
|
|
||
| // No call, no steps -> mock mode | ||
| AggregateFunction fn = new AggregateFunction(spec, null, "shipyard"); | ||
|
|
||
| Map<String, Object> callerParams = new HashMap<>(); | ||
| callerParams.put("voyage-id", "VOY-2026-042"); | ||
| FunctionResult result = fn.execute(callerParams); | ||
|
|
||
| assertTrue(result.isMock(), "Should be mock mode"); | ||
| assertNotNull(result.mockOutput, "Mock output should not be null"); | ||
|
|
||
| String outputValue = result.mockOutput.get("voyage-id").asText(); | ||
| assertEquals("VOY-2026-042", outputValue, | ||
| "Namespace-qualified 'with' should resolve to caller's argument, " | ||
| + "not the literal 'shipyard.voyage-id'"); | ||
| } | ||
| } |
108 changes: 108 additions & 0 deletions
108
src/test/java/io/naftiko/engine/aggregates/AggregateStepNamespaceIntegrationTest.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,108 @@ | ||
| /** | ||
| * Copyright 2025-2026 Naftiko | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
| * in compliance with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under the License | ||
| * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
| * or implied. See the License for the specific language governing permissions and limitations under | ||
| * the License. | ||
| */ | ||
| package io.naftiko.engine.aggregates; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| import java.io.File; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import com.fasterxml.jackson.databind.DeserializationFeature; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
| import io.naftiko.Capability; | ||
| import io.naftiko.engine.exposes.OperationStepExecutor; | ||
| import io.naftiko.spec.AggregateSpec; | ||
| import io.naftiko.spec.NaftikoSpec; | ||
|
|
||
| /** | ||
| * Integration test for issue #290: namespace-qualified references in aggregate function steps. | ||
| * | ||
| * Loads a capability YAML where an aggregate function has a step with | ||
| * {@code with: {voyage-id: shipyard.voyage-id}} and verifies that executing the function | ||
| * resolves the namespace-qualified reference before building the HTTP request URL. | ||
| * | ||
| * Uses a parameter-capturing executor to observe what parameters are passed to the consumed | ||
| * operation, independent of HTTP transport success/failure. | ||
| * | ||
| * Before the fix: the aggregate namespace was not propagated to the step executor, so the | ||
| * literal "shipyard.voyage-id" appeared in the URL instead of the resolved value. | ||
| */ | ||
| public class AggregateStepNamespaceIntegrationTest { | ||
|
|
||
| private Capability capability; | ||
| private NaftikoSpec spec; | ||
|
|
||
| @BeforeEach | ||
| void setUp() throws Exception { | ||
| String path = "src/test/resources/aggregates/aggregate-step-with-namespace.yaml"; | ||
| File file = new File(path); | ||
| assertTrue(file.exists(), "Test capability file should exist at " + path); | ||
|
|
||
| ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); | ||
| mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
| spec = mapper.readValue(file, NaftikoSpec.class); | ||
| capability = new Capability(spec); | ||
| } | ||
|
|
||
| /** | ||
| * Execute the aggregate function and verify the step-level namespace-qualified reference | ||
| * resolves correctly. A CapturingStepExecutor captures the resolved parameters before the | ||
| * HTTP call, so the assertion does not depend on error message contents. | ||
| */ | ||
| @Test | ||
| void aggregateFunctionExecuteShouldResolveNamespaceQualifiedWithInSteps() { | ||
| CapturingStepExecutor executor = new CapturingStepExecutor(capability); | ||
|
|
||
| AggregateSpec aggregateSpec = spec.getCapability().getAggregates().get(0); | ||
| Aggregate aggregate = new Aggregate(aggregateSpec, executor); | ||
| AggregateFunction fn = aggregate.findFunction("get-voyage-manifest"); | ||
| assertNotNull(fn, "Aggregate function should be found"); | ||
|
|
||
| Map<String, Object> params = new HashMap<>(); | ||
| params.put("voyage-id", "VOY-2026-042"); | ||
|
|
||
| try { | ||
| fn.execute(params); | ||
| } catch (Exception expected) { | ||
| // HTTP connection failure expected — no server on port 19999 | ||
| } | ||
|
|
||
| assertNotNull(executor.capturedParams, | ||
| "Parameters should have been captured before HTTP call"); | ||
| assertEquals("VOY-2026-042", executor.capturedParams.get("voyage-id"), | ||
| "Namespace-qualified reference 'shipyard.voyage-id' should resolve to " | ||
| + "the caller's argument, not be passed as literal"); | ||
| } | ||
|
|
||
| /** | ||
| * Test-only subclass that captures parameters at the HTTP request construction point. | ||
| */ | ||
| static class CapturingStepExecutor extends OperationStepExecutor { | ||
| Map<String, Object> capturedParams; | ||
|
|
||
| CapturingStepExecutor(Capability capability) { | ||
| super(capability); | ||
| } | ||
|
|
||
| @Override | ||
| public HandlingContext findClientRequestFor(String clientNamespace, String clientOpName, | ||
| Map<String, Object> parameters) { | ||
| capturedParams = new HashMap<>(parameters); | ||
| return super.findClientRequestFor(clientNamespace, clientOpName, parameters); | ||
| } | ||
| } | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.