Skip to content

Commit 99d556a

Browse files
committed
Dump S3 model in integ, fix build (?), fix test
1 parent 168358a commit 99d556a

File tree

3 files changed

+72
-13
lines changed

3 files changed

+72
-13
lines changed

smithy-aws-endpoints/build.gradle.kts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dependencies {
2626
}
2727

2828
// Integration test source set for tests that require the S3 model
29-
// These tests require JDK 21+ due to the S3 model dependency
29+
// These tests require JDK 17+ due to the S3 model dependency
3030
sourceSets {
3131
create("it") {
3232
compileClasspath += sourceSets["main"].output + sourceSets["test"].output
@@ -38,15 +38,15 @@ configurations["itImplementation"].extendsFrom(configurations["testImplementatio
3838
configurations["itRuntimeOnly"].extendsFrom(configurations["testRuntimeOnly"])
3939
configurations["itImplementation"].extendsFrom(s3Model)
4040

41-
// Configure IT source set to compile with JDK 21
41+
// Configure IT source set to compile with JDK 17
4242
tasks.named<JavaCompile>("compileItJava") {
4343
javaCompiler.set(
4444
javaToolchains.compilerFor {
45-
languageVersion.set(JavaLanguageVersion.of(21))
45+
languageVersion.set(JavaLanguageVersion.of(17))
4646
},
4747
)
48-
sourceCompatibility = "21"
49-
targetCompatibility = "21"
48+
sourceCompatibility = "17"
49+
targetCompatibility = "17"
5050
}
5151

5252
val integrationTest by tasks.registering(Test::class) {
@@ -57,10 +57,18 @@ val integrationTest by tasks.registering(Test::class) {
5757
dependsOn(tasks.jar)
5858
shouldRunAfter(tasks.test)
5959

60-
// Run with JDK 21
60+
// Pass build directory to tests
61+
systemProperty(
62+
"buildDir",
63+
layout.buildDirectory
64+
.get()
65+
.asFile.absolutePath,
66+
)
67+
68+
// Run with JDK 17
6169
javaLauncher.set(
6270
javaToolchains.launcherFor {
63-
languageVersion.set(JavaLanguageVersion.of(21))
71+
languageVersion.set(JavaLanguageVersion.of(17))
6472
},
6573
)
6674
}

smithy-aws-endpoints/src/it/java/software/amazon/smithy/rulesengine/aws/language/functions/S3BddTest.java

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66

77
import static org.junit.jupiter.api.Assertions.assertFalse;
88

9+
import java.io.IOException;
10+
import java.nio.file.Files;
11+
import java.nio.file.Path;
12+
import java.nio.file.Paths;
913
import java.util.List;
1014
import org.junit.jupiter.api.BeforeAll;
1115
import org.junit.jupiter.api.Test;
1216
import software.amazon.smithy.model.Model;
17+
import software.amazon.smithy.model.node.Node;
18+
import software.amazon.smithy.model.shapes.ModelSerializer;
1319
import software.amazon.smithy.model.shapes.ServiceShape;
1420
import software.amazon.smithy.model.shapes.ShapeId;
1521
import software.amazon.smithy.rulesengine.aws.s3.S3TreeRewriter;
@@ -25,18 +31,20 @@
2531

2632
class S3BddTest {
2733
private static final ShapeId S3_SERVICE_ID = ShapeId.from("com.amazonaws.s3#AmazonS3");
34+
private static Model model;
35+
private static ServiceShape s3Service;
2836
private static EndpointRuleSet originalRules;
2937
private static EndpointRuleSet rules;
3038
private static List<EndpointTestCase> testCases;
3139

3240
@BeforeAll
3341
static void loadS3Model() {
34-
Model model = Model.assembler()
42+
model = Model.assembler()
3543
.discoverModels()
3644
.assemble()
3745
.unwrap();
3846

39-
ServiceShape s3Service = model.expectShape(S3_SERVICE_ID, ServiceShape.class);
47+
s3Service = model.expectShape(S3_SERVICE_ID, ServiceShape.class);
4048
originalRules = s3Service.expectTrait(EndpointRuleSetTrait.class).getEndpointRuleSet();
4149
rules = S3TreeRewriter.transform(originalRules);
4250
testCases = s3Service.expectTrait(EndpointTestsTrait.class).getTestCases();
@@ -83,5 +91,42 @@ void compileToBddWithOptimizations() {
8391
}
8492

8593
System.out.println(sb);
94+
95+
// Write model with BDD trait to build directory
96+
writeModelWithBddTrait(optimizedTrait);
97+
}
98+
99+
private void writeModelWithBddTrait(EndpointBddTrait bddTrait) {
100+
String buildDir = System.getProperty("buildDir");
101+
if (buildDir == null) {
102+
System.out.println("buildDir system property not set, skipping model output");
103+
return;
104+
}
105+
106+
// Create updated service with BDD trait instead of RuleSet trait
107+
ServiceShape updatedService = s3Service.toBuilder()
108+
.removeTrait(EndpointRuleSetTrait.ID)
109+
.addTrait(bddTrait)
110+
.build();
111+
112+
// Build updated model
113+
Model updatedModel = model.toBuilder()
114+
.removeShape(s3Service.getId())
115+
.addShape(updatedService)
116+
.build();
117+
118+
// Serialize to JSON
119+
ModelSerializer serializer = ModelSerializer.builder().build();
120+
String json = Node.prettyPrintJson(serializer.serialize(updatedModel));
121+
122+
// Write to build directory
123+
Path outputPath = Paths.get(buildDir, "s3-bdd-model.json");
124+
try {
125+
Files.createDirectories(outputPath.getParent());
126+
Files.writeString(outputPath, json);
127+
System.out.println("Wrote S3 BDD model to: " + outputPath);
128+
} catch (IOException e) {
129+
throw new RuntimeException("Failed to write S3 BDD model", e);
130+
}
86131
}
87132
}

smithy-rules-engine/src/test/java/software/amazon/smithy/rulesengine/logic/cfg/CfgBuilderTest.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,21 @@ void createConditionReferenceHandlesBooleanEqualsCanonicalizations() {
202202
}
203203

204204
@Test
205-
void createConditionReferenceDoesNotCanonicalizeWithoutDefault() {
206-
// Test that booleanEquals(region, false) is not canonicalized (no default)
205+
void createConditionReferenceCanonicalizesEvenWithoutDefault() {
206+
// booleanEquals(X, false) -> booleanEquals(X, true) with negation is a valid
207+
// algebraic transformation regardless of whether the parameter has a default
207208
Expression ref = Expression.getReference(Identifier.of("region"));
208209
Condition cond = Condition.builder().fn(BooleanEquals.ofExpressions(ref, false)).build();
209210

210211
ConditionReference condRef = builder.createConditionReference(cond);
211212

212-
assertFalse(condRef.isNegated());
213-
assertEquals(cond.getFunction(), condRef.getCondition().getFunction());
213+
// Should be canonicalized to booleanEquals(region, true) with negation
214+
assertTrue(condRef.isNegated());
215+
assertInstanceOf(BooleanEquals.class, condRef.getCondition().getFunction());
216+
217+
BooleanEquals fn = (BooleanEquals) condRef.getCondition().getFunction();
218+
assertEquals(ref, fn.getArguments().get(0));
219+
assertEquals(Literal.booleanLiteral(true), fn.getArguments().get(1));
214220
}
215221

216222
@Test

0 commit comments

Comments
 (0)