diff --git a/build-logic/AGENTS.md b/build-logic/AGENTS.md index 3600cfc1..f48e37f6 100644 --- a/build-logic/AGENTS.md +++ b/build-logic/AGENTS.md @@ -23,6 +23,12 @@ registry, settings, build-logic, 루트 라이프사이클이 정하는 것을 - `PERFORMANCE` lane은 상한을 매번 단언한다. 끄는 스위치가 없다. convention이 테스트 JVM에 `performance.assertions.enabled=true`를 넣고, 빌드(`-P`·`GRADLE_OPTS`)나 lane이 다른 값을 주면 테스트 전에 실패한다. skip된 테스트가 하나라도 있어도 실패한다(`rejectSkipped`를 따로 쓰지 않아도). 사람이 손으로 돌리는 `./gradlew performanceCheck`와 workflow가 같은 상한을 단언한다. - `verifyEnvKeys`는 app-bootstrap 태스크로 유지한다(2026-09-25 소유자 결정). 구현은 build-logic의 `ca.config-contract`다. +## 설정 단계에서 보지 않는 것 + +- 플러그인의 `apply`·`afterEvaluate`는 leaf의 `src/` 아래 소스·자원이 있는지 보지 않는다. 이미지 빌드의 의존성 단계(`Dockerfile` builder)는 그것을 복사하지 않은 채 모든 project를 설정하고 `verifyDependencyLocks`를 돈다. 그 단계가 복사하는 것(Gradle wrapper와 설정, build 스크립트와 lockfile, `release/` 데이터, `build-logic/`)의 정본은 `Dockerfile`의 그 단계 `COPY` 줄이다. 그 단계에서 설정이 실패하면 이미지가 만들어지지 않는다. +- 파일이 있어야 하는 검사는 그 파일을 읽는 태스크의 실행에서 한다(예: `AdditionalSourceRoots`). 2026-11-13에 API surface의 추가 source root 검사를 설정 단계에 두었다가 nightly compose smoke의 18개 lane이 모두 이미지 빌드에서 멈췄다(2026-11-18 확인). 같은 Dockerfile을 쓰는 release 이미지 빌드와 로컬 `scripts/bootstrap-local.sh`도 같은 단계를 지난다. +- 설정 단계 동작을 바꿨으면 desktop에서 이미지 빌드를 한 번 본다: `bash scripts/run-compose-runtime-smoke.sh --lane off-local`. + ## 단계 job의 모양 - `verifyStrictLaneStages --dry-run`(PR)은 `explicitOnly`가 아닌 strict lane마다 `build.gradle`의 `strictLaneStages`가 선언한 단계 태스크 하나의 계획에 들어 있는지 본다(그래프 검사). diff --git a/build-logic/src/main/java/dev/caskeleton/buildlogic/apisurface/AdditionalSourceRoots.java b/build-logic/src/main/java/dev/caskeleton/buildlogic/apisurface/AdditionalSourceRoots.java new file mode 100644 index 00000000..4d08c40a --- /dev/null +++ b/build-logic/src/main/java/dev/caskeleton/buildlogic/apisurface/AdditionalSourceRoots.java @@ -0,0 +1,32 @@ +package dev.caskeleton.buildlogic.apisurface; + +import java.io.File; +import java.util.Collection; +import java.util.List; +import org.gradle.api.GradleException; + +/** + * The extra source roots an API surface reads, which must exist when the surface is computed. + * + *

