Files
clean-architecture-backend-…/build.gradle
DongHyeonka 474bd0462c
pr / done (pull_request) Successful in 1m42s
fix(compose): 계약 검사의 판정을 시험 있는 스크립트로 옮기고 빈 입력 통과를 막는다
scripts/verify-compose-profile-contracts.sh는 prCheck의 게이트인데 판정
열 가지가 셸 안의 jq라 시험이 없다. 고장 난 입력을 넣어 보면 넷이 통과한다.
- 계약의 lanes가 비면 lane 반복이 돌지 않고 "all 0 lanes match"로 끝난다.
- persistence-jpa를 켠 lane에 expectedPersistenceVendor가 없으면 통과한다.
  smoke는 보고된 vendor를 그 칸과 비교하니 그 lane은 매번 실패한다.
- heap dump 경로는 짧은 `tmpfs:` 목록의 같은 항목만 비교한다. 위 디렉터리의
  tmpfs(/var/tmp)나 long syntax `type: tmpfs` volume은 통과한다.
- Redis 계정을 이름 그대로가 아니라 정규식으로 찾아 `.`이 아무 글자와 맞는다.
  `ca.skeleton-application`을 가리키는 lane이 `ca-skeleton-application` 줄로
  통과한다.

판정을 scripts/compose-contract-verdict.py로 옮긴다. 셸은 docker만 부른다.
`version`으로 Compose 하한을 먼저 보고, `lanes`가 준 lane별 인자로
`config --services`와 `config --format json`을 돌려 출력과 rc를 파일에 쓴다.
rc는 조건 밖에서 읽는다. 그다음 `judge`가 그 디렉터리를 읽는다. 판정은 위
넷을 실패로 보고, 파일 없는 lane, 겹치는 id, smoke가 읽는 목록이 없거나 그
목록에 이름이 아닌 원소가 든 lane, 셸이 렌더 기록을 남기지 않은 lane도 실패로
본다. docker 호출의 stdin은 /dev/null이라 lane 목록을 먹지 않는다.
scripts/tests/test_compose_contract_verdict.py가 판정마다 고장 난 입력과 정상
입력을 보고, 셸을 가짜 docker로 돌려 lane 인자·rc 기록·판정 rc를 본다.
prCheck의 testDocumentChecks가 돌린다. 루트 build.gradle의 주석은 PR 단계
Exec 태스크마다 시험 파일을 적어 사실과 맞춘다.

버린 안: 모델 JSON의 service key로 `config --services`를 대신하기. 렌더를
한 번 줄이지만 지금 lane 결과와 같은지 따로 보여야 해서 두 호출을 그대로 둔다.
bats는 desktop과 runner 둘 다에 새 도구를 깔아야 한다.

위험·한계: 판정이 jq와 다른 곳은 위 넷 말고도 있다. main이 통과시키고 이제
실패로 보는 것: 같은 사용자를 두 줄에서 켠 ACL(Redis가 거절한다), 값이
null·false인 realm의 `_` key, 최상위 값이 둘인 realm, LANE_ID 꼴이 아닌 id,
빈 springRuntime, `files`가 없는 lane, 이름이 아닌 목록 원소, 읽을 수 없는
Compose 버전. main이 실패시키고 이제 통과하는 것: ACL 줄의 겹친 공백과 CRLF,
끝에 `/`가 붙은 bind target, 로캘에 따라 달라지던 service 정렬, list 꼴
environment, 파일 하나로 bind mount한 ACL(target이 --aclfile 경로와 같음).
Redis가 ACL 줄의 `\r`와 겹친 공백을 받아들인다는 것은 acl.c를 열어 보지 않은
판단이다. 실제 계약 18 lane에서는 main과 이 트리의 출력 줄이 같다(PR 본문).

검증: 노트북 `python3 -m unittest discover -s scripts/tests` 275개 통과. 판정의
빈 lane 거절·vendor 검사·heap 상위 tmpfs·long syntax tmpfs·비밀번호 글자 비교·
정확한 service 집합·사용자 이름 비교·렌더 기록 없음·파일 없는 lane·목록 원소
검사를 되돌리거나, judge_lane에서 판정 하나를 빼거나 realm 판정을 빼거나, 셸의
두 렌더 rc를 `|| true`로 삼키거나, docker가 stdin을 읽게 두거나, judge 호출을
지우거나 `|| true`로 바꾸거나, version 실패를 무시하거나, profile 인자를 빼면
새 시험이 실패한다(변이 23개 모두). desktop RED·GREEN과 prCheck 결과는 PR
본문에 있다.

