fix!: 재리뷰가 찾은 결함과 색인에서 빠졌던 발견 5건을 고친다

문제: 성숙도 리뷰 수정을 다시 읽은 재리뷰(Critical 0, 회귀 0)가
Important 27건·Minor 41건을 찾았다. 수정이 새로 만든 결함이 많았다.
@SystemInvoked가 권한 규칙의 탈출구가 됐고, 데모 계정 거부가 정확히
prod일 때만 걸렸고, outbox 순서 번호가 업그레이드 때 뒤로 갔고,
GraphQL union 아래 복잡도가 0이었고, 서블릿 오류 응답이 success:true로
나갔고, 호출자 deadline이 breaker를 열었다. 원래 리뷰 색인이 06 영역
발견 5건(06-10~14)을 빠뜨려 그동안 처리되지 않았다.

방법: 영역별 7묶음이 test-driven-development 절차로 실패 테스트를
먼저 쓰고 고쳤다. 결정은 재리뷰 README 4절에 적었다: 순서 번호는 V21이
기록한 전역 floor부터, 데모 계정은 local·test·demo 허용 목록,
@SystemInvoked bean은 기동 실패, complete 단계 실패는
IDEMPOTENCY_COMPLETION_UNKNOWN(결과 불명), 캐시 조건부 쓰기는 별도
SCRIPT lane, strict lane 정책은 build cache 입력, 끝나지 않는 재시도
행은 원인 코드·지표·PARKED 절차. 레지스트리가 선언만 하고 아무 코드도
내보내지 않던 redis.capability.* 지표 6개는 빼고 runbook을 실제
지표(redis.lane.*) 기준으로 고쳤다.

위험·한계: V21을 V22 없이 직접 고쳤다(어느 배포에도 아직 없음). 이
브랜치의 V21을 적용한 개발 DB는 다시 만들어야 한다. 서블릿 오류
디스패치를 보안 체인이 허용한다. 발행·저장소 포트 시그니처가 바뀌어
파생 서비스 코드가 깨진다. prod에서 fixture-로 시작하는 설정값은
기동을 막는다. httpclient failure-injection lane의 main 단계 중복
실행은 이전 결정대로 남겼다. 실제 CI runner 실행은 확인하지 못했다.

검증: ci, mainCheck, :integrationCheck, -p optional-platforms ci
integrationCheck performanceCheck, :performanceCheck, :releaseCheck
(-PgitRevision), verify-compose-profile-contracts(18 lane) 통과.
첫 실행의 실패 2건(FindSecBugs 1, sample 동시 생성 테스트의 v4 event
id)은 고친 뒤 ci·integrationCheck·mainCheck를 다시 돌려 통과했다.

