Merge remote-tracking branch 'origin/claude/r8-f2-arch-rules-60140e' into claude/integration-r8-a4196a

This commit is contained in:
DongHyeonka
2026-11-07 01:40:39 +09:00
15 changed files with 673 additions and 91 deletions
@@ -459,43 +459,70 @@ class ApplicationBoundaryArchitectureTest {
};
/**
* What makes a class a way in for a user request: a user-transport adapter package or the
* framework types an endpoint is built from. {@code org.springframework.messaging} is named only
* for STOMP ({@code simp}, {@code @MessageMapping}): a broker listener's {@code @Payload} and
* {@code @Header} live beside them and are a system consumer's, not a user's.
* The framework packages user-transport endpoints are built from, each with its subpackages.
* {@code org.springframework.messaging} is named only for STOMP ({@code simp}, {@code
* MessageMapping} in {@link #USER_TRANSPORT_TYPE_NAMES}): a broker listener's {@code @Payload}
* and {@code @Header} live beside them and are a system consumer's, not a user's.
*
* <p>The framework half is a list, unlike the package allowlist above: a transport library
* missing from it is not recognised as one. A service that brings in a new transport library adds
* its packages here (review 2026-11-04 RR3-01-02).
* <p>This is a list, unlike the package allowlist above: a transport library missing from it is
* not recognised as one. A service that brings in a new transport library adds its packages here
* (review 2026-11-04 RR3-01-02).
*/
static final List<String> USER_TRANSPORT_FRAMEWORK_PACKAGES =
List.of(
"org.springframework.web",
"org.springframework.graphql",
"org.springframework.messaging.simp",
"io.grpc",
"jakarta.servlet",
"jakarta.websocket",
"jakarta.ws.rs",
"graphql");
/** The single user-transport types named beside the framework packages. */
static final Set<String> USER_TRANSPORT_TYPE_NAMES =
Set.of(
"org.springframework.stereotype.Controller",
"org.springframework.messaging.handler.annotation.MessageMapping");
/**
* What makes a class a way in for a user request: a user-transport adapter package, or the
* framework types an endpoint is built from ({@link #USER_TRANSPORT_FRAMEWORK_PACKAGES}, {@link
* #USER_TRANSPORT_TYPE_NAMES}).
*/
private static final DescribedPredicate<JavaClass> ARE_USER_TRANSPORT_TYPES =
JavaClass.Predicates.resideInAnyPackage(
"..adapter.inbound.web..",
"..adapter.inbound.graphql..",
"..adapter.inbound.grpc..",
"..adapter.inbound.websocket..",
"org.springframework.web..",
"org.springframework.graphql..",
"org.springframework.messaging.simp..",
"io.grpc..",
"jakarta.servlet..",
"jakarta.websocket..",
"jakarta.ws.rs..",
"graphql..")
"..adapter.inbound.websocket..")
.or(
com.tngtech.archunit.core.domain.properties.HasName.Predicates.name(
"org.springframework.stereotype.Controller"))
.or(
com.tngtech.archunit.core.domain.properties.HasName.Predicates.name(
"org.springframework.messaging.handler.annotation.MessageMapping"))
JavaClass.Predicates.resideInAnyPackage(
withSubpackages(USER_TRANSPORT_FRAMEWORK_PACKAGES)))
.or(namedAnyOf("user-transport annotations", USER_TRANSPORT_TYPE_NAMES))
.as("user-transport types (web, JAX-RS, GraphQL, gRPC, WebSocket/STOMP endpoints)");
/** Spring's configuration stereotype, which {@code @AutoConfiguration} carries as well. */
private static final String CONFIGURATION =
"org.springframework.context.annotation.Configuration";
/**
* The packages, with their subpackages, of the framework types request-handling code is written
* against or registered with. {@link #ARE_REQUEST_HANDLER_TYPES} names them.
*/
static final List<String> REQUEST_HANDLER_PACKAGES =
List.of(
"org.springframework.web.bind.annotation",
"org.springframework.web.servlet.function",
"org.springframework.web.reactive.function.server",
"org.springframework.web.socket.handler",
"org.springframework.graphql.data.method.annotation",
"org.springframework.graphql.server",
"jakarta.servlet.http",
"graphql.schema");
/** The single request-handler types {@code ARE_REQUEST_HANDLER_TYPES} names beside packages. */
private static final Set<String> REQUEST_HANDLER_TYPE_NAMES =
static final Set<String> REQUEST_HANDLER_TYPE_NAMES =
Set.of(
"org.springframework.stereotype.Controller",
"org.springframework.messaging.handler.annotation.MessageMapping",
@@ -519,74 +546,134 @@ class ApplicationBoundaryArchitectureTest {
"io.grpc.stub.StreamObserver");
/**
* The framework types request-handling code is written against: an annotated controller, a
* functional route or handler function, a servlet, filter or handler interceptor, a WebSocket
* handler, a GraphQL data fetcher, runtime wiring or request interceptor, a gRPC service, call
* handler or server interceptor. A configuration names one only when request-handling code is in
* it — a route or data fetcher written as a lambda compiles into a method of the configuration
* itself — and then the configuration is an endpoint (review 2026-11-05 RR6-01-01). The types a
* configuration names to set a transport up — {@code WebMvcConfigurer}, {@code CorsRegistry}, the
* controller beans it builds — are not here (RR4-01-02).
* The framework types request-handling code is written against or registered with: an annotated
* controller, a functional route or handler function, a servlet, filter or handler interceptor, a
* WebSocket handler, a GraphQL data fetcher, runtime wiring or request interceptor, a gRPC
* service, call handler or server interceptor. A configuration that names one holds or registers
* request-handling code, and then the configuration is an endpoint: a route or data fetcher
* written as a lambda compiles into a method of the configuration itself (review 2026-11-05
* RR6-01-01), and a route registered by method reference names the same route builder although
* its handling code is in another class (review 2026-11-06 RR7-01-02). Class dependencies cannot
* tell that registration from handling code, so routes are registered in a configuration apart
* from the one that builds a system caller. The types a configuration names to set a transport up
* — {@link #ARE_TRANSPORT_SETUP_TYPES}, the controller beans it builds — do not count
* (RR4-01-02).
*
* <p>Like the type list above, this is a list: a request-handler type missing from it is not
* recognised in a configuration (manual 07 「규칙이 못 보는 길」).
* <p>Only a configuration itself is read with this list; a class nested in one is read with the
* wider user-transport list (RR7-01-01). Like that list, this one is a list: a request-handler
* type missing from it is not recognised in a configuration (manual 07 「규칙이 못 보는 길」). Every entry
* is a user-transport type too, so an endpoint moved from a configuration into a class nested in
* it is still caught ({@code UserTransportTypeListsTest}).
*/
private static final DescribedPredicate<JavaClass> ARE_REQUEST_HANDLER_TYPES =
JavaClass.Predicates.resideInAnyPackage(
"org.springframework.web.bind.annotation..",
"org.springframework.web.servlet.function..",
"org.springframework.web.reactive.function.server..",
"org.springframework.web.socket.handler..",
"org.springframework.graphql.data.method.annotation..",
"org.springframework.graphql.server..",
"jakarta.servlet.http..",
"graphql.schema..")
.or(
DescribedPredicate.describe(
"request-handler interfaces",
type -> REQUEST_HANDLER_TYPE_NAMES.contains(type.getName())))
JavaClass.Predicates.resideInAnyPackage(withSubpackages(REQUEST_HANDLER_PACKAGES))
.or(namedAnyOf("request-handler interfaces", REQUEST_HANDLER_TYPE_NAMES))
.as("request-handler types (controllers, routes, servlets, filters, interceptors, ...)");
/**
* The packages, with their subpackages, of the types a configuration names to set a transport up
* rather than to handle a request: Spring MVC's, WebFlux's and WebSocket's configurers and
* registries, the STOMP broker registry, and CORS settings. Their code runs while the application
* starts. A class that implements one of them for a request — a CORS source, a CORS processor —
* takes the request as a parameter, and that type counts.
*/
static final List<String> TRANSPORT_SETUP_PACKAGES =
List.of(
"org.springframework.web.servlet.config.annotation",
"org.springframework.web.reactive.config",
"org.springframework.web.socket.config.annotation",
"org.springframework.messaging.simp.config",
"org.springframework.web.cors");
/**
* The single setup types: the HTTP method values a CORS mapping lists, which live among the
* controller annotations (review 2026-11-06 RR7-01-02).
*/
static final Set<String> TRANSPORT_SETUP_TYPE_NAMES =
Set.of("org.springframework.web.bind.annotation.RequestMethod");
/**
* The types a configuration names to set a transport up: they make neither a configuration nor a
* class nested in one a way in. An anonymous {@code WebMvcConfigurer} that reads the
* configuration's field is part of the configuration (review 2026-11-05 RR6-01-02).
*
* <p>A setup type missing from here fails the build: the configurer naming it is read as a
* transport. A request-handler type added here would hide an endpoint instead, so no entry may
* cover one ({@code UserTransportTypeListsTest}).
*/
private static final DescribedPredicate<JavaClass> ARE_TRANSPORT_SETUP_TYPES =
JavaClass.Predicates.resideInAnyPackage(withSubpackages(TRANSPORT_SETUP_PACKAGES))
.or(namedAnyOf("transport setup values", TRANSPORT_SETUP_TYPE_NAMES))
.as("transport setup types (configurers, registries, CORS settings)");
/** What makes a configuration a way in: a request-handler type that is no setup type. */
private static final DescribedPredicate<JavaClass> MAKE_A_CONFIGURATION_A_WAY_IN =
ARE_REQUEST_HANDLER_TYPES.and(DescribedPredicate.not(ARE_TRANSPORT_SETUP_TYPES));
/** What makes a class nested in a configuration a way in: any user-transport type but setup. */
private static final DescribedPredicate<JavaClass> MAKE_A_NESTED_CLASS_A_WAY_IN =
ARE_USER_TRANSPORT_TYPES.and(DescribedPredicate.not(ARE_TRANSPORT_SETUP_TYPES));
/**
* A class a user request comes in through: it lives in a user-transport package; or it is a
* configuration, or nested in one, that is built from a request-handler type; or it is any other
* class built from a user-transport type.
* configuration built from a request-handler type; or it is nested in a configuration and built
* from a user-transport type other than a setup type; or it is any other class built from a
* user-transport type.
*
* <p>A configuration is the composition root, and naming a web type does not make it a way in: a
* feature's configuration registers its message handler beside a {@code WebMvcConfigurer} or its
* controller without any request passing through it (review 2026-11-04 RR4-01-02). A controller
* it builds is checked itself, by its package or its own transport types. What does make it a way
* in is request-handling code written in it: a functional route or a data fetcher is a lambda,
* compiled into the configuration's own method, so the configuration that holds one is the
* endpoint (review 2026-11-05 RR6-01-01). A class nested in a configuration — an anonymous {@code
* WebMvcConfigurer} reading the configuration's field — is read the same way, request handlers
* nested there included (RR6-01-02).
* in is request-handling code it holds or registers: a functional route or a data fetcher written
* as a lambda compiles into the configuration's own method (review 2026-11-05 RR6-01-01), and a
* route registered by method reference names the route builder (review 2026-11-06 RR7-01-02).
*
* <p>A class nested in a configuration is read like any other class, with the full user-transport
* list, so an endpoint of any transport library kept there is caught — a JAX-RS resource or an
* annotated JSR-356 endpoint as much as a handler function — and so is one that runs the job
* through the configuration that holds it (review 2026-11-06 RR7-01-01). Only setup types are
* left out: an anonymous {@code WebMvcConfigurer} reading the configuration's field is part of
* the configuration (RR6-01-02).
*/
private static final DescribedPredicate<JavaClass> ARE_USER_TRANSPORTS =
new DescribedPredicate<>(
"are user transports (in a user-transport package, a configuration with request-handling"
+ " code, or another class built from a user-transport type)") {
"are user transports (in a user-transport package, a configuration that holds or registers"
+ " request-handling code, or another class built from a user-transport type)") {
@Override
public boolean test(JavaClass candidate) {
if (ARE_USER_TRANSPORT_TYPES.test(candidate)) {
return true;
}
DescribedPredicate<JavaClass> wayIn =
isOrIsNestedInAConfiguration(candidate)
? ARE_REQUEST_HANDLER_TYPES
: ARE_USER_TRANSPORT_TYPES;
DescribedPredicate<JavaClass> wayIn = waysInFor(candidate);
return candidate.getDirectDependenciesFromSelf().stream()
.anyMatch(dependency -> wayIn.test(dependency.getTargetClass()));
}
};
private static boolean isOrIsNestedInAConfiguration(JavaClass candidate) {
for (JavaClass type = candidate; type != null; type = type.getEnclosingClass().orElse(null)) {
if (type.isAnnotatedWith(CONFIGURATION) || type.isMetaAnnotatedWith(CONFIGURATION)) {
return true;
private static DescribedPredicate<JavaClass> waysInFor(JavaClass candidate) {
if (isAConfiguration(candidate)) {
return MAKE_A_CONFIGURATION_A_WAY_IN;
}
for (JavaClass type = candidate.getEnclosingClass().orElse(null);
type != null;
type = type.getEnclosingClass().orElse(null)) {
if (isAConfiguration(type)) {
return MAKE_A_NESTED_CLASS_A_WAY_IN;
}
}
return false;
return ARE_USER_TRANSPORT_TYPES;
}
private static boolean isAConfiguration(JavaClass type) {
return type.isAnnotatedWith(CONFIGURATION) || type.isMetaAnnotatedWith(CONFIGURATION);
}
private static String[] withSubpackages(List<String> packages) {
return packages.stream().map(name -> name + "..").toArray(String[]::new);
}
private static DescribedPredicate<JavaClass> namedAnyOf(String description, Set<String> names) {
return DescribedPredicate.describe(description, type -> names.contains(type.getName()));
}
/**
@@ -692,16 +779,17 @@ class ApplicationBoundaryArchitectureTest {
* no permission guards (review 2026-11-04 RR3-01-01). Reaching the job's own interface, or any
* project type the job extends or implements, counts as reaching the job: that is the type the
* endpoint is handed when it injects by interface (RR4-01-01). A configuration may register the
* handler beside web beans (RR4-01-02), but not beside request-handling code of its own, such as
* a functional route (RR6-01-01).
* handler beside web beans (RR4-01-02), but not beside request-handling code it holds or
* registers, such as a functional route, whether written as a lambda (RR6-01-01) or a method
* reference (review 2026-11-06 RR7-01-02).
*
* <p>It reads class dependencies, so it sees every typed path, including {@code
* ObjectProvider<TheJob>} and {@code getBean(TheJob.class)}: both name the type. It cannot see a
* path that names no type the job is handed as — a lookup by bean name or by {@code Object}, or a
* configuration that passes a user transport a function wrapping the job ({@code job::run} as a
* {@code Runnable}) — nor request-handling code in a configuration written against a type {@code
* ARE_REQUEST_HANDLER_TYPES} does not list. Manual 07 「시스템이 부르는 쓰기」 lists those paths and what
* holds them.
* {@code Runnable}) — nor request-handling code in a configuration itself written against a type
* {@code ARE_REQUEST_HANDLER_TYPES} does not list. Manual 07 「시스템이 부르는 쓰기」 lists those paths and
* what holds them.
*/
@ArchTest
static final ArchRule USER_TRANSPORTS_DO_NOT_REACH_SYSTEM_CALLERS =
@@ -711,13 +799,16 @@ class ApplicationBoundaryArchitectureTest {
.transitivelyDependOnClassesThat(ARE_TYPES_A_SYSTEM_CALLER_IS_HANDED_AS)
.as(
"USER_TRANSPORTS_DO_NOT_REACH_SYSTEM_CALLERS: a class a user request comes in "
+ "through (a user-transport package; a configuration, or a class nested in one, "
+ "with request-handling code such as a functional route or a data fetcher; any "
+ "other class built from a web, JAX-RS, GraphQL, gRPC or WebSocket type) does "
+ "not reach a @SystemCaller or a "
+ "through (a user-transport package; a configuration that holds or registers "
+ "request-handling code such as a functional route, a data fetcher or an "
+ "interceptor; a class nested in a configuration built from a web, JAX-RS, "
+ "GraphQL, gRPC or WebSocket type other than a setup type such as "
+ "WebMvcConfigurer; any other class built from one of those types) does not "
+ "reach a @SystemCaller or a "
+ "project type one extends or implements, directly or through other classes — "
+ "the system caller runs a @SystemInvoked write with no permission check. A "
+ "user-triggered run of the same work is its own use case with "
+ "the system caller runs a @SystemInvoked write with no permission check. "
+ "Register routes in a configuration apart from the one that builds the system "
+ "caller. A user-triggered run of the same work is its own use case with "
+ "@RequiresPermission (manual 07 「시스템이 부르는 쓰기」)")
.allowEmptyShould(true);
@@ -13,7 +13,11 @@ import dev.caskeleton.bootstrap.architecture.allowed.adapter.inbound.messaging.S
import dev.caskeleton.bootstrap.architecture.allowed.adapter.inbound.messaging.SystemCallerWithNestedValueTypesFixture;
import dev.caskeleton.bootstrap.architecture.allowed.adapter.inbound.web.PingControllerFixture;
import dev.caskeleton.bootstrap.architecture.allowed.application.CleanProjectionQueryPort;
import dev.caskeleton.bootstrap.architecture.allowed.configuration.OrderHandlerFixture;
import dev.caskeleton.bootstrap.architecture.allowed.configuration.OrderRoutesConfigurationFixture;
import dev.caskeleton.bootstrap.architecture.allowed.configuration.SystemCallerBesideControllerRegistrationFixture;
import dev.caskeleton.bootstrap.architecture.allowed.configuration.SystemCallerBesideCorsMappingFixture;
import dev.caskeleton.bootstrap.architecture.allowed.configuration.SystemCallerBesideCorsSourceFixture;
import dev.caskeleton.bootstrap.architecture.allowed.configuration.SystemCallerBesideFieldReadingWebMvcConfigurerFixture;
import dev.caskeleton.bootstrap.architecture.allowed.configuration.SystemCallerBesideWebMvcRegistrationFixture;
import dev.caskeleton.bootstrap.architecture.fixtures.application.RootWriteTransactionBoundaryUseCase;
@@ -44,6 +48,7 @@ import dev.caskeleton.bootstrap.architecture.violations.application.OutboundWith
import dev.caskeleton.bootstrap.architecture.violations.application.RawLeakQueryPort;
import dev.caskeleton.bootstrap.architecture.violations.application.ReadOnlyRepositoryWriteUseCase;
import dev.caskeleton.bootstrap.architecture.violations.application.SystemInvokedFixtureUseCase;
import dev.caskeleton.bootstrap.architecture.violations.configuration.RoutesBesideASystemCallerConfigurationFixture;
import dev.caskeleton.bootstrap.architecture.violations.configuration.RunNowHandlerFunctionConfigurationFixture;
import dev.caskeleton.bootstrap.architecture.violations.configuration.RunNowRouteConfigurationFixture;
import dev.caskeleton.bootstrap.architecture.violations.domain.AnnotatedPublicNoArgValueObjectFixture;
@@ -322,9 +327,8 @@ class ArchitectureViolationFixtureTest {
"dev.caskeleton.bootstrap.architecture.violations.configuration.graphqljava",
"dev.caskeleton.bootstrap.architecture.allowed.adapter.inbound.messaging");
// RR6-01-02: a class nested in a configuration is read as the configuration is — a request
// handler
// nested there is still a transport, a configurer reading the configuration's field is not.
// RR6-01-02: a request handler nested in a configuration is still a transport; a configurer
// reading the configuration's field names only setup types and is not.
private static final JavaClasses HANDLER_FUNCTION_NESTED_IN_A_CONFIGURATION_FIXTURE_ONLY =
new ClassFileImporter()
.importClasses(
@@ -345,6 +349,63 @@ class ArchitectureViolationFixtureTest {
SystemCallerBesideFieldReadingWebMvcConfigurerFixture.class,
SystemCallerHandlerFixture.class));
// Review 2026-11-06 RR7-01-01: endpoints a configuration keeps nested in it, built from types the
// request-handler list does not name — a JAX-RS resource, one that runs the job through its
// configuration, an annotated JSR-356 endpoint. importPackages, so the compile-only JAX-RS and
// WebSocket types are never linked.
private static final String NESTED_JAXRS_FIXTURES =
"dev.caskeleton.bootstrap.architecture.violations.configuration.jaxrs";
private static final JavaClasses JAXRS_RESOURCES_IN_A_CONFIGURATION_FIXTURE_ONLY =
new ClassFileImporter()
.importPackages(
NESTED_JAXRS_FIXTURES,
"dev.caskeleton.bootstrap.architecture.allowed.adapter.inbound.messaging");
private static final JavaClasses SERVER_ENDPOINT_IN_A_CONFIGURATION_FIXTURE_ONLY =
new ClassFileImporter()
.importPackages(
"dev.caskeleton.bootstrap.architecture.violations.configuration.jsr356",
"dev.caskeleton.bootstrap.architecture.allowed.adapter.inbound.messaging");
// RR7-01-02: routes registered by method reference make their configuration an endpoint, so the
// configuration that also builds a system caller is caught and the same routes in a configuration
// of their own pass. A CORS setup naming RequestMethod is setup, in the configuration and in its
// configurer alike.
private static final JavaClasses ROUTES_BESIDE_A_SYSTEM_CALLER_FIXTURE_ONLY =
new ClassFileImporter()
.importClasses(
RoutesBesideASystemCallerConfigurationFixture.class,
OrderHandlerFixture.class,
SystemCallerHandlerFixture.class,
SystemInvokedFixtureUseCase.class);
private static final JavaClasses ROUTES_APART_FROM_A_SYSTEM_CALLER_FIXTURE_ONLY =
new ClassFileImporter()
.importClasses(
OrderRoutesConfigurationFixture.class,
OrderHandlerFixture.class,
SystemCallerHandlerRegistrationFixture.class,
SystemCallerHandlerFixture.class,
SystemInvokedFixtureUseCase.class);
private static final JavaClasses CORS_SOURCE_BESIDE_A_SYSTEM_CALLER_FIXTURE_ONLY =
new ClassFileImporter()
.importClasses(
SystemCallerBesideCorsSourceFixture.class,
SystemCallerHandlerFixture.class,
SystemInvokedFixtureUseCase.class);
// The anonymous configurer has no class literal, as above.
private static final JavaClasses CORS_MAPPING_BESIDE_A_SYSTEM_CALLER_FIXTURE_ONLY =
new ClassFileImporter()
.importPackages(
"dev.caskeleton.bootstrap.architecture.allowed.configuration",
"dev.caskeleton.bootstrap.architecture.allowed.adapter.inbound.messaging")
.that(
JavaClass.Predicates.belongToAnyOf(
SystemCallerBesideCorsMappingFixture.class, SystemCallerHandlerFixture.class));
// RR6-01-03: a system caller's nested record, enum and exception, and a system caller that is a
// record — none of them a type an endpoint injects it as.
private static final JavaClasses SYSTEM_CALLER_WITH_NESTED_VALUE_TYPES_FIXTURE_ONLY =
@@ -626,6 +687,112 @@ class ArchitectureViolationFixtureTest {
assertThat(result.getFailureReport().getDetails()).isEmpty();
}
@Test
void aJaxRsResourceNestedInAConfigurationThatCallsASystemCallerIsCaught() {
// when
EvaluationResult result =
ApplicationBoundaryArchitectureTest.USER_TRANSPORTS_DO_NOT_REACH_SYSTEM_CALLERS.evaluate(
JAXRS_RESOURCES_IN_A_CONFIGURATION_FIXTURE_ONLY);
// then
assertThat(result.getFailureReport().getDetails())
.anySatisfy(
detail ->
assertThat(detail)
.contains(
"<"
+ NESTED_JAXRS_FIXTURES
+ ".RunNowResourceConfigurationFixture$RunNowResource>")
.contains(SystemCallerHandlerFixture.class.getName()));
}
@Test
void aNestedEndpointThatRunsASystemCallerThroughItsConfigurationIsCaught() {
// when
EvaluationResult result =
ApplicationBoundaryArchitectureTest.USER_TRANSPORTS_DO_NOT_REACH_SYSTEM_CALLERS.evaluate(
JAXRS_RESOURCES_IN_A_CONFIGURATION_FIXTURE_ONLY);
// then
assertThat(result.getFailureReport().getDetails())
.anySatisfy(
detail ->
assertThat(detail)
.contains(
"<"
+ NESTED_JAXRS_FIXTURES
+ ".RunNowThroughTheConfigurationFixture$RunNowResource>")
.contains(SystemCallerHandlerFixture.class.getName()));
}
@Test
void anAnnotatedWebSocketEndpointNestedInAConfigurationThatCallsASystemCallerIsCaught() {
// when
EvaluationResult result =
ApplicationBoundaryArchitectureTest.USER_TRANSPORTS_DO_NOT_REACH_SYSTEM_CALLERS.evaluate(
SERVER_ENDPOINT_IN_A_CONFIGURATION_FIXTURE_ONLY);
// then
assertThat(result.getFailureReport().getDetails())
.anySatisfy(
detail ->
assertThat(detail)
.contains(
"<dev.caskeleton.bootstrap.architecture.violations.configuration.jsr356"
+ ".RunNowEndpointConfigurationFixture$RunNowEndpoint>")
.contains(SystemCallerHandlerFixture.class.getName()));
}
@Test
void aConfigurationThatRegistersMethodReferenceRoutesBesideASystemCallerIsCaught() {
// when
EvaluationResult result =
ApplicationBoundaryArchitectureTest.USER_TRANSPORTS_DO_NOT_REACH_SYSTEM_CALLERS.evaluate(
ROUTES_BESIDE_A_SYSTEM_CALLER_FIXTURE_ONLY);
// then
assertThat(result.getFailureReport().getDetails())
.anySatisfy(
detail ->
assertThat(detail)
.contains(
"<" + RoutesBesideASystemCallerConfigurationFixture.class.getName() + ">")
.contains(SystemCallerHandlerFixture.class.getName()));
}
@Test
void routesRegisteredApartFromTheSystemCallersConfigurationPass() {
// when
EvaluationResult result =
ApplicationBoundaryArchitectureTest.USER_TRANSPORTS_DO_NOT_REACH_SYSTEM_CALLERS.evaluate(
ROUTES_APART_FROM_A_SYSTEM_CALLER_FIXTURE_ONLY);
// then
assertThat(result.getFailureReport().getDetails()).isEmpty();
}
@Test
void aConfigurationNamingRequestMethodForCorsMayRegisterASystemCaller() {
// when
EvaluationResult result =
ApplicationBoundaryArchitectureTest.USER_TRANSPORTS_DO_NOT_REACH_SYSTEM_CALLERS.evaluate(
CORS_SOURCE_BESIDE_A_SYSTEM_CALLER_FIXTURE_ONLY);
// then
assertThat(result.getFailureReport().getDetails()).isEmpty();
}
@Test
void aCorsConfigurerNestedInAConfigurationMayNameRequestMethodAndReadTheConfigurationsField() {
// when
EvaluationResult result =
ApplicationBoundaryArchitectureTest.USER_TRANSPORTS_DO_NOT_REACH_SYSTEM_CALLERS.evaluate(
CORS_MAPPING_BESIDE_A_SYSTEM_CALLER_FIXTURE_ONLY);
// then
assertThat(result.getFailureReport().getDetails()).isEmpty();
}
@Test
void aSystemCallersNestedRecordEnumAndExceptionPassTheSupertypeRule() {
// when
@@ -0,0 +1,81 @@
package dev.caskeleton.bootstrap.architecture;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
/**
* The three type lists {@code USER_TRANSPORTS_DO_NOT_REACH_SYSTEM_CALLERS} reads a class with stay
* in the shape that keeps the rule closed.
*
* <p>A configuration is read with the request-handler list, a class nested in one with the full
* user-transport list, and both leave out setup types. The two lists drifted apart once: the
* request-handler list named no JAX-RS type, and while nested classes were read with it, a JAX-RS
* resource kept in a configuration passed (review 2026-11-06 RR7-01-01). So every request-handler
* entry has to be a user-transport type too — then moving an endpoint from a configuration into a
* class nested in it cannot hide it — and no setup entry may cover a request-handler type, or it
* would hide that endpoint in both places.
*/
class UserTransportTypeListsTest {
@Test
void everyRequestHandlerAndSetupEntryIsAUserTransportType() {
// given
List<String> entries =
Stream.<Collection<String>>of(
ApplicationBoundaryArchitectureTest.REQUEST_HANDLER_PACKAGES,
ApplicationBoundaryArchitectureTest.REQUEST_HANDLER_TYPE_NAMES,
ApplicationBoundaryArchitectureTest.TRANSPORT_SETUP_PACKAGES,
ApplicationBoundaryArchitectureTest.TRANSPORT_SETUP_TYPE_NAMES)
.flatMap(Collection::stream)
.toList();
// when
List<String> outsideTheUserTransportTypes =
entries.stream()
.filter(
entry ->
!ApplicationBoundaryArchitectureTest.USER_TRANSPORT_TYPE_NAMES.contains(entry)
&& !isInAnyOf(
entry,
ApplicationBoundaryArchitectureTest.USER_TRANSPORT_FRAMEWORK_PACKAGES))
.toList();
// then
assertThat(outsideTheUserTransportTypes).isEmpty();
}
@Test
void noSetupEntryCoversARequestHandlerType() {
// given
List<String> setupPackages = ApplicationBoundaryArchitectureTest.TRANSPORT_SETUP_PACKAGES;
List<String> handlerPackages = ApplicationBoundaryArchitectureTest.REQUEST_HANDLER_PACKAGES;
// when
List<String> handlerNamesTreatedAsSetup =
ApplicationBoundaryArchitectureTest.REQUEST_HANDLER_TYPE_NAMES.stream()
.filter(
name ->
ApplicationBoundaryArchitectureTest.TRANSPORT_SETUP_TYPE_NAMES.contains(name)
|| isInAnyOf(name, setupPackages))
.toList();
List<String> overlappingPackages =
Stream.concat(
setupPackages.stream().filter(setup -> isInAnyOf(setup, handlerPackages)),
handlerPackages.stream().filter(handler -> isInAnyOf(handler, setupPackages)))
.toList();
// then
assertThat(handlerNamesTreatedAsSetup).isEmpty();
assertThat(overlappingPackages).isEmpty();
}
/** Whether a type or package name is one of the packages or inside one of them. */
private static boolean isInAnyOf(String name, List<String> packages) {
return packages.stream()
.anyMatch(container -> name.equals(container) || name.startsWith(container + "."));
}
}
@@ -0,0 +1,12 @@
package dev.caskeleton.bootstrap.architecture.allowed.configuration;
import org.springframework.web.servlet.function.ServerRequest;
import org.springframework.web.servlet.function.ServerResponse;
/** A feature's functional-endpoint handler, which reaches no system caller. */
public final class OrderHandlerFixture {
public ServerResponse list(ServerRequest request) {
return ServerResponse.ok().build();
}
}
@@ -0,0 +1,21 @@
package dev.caskeleton.bootstrap.architecture.allowed.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.function.RouterFunction;
import org.springframework.web.servlet.function.RouterFunctions;
import org.springframework.web.servlet.function.ServerResponse;
/**
* A feature's route registration in a configuration of its own, apart from the configuration that
* builds the feature's message handler ({@code SystemCallerHandlerRegistrationFixture}). This
* configuration is an endpoint, and it reaches no system caller (review 2026-11-06 RR7-01-02).
*/
@Configuration(proxyBeanMethods = false)
public class OrderRoutesConfigurationFixture {
@Bean
RouterFunction<ServerResponse> orderRoutes(OrderHandlerFixture orders) {
return RouterFunctions.route().GET("/orders", orders::list).build();
}
}
@@ -0,0 +1,42 @@
package dev.caskeleton.bootstrap.architecture.allowed.configuration;
import dev.caskeleton.bootstrap.architecture.allowed.adapter.inbound.messaging.SystemCallerHandlerFixture;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* One feature configuration: a CORS mapping that reads the configuration's own max age, and the
* feature's message handler. The anonymous configurer names only setup types — the configurer, the
* registry and {@code RequestMethod} — so it is part of the configuration, not a way in, although
* it reaches the handler through the field it reads (review 2026-11-06 RR7-01-02).
*/
@Configuration(proxyBeanMethods = false)
public class SystemCallerBesideCorsMappingFixture {
private final long corsMaxAgeSeconds;
public SystemCallerBesideCorsMappingFixture(long corsMaxAgeSeconds) {
this.corsMaxAgeSeconds = corsMaxAgeSeconds;
}
@Bean
WebMvcConfigurer featureCorsMapping() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry
.addMapping("/features/**")
.allowedMethods(RequestMethod.GET.name(), RequestMethod.HEAD.name())
.maxAge(corsMaxAgeSeconds);
}
};
}
@Bean
SystemCallerHandlerFixture systemCallerHandler() {
return new SystemCallerHandlerFixture();
}
}
@@ -0,0 +1,33 @@
package dev.caskeleton.bootstrap.architecture.allowed.configuration;
import dev.caskeleton.bootstrap.architecture.allowed.adapter.inbound.messaging.SystemCallerHandlerFixture;
import java.util.List;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.CorsConfigurationSource;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
/**
* One feature configuration: its CORS source and its message handler. The configuration names
* {@code RequestMethod} for the methods it allows. That enum lives among the controller annotations
* but is a setup value, not request-handling code (review 2026-11-06 RR7-01-02).
*/
@Configuration(proxyBeanMethods = false)
public class SystemCallerBesideCorsSourceFixture {
@Bean
CorsConfigurationSource featureCorsSource() {
CorsConfiguration cors = new CorsConfiguration();
cors.setAllowedMethods(List.of(RequestMethod.GET.name(), RequestMethod.HEAD.name()));
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/features/**", cors);
return source;
}
@Bean
SystemCallerHandlerFixture systemCallerHandler() {
return new SystemCallerHandlerFixture();
}
}
@@ -1,9 +1,10 @@
/**
* "Allowed-as-data" composition for {@code USER_TRANSPORTS_DO_NOT_REACH_SYSTEM_CALLERS}: a
* feature's configuration that registers its message handler beside its web beans — a {@code
* WebMvcConfigurer}, or the feature's controller. A configuration is the composition root, not a
* way a user request comes in, so naming a web type does not make it a user transport (review
* 2026-11-04 RR4-01-02). Manual 09 「소비」 step 4 registers the handler in "this leaf's configuration
* class", which is where both kinds of bean meet.
* WebMvcConfigurer}, a CORS setup, or the feature's controller. A configuration is the composition
* root, not a way a user request comes in, so naming a web type does not make it a user transport
* (review 2026-11-04 RR4-01-02); registering routes does, so the feature's routes sit in a
* configuration of their own (review 2026-11-06 RR7-01-02). Manual 09 「소비」 step 4 registers the
* handler in "this leaf's configuration class", which is where both kinds of bean meet.
*/
package dev.caskeleton.bootstrap.architecture.allowed.configuration;
@@ -0,0 +1,32 @@
package dev.caskeleton.bootstrap.architecture.violations.configuration;
import dev.caskeleton.bootstrap.architecture.allowed.adapter.inbound.messaging.SystemCallerHandlerFixture;
import dev.caskeleton.bootstrap.architecture.allowed.configuration.OrderHandlerFixture;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.function.RouterFunction;
import org.springframework.web.servlet.function.RouterFunctions;
import org.springframework.web.servlet.function.ServerResponse;
/**
* Negative fixture for {@code USER_TRANSPORTS_DO_NOT_REACH_SYSTEM_CALLERS}: one feature
* configuration registers its functional routes and builds its message handler. The handling code
* is in {@link OrderHandlerFixture}, referenced by method, so no request runs through this class.
* Registering the route still names the route builder, a request-handler type, and class
* dependencies cannot tell the registration from handling code: the configuration is read as an
* endpoint that reaches the handler. The routes go in a configuration of their own ({@code
* OrderRoutesConfigurationFixture}) (review 2026-11-06 RR7-01-02).
*/
@Configuration(proxyBeanMethods = false)
public class RoutesBesideASystemCallerConfigurationFixture {
@Bean
RouterFunction<ServerResponse> orderRoutes(OrderHandlerFixture orders) {
return RouterFunctions.route().GET("/orders", orders::list).build();
}
@Bean
SystemCallerHandlerFixture systemCallerHandler() {
return new SystemCallerHandlerFixture();
}
}
@@ -10,8 +10,9 @@ import org.springframework.web.servlet.function.ServerResponse;
/**
* Negative fixture for {@code USER_TRANSPORTS_DO_NOT_REACH_SYSTEM_CALLERS}: the configuration
* itself names no request-handler type, but the handler function it registers is a class nested in
* it. A class nested in a configuration is read as the configuration is, request handlers included,
* so the nested endpoint is still a user transport (review 2026-11-05 RR6-01-02).
* it. A class nested in a configuration is a user transport when it is built from a user-transport
* type other than a setup type, so the nested endpoint is caught (review 2026-11-05 RR6-01-02,
* 2026-11-06 RR7-01-01).
*/
@Configuration(proxyBeanMethods = false)
public class RunNowHandlerFunctionConfigurationFixture {
@@ -0,0 +1,33 @@
package dev.caskeleton.bootstrap.architecture.violations.configuration.jaxrs;
import dev.caskeleton.bootstrap.architecture.allowed.adapter.inbound.messaging.SystemCallerHandlerFixture;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import org.springframework.context.annotation.Configuration;
/**
* Negative fixture for {@code USER_TRANSPORTS_DO_NOT_REACH_SYSTEM_CALLERS}: a JAX-RS "run now"
* resource kept in the feature configuration. The request-handler list a configuration is read with
* names no JAX-RS type; a class nested in a configuration is read with the full user-transport
* list, so the resource is still a transport (review 2026-11-06 RR7-01-01). Loaded with {@code
* importPackages}: {@code jakarta.ws.rs-api} is compile-only here, so JUnit must never link it.
*/
@Configuration(proxyBeanMethods = false)
public class RunNowResourceConfigurationFixture {
/** The resource, kept beside the configuration. */
@Path("/admin/nightly/run-now")
public static final class RunNowResource {
private final SystemCallerHandlerFixture handler;
public RunNowResource(SystemCallerHandlerFixture handler) {
this.handler = handler;
}
@POST
public void runNow() {
handler.handle();
}
}
}
@@ -0,0 +1,34 @@
package dev.caskeleton.bootstrap.architecture.violations.configuration.jaxrs;
import dev.caskeleton.bootstrap.architecture.allowed.adapter.inbound.messaging.SystemCallerHandlerFixture;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import org.springframework.context.annotation.Configuration;
/**
* Negative fixture for {@code USER_TRANSPORTS_DO_NOT_REACH_SYSTEM_CALLERS}: a "run now" resource
* nested in the configuration that holds the system caller. The resource never names the caller; it
* asks the configuration to run it. The path through the enclosing configuration is followed like
* any other, so the resource is caught — which is why a configurer reading the configuration's
* field is let through by its setup types, not by skipping that path (review 2026-11-06 RR7-01-01).
* Loaded with {@code importPackages}: {@code jakarta.ws.rs-api} is compile-only here.
*/
@Configuration(proxyBeanMethods = false)
public class RunNowThroughTheConfigurationFixture {
private final SystemCallerHandlerFixture handler = new SystemCallerHandlerFixture();
void runNightly() {
handler.handle();
}
/** The resource, an inner class that runs the job through its configuration. */
@Path("/admin/nightly/run-now")
public final class RunNowResource {
@POST
public void runNow() {
runNightly();
}
}
}
@@ -0,0 +1,29 @@
package dev.caskeleton.bootstrap.architecture.violations.configuration.jsr356;
import dev.caskeleton.bootstrap.architecture.allowed.adapter.inbound.messaging.SystemCallerHandlerFixture;
import jakarta.websocket.OnMessage;
import jakarta.websocket.server.ServerEndpoint;
import org.springframework.context.annotation.Configuration;
/**
* Negative fixture for {@code USER_TRANSPORTS_DO_NOT_REACH_SYSTEM_CALLERS}: an annotated JSR-356
* "run now" endpoint kept in the feature configuration. Like the JAX-RS resource beside it, it is
* built from types only the full user-transport list names (review 2026-11-06 RR7-01-01). Loaded
* with {@code importPackages}: {@code jakarta.websocket-api} is compile-only here.
*/
@Configuration(proxyBeanMethods = false)
public class RunNowEndpointConfigurationFixture {
/** The endpoint, kept beside the configuration. */
@ServerEndpoint("/admin/nightly/run-now")
public static final class RunNowEndpoint {
private final SystemCallerHandlerFixture handler = new SystemCallerHandlerFixture();
@OnMessage
public String onMessage(String message) {
handler.handle();
return message;
}
}
}