From 6b1b246ee28ee2ae5eb3191c5e815d945cd01d63 Mon Sep 17 00:00:00 2001 From: donghyeon-ka Date: Thu, 12 Nov 2026 07:19:00 +0900 Subject: [PATCH] =?UTF-8?q?test(registry):=20=EC=8A=A4=ED=82=A4=EB=A7=88?= =?UTF-8?q?=20=EC=9C=84=EB=B0=98=EC=9D=84=20PR=20=EB=A0=88=EC=9D=B8?= =?UTF-8?q?=EC=97=90=EC=84=9C=20=EB=A7=89=EA=B3=A0=20=EB=88=84=EB=9D=BD=20?= =?UTF-8?q?=ED=95=84=EB=93=9C=EB=A5=BC=20=EB=98=90=EB=A0=B7=EC=9D=B4=20?= =?UTF-8?q?=EC=95=8C=EB=A6=B0=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ContractRegistrySchemaGovernanceTest(모든 레지스트리 행에 legal compatibility_impact + non-blank required_test 강제)는 @Tag(document-contract) 라 main 스테이지에서만 돈다. PR 레인은 repository-contract이고 그 입력에 docs/**가 빠져 있어, 잘못된 env-keys가 prCheck를 통과하고 병합 뒤 mainCheck 에서야 깨졌다(BE-CONFIG-001이 그렇게 새어 나갔다). 또 필드가 아예 빠지면 Set.of(...).contains(null)이 NPE를 던져 어느 행이 문제인지 알 수 없었다. - RegistrySchemaPullRequestGateTest(@Tag repository-contract): 같은 RegistryGovernanceCatalog.validate를 PR 레인에서 돌려 위반이 병합 전에 막히게 한다. - app build.gradle repositoryContractInputs에 docs/registries/**를 더해 레지스트리가 바뀌면 PR 레인이 재실행된다. - RegistryGovernanceCatalog: compatibility_impact가 null이면 "... must be one of [...], but was null"로 또렷이 실패한다(NPE 대신). 누락-필드 음성 사례를 ContractRegistrySchemaGovernanceTest에 더했다. - ManagementActuatorSecurityContractTest javadoc에 actuator-contract:management-address-loopback 항목을 더해 열거를 맞춘다. 버린 대안: required_test가 실제 시험을 가리키는지 범용 강제는 안 넣었다 — env-keys의 distinct required_test 193개 중 테스트 소스에 literal로 있는 건 7개뿐이라(나머지는 문서적 식별자), 범용 강제는 기존 186행을 깨뜨린다. 위험·한계: PR 레인이 docs/registries 변경에도 재실행된다(의도). 검증(desktop, 고친 env-keys): spotlessCheck·verifyEnvKeys·build-logic test· documentContractTest·repositoryContractTest(새 게이트)· ManagementActuatorSecurityContractTest·web-fileserver·web-advanced 모두 rc=0. RED 재현: 고치기 전 새 게이트가 "env-keys.yaml row MANAGEMENT_SERVER_PORT compatibility_impact must be one of [...], but was null"로 실패. --- src/bootstrap/app/build.gradle | 4 ++- .../ContractRegistrySchemaGovernanceTest.java | 10 ++++++ ...anagementActuatorSecurityContractTest.java | 2 ++ .../contract/RegistryGovernanceCatalog.java | 10 ++++-- .../RegistrySchemaPullRequestGateTest.java | 33 +++++++++++++++++++ 5 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/RegistrySchemaPullRequestGateTest.java diff --git a/src/bootstrap/app/build.gradle b/src/bootstrap/app/build.gradle index 0ef49b8b..e0697407 100644 --- a/src/bootstrap/app/build.gradle +++ b/src/bootstrap/app/build.gradle @@ -340,7 +340,9 @@ def repositoryRootForContractTests = rootProject.projectDir def repositoryContractExcludes = ['**/build/**', '**/.gradle/**', '**/node_modules/**', '.claude/worktrees/**'] def repositoryContractInputs = files( fileTree(repositoryRootForContractTests) { - include '.gitea/**', '.github/**', 'compose/**', 'scripts/**', '*.yml', '*.yaml', '*.example', '.tool-versions' + // docs/registries/** are machine contracts, not prose: a malformed registry must fail + // the pull request (RegistrySchemaPullRequestGateTest), so the lane reruns when one changes. + include '.gitea/**', '.github/**', 'compose/**', 'scripts/**', '*.yml', '*.yaml', 'docs/registries/**', '*.example', '.tool-versions' exclude '**/*.md' exclude repositoryContractExcludes }, diff --git a/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/ContractRegistrySchemaGovernanceTest.java b/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/ContractRegistrySchemaGovernanceTest.java index bed07c83..337509ce 100644 --- a/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/ContractRegistrySchemaGovernanceTest.java +++ b/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/ContractRegistrySchemaGovernanceTest.java @@ -278,6 +278,16 @@ class ContractRegistrySchemaGovernanceTest { required_test: test:metric """, "compatibility_impact"); + // A row that simply OMITS compatibility_impact must fail with the same descriptive error, not a + // NullPointerException from Set.of(...).contains(null) (W4 BE-CONFIG-001 stranded this field). + assertInvalidUniversalMetric( + tempDir.resolve("missing-compatibility"), + """ + - name: metric + owner_branch: owner + required_test: test:metric + """, + "compatibility_impact"); assertInvalidUniversalMetric( tempDir.resolve("blank-required-test"), """ diff --git a/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/ManagementActuatorSecurityContractTest.java b/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/ManagementActuatorSecurityContractTest.java index 723b8a55..ccd86de7 100644 --- a/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/ManagementActuatorSecurityContractTest.java +++ b/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/ManagementActuatorSecurityContractTest.java @@ -37,6 +37,8 @@ import org.yaml.snakeyaml.Yaml; * env-keys.yaml). *
  • {@code actuator-contract:management-port-separated} — management.server.port=9001 ≠ * server.port=8080. + *
  • {@code actuator-contract:management-address-loopback} — management.server.address defaults + * to a loopback address (BE-CONFIG-001). *
  • {@code actuator-contract:exposure-policy} — env/configprops/heapdump/threaddump/shutdown * NOT in include set. *
  • {@code actuator-contract:show-details-never} — health show-details = never. The actuator diff --git a/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/RegistryGovernanceCatalog.java b/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/RegistryGovernanceCatalog.java index b4125fdb..ba32bdc9 100644 --- a/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/RegistryGovernanceCatalog.java +++ b/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/RegistryGovernanceCatalog.java @@ -206,13 +206,19 @@ final class RegistryGovernanceCatalog { return; } Object compatibilityImpact = row.get("compatibility_impact"); - if (!LEGAL_COMPATIBILITY_IMPACT.contains(compatibilityImpact)) { + // A missing field is null; Set.of(...).contains(null) throws NPE, so a row that simply omits + // compatibility_impact must be caught here rather than surfacing as a cryptic + // NullPointerException + // (W4 BE-CONFIG-001: MANAGEMENT_SERVER_PORT lost this field to a misplaced sibling row). + if (compatibilityImpact == null || !LEGAL_COMPATIBILITY_IMPACT.contains(compatibilityImpact)) { throw new IllegalArgumentException( definition.fileName() + " row " + identity + " compatibility_impact must be one of " - + LEGAL_COMPATIBILITY_IMPACT); + + LEGAL_COMPATIBILITY_IMPACT + + ", but was " + + compatibilityImpact); } requireNonBlankString(definition, identity, row, "required_test"); } diff --git a/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/RegistrySchemaPullRequestGateTest.java b/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/RegistrySchemaPullRequestGateTest.java new file mode 100644 index 00000000..9d66d971 --- /dev/null +++ b/src/bootstrap/app/src/test/java/dev/caskeleton/bootstrap/contract/RegistrySchemaPullRequestGateTest.java @@ -0,0 +1,33 @@ +package dev.caskeleton.bootstrap.contract; + +import dev.caskeleton.bootstrap.contract.support.RepositoryContractResources; +import java.nio.file.Path; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; + +/** + * Pull-request gate for the contract-registry schema. + * + *

    {@link ContractRegistrySchemaGovernanceTest} owns the registry schema — every universal row + * must carry a legal {@code compatibility_impact} and a non-blank {@code required_test} — but it is + * tagged {@code document-contract}, so it runs only in the main stage. A malformed registry (W4 red + * team BE-CONFIG-001 inserted {@code MANAGEMENT_SERVER_ADDRESS} mid-row and stranded {@code + * MANAGEMENT_SERVER_PORT}'s {@code compatibility_impact} and {@code required_test} onto it) + * therefore passes {@code prCheck} and fails only after merge, in {@code mainCheck} — found after + * the merge it should have blocked. + * + *

    This runs the identical fail-closed {@link RegistryGovernanceCatalog} validation in the {@code + * repository-contract} lane, so the same defect blocks the pull request instead of landing on main. + * {@code docs/registries/**} is wired as a repository-contract input (this leaf's build.gradle) so + * the lane reruns whenever a registry changes rather than passing on a stale up-to-date result. + */ +@Tag("repository-contract") +class RegistrySchemaPullRequestGateTest { + + @Test + void everyContractRegistryPassesSchemaGovernanceBeforeMerge() throws Exception { + Path registriesDir = + RepositoryContractResources.fromSystemProperty().requireTrackedDirectory("docs/registries"); + RegistryGovernanceCatalog.validate(registriesDir); + } +}