test(registry): 스키마 위반을 PR 레인에서 막고 누락 필드를 또렷이 알린다
pr / gradle (pull_request) Successful in 11m1s
pr / vulnerabilities (pull_request) Successful in 1m8s
pr / done (pull_request) Canceled after 0s

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"로 실패.
This commit is contained in:
donghyeon-ka
2026-11-12 07:19:00 +09:00
parent 156046e274
commit 6b1b246ee2
5 changed files with 56 additions and 3 deletions
+3 -1
View File
@@ -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
},
@@ -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"),
"""
@@ -37,6 +37,8 @@ import org.yaml.snakeyaml.Yaml;
* env-keys.yaml).
* <li>{@code actuator-contract:management-port-separated} — management.server.port=9001 ≠
* server.port=8080.
* <li>{@code actuator-contract:management-address-loopback} — management.server.address defaults
* to a loopback address (BE-CONFIG-001).
* <li>{@code actuator-contract:exposure-policy} — env/configprops/heapdump/threaddump/shutdown
* NOT in include set.
* <li>{@code actuator-contract:show-details-never} — health show-details = never. The actuator
@@ -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");
}
@@ -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.
*
* <p>{@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.
*
* <p>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);
}
}