A missing root used to be skipped without a word, so an approved update recorded a surface + * with a whole module's types gone (2026-11-12 review). The check runs when a surface task runs, + * not while Gradle configures the project: a build that configures every project without its + * sources — the image build's dependency-resolution stage copies only the build scripts — then + * failed on a folder no task of that build was going to read (nightly compose smoke, + * 2026-11-13..17). + */ +final class AdditionalSourceRoots { + + private AdditionalSourceRoots() {} + + static void requireExisting(String projectPath, Collection roots) { + List missing = + roots.stream().filter(root -> !root.isDirectory()).sorted().toList(); + if (!missing.isEmpty()) { + throw new GradleException( + projectPath + + " apiSurface.additionalSourceRoots names a folder that does not exist: " + + missing); + } + } +} diff --git a/build-logic/src/main/java/dev/caskeleton/buildlogic/apisurface/ApiSurfacePlugin.java b/build-logic/src/main/java/dev/caskeleton/buildlogic/apisurface/ApiSurfacePlugin.java index 9f261c36..b459e93e 100644 --- a/build-logic/src/main/java/dev/caskeleton/buildlogic/apisurface/ApiSurfacePlugin.java +++ b/build-logic/src/main/java/dev/caskeleton/buildlogic/apisurface/ApiSurfacePlugin.java @@ -39,15 +39,8 @@ public final class ApiSurfacePlugin implements Plugin { .filter(path -> path != null && !path.isBlank()) .map(project::file) .toList(); - // A missing additional root used to be skipped without a word, so an approved update - // recorded a surface with a whole module's types gone (2026-11-12 review). - List missing = additional.stream().filter(root -> !root.isDirectory()).toList(); - if (!missing.isEmpty()) { - throw new GradleException( - project.getPath() - + " apiSurface.additionalSourceRoots names a folder that does not exist: " - + missing); - } + // Each additional root must exist, which the surface tasks check when they run + // (AdditionalSourceRoots says why not here). List roots = new ArrayList<>(sourcePaths.stream().map(project::file).toList()); roots.addAll(additional); String verifyTaskName = "verify" + label + "ApiSurface"; @@ -70,6 +63,7 @@ public final class ApiSurfacePlugin implements Plugin { + label + " public API surface drifts."); task.getSourceRoots().from(roots); + task.getAdditionalSourceRoots().from(additional); task.getBaseline().fileValue(baseline); task.getLabel().set(label); task.getSurfaceDescription() @@ -99,6 +93,7 @@ public final class ApiSurfacePlugin implements Plugin { + label + " public API surface baseline after review."); task.getSourceRoots().from(roots); + task.getAdditionalSourceRoots().from(additional); task.getBaseline().fileValue(baseline); task.getLabel().set(label); task.getSurfaceDescription() diff --git a/build-logic/src/main/java/dev/caskeleton/buildlogic/apisurface/UpdateApiSurfaceTask.java b/build-logic/src/main/java/dev/caskeleton/buildlogic/apisurface/UpdateApiSurfaceTask.java index 34513dca..6938feb1 100644 --- a/build-logic/src/main/java/dev/caskeleton/buildlogic/apisurface/UpdateApiSurfaceTask.java +++ b/build-logic/src/main/java/dev/caskeleton/buildlogic/apisurface/UpdateApiSurfaceTask.java @@ -15,6 +15,7 @@ import org.gradle.api.provider.ListProperty; import org.gradle.api.provider.Property; import org.gradle.api.tasks.Input; import org.gradle.api.tasks.InputFiles; +import org.gradle.api.tasks.Internal; import org.gradle.api.tasks.OutputFile; import org.gradle.api.tasks.TaskAction; import org.gradle.work.DisableCachingByDefault; @@ -24,6 +25,10 @@ public abstract class UpdateApiSurfaceTask extends DefaultTask { @InputFiles public abstract ConfigurableFileCollection getSourceRoots(); + /** The extension's additional roots, also in {@link #getSourceRoots()}; each must exist. */ + @Internal + public abstract ConfigurableFileCollection getAdditionalSourceRoots(); + @OutputFile public abstract RegularFileProperty getBaseline(); @@ -38,6 +43,8 @@ public abstract class UpdateApiSurfaceTask extends DefaultTask { @TaskAction public void updateSurface() { + AdditionalSourceRoots.requireExisting( + getOwningProjectPath().get(), getAdditionalSourceRoots().getFiles()); if (!getApproved().get()) { throw new GradleException( getName() diff --git a/build-logic/src/main/java/dev/caskeleton/buildlogic/apisurface/VerifyApiSurfaceTask.java b/build-logic/src/main/java/dev/caskeleton/buildlogic/apisurface/VerifyApiSurfaceTask.java index 14c4dc4d..29af681f 100644 --- a/build-logic/src/main/java/dev/caskeleton/buildlogic/apisurface/VerifyApiSurfaceTask.java +++ b/build-logic/src/main/java/dev/caskeleton/buildlogic/apisurface/VerifyApiSurfaceTask.java @@ -25,6 +25,10 @@ public abstract class VerifyApiSurfaceTask extends DefaultTask { @InputFiles public abstract ConfigurableFileCollection getSourceRoots(); + /** The extension's additional roots, also in {@link #getSourceRoots()}; each must exist. */ + @Internal + public abstract ConfigurableFileCollection getAdditionalSourceRoots(); + @Internal public abstract RegularFileProperty getBaseline(); @@ -52,6 +56,8 @@ public abstract class VerifyApiSurfaceTask extends DefaultTask { @TaskAction public void verifySurface() { + AdditionalSourceRoots.requireExisting( + getOwningProjectPath().get(), getAdditionalSourceRoots().getFiles()); if (getUpdateApproved().get()) { throw new GradleException( getName() diff --git a/build-logic/src/test/java/dev/caskeleton/buildlogic/apisurface/ApiSurfaceConventionTest.java b/build-logic/src/test/java/dev/caskeleton/buildlogic/apisurface/ApiSurfaceConventionTest.java index ab4550d8..322761d9 100644 --- a/build-logic/src/test/java/dev/caskeleton/buildlogic/apisurface/ApiSurfaceConventionTest.java +++ b/build-logic/src/test/java/dev/caskeleton/buildlogic/apisurface/ApiSurfaceConventionTest.java @@ -1,5 +1,6 @@ package dev.caskeleton.buildlogic.apisurface; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -7,9 +8,12 @@ import java.nio.file.Files; import java.nio.file.Path; import org.gradle.testkit.runner.BuildResult; import org.gradle.testkit.runner.GradleRunner; +import org.gradle.testkit.runner.TaskOutcome; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; class ApiSurfaceConventionTest { @TempDir Path projectDir; @@ -173,25 +177,48 @@ class ApiSurfaceConventionTest { """); } - @Test - @org.junit.jupiter.api.DisplayName("없는 추가 source root는 건너뛰지 않고 그 경로를 짚어 실패한다") - void aMissingAdditionalSourceRootFailsInsteadOfShrinkingTheSurface() throws Exception { + @ParameterizedTest + @ValueSource( + strings = { + "verifyFixtureApiSurface", + "updateFixtureApiSurface -PapproveFixtureApiSurfaceChange" + }) + @org.junit.jupiter.api.DisplayName("없는 추가 source root는 건너뛰지 않고 surface 태스크가 그 경로를 짚어 실패한다") + void aMissingAdditionalSourceRootFailsInsteadOfShrinkingTheSurface(String arguments) + throws Exception { // given + declareAMissingAdditionalSourceRoot(); + + // when + BuildResult result = runner(arguments.split(" ")).buildAndFail(); + + // then + assertTrue( + result.getOutput().contains("additionalSourceRoots names a folder that does not exist"), + result.getOutput()); + } + + @Test + @org.junit.jupiter.api.DisplayName( + "없는 추가 source root가 surface를 읽지 않는 빌드의 설정을 막지 않는다(이미지 빌드의 의존성 단계는 소스가 없다)") + void aMissingAdditionalSourceRootDoesNotFailABuildThatReadsNoSurface() throws Exception { + // given + declareAMissingAdditionalSourceRoot(); + + // when + BuildResult result = runner("help").build(); + + // then + assertEquals(TaskOutcome.SUCCESS, result.task(":help").getOutcome(), result.getOutput()); + } + + private void declareAMissingAdditionalSourceRoot() throws Exception { Files.writeString( projectDir.resolve("build.gradle"), Files.readString(projectDir.resolve("build.gradle")) .replace( "baseline = file('surface.txt')", "baseline = file('surface.txt')\n additionalSourceRoots = ['../moved/src/main/java']")); - - // when - BuildResult result = - runner("updateFixtureApiSurface", "-PapproveFixtureApiSurfaceChange").buildAndFail(); - - // then - assertTrue( - result.getOutput().contains("additionalSourceRoots names a folder that does not exist"), - result.getOutput()); } private void writeConfiguredBuild(String sourceRoot) throws Exception { diff --git a/docs/work/reference/gates.md b/docs/work/reference/gates.md index c31d2948..1f38fc1d 100644 --- a/docs/work/reference/gates.md +++ b/docs/work/reference/gates.md @@ -72,7 +72,7 @@ workflow에만 있는 job: `pr.yml` `done`의 마지막 step과 `main.yml`의 `v | 패키지 규칙, 생성 명령 템플릿 | `verifyFeatureScaffold`(`mainCheck` 안) | | 마이그레이션 | persistence-jpa `check`, 잠금 대기 lane(`postgresqlMigrationLockWaitIntegrationTest`), 마이그레이션 lane | | 테스트 코드(ArchUnit fixture 포함) | 그 leaf `testQualityCheck` | -| compose·Dockerfile | `verifyComposeProfiles`(compose 렌더링), 실제 `docker build`와 기동(`scripts/verify.sh nightly`의 smoke) | +| compose·Dockerfile, build-logic 플러그인의 설정 단계 동작 | `verifyComposeProfiles`(compose 렌더링), 실제 `docker build`와 기동(`scripts/verify.sh nightly`의 smoke, 설정 단계만 바꿨으면 `bash scripts/run-compose-runtime-smoke.sh --lane off-local` 한 lane). 이미지의 의존성 단계는 소스 없이 모든 project를 설정한다(`build-logic/AGENTS.md`) | - ArchUnit 위반·허용 fixture도 `testQualityCheck`(SpotBugs)가 분석한다. 외부 라이브러리의 Lombok 클래스를 상속한 fixture는 SpotBugs가 `lombok.Generated`를 찾지 못해 실패한다(missing analysis class). 그런 상속 fixture는 두지 않는다. diff --git a/scripts/run-compose-runtime-smoke.sh b/scripts/run-compose-runtime-smoke.sh index 1092bc9a..c944db8d 100755 --- a/scripts/run-compose-runtime-smoke.sh +++ b/scripts/run-compose-runtime-smoke.sh @@ -91,6 +91,37 @@ PROJECT="" LANE_TMP="" LANE_EVIDENCE="" LANE_ARGS=() +# The step the lane is in and the evidence file that step writes. A failed lane reports both, because +# the job log is all a CI reader gets: the evidence directory dies with the job container, and the +# nightly matrix of 2026-11-13..17 failed all eighteen lanes with nothing in the log but their names. +LANE_STEP="" +LANE_STEP_LOG="" +lane_step() { LANE_STEP="$1"; LANE_STEP_LOG="${2:-}"; } + +# A few lines that name the cause, on stderr: the step, the end of that step's log, the state of each +# container and the last error lines of the stack. Everything printed is already redacted evidence. +# Called from the trap with `|| true`, so nothing in here can skip the teardown after it. +report_lane_failure() { + local lane + lane="$(basename "$(dirname "${LANE_EVIDENCE}")")" + echo "-- ${lane}: failed in step '${LANE_STEP:-unknown}' (evidence ${LANE_EVIDENCE})" + if [[ -n "${LANE_STEP_LOG}" && -s "${LANE_STEP_LOG}" ]]; then + redact_in_place "${LANE_STEP_LOG}" + echo "-- ${lane}: last lines of $(basename "${LANE_STEP_LOG}"):" + tail -n 25 "${LANE_STEP_LOG}" | cut -c1-300 | sed 's/^/ | /' + fi + if [[ -s "${LANE_EVIDENCE}/containers.json" ]]; then + echo "-- ${lane}: containers:" + jq -r 'if type == "array" then .[] else . end + | " | \(.Service) \(.State) exit=\(.ExitCode) health=\(.Health // "-") \(.Status)"' \ + "${LANE_EVIDENCE}/containers.json" 2>/dev/null + fi + if [[ -s "${LANE_EVIDENCE}/compose.log" ]]; then + echo "-- ${lane}: last error lines of compose.log:" + grep -E 'ERROR|FATAL|Exception|exited with code' "${LANE_EVIDENCE}/compose.log" | tail -n 15 \ + | cut -c1-300 | sed 's/^/ | /' + fi +} >&2 cleanup_lane() { local status=$? @@ -109,6 +140,9 @@ cleanup_lane() { # one artifact Wave 4's gate reads was the one that could not see them. grep -E ' (WARN|ERROR) ' "${LANE_EVIDENCE}/compose.log" 2>/dev/null \ >"${LANE_EVIDENCE}/warnings.log" || true + if [[ ${status} -ne 0 ]]; then + report_lane_failure || true + fi fi # This project only. Never a bare `down`, which would take out whatever else the developer has # running, and never a volume outside it. @@ -177,6 +211,7 @@ run_lane() { return 1 fi mkdir -p "${LANE_EVIDENCE}" + lane_step "prepare (secrets, certificates, overlay)" LANE_TMP="$(mktemp -d)" chmod 700 "${LANE_TMP}" @@ -405,14 +440,17 @@ run_lane() { # 2. render, then create. The static contract ran once for the whole run, before the first lane # (it renders every lane itself, so running it per lane rendered the matrix once per lane). + lane_step "render (compose config)" ( cd "${REPO_ROOT}" && docker compose -p "${PROJECT}" "${LANE_ARGS[@]}" config >"${LANE_EVIDENCE}/rendered.yml" ) redact_in_place "${LANE_EVIDENCE}/rendered.yml" # Build before create. The app service declares both `build:` and `image:`, so Compose reuses a # matching tag if one is lying around — and the first run of this lane did exactly that, starting # a jar built from a different state of the repository and failing on a class that no longer # exists in the tree. A lane that runs a stale image produces evidence about code nobody changed. + lane_step "build app image" "${LANE_EVIDENCE}/build.log" ( cd "${REPO_ROOT}" && docker compose -p "${PROJECT}" "${LANE_ARGS[@]}" build app \ >"${LANE_EVIDENCE}/build.log" 2>&1 ) + lane_step "create" ( cd "${REPO_ROOT}" && docker compose -p "${PROJECT}" "${LANE_ARGS[@]}" create >/dev/null ) # 3a. Anything that has to happen before the application starts, in the order the lane lists it. @@ -434,6 +472,7 @@ run_lane() { while read -r -u 4 pre_start; do [[ -z "${pre_start}" ]] && continue echo "-- ${id}: ${pre_start} (before start)" + lane_step "pre-start ${pre_start}" "${LANE_EVIDENCE}/${pre_start}.log" if ! ( cd "${REPO_ROOT}" && docker compose -p "${PROJECT}" "${LANE_ARGS[@]}" run --rm "${pre_start}" "${LANE_EVIDENCE}/${pre_start}.log" 2>&1; then redact_in_place "${LANE_EVIDENCE}/${pre_start}.log" @@ -451,6 +490,7 @@ run_lane() { # retries, and the silent-startup check below failed on a race rather than a defect (local-messaging, # main run 59, 2026-11-11; the same lane passed in the run before and on the desktop). backing="$(grep -vx app <<<"${long_running}" || true)" + lane_step "up --wait" if [[ -n "${backing}" ]]; then # shellcheck disable=SC2086 ( cd "${REPO_ROOT}" && docker compose -p "${PROJECT}" "${LANE_ARGS[@]}" up --wait --wait-timeout 300 ${backing} ) @@ -459,6 +499,7 @@ run_lane() { ( cd "${REPO_ROOT}" && docker compose -p "${PROJECT}" "${LANE_ARGS[@]}" up --wait --wait-timeout 300 ${long_running} ) await_application_report() { + lane_step "application report (health, info)" # The application's own answer, not this script's input. # # The management port, not the application port. Actuator runs on its own connector here so the @@ -536,6 +577,7 @@ run_lane() { second_smoke="$(jq -r '.handoff.secondPhaseSmoke' <<<"${lane_json}")" echo "-- ${id}: ${first_smoke} (handoff phase 1)" + lane_step "handoff phase 1" "${LANE_EVIDENCE}/notification-smoke-phase1.log" if ! ( cd "${REPO_ROOT}" && NOTIFICATION_SMOKE_PHASE="${first_smoke}" \ docker compose -p "${PROJECT}" "${LANE_ARGS[@]}" run --rm notification-smoke "${LANE_EVIDENCE}/notification-smoke-phase1.log" 2>&1; then @@ -549,6 +591,7 @@ run_lane() { # Recorded before the recreate: --force-recreate makes a new container whose restart count # starts at zero, so a kill during the first phase would otherwise leave no trace. + lane_step "handoff restart into the second phase" record_restarts phase1 || return 1 # The application only. The database and its volume stay up, which is the whole point. @@ -556,6 +599,7 @@ run_lane() { ( cd "${REPO_ROOT}" && docker compose -p "${PROJECT}" "${LANE_ARGS[@]}" stop app >/dev/null 2>&1 ) write_lane_overlay '{}' + lane_step "handoff restart into the second phase" ( cd "${REPO_ROOT}" && docker compose -p "${PROJECT}" "${LANE_ARGS[@]}" \ up -d --force-recreate --wait --wait-timeout 300 app ) await_application_report || return 1 @@ -572,6 +616,7 @@ run_lane() { # StartupWarningZeroTest asserts the same property in-process for the all-off composition. This is # the same assertion against a real container with the lane's switches actually on. local startup_log="${LANE_EVIDENCE}/startup.log" + lane_step "startup log is silent" "${startup_log}" docker compose -p "${PROJECT}" "${LANE_ARGS[@]}" logs --no-color app \ >"${startup_log}" 2>&1 || true redact_in_place "${startup_log}" @@ -595,6 +640,7 @@ run_lane() { while read -r -u 4 one_shot; do [[ -z "${one_shot}" ]] && continue echo "-- ${id}: ${one_shot}" + lane_step "one-shot ${one_shot}" "${LANE_EVIDENCE}/${one_shot}.log" if ! ( cd "${REPO_ROOT}" && docker compose -p "${PROJECT}" "${LANE_ARGS[@]}" run --rm "${one_shot}" "${LANE_EVIDENCE}/${one_shot}.log" 2>&1; then redact_in_place "${LANE_EVIDENCE}/${one_shot}.log" @@ -604,6 +650,7 @@ run_lane() { redact_in_place "${LANE_EVIDENCE}/${one_shot}.log" ran_one_shots=$((ran_one_shots + 1)) done 4< <(jq -r '.oneShotServices[]?' <<<"${lane_json}") + lane_step "one-shot count" if [[ "${ran_one_shots}" -ne "${declared_one_shots}" ]]; then echo "${id}: ran ${ran_one_shots} of ${declared_one_shots} one-shots; a partial lane is not a pass" >&2 return 1 @@ -619,6 +666,7 @@ run_lane() { # the restart itself has to be the failure. The peak memory is recorded beside it, so a lane that # is close to its limit is visible before it crosses it. local restarted="" + lane_step "no restart, no OOM kill" "${LANE_EVIDENCE}/restarts.txt" docker compose -p "${PROJECT}" "${LANE_ARGS[@]}" exec -T app cat /sys/fs/cgroup/memory.peak \ >"${LANE_EVIDENCE}/app-memory-peak-bytes.txt" 2>/dev/null || true record_restarts final || return 1 @@ -650,7 +698,9 @@ FAILED_LANES=() mkdir -p "${EVIDENCE_ROOT}" CONTRACT_LOG="${EVIDENCE_ROOT}/contract-${RUN_ID}.log" "${REPO_ROOT}/scripts/verify-compose-profile-contracts.sh" >"${CONTRACT_LOG}" 2>&1 \ - || { echo "run-compose-runtime-smoke: the static Compose contract failed; see ${CONTRACT_LOG}" >&2; exit 1; } + || { echo "run-compose-runtime-smoke: the static Compose contract failed; see ${CONTRACT_LOG}" >&2 + tail -n 25 "${CONTRACT_LOG}" | sed 's/^/ | /' >&2 + exit 1; } if [[ "${MODE}" == "lane" ]]; then lane_json="$(jq -c --arg id "${SELECTED_LANE}" '.lanes[] | select(.id == $id)' "${CONTRACTS}")"