diff --git a/src/test/java/io/floci/aws/tools/CoreBoundImportGuardTest.java b/src/test/java/io/floci/aws/tools/CoreBoundImportGuardTest.java index 2ec176ca09..2e87d92b25 100644 --- a/src/test/java/io/floci/aws/tools/CoreBoundImportGuardTest.java +++ b/src/test/java/io/floci/aws/tools/CoreBoundImportGuardTest.java @@ -17,7 +17,6 @@ import java.util.Set; import java.util.TreeSet; import java.util.regex.Matcher; import java.util.regex.Pattern; -import java.util.stream.Collectors; import java.util.stream.Stream; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -47,10 +46,9 @@ import static org.junit.jupiter.api.Assertions.fail; * import of one of its nested types. * * - *

Comments are ignored. The references that predate this guard are recorded in - * {@code src/test/resources/core-boundary/allowlist.tsv}, one {@code classreference} per line. - * A reference that is not in the allowlist fails, and so does an allowlist line that no longer - * matches anything, so the list can only shrink. + *

Comments are ignored. Any match fails the build: give the class a seam instead (a hook, a + * contributor, a neutral config key or an interface the service implements), or take it off + * {@code core-bound.txt} if it does not belong in floci-core. * *

Classes that the ADR names but that live under {@code services/} are not scanned: ACM's * {@code CertificateGenerator} builds on the core {@code TlsCertificateGenerator} and adds what only @@ -62,18 +60,11 @@ import static org.junit.jupiter.api.Assertions.fail; * generic {@code io.floci.aws.core.storage.base.StorageFactory} and its own scoped-storage decorator, * which each emulator configures with its key format, so the AWS scoping classes remain AWS code and * stay where their callers already import them from. - * - *

Enforced. The guard started in report mode, with an allowlist recording the references - * still to untangle, and each untangling change removed its lines (the stale-entry check forced - * it). The allowlist is now empty and must stay empty, so a core-bound class that references - * service code fails the build, and adding a line back to the allowlist fails too. Give the class - * a seam instead (a hook, a contributor or an interface the service implements). */ class CoreBoundImportGuardTest { private static final Path SOURCES = Path.of("src/main/java"); private static final Path CORE_BOUND = Path.of("src/test/resources/core-boundary/core-bound.txt"); - private static final Path ALLOWLIST = Path.of("src/test/resources/core-boundary/allowlist.tsv"); private static final Path EMULATOR_CONFIG = SOURCES.resolve("io/floci/aws/config/EmulatorConfig.java"); @Test @@ -98,53 +89,20 @@ class CoreBoundImportGuardTest { } @Test - void coreBoundClassesReferenceNoAwsServiceCodeBeyondTheAllowlist() { - Set allowed = allowlist().keySet(); + void coreBoundClassesReferenceNoAwsServiceCode() { List violations = new ArrayList<>(); - for (Map.Entry> entry : scanCoreBound().entrySet()) { - for (SourceScanner.Finding finding : entry.getValue()) { - if (!allowed.contains(entry.getKey() + "\t" + finding.reference())) { - violations.add(SOURCES.resolve(sourceOf(entry.getKey())) + ":" + finding.line() - + ": " + finding.reference() + " (" + finding.rule() + ")"); - } - } - } + scanCoreBound().forEach((className, findings) -> findings.forEach(finding -> + violations.add(SOURCES.resolve(sourceOf(className)) + ":" + finding.line() + + ": " + finding.reference() + " (" + finding.rule() + ")"))); if (!violations.isEmpty()) { fail("Classes bound for floci-core reference AWS service code:\n " + String.join("\n ", violations) + "\n" - + "Move the dependency behind an interface the AWS service implements (an SPI, a " - + "hook, a neutral config key), or take the class off core-bound.txt if it does " - + "not belong in floci-core. " + ALLOWLIST + " only records references that " - + "predate this guard and must not grow."); + + "Give the class a seam instead (a hook, a contributor, a neutral config key or " + + "an interface the AWS service implements), or take it off core-bound.txt if it " + + "does not belong in floci-core."); } } - @Test - void everyAllowlistEntryStillOccurs() { - Map> found = new LinkedHashMap<>(); - scanCoreBound().forEach((className, findings) -> found.put(className, - findings.stream().map(SourceScanner.Finding::reference).collect(Collectors.toSet()))); - List stale = new ArrayList<>(); - allowlist().forEach((key, line) -> { - String[] parts = key.split("\t", 2); - if (!found.getOrDefault(parts[0], Set.of()).contains(parts[1])) { - stale.add(ALLOWLIST + ":" + line + ": " + parts[0] + " -> " + parts[1]); - } - }); - assertTrue(stale.isEmpty(), "Stale allowlist entries: the reference no longer occurs in a " - + "core-bound class. Remove them:\n " + String.join("\n ", stale)); - } - - @Test - void allowlistIsEmptyOnceTheBoundaryIsEnforced() { - Map entries = allowlist(); - assertTrue(entries.isEmpty(), "The core boundary is enforced, so " + ALLOWLIST - + " must be empty, but it lists " + entries.size() + " references:\n " - + entries.entrySet().stream() - .map(entry -> ALLOWLIST + ":" + entry.getValue() + ": " + entry.getKey().replace("\t", " -> ")) - .collect(Collectors.joining("\n "))); - } - @Test void serviceConfigAccessorsAreReadFromEmulatorConfig() { SourceScanner scanner = SourceScanner.fromEmulatorConfig(readString(EMULATOR_CONFIG)); @@ -325,26 +283,6 @@ class CoreBoundImportGuardTest { return classes; } - /** {@code classreference} to its line number in the allowlist file. */ - private static Map allowlist() { - Map entries = new LinkedHashMap<>(); - List lines = read(ALLOWLIST); - for (int i = 0; i < lines.size(); i++) { - String line = lines.get(i); - if (line.isBlank() || line.startsWith("#")) { - continue; - } - String[] parts = line.split("\t"); - if (parts.length != 2 || parts[0].isBlank() || parts[1].isBlank()) { - fail(ALLOWLIST + ":" + (i + 1) + ": expected classreference, got: " + line); - } - if (entries.put(line, i + 1) != null) { - fail(ALLOWLIST + ":" + (i + 1) + ": duplicate entry: " + line); - } - } - return entries; - } - private static Path sourceOf(String className) { return Path.of(className.replace('.', '/') + ".java"); } diff --git a/src/test/resources/core-boundary/allowlist.tsv b/src/test/resources/core-boundary/allowlist.tsv deleted file mode 100644 index 784707c26e..0000000000 --- a/src/test/resources/core-boundary/allowlist.tsv +++ /dev/null @@ -1 +0,0 @@ -# class reference