Files
clean-architecture-backend-…/build-logic/src/test/java/dev/caskeleton/buildlogic/architecture/CleanArchitectureResolvedClasspathFunctionalTest.java
T
DongHyeonka 6a792b8144 refactor(layout)!: 옮긴 경로를 부르는 곳을 모두 새 배치에 맞춘다
문제: 앞 커밋이 Gradle 루트를 저장소 루트로 옮기고 계층 폴더를 묶었다.
빌드 스크립트·build-logic·시험·workflow·스크립트·문서가 아직 옛 배치
(Gradle 루트 = src/)를 가정해 빌드가 되지 않는다.

고른 방법:
- Gradle 경로와 registry id는 그대로 둔다(:app-bootstrap, :application-core,
  :composition:*). registry의 source_path만 새 폴더를 가리킨다. 폴더에 맞춘
  이름(:domain:core, :application:core)은 프로젝트 이름 core가 둘이 되어
  boot jar의 BOOT-INF/lib와 기본 capability가 겹치고, 파생 서비스의 모든
  project(':…') 줄을 바꾸게 한다.
- registry는 gradle/modules.json, 시험 이미지 목록은
  gradle/container-images.properties: 버전 카탈로그 옆, 빌드가 고정하는 것.
  config/는 코드 검사 도구 설정만 둔다.
- build-logic: settings·architecture 플러그인의 저장소 루트를 Gradle 루트로
  (getParentFile 제거). config contract의 파일 트리는 src/만 훑는다(루트를
  훑으면 docs·.claude/worktrees까지 줍는다).
- 빌드 스크립트: rootProject.projectDir.parentFile → rootProject.projectDir,
  rootProject.file('../…') → rootProject.file('…'), 옛 src 기준 include에
  src/를 붙인다. notification API surface의 application-notification 소스
  루트를 새 폴더로(놓치면 272개 타입이 surface에서 말없이 빠진다).
- 시험: 옛 src 기준 모듈 목록과 ../ 개수를 고친다. 없는 폴더를 말없이
  건너뛰던 목록(MessagingAuthority, NotificationPayloadAtRest 등)을 새
  폴더로, FileserverDocumentationCoverageTest는 Gradle 경로 → 폴더를
  registry로 찾는다. Docker 계약은 WORKDIR /build, 새 jar 경로.
- Docker: 빌드 context를 저장소 루트로, .dockerignore는 허용 목록으로 다시
  써서 전에 context였던 것만 들어가게 한다. compose의 build.context는 .,
  env_file은 ./.env.