Refs: REV-BE-0016
2026-11-22 01:10:29 +09:00

307 lines
18 KiB
Groovy

plugins {
// Spring Boot stays on the root build script classpath because a leaf applies it by id
// (`app-bootstrap`) and a leaf resolves plugin classes from the root.
//
// Spotless, SpotBugs, Error Prone and Spring's dependency-management are NOT here any more. They
// were declared `apply false` for a `configure(subprojects)` block that applied them to every
// leaf; build-logic's `ca.quality-conventions` and `ca.java-conventions` apply them now, and a
// plugin reachable from two classpaths is two versions waiting to differ. Their versions are the
// same catalog entries either way — build-logic/settings.gradle reads gradle/libs.versions.toml.
alias(libs.plugins.spring.boot) apply false
// JMH benchmarks in the leaves that apply this plugin (`./gradlew :<leaf>:jmh`); never part of a gate.
alias(libs.plugins.jmh) apply false
// Convention plugin from the included build, applied to the ROOT because the rules it owns are
// about the repository: the architecture gates. The release version/revision is each leaf's
// `ca.java-conventions` (ca.release-provenance was removed, BUILD-O3-5). The public-path
// baseline is app-bootstrap's approval test, the local start-up is scripts/bootstrap-local.sh,
// and archive hygiene is gone with the revision it cleaned out of every leaf's jar name (review
// 2026-09-24 BUILD-O3-5).
id 'ca.architecture'
// Every strict lane belongs to a stage, and each stage's workflow job runs it (review
// 2026-11-01 08-01).
id 'ca.strict-lane-stages'
}
group = 'dev.caskeleton'
// A release archive has to name the commit that produced it. The revision rule is the one every
// leaf's version uses (JavaConventionsPlugin.sourceRevision, tested in build-logic), read here so
// the tag-only gate and the jars cannot disagree about what counts as a commit id.
tasks.register('verifyReleaseProvenance') {
group = 'verification'
description = 'Fails when the build cannot name the source revision it was produced from.'
String revision = dev.caskeleton.buildlogic.java.JavaConventionsPlugin.sourceRevision(providers)
boolean traceable = revision != dev.caskeleton.buildlogic.java.JavaConventionsPlugin.UNKNOWN_REVISION
outputs.upToDateWhen { false }
doLast { task ->
if (!traceable) {
throw new GradleException('verifyReleaseProvenance: no source revision. A release archive has to name the '
+ 'commit that produced it; supply -PgitRevision=<sha>, GIT_SHA or GITHUB_SHA.')
}
task.logger.lifecycle("verifyReleaseProvenance: OK — revision ${revision}")
}
}
// One explicit command regenerates every module's Gradle-default lockfile.
tasks.register('resolveAndLockAll') {
group = 'build setup'
description = 'Regenerates dependency locks for all subprojects (requires --write-locks).'
dependsOn subprojects.findAll { it.childProjects.isEmpty() }.collect { "${it.path}:resolveAndLockAll" }
}
tasks.register('verifyDependencyLocks') {
group = 'verification'
description = 'Verifies strict dependency lock state for production CI subprojects.'
dependsOn subprojects.findAll { it.childProjects.isEmpty() }.collect { "${it.path}:verifyDependencyLocks" }
}
// feature-developer-experience-contract D3 — the ordered local bootstrap lifecycle is
// scripts/bootstrap-local.sh (compile, Docker preflight, dependency wait, start, smoke). Startup
// Flyway runs only when the persistence-jpa runtimeOnly line is on; the default composition is web.
// ---------------------------------------------------------------------------------------------
// Lifecycle.
//
// :<leaf>:check that leaf — compile, its tests, Spotless, Checkstyle, Error Prone
// check every leaf's check (Gradle matches the name across projects)
// architectureCheck dependency direction + purity + app-bootstrap whole-repository ArchUnit
// qualityCheck SpotBugs + FindSecBugs across every leaf (ca.quality-conventions)
// ci leaf checks + architectureCheck + qualityCheck
// prCheck the pull-request stage: ci + testQualityCheck + every leaf's
// auxiliaryStyleCheck + dependency locks + the Compose render, the
// repository layout and the document checks (scripts outside Gradle)
// mainCheck the main-branch stage: environment contract, full-boot qualification,
// public-path baseline, transport and messaging qualification lanes, the
// GraphQL transport-boundary lane (graphqlStableTest), each leaf's
// document-contract lanes, and the feature generator round trip
// (verifyFeatureScaffold)
// integrationCheck the declared strict integration lanes (several need a container runtime)
// performanceCheck the declared strict performance lanes (load, shutdown, pool and resource
// bounds; real servers and containers)
// releaseCheck the tag-only checks: release provenance + public path snapshot (not `ci`
// again — a tag is cut from a main commit the PR and main stages ran on)
//
// A leaf's check is that leaf's; a repository question gets a repository task named after it.
// Task PATHS, not TaskProviders: a leaf's tasks are created by convention plugins after the root is
// evaluated, and a path is resolved when the task graph is built.
// ---------------------------------------------------------------------------------------------
List<String> leafPaths = subprojects.findAll { it.childProjects.isEmpty() }.collect { it.path }.toSorted()
tasks.register('qualityCheck') {
group = 'verification'
description = 'Runs SpotBugs and FindSecBugs across every production CI leaf.'
dependsOn leafPaths.collect { "${it}:qualityCheck" }
}
tasks.register('configContractCheck') {
group = 'verification'
description = 'Runs the environment contract owned by the composition root.'
dependsOn ':app-bootstrap:verifyEnvKeys'
}
// A lane that needs an input this build was not given (the Redis topology coordinates, the protected
// AWS sandbox authority) is explicit-only: the aggregate leaves it out and names it when it runs
// (review NEW-16).
tasks.register('integrationCheck') {
group = 'verification'
description = "Runs every production CI leaf's integration-category test lanes. Several need a container runtime."
dependsOn leafPaths.collect { "${it}:integrationTestLaneCheck" }
}
// Performance lanes are not the pull request's or the main stage's: their bounds need a machine that
// is not compiling something else. main.yml runs this aggregate nightly, after its other jobs.
tasks.register('performanceCheck') {
group = 'verification'
description = "Runs every production CI leaf's performance-category test lanes. Several need a container runtime."
dependsOn leafPaths.collect { "${it}:performanceTestLaneCheck" }
}
tasks.named('architectureCheck') {
dependsOn leafPaths.collect { "${it}:architectureTestLaneCheck" }
}
// app-bootstrap is left out: its `check` already runs its full-boot lane in the pull-request gate,
// and the main stage ran the same lane a second time on every main push (review 2026-11-01 08-02).
// The lane stays merge-blocking, because a composition that does not boot must not merge.
tasks.register('systemTestCheck') {
group = 'verification'
description = "Runs every production CI leaf's full application/system test lanes that `ci` does not already run."
dependsOn leafPaths.findAll { it != ':app-bootstrap' }.collect { "${it}:systemTestLaneCheck" }
}
tasks.register('qualificationCheck') {
group = 'verification'
description = 'Runs repository/build-behavior qualification that is intentionally outside local leaf checks.'
dependsOn tasks.named('systemTestCheck')
dependsOn leafPaths.collect { "${it}:auxiliaryStyleCheck" }
dependsOn tasks.named('testQualityCheck')
}
// SpotBugs + FindSecBugs over every leaf's test source sets, against config/spotbugs/exclude-test.xml.
// It ran in no stage until 2026-11-04, and 53 of these tasks had been failing unseen. From then it ran
// in the main stage only, so a finding in test code surfaced after the merge (main run 269: a dead
// local store in graphql's systemTest). Since 2026-11-20 prCheck runs it and every leaf's
// auxiliaryStyleCheck too: a pull request restores the build cache main's `done` job fills, so the
// analysis of a leaf whose inputs did not change comes from it (desktop 2026-11-13, the unchanged tree
// in a second checkout: +29 s with a warm cache, +310 s without). qualificationCheck keeps both as
// well; taking a gate out of a stage is the owner's call.
tasks.register('testQualityCheck') {
group = 'verification'
description = 'Runs SpotBugs and FindSecBugs over every leaf\'s test source sets.'
dependsOn leafPaths.collect { "${it}:testQualityCheck" }
}
// The feature generator's round trip (review 2026-11-01 개선 순서 4): scripts/new-feature.sh writes
// two features into a throwaway copy of the working tree and that copy's own Gradle runs the checks
// of the five leaves they touch plus architectureCheck, which runs every leaf's architecture lane. A
// nested build that long belongs to the main stage, not the pull request. The script is the whole
// check; this task only gives it a stage.
tasks.register('verifyFeatureScaffold', Exec) {
group = 'verification'
description = 'Generates features with scripts/new-feature.sh in a scratch copy and runs the gates they must pass.'
workingDir = rootProject.projectDir
commandLine 'bash', 'scripts/verify-feature-scaffold.sh'
}
// Each lane below names its tests and rejects skips; these two only aggregate them.
tasks.register('conditionalTransportQualification') {
group = 'verification'
description = 'Runs the no-skip GraphQL, gRPC and WebSocket transport lanes and the opt-in classpath contract.'
dependsOn ':adapter:inbound:graphql:graphqlTransportQualificationTest',
':adapter:inbound:grpc:grpcTransportQualificationTest',
':adapter:inbound:websocket:websocketTransportQualificationTest',
':app-bootstrap:conditionalTransportBuildContractTest'
}
tasks.register('verifyMessagingContracts') {
group = 'verification'
description = 'Qualifies the application integration-event contract and the shared envelope schema.'
dependsOn ':application-core:messagingApplicationContractQualificationTest',
':shared-contract:messagingSharedSchemaQualificationTest'
}
tasks.register('ci') {
group = 'verification'
description = 'The pull-request gate: every production CI leaf check plus the architecture and quality gates.'
dependsOn leafPaths.collect { "${it}:check" }
dependsOn tasks.named('architectureCheck')
dependsOn tasks.named('qualityCheck')
}
tasks.register('mainCheck') {
group = 'verification'
description = 'The main-branch stage: the gates that are not worth a pull request\'s wait.'
dependsOn leafPaths.collect { "${it}:mainCheck" }
dependsOn tasks.named('configContractCheck')
dependsOn tasks.named('qualificationCheck')
dependsOn tasks.named('verifyPublicPathSnapshot')
dependsOn tasks.named('conditionalTransportQualification')
dependsOn tasks.named('verifyMessagingContracts')
dependsOn ':adapter:inbound:graphql:graphqlStableTest'
dependsOn tasks.named('verifyFeatureScaffold')
}
// The checks outside Gradle that the pull-request stage runs. Each has its tests in scripts/tests,
// which testDocumentChecks runs: verifyComposeProfiles in test_compose_contract_verdict.py (its shell
// keeps the docker calls, scripts/compose-contract-verdict.py the judgements), verifyRepositoryLayout
// in test_check_repo_layout.py, verifyWorkDocs in test_check_work_docs.py, documentCheck in
// test_check_docs.py. These tasks only give them a stage, so pr.yml and scripts/verify.sh run the same
// one line. Repository root as working directory: that is where the scripts expect to start.
def repositoryRoot = rootProject.projectDir
tasks.register('verifyComposeProfiles', Exec) {
group = 'verification'
description = 'Renders every Compose lane and checks it renders exactly what it declares.'
workingDir = repositoryRoot
commandLine 'bash', 'scripts/verify-compose-profile-contracts.sh'
}
tasks.register('verifyRepositoryLayout', Exec) {
group = 'verification'
description = 'Refuses a top-level entry of the repository or src/ outside the allow list.'
workingDir = repositoryRoot
commandLine 'python3', 'scripts/check-repo-layout.py'
}
tasks.register('verifyWorkDocs', Exec) {
group = 'verification'
description = 'Checks the work manual: size limits, no history IDs, playbook skeleton, relative links.'
workingDir = repositoryRoot
commandLine 'python3', 'scripts/check-work-docs.py'
}
tasks.register('testDocumentChecks', Exec) {
group = 'verification'
description = 'Runs the tests of the scripts outside Gradle (document checker, hooks, ledger).'
workingDir = repositoryRoot
commandLine 'python3', '-m', 'unittest', 'discover', '-s', 'scripts/tests'
}
tasks.register('documentCheck', Exec) {
group = 'verification'
description = 'Checks living documents: language, head blocks, references, numbers, links, style.'
workingDir = repositoryRoot
commandLine 'python3', 'scripts/check-docs.py'
dependsOn tasks.named('testDocumentChecks')
}
tasks.register('prCheck') {
group = 'verification'
description = 'The pull-request stage: ci, test-code analysis and style, dependency locks, the Compose render, the layout, the work manual and the documents.'
dependsOn tasks.named('ci')
dependsOn tasks.named('testQualityCheck')
dependsOn leafPaths.collect { "${it}:auxiliaryStyleCheck" }
dependsOn tasks.named('verifyDependencyLocks')
dependsOn tasks.named('verifyComposeProfiles')
dependsOn tasks.named('verifyRepositoryLayout')
dependsOn tasks.named('verifyWorkDocs')
dependsOn tasks.named('documentCheck')
}
// The stages a strict lane may belong to, and the one workflow job that runs each.
// `verifyStrictLaneStages --dry-run` (pull-request stage) fails when a strict lane that is not
// `explicitOnly` is in the plan of none of them — the gap that left fourteen lanes running nowhere
// while each one failed closed (review 2026-11-01 08-01) — or when a stage job is not the line
// `./gradlew <stage> <options>` under the declared event and condition. A new lane joins a stage
// through its category aggregate; no workflow line names it. The performance lane runs only
// nightly, after the other heavy jobs, on a runner nothing else is using (owner decision 2026-11-07).
strictLaneStages {
workflowDirectory = layout.projectDirectory.dir('.gitea/workflows')
stage ':prCheck', workflow: 'pr.yml', event: 'pull_request', job: 'done'
// One job and one Gradle run for both main-branch stages: it compiles once, and the
// main stage's analysis and the feature generator's nested build run while the integration
// lanes take turns on the one real-server slot. Two jobs spent about 34 runner minutes on a push
// (run 79), two of them compiling the same modules twice.
// integrationCheck comes first on the line because Gradle starts ready work in the order of
// the requested tasks: the integration lanes' compiles go first and the slot is busy from the
// first minute. Second on the line, the lanes waited about ten minutes behind the main stage's
// analysis and then ran one at a time on an idle machine (desktop 1,760 s, first on the line
// 1,484 s, same commit range).
stage ':mainCheck', workflow: 'main.yml', event: 'push', filter: 'branches: [main]', job: 'main',
options: '--continue', line: ':integrationCheck :mainCheck'
stage ':integrationCheck', workflow: 'main.yml', event: 'push', filter: 'branches: [main]', job: 'main',
options: '--continue', line: ':integrationCheck :mainCheck'
stage ':performanceCheck', workflow: 'main.yml', event: 'schedule', job: 'performance', options: '--continue',
condition: '${{ github.event_name != \'push\' }}'
stage ':releaseCheck', workflow: 'release.yml', event: 'push', filter: 'tags: ["v*"]', job: 'release'
}
// The deny-by-default public path baseline: app-bootstrap's approval-test lane under its old name.
// It only compares, and fails when the build sets approvePublicPathChange. After review,
// `updatePublicPathSnapshot -PapprovePublicPathChange` rewrites the baseline.
tasks.register('verifyPublicPathSnapshot') {
group = 'verification'
description = 'Fails when the public path surface (default, profile overrides, filter-chain permitAll and securityMatcher statements) drifts from docs/security/public-paths-snapshot.txt.'
dependsOn ':app-bootstrap:publicPathSnapshotTest'
}
tasks.register('updatePublicPathSnapshot') {
group = 'verification'
description = 'Rewrites docs/security/public-paths-snapshot.txt from the current public path surface after review. Requires -PapprovePublicPathChange.'
dependsOn ':app-bootstrap:publicPathSnapshotUpdate'
}
// The checks that only matter for a release artifact. Not `ci` again: a release tag is cut from a
// main commit that the pull-request gate and the main stage already ran on (review BUILD-중복-6).
tasks.register('releaseCheck') {
group = 'verification'
description = 'The tag-only checks: release provenance and the public path baseline.'
dependsOn tasks.named('verifyReleaseProvenance')
dependsOn tasks.named('verifyPublicPathSnapshot')
}