Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.knowledge.TopDownIndex;
import software.amazon.smithy.model.node.Node;
import software.amazon.smithy.model.node.ObjectNode;
import software.amazon.smithy.model.node.StringNode;
import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.model.shapes.StructureShape;
Expand Down Expand Up @@ -71,6 +75,7 @@ private void validateEndpointRuleSet(
// be used frequently in downstream validation.
List<Parameter> builtInParamsWithDefaults = new ArrayList<>();
List<Parameter> builtInParamsWithoutDefaults = new ArrayList<>();
Map<String, String> builtInParameters = new HashMap<>();

for (Parameter parameter : parameters) {
if (parameter.isBuiltIn()) {
Expand All @@ -79,6 +84,7 @@ private void validateEndpointRuleSet(
} else {
builtInParamsWithoutDefaults.add(parameter);
}
builtInParameters.put(parameter.getName().getName().getValue(), parameter.getBuiltIn().get());
}
}

Expand Down Expand Up @@ -112,6 +118,11 @@ private void validateEndpointRuleSet(
testCase,
testOperationInput,
events);
validateBuiltInsUseInconsistentValues(serviceShape,
builtInParameters,
testCase,
testOperationInput,
events);

StructureShape inputShape = model.expectShape(
operationNameMap.get(operationName).getInputShape(),
Expand Down Expand Up @@ -149,12 +160,8 @@ private void validateConfiguredBuiltInValues(
for (Map.Entry<Parameter, Node> builtInParasWithNonDefaultValue : builtInParamsWithNonDefaultValues
.entrySet()) {
String builtInName = builtInParasWithNonDefaultValue.getKey().getBuiltIn().get();
// Emit if either the built-in with a non-matching value isn't
// specified or the value set for it doesn't match.
if (!testOperationInput.getBuiltInParams().containsMember(builtInName)
|| !testOperationInput.getBuiltInParams()
.expectMember(builtInName)
.equals(builtInParasWithNonDefaultValue.getValue())) {
// Emit if the built-in with a non-matching value isn't specified.
if (!testOperationInput.getBuiltInParams().containsMember(builtInName)) {
events.add(error(serviceShape,
testOperationInput,
String.format("Test case does not supply the `%s` value for the `%s` parameter's "
Expand Down Expand Up @@ -186,6 +193,45 @@ private void validateBuiltInsWithoutDefaultsHaveValues(
}
}

private void validateBuiltInsUseInconsistentValues(
ServiceShape serviceShape,
Map<String, String> builtInParameters,
EndpointTestCase testCase,
EndpointTestOperationInput testOperationInput,
List<ValidationEvent> events
) {
if (testOperationInput == null) {
return;
}
for (Entry<StringNode, Node> testCaseParam : testCase.getParams().getMembers().entrySet()) {
if (!builtInParameters.containsKey(testCaseParam.getKey().getValue())) {
continue;
}

ObjectNode operationInputBuiltInParams = testOperationInput.getBuiltInParams();
if (operationInputBuiltInParams == null) {
continue;
}

String builtInName = builtInParameters.get(testCaseParam.getKey().getValue());
if (!operationInputBuiltInParams.containsMember(builtInName)) {
continue;
}

Optional<Node> paramValue = operationInputBuiltInParams.getMember(builtInName);
if (!paramValue.isPresent()) {
continue;
}

if (!paramValue.get().equals(testCaseParam.getValue())) {
events.add(error(
serviceShape,
"Inconsistent testcase parameters: " + testCaseParam.getValue()
+ " and " + paramValue.get()));
}
}
}

private void validateOperationInput(
Model model,
ServiceShape serviceShape,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ private void validateTestsParameters(

// All required params from a ruleset must be present in all test cases.
if (parameter.isRequired() && !parameter.getDefault().isPresent()
&& (!testSuiteHasParam || testSuiteParams.get(name).size() != trait.getTestCases().size())) {
&& (!testSuiteHasParam || testSuiteParams.get(name).size() < trait.getTestCases().size())) {
Copy link
Contributor Author

@rchache rchache Feb 4, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is only a partial/bandaid fix. there is still a bug in extractTestSuiteParameters that double counts and causes testSuiteParams to be larger than it should be.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a plan to get the root cause fixed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a look and it seemed fairly complicated at least to me. I didn't want to accidentally create a regression, so I did this minimal fix for now

errors.add(parameterError(serviceShape,
parameter,
"TestCase.RequiredMissing",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[WARNING] example#FizzBuzz: This shape applies a trait that is unstable: smithy.rules#endpointRuleSet | UnstableTrait.smithy.rules#endpointRuleSet
[WARNING] example#FizzBuzz: This shape applies a trait that is unstable: smithy.rules#endpointTests | UnstableTrait.smithy.rules#endpointTests
[ERROR] example#FizzBuzz: Inconsistent testcase parameters: https://another.example.com and https://custom.example.com | EndpointTestsTrait
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
$version: "1.0"

namespace example

use smithy.rules#endpointRuleSet
use smithy.rules#endpointTests

@endpointRuleSet({
"version": "1.3",
parameters: {
endpoint: {
type: "string"
builtIn: "SDK::Endpoint"
documentation: "docs"
}
},
"rules": [
{
"conditions": [],
"documentation": "base rule",
"endpoint": {
"url": "https://fizzbuzz.amazonaws.com",
"headers": {}
},
"type": "endpoint"
}
]
})
@endpointTests(
version: "1.3",
testCases: [
{
"documentation": "Inconsistent",
"params": {
endpoint: "https://another.example.com"
},
"expect": {
"endpoint": {
"url": "https://fizzbuzz.amazonaws.com"
}
},
"operationInputs": [
{
"operationName": "ListShards",
"builtInParams": {
"SDK::Endpoint": "https://custom.example.com",
}
}
]
}
{
"documentation": "Consistent",
"params": {
endpoint: "https://another.example.com"
},
"expect": {
"endpoint": {
"url": "https://fizzbuzz.amazonaws.com"
}
},
"operationInputs": [
{
"operationName": "ListShards",
"builtInParams": {
"SDK::Endpoint": "https://another.example.com",
}
}
]
}
]
)
service FizzBuzz {
operations: [
ListShards
]
}

operation ListShards {
input: Struct
}

structure Struct {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[WARNING] smithy.example#ExampleService: This shape applies a trait that is unstable: smithy.rules#endpointRuleSet | UnstableTrait
[WARNING] smithy.example#ExampleService: This shape applies a trait that is unstable: smithy.rules#endpointTests | UnstableTrait
[ERROR] smithy.example#ExampleService: Test case does not supply the `"https://another.example.com"` value for the `endpoint` parameter's `SDK::Endpoint` built-in. | EndpointTestsTrait
[ERROR] smithy.example#ExampleService: Inconsistent testcase parameters: https://another.example.com and https://custom.example.com | EndpointTestsTrait
[ERROR] smithy.example#ExampleService: Test case does not supply the `"https://some.example.com"` value for the `endpoint` parameter's `SDK::Endpoint` built-in. | EndpointTestsTrait