- workflow: working-directory: src 기본값과 그것을 되돌리던 줄을 지운다.
- scripts: verify.sh, ci/*, bootstrap-local, new-feature,
  verify-feature-scaffold, mongo 검증, hooks, check-repo-layout 허용 목록.
  check-docs의 경로 검사는 build-logic/·gradle/로 시작하는 경로도 본다.
- 문서: AGENTS.md 지도, README 구조 표, leaf AGENTS.md의 cd src, gates·
  operate·결정 색인, src/bootstrap/AGENTS.md를 조립 계층 family 규칙으로
  다시 쓴다. 기록 문서(docs/design·history·reviews, 지난 upgrade 안내,
  capability-status 제거 표)는 머리 블록만 고친다. 파생 서비스용 안내
  docs/upgrade/2026-11-relayout.md를 더한다.

위험: bootRun working dir가 저장소 루트가 되어 .env와 상대 경로 설정이
루트 기준이다. 루트 .env는 compose 보간에도 읽힌다(upgrade 안내 5절).
파생 서비스는 태그 pre-relayout-2026-11까지 받은 뒤 이 묶음을 받는다.

검증: desktop에서 캐시 없이 scripts/verify.sh docs·pr·main·release,
compose smoke 18 lane, 빠른 시작(scripts/verify.sh app). 결과는 PR 본문.
구조 리뷰(arch-reviewer) 지적 5건을 반영했다.

BREAKING CHANGE: Gradle은 저장소 루트에서 돈다(cd src 없음). registry는
gradle/modules.json, 이미지 빌드 context는 저장소 루트다. 옛 경로 → 새 경로
표는 docs/upgrade/2026-11-relayout.md.
Refs: design-docs repo-structure/01-backend-layout.md 6.1절 가-2·가-3
2026-11-11 22:15:42 +09:00

453 lines
15 KiB
Java

package dev.caskeleton.buildlogic.architecture;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
class CleanArchitectureResolvedClasspathFunctionalTest {
@Test
void transitiveApiProjectMustBeRegisteredForTheCompileVisibleConsumer(@TempDir Path temporaryRoot)
throws IOException {
Path project = fixture(temporaryRoot, false);
BuildResult result = runner(project, "verifyCleanArchitectureDependencies").buildAndFail();
assertThat(result.getOutput())
.contains("Module ':c' has forbidden project dependencies [a]")
.contains(
"Direct and compile-visible production project edges must be explicitly registered");
}
@Test
void aSecondCompositionRootIsGovernedByTheSameDependencyPolicy(
@TempDir Path temporaryRoot) throws IOException {
Path repository = temporaryRoot.resolve("repository");
Path project = repository;
Files.createDirectories(project.resolve("gradle"));
Files.createDirectories(project.resolve("a"));
Files.createDirectories(project.resolve("example-app"));
Files.writeString(
project.resolve("settings.gradle"),
"""
rootProject.name = 'main'
include 'a', 'example-app'
""",
UTF_8);
Files.writeString(
project.resolve("build.gradle"),
"""
plugins { id 'ca.architecture' }
subprojects { apply plugin: 'java-library' }
project(':example-app') {
dependencies { implementation project(':a') }
}
""",
UTF_8);
Files.writeString(
project.resolve("gradle/modules.json"),
"""
{
"modules": [
{
"id": "a",
"gradle_path": ":a",
"source_path": "a",
"allowed_dependencies": []
},
{
"id": "example-app",
"gradle_path": ":example-app",
"source_path": "example-app",
"allowed_dependencies": []
}
]
}
""",
UTF_8);
BuildResult result = runner(project, "verifyCleanArchitectureDependencies").buildAndFail();
assertThat(result.getOutput())
.contains("Module ':example-app' has forbidden project dependencies [a]");
}
@Test
void explicitlyRegisteredCompileVisibleTransitiveProjectPasses(@TempDir Path temporaryRoot)
throws IOException {
Path project = fixture(temporaryRoot, true);
BuildResult result = runner(project, "verifyCleanArchitectureDependencies").build();
assertThat(result.getOutput()).contains("BUILD SUCCESSFUL");
}
@Test
@DisplayName("registry에 등록하지 않은 leaf 디렉터리에 build 스크립트가 있으면 방향 게이트가 그 경로로 실패한다")
void aLeafDirectoryMissingFromTheRegistryFailsTheGate(@TempDir Path temporaryRoot)
throws IOException {
// given
Path project = fixture(temporaryRoot, true);
Files.createDirectories(project.resolve("d"));
Files.writeString(project.resolve("d/build.gradle"), "plugins { id 'java' }\n", UTF_8);
// when
BuildResult result = runner(project, "verifyCleanArchitectureDependencies").buildAndFail();
// then
assertThat(result.getOutput()).contains("d/build.gradle").contains("no registry entry");
}
@Test
@DisplayName("소유 group 라이브러리를 runtimeOnly로만 실어도 allowed_libraries에 없으면 방향 게이트가 실패한다")
void aRuntimeOnlyOwnedLibraryMissingFromAllowedLibrariesFailsTheGate(
@TempDir Path temporaryRoot) throws IOException {
// given
Path project = libraryFixture(temporaryRoot, "runtimeOnly 'dev.cakit.demo:demo-starter:1.0.0'", "[]");
// when
BuildResult result = runner(project, "verifyCleanArchitectureDependencies").buildAndFail();
// then
assertThat(result.getOutput())
.contains("Module ':c' has forbidden library dependencies [dev.cakit.demo:demo-starter]")
.contains("allowed_libraries");
}
@Test
@DisplayName("소유 group 라이브러리가 api로 내보내 컴파일에 보이는 모듈도 allowed_libraries에 있어야 한다")
void aCompileVisibleOwnedLibraryMustBeListedToo(@TempDir Path temporaryRoot)
throws IOException {
// given: demo-api's POM brings demo-core in compile scope, so c compiles against both.
Path project =
libraryFixture(
temporaryRoot,
"implementation 'dev.cakit.demo:demo-api:1.0.0'",
"[\"dev.cakit.demo:demo-api\"]");
// when
BuildResult result = runner(project, "verifyCleanArchitectureDependencies").buildAndFail();
// then
assertThat(result.getOutput())
.contains("Module ':c' has forbidden library dependencies [dev.cakit.demo:demo-core]");
}
@Test
void ownedLibrariesListedInAllowedLibrariesPass(@TempDir Path temporaryRoot)
throws IOException {
// given
Path project =
libraryFixture(
temporaryRoot,
"implementation 'dev.cakit.demo:demo-api:1.0.0'\n"
+ " runtimeOnly 'dev.cakit.demo:demo-starter:1.0.0'",
"[\"dev.cakit.demo:demo-api\", \"dev.cakit.demo:demo-core\","
+ " \"dev.cakit.demo:demo-starter\"]");
// when
BuildResult result = runner(project, "verifyCleanArchitectureDependencies").build();
// then
assertThat(result.getOutput()).contains("BUILD SUCCESSFUL");
}
@Test
void aLibraryOutsideTheOwnedGroupsIsNotGoverned(@TempDir Path temporaryRoot)
throws IOException {
// given
Path project = libraryFixture(temporaryRoot, "implementation 'org.example:other:1.0.0'", "[]");
// when
BuildResult result = runner(project, "verifyCleanArchitectureDependencies").build();
// then
assertThat(result.getOutput()).contains("BUILD SUCCESSFUL");
}
@Test
@DisplayName("--include-build로 끼운 라이브러리 모듈은 프로젝트가 아니라 그 좌표로 allowed_libraries와 대조한다")
void aLibrarySubstitutedFromAnIncludedBuildIsCheckedByItsCoordinate(@TempDir Path temporaryRoot)
throws IOException {
// given: the library's own build next to the repository; demo-included exports demo-extra.
Path project =
libraryFixture(
temporaryRoot,
"implementation 'dev.cakit.demo:demo-included:1.0.0'",
"[\"dev.cakit.demo:demo-included\"]");
Path library = includedLibrary(temporaryRoot);
// when
BuildResult result =
runner(
project,
"--include-build",
library.toString(),
"verifyCleanArchitectureDependencies")
.buildAndFail();
// then: the module the included project exports is named as a library, not a project edge.
assertThat(result.getOutput())
.contains("Module ':c' has forbidden library dependencies [dev.cakit.demo:demo-extra]")
.doesNotContain("forbidden project dependencies");
}
@Test
void anIncludedLibraryWhoseModulesAreAllListedPasses(@TempDir Path temporaryRoot)
throws IOException {
// given
Path project =
libraryFixture(
temporaryRoot,
"implementation 'dev.cakit.demo:demo-included:1.0.0'",
"[\"dev.cakit.demo:demo-included\", \"dev.cakit.demo:demo-extra\"]");
Path library = includedLibrary(temporaryRoot);
// when
BuildResult result =
runner(
project,
"--include-build",
library.toString(),
"verifyCleanArchitectureDependencies")
.build();
// then
assertThat(result.getOutput()).contains("BUILD SUCCESSFUL");
}
@Test
@DisplayName("계층 leaf(domain-core 등) 행에 allowed_libraries를 적으면 registry 위반으로 실패한다")
void aLayerModuleThatAllowsALibraryIsARegistryViolation(@TempDir Path temporaryRoot)
throws IOException {
// given
Path project = temporaryRoot.resolve("repository");
Files.createDirectories(project.resolve("gradle"));
Files.createDirectories(project.resolve("domain-core"));
Files.writeString(
project.resolve("settings.gradle"), "rootProject.name = 'main'\ninclude 'domain-core'\n", UTF_8);
Files.writeString(
project.resolve("build.gradle"),
"plugins { id 'ca.architecture' }\nsubprojects { apply plugin: 'java-library' }\n",
UTF_8);
Files.writeString(
project.resolve("gradle/modules.json"),
"""
{
"library_groups": ["dev.cakit"],
"modules": [
{
"id": "domain-core",
"gradle_path": ":domain-core",
"source_path": "domain-core",
"allowed_dependencies": [],
"allowed_libraries": ["dev.cakit.demo:demo-api"]
}
]
}
""",
UTF_8);
// when
BuildResult result = runner(project, "verifyCleanArchitectureDependencies").buildAndFail();
// then
assertThat(result.getOutput())
.contains("'domain-core' is a layer module")
.contains("[dev.cakit.demo:demo-api]");
}
/** A library build of two projects in group dev.cakit.demo; demo-included exports demo-extra. */
private static Path includedLibrary(Path temporaryRoot) throws IOException {
Path library = temporaryRoot.resolve("library");
Files.createDirectories(library.resolve("demo-included"));
Files.createDirectories(library.resolve("demo-extra"));
Files.writeString(
library.resolve("settings.gradle"),
"rootProject.name = 'library'\ninclude 'demo-included', 'demo-extra'\n",
UTF_8);
Files.writeString(
library.resolve("build.gradle"),
"""
subprojects {
apply plugin: 'java-library'
group = 'dev.cakit.demo'
version = '1.0.0'
}
project(':demo-included') {
dependencies { api project(':demo-extra') }
}
""",
UTF_8);
return library;
}
/**
* One module {@code c} that declares {@code declaration} against a file repository of POM-only
* modules: {@code dev.cakit.demo:demo-api} (bringing {@code demo-core} in compile scope),
* {@code demo-starter}, and {@code org.example:other}. The direction check reads the resolved
* graph, not the artifacts, so no jar is needed.
*/
private static Path libraryFixture(Path temporaryRoot, String declaration, String cLibraries)
throws IOException {
Path repository = temporaryRoot.resolve("repository");
Path project = repository;
Files.createDirectories(project.resolve("gradle"));
Files.createDirectories(project.resolve("c"));
Path maven = temporaryRoot.resolve("maven");
pom(maven, "dev.cakit.demo", "demo-core", "");
pom(
maven,
"dev.cakit.demo",
"demo-api",
"""
<dependencies><dependency><groupId>dev.cakit.demo</groupId><artifactId>demo-core</artifactId>\
<version>1.0.0</version><scope>compile</scope></dependency></dependencies>""");
pom(maven, "dev.cakit.demo", "demo-starter", "");
pom(maven, "org.example", "other", "");
Files.writeString(
project.resolve("settings.gradle"),
"""
rootProject.name = 'main'
include 'c'
""",
UTF_8);
Files.writeString(
project.resolve("build.gradle"),
"""
plugins { id 'ca.architecture' }
subprojects {
apply plugin: 'java-library'
repositories { maven { url = '%s' } }
}
project(':c') {
dependencies {
%s
}
}
"""
.formatted(maven.toUri(), declaration),
UTF_8);
Files.writeString(
project.resolve("gradle/modules.json"),
"""
{
"library_groups": ["dev.cakit"],
"modules": [
{
"id": "c",
"gradle_path": ":c",
"source_path": "c",
"allowed_dependencies": [],
"allowed_libraries": %s
}
]
}
"""
.formatted(cLibraries),
UTF_8);
return project;
}
private static void pom(Path maven, String group, String artifact, String dependencies)
throws IOException {
Path directory = maven.resolve(group.replace('.', '/')).resolve(artifact).resolve("1.0.0");
Files.createDirectories(directory);
Files.writeString(
directory.resolve(artifact + "-1.0.0.pom"),
"""
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>%s</groupId><artifactId>%s</artifactId><version>1.0.0</version>
<packaging>pom</packaging>
%s
</project>
"""
.formatted(group, artifact, dependencies),
UTF_8);
}
private static Path fixture(Path temporaryRoot, boolean allowTransitiveA) throws IOException {
Path repository = temporaryRoot.resolve("repository");
Path project = repository;
Files.createDirectories(project.resolve("gradle"));
for (String module : new String[] {"a", "b", "c"}) {
Files.createDirectories(project.resolve(module));
}
Files.writeString(
project.resolve("settings.gradle"),
"""
rootProject.name = 'main'
include 'a', 'b', 'c'
""",
UTF_8);
Files.writeString(
project.resolve("build.gradle"),
"""
plugins { id 'ca.architecture' }
subprojects { apply plugin: 'java-library' }
project(':b') {
dependencies { api project(':a') }
}
project(':c') {
dependencies { implementation project(':b') }
}
""",
UTF_8);
String cAllowed = allowTransitiveA ? "[\"b\", \"a\"]" : "[\"b\"]";
Files.writeString(
project.resolve("gradle/modules.json"),
"""
{
"modules": [
{
"id": "a",
"gradle_path": ":a",
"source_path": "a",
"allowed_dependencies": []
},
{
"id": "b",
"gradle_path": ":b",
"source_path": "b",
"allowed_dependencies": ["a"]
},
{
"id": "c",
"gradle_path": ":c",
"source_path": "c",
"allowed_dependencies": %s
}
]
}
"""
.formatted(cAllowed),
UTF_8);
return project;
}
private static GradleRunner runner(Path project, String... arguments) {
String[] fullArguments = new String[arguments.length + 2];
fullArguments[0] = "--console=plain";
fullArguments[1] = "--stacktrace";
System.arraycopy(arguments, 0, fullArguments, 2, arguments.length);
return GradleRunner.create()
.withProjectDir(project.toFile())
.withPluginClasspath()
.withArguments(fullArguments);
}
}