test(core): drop the core boundary allowlist now that the boundary is enforced (#10195)

Now that the core boundary allowlist must stay empty, the allowlist file, its stale-entry test and the allowlist lookup can no longer change any outcome. Drop them and rename the check to coreBoundClassesReferenceNoAwsServiceCode; its failure message now points at giving the class a seam, or taking it off core-bound.txt.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-12-04 19:58:38 -04:00
1 parent de0b1dc485
commit 1bff6ec758
2 files changed
+10 -73

No files matched your search

@@ -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.</li>
* </ul>
*
* <p>Comments are ignored. The references that predate this guard are recorded in
* {@code src/test/resources/core-boundary/allowlist.tsv}, one {@code class<TAB>reference} 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.
* <p>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.
*
* <p>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.
*
* <p><b>Enforced.</b> 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<String> allowed = allowlist().keySet();
void coreBoundClassesReferenceNoAwsServiceCode() {
List<String> violations = new ArrayList<>();
for (Map.Entry<String, List<SourceScanner.Finding>> 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<String, Set<String>> found = new LinkedHashMap<>();
scanCoreBound().forEach((className, findings) -> found.put(className,
findings.stream().map(SourceScanner.Finding::reference).collect(Collectors.toSet())));
List<String> 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<String, Integer> 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 class<TAB>reference} to its line number in the allowlist file. */
private static Map<String, Integer> allowlist() {
Map<String, Integer> entries = new LinkedHashMap<>();
List<String> 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 class<TAB>reference, 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");
}
@@ -1 +0,0 @@
# class reference
1 # class reference