Refs: docs/reviews/2026-11-03-rereview/README.md 3·4·6·7절
BREAKING CHANGE: outbox 발행 포트와 저장소 포트 시그니처, 순서 번호
첫 값(V21 floor 다음), 샘플 데모 계정 프로필 허용 목록, 새 오류 코드
IDEMPOTENCY_COMPLETION_UNKNOWN, prod의 fixture- 값 거부, 기동 rule은
static·의존 없음이어야 한다.
This commit is contained in:
DongHyeonka
2026-11-03 23:29:35 +09:00
parent 7ef8d0b4cb
commit bbe944bd3c
406 changed files with 13493 additions and 1656 deletions
@@ -21,6 +21,11 @@ import org.springframework.core.env.Environment;
* dependencies, read only when the rule runs (the secret guard reads each module's {@code
* RequiredProductionSecrets} this way). A check that needs a live connection — the datasource
* version check — is not a rule; it stays a bean and is ordered before what it protects.
*
* <p>The runner enforces this: when creating or running a rule brings any other singleton into
* existence — a configuration class behind a non-static {@code @Bean} method, a settings bean the
* method takes — the boot fails with that bean's name, because a bean created before the
* post-processors would keep unbound settings for the whole run (RR-06-01).
*/
public interface StartupRule {
@@ -1,8 +1,11 @@
package dev.caskeleton.adapter.outbound.support.startup;
import java.util.ArrayList;
import java.util.IdentityHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.core.Ordered;
@@ -33,6 +36,17 @@ import org.springframework.core.env.Environment;
* static} {@code @Bean} method: it then pulls neither another bean nor its configuration class
* forward. Rules are found without eager initialization, so no {@code FactoryBean} — an entity
* manager factory, say — is created to learn its type.
*
* <h2>What a rule may not pull forward</h2>
*
* <p>A bean created this early is created without the post-processors: a JavaBean
* {@code @ConfigurationProperties} class it takes is never bound and keeps its defaults for the
* whole run, and so does every other consumer of that singleton (RR-06-01). The {@code static}
* declaration used to be a sentence in Javadoc; now the runner checks it. Any singleton that comes
* into existence while a rule is created or run fails the boot with its name — unless it is itself
* a {@link StartupRule} or a {@link RequiredProductionSecrets}, the two kinds that are declared
* {@code static} and argument-free for exactly this reason (a non-static one creates its
* configuration class, which is reported).
*/
public final class StartupRuleRunner implements BeanFactoryPostProcessor, Ordered {
@@ -49,8 +63,22 @@ public final class StartupRuleRunner implements BeanFactoryPostProcessor, Ordere
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) {
for (StartupRule rule : rules(beanFactory)) {
enforce(rule, environment);
IdentityHashMap<StartupRule, String> names = new IdentityHashMap<>();
List<StartupRule> rules = new ArrayList<>();
for (String name : beanFactory.getBeanNamesForType(StartupRule.class, true, false)) {
Set<String> before = singletons(beanFactory);
StartupRule rule = beanFactory.getBean(name, StartupRule.class);
refusePulledForward(beanFactory, name, "creating it", before);
rules.add(rule);
names.put(rule, name);
}
AnnotationAwareOrderComparator.sort(rules);
for (StartupRule rule : rules) {
String name = names.get(rule);
Set<String> before = singletons(beanFactory);
List<String> violations = rule.violations(environment);
refusePulledForward(beanFactory, name, "running it", before);
raise(rule, violations);
}
}
@@ -60,13 +88,46 @@ public final class StartupRuleRunner implements BeanFactoryPostProcessor, Ordere
return Ordered.HIGHEST_PRECEDENCE;
}
private static List<StartupRule> rules(ConfigurableListableBeanFactory beanFactory) {
List<StartupRule> rules = new ArrayList<>();
for (String name : beanFactory.getBeanNamesForType(StartupRule.class, true, false)) {
rules.add(beanFactory.getBean(name, StartupRule.class));
private static Set<String> singletons(ConfigurableListableBeanFactory beanFactory) {
return Set.of(beanFactory.getSingletonNames());
}
/**
* Fails when creating or running the rule {@code ruleName} brought a singleton into existence
* other than a rule or a {@link RequiredProductionSecrets}: that bean was built before the bean
* post-processors, so its settings are unbound and it is not proxied, for the rest of the run.
*/
private static void refusePulledForward(
ConfigurableListableBeanFactory beanFactory,
String ruleName,
String stage,
Set<String> before) {
Set<String> pulled = new LinkedHashSet<>();
for (String name : beanFactory.getSingletonNames()) {
if (!before.contains(name)
&& !beanFactory.isTypeMatch(name, StartupRule.class)
&& !beanFactory.isTypeMatch(name, RequiredProductionSecrets.class)) {
pulled.add(name);
}
}
AnnotationAwareOrderComparator.sort(rules);
return rules;
if (pulled.isEmpty()) {
return;
}
// A configuration error of the composition, so the configuration exit code (78): no
// environment fixes it, but neither does a retry, and it must not look like a crash.
throw StartupFailures.envValidation(
"startup rule '"
+ ruleName
+ "' created "
+ pulled
+ " while "
+ stage
+ ". Rules run before any bean post-processor exists, so a bean created then is never"
+ " bound to its @ConfigurationProperties and never proxied, for the whole run. Declare"
+ " the rule with a static @Bean method that takes only the Environment, the bean"
+ " factory, or an ObjectProvider of RequiredProductionSecrets beans that are"
+ " themselves static @Bean methods without parameters. A check that needs another"
+ " bean is not a rule: keep it a bean, ordered before what it protects.");
}
/**
@@ -77,8 +138,12 @@ public final class StartupRuleRunner implements BeanFactoryPostProcessor, Ordere
* @throws StartupFailureException when the rule found a violation
*/
public static void enforce(StartupRule rule, Environment environment) {
raise(rule, rule.violations(environment));
}
private static void raise(StartupRule rule, List<String> violations) {
StartupValidationContext.forPhase(rule.phase())
.rejectAll(rule.violations(environment))
.rejectAll(violations)
.failIfViolated(rule.summary(), rule.remedy());
}
}
@@ -50,7 +50,7 @@ class JsonIntegrationEventEncoderTest {
// then
assertThat(new String(event.envelopeBytes(), StandardCharsets.UTF_8))
.isEqualTo(
"{\"envelopeVersion\":1,\"eventId\":\"event-1\",\"contractId\":\"testkit.encoder-sample\","
"{\"envelopeVersion\":1,\"eventId\":\"01994e11-4d88-7000-8000-0000000000e1\",\"contractId\":\"testkit.encoder-sample\","
+ "\"payloadVersion\":1,\"logicalDestination\":\"sample-events\","
+ "\"aggregate\":{\"type\":\"sample\",\"id\":\"sample-1\",\"sequence\":3,\"eventIndex\":0},"
+ "\"occurredAt\":\"2026-09-28T01:02:03Z\",\"correlationId\":\"correlation-1\","
@@ -267,7 +267,7 @@ class JsonIntegrationEventEncoderTest {
private static IntegrationEventDraft<SamplePayload> draft(
SamplePayload payload, String destination) {
return new IntegrationEventDraft<>(
new EventId("event-1"),
new EventId("01994e11-4d88-7000-8000-0000000000e1"),
new ContractId("testkit.encoder-sample"),
1,
new LogicalDestinationId(destination),
@@ -7,8 +7,13 @@ import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
class StartupRuleRunnerTest {
@@ -103,6 +108,61 @@ class StartupRuleRunnerTest {
assertThat(seen).containsExactly("resolved");
}
@Test
@DisplayName("설정 bean을 받는 non-static 규칙은 바인딩 안 된 설정으로 조용히 돌지 않고, 앞당긴 bean 이름을 대며 기동을 실패시킨다")
void aRuleThatPullsASettingsBeanForwardFailsTheBootInsteadOfReadingUnboundSettings() {
// given
ProbeRuleConfig.SEEN.clear();
// when
runner
.withPropertyValues("probe.name=bound")
.withUserConfiguration(ProbeRuleConfig.class)
.run(
context -> {
// then
assertThat(ProbeRuleConfig.SEEN).doesNotContainNull();
assertThat(context.getStartupFailure())
.isInstanceOf(StartupFailureException.class)
.hasMessageContaining("probeRule")
.hasMessageContaining("probe-dev.caskeleton")
.hasMessageContaining("static");
});
}
@Test
@DisplayName("규칙이 실행 중에 꺼내는 RequiredProductionSecrets가 다른 bean을 앞당기면 기동이 실패한다")
void aProductionSecretsBeanThatPullsItsConfigurationForwardFailsTheBoot() {
// when
runner
.withUserConfiguration(SecretReadingRuleConfig.class, NonStaticSecretsConfig.class)
.run(
context -> {
// then
assertThat(context.getStartupFailure())
.isInstanceOf(StartupFailureException.class)
.hasMessageContaining("secretReadingRule")
.hasMessageContaining("NonStaticSecretsConfig");
});
}
@Test
@DisplayName("static이고 의존이 없는 RequiredProductionSecrets를 규칙이 실행 중에 읽는 것은 허용된다")
void aRuleMayReadStaticProductionSecretsWhenItRuns() {
// given
SecretReadingRuleConfig.SEEN.clear();
// when
runner
.withUserConfiguration(SecretReadingRuleConfig.class, StaticSecretsConfig.class)
.run(
context -> {
// then
assertThat(context).hasNotFailed();
assertThat(SecretReadingRuleConfig.SEEN).containsExactly("APP_PROBE_SECRET");
});
}
private static StartupRule rule(StartupPhase phase, String summary, List<String> violations) {
return new StartupRule() {
@Override
@@ -121,4 +181,87 @@ class StartupRuleRunnerTest {
}
};
}
/** The shape RR-06-01 found: a JavaBean settings class, and a rule that takes it. */
@ConfigurationProperties("probe")
public static class ProbeSettings {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(ProbeSettings.class)
static class ProbeRuleConfig {
static final List<String> SEEN = new ArrayList<>();
@Bean
StartupRule probeRule(ProbeSettings settings) {
return new StartupRule() {
@Override
public StartupPhase phase() {
return StartupPhase.ENV_VALIDATION;
}
@Override
public String summary() {
return "probe";
}
@Override
public List<String> violations(Environment environment) {
SEEN.add(settings.getName());
return List.of();
}
};
}
}
@Configuration(proxyBeanMethods = false)
static class SecretReadingRuleConfig {
static final List<String> SEEN = new ArrayList<>();
@Bean
static StartupRule secretReadingRule(ObjectProvider<RequiredProductionSecrets> secrets) {
return new StartupRule() {
@Override
public StartupPhase phase() {
return StartupPhase.ENV_VALIDATION;
}
@Override
public String summary() {
return "secrets";
}
@Override
public List<String> violations(Environment environment) {
secrets.orderedStream().forEach(each -> SEEN.addAll(each.requiredSecrets(environment)));
return List.of();
}
};
}
}
@Configuration(proxyBeanMethods = false)
static class StaticSecretsConfig {
@Bean
static RequiredProductionSecrets probeSecrets() {
return environment -> List.of("APP_PROBE_SECRET");
}
}
@Configuration(proxyBeanMethods = false)
static class NonStaticSecretsConfig {
@Bean
RequiredProductionSecrets probeSecrets() {
return environment -> List.of("APP_PROBE_SECRET");
}
}
}