문제 제품 확장 지점이 실행 경로에서는 동작했지만 타입 검사 경로에서 막혔다. (a) 문서대로 product-composition.ts에서 FeaturePlatformCapabilities를 보강하면 check:types:node가 실패했다. scripts 프로그램은 기능 코드를 끌어오지만 product-composition.ts는 끌어오지 않아 보강이 보이지 않았고, 오류는 기능 파일을 가리켰다. (b) 기본값 있는 제품 설정 키(.default()) 하나가 RuntimeConfig를 리터럴로 쓰는 템플릿 테스트 7개 파일의 타입을 깼다. 픽스처는 vi.mock이라 이 경로를 지나지 않았다. 고른 방법 - 제품 소유 빈 파일 src/features/product-capabilities.ts를 두고 FeaturePlatformCapabilities가 그 ProductFeaturePlatformCapabilities를 extends한다. feature-adapter-contribution.ts가 import하므로 기능을 보는 모든 프로그램에 들어간다. 문서만 "기능 파일 안에서 보강"으로 고치는 최소안은 capability 하나를 여러 기능이 쓸 때 보강 위치가 갈려 버렸다. 기존 제품 소유 파일에 칸을 더하지 않고 새 파일로 둔 이유: 템플릿은 복사 뒤 제품 소유 파일을 고치지 않으므로, 새 파일이어야 동기화 때 충돌 없이 들어간다. - tests/helpers/runtime-config.ts의 testRuntimeConfig: 템플릿 키는 테스트가 쓰고, 제품 키는 실제 스키마(validateRuntimeConfig)로 기본값을 채운다. 템플릿 테스트 6개 파일이 이것을 쓰고, release-coherence는 문서 타입을 z.input으로 바꿨다. 제품 키를 모두 Partial로 하는 대안은 기본값 키에도 undefined 처리를 강요해 버렸다. - tests/unit/product-extension-typecheck.test.ts: 복사본에 제품 소유 파일 세 개와 기능 하나를 실제 파일로 채우고 tsc app·node·test를 돈다. - 문서: starter-experience 표, 매뉴얼 01·03·patterns·create-feature, frontend-application-foundation, 계약 주석. 위험·한계 - 기본값 없는 필수 제품 키는 여전히 템플릿 테스트에서 실패한다(이제 타입이 아니라 helper가 이유를 적고 throw). 문서에 ".default() 또는 .optional()"을 적었다. - product-composition.ts 안에서 이미 보강한 다운스트림은 보강을 새 파일로 옮겨야 node 검사가 통과한다. 검증 - RED: 새 typecheck 테스트가 수정 전 app·node(보강 미연결)와 test(템플릿 테스트 8건, E-PROD와 같은 위치)에서 실패. - 수정 후 그 테스트와 영향받는 9개 테스트 파일 → 10 files / 83 tests 통과. - check:types(tsc app·node·test), check:architecture, eslint, verify:documentation PASS_SCOPED. Refs: docs/reviews/2026-11-03-maturity-review/09-app-core.md 09-02
59 lines
2.1 KiB
TypeScript
59 lines
2.1 KiB
TypeScript
import {
|
|
validateRuntimeConfig,
|
|
type RuntimeConfig,
|
|
} from "../../src/bootstrap/runtime-config-schema.ts";
|
|
import { PRODUCT_RUNTIME_CONFIG_FIELDS } from "../../src/contracts/product-contracts.ts";
|
|
|
|
type ProductKey = keyof typeof PRODUCT_RUNTIME_CONFIG_FIELDS;
|
|
|
|
/** The template's half of `RuntimeConfig`: what a template test writes. */
|
|
export type TemplateRuntimeConfig = Omit<RuntimeConfig, ProductKey>;
|
|
|
|
/** A V2 document with every template key, as in `config/runtime/local.json`. */
|
|
const TEMPLATE_DOCUMENT = Object.freeze({
|
|
APP_ENV: "local",
|
|
API_BASE_URL: "http://localhost:8080/",
|
|
REQUEST_TIMEOUT_MS: 10_000,
|
|
MAX_RETRY_ATTEMPTS: 2,
|
|
TELEMETRY_ENABLED: false,
|
|
AUTH_MODE: "demo",
|
|
CONFIG_SCHEMA_VERSION: "2.0",
|
|
RELEASE_MANIFEST_URL: "/release-manifest.json",
|
|
CAPABILITY_OVERRIDES: Object.freeze({
|
|
REALTIME: "DEFAULT",
|
|
WEB_WORKER: "DEFAULT",
|
|
SERVICE_WORKER: "DEFAULT",
|
|
OFFLINE_COMMANDS: "DEFAULT",
|
|
}),
|
|
FEATURE_OVERRIDES: Object.freeze({}),
|
|
});
|
|
|
|
function productDefaults(): Pick<RuntimeConfig, ProductKey> {
|
|
const validated = validateRuntimeConfig(TEMPLATE_DOCUMENT);
|
|
if (!validated.success) {
|
|
throw new TypeError(
|
|
`A product runtime-config key in src/contracts/product-contracts.ts has no default; give it .default() or .optional() (${validated.issues
|
|
.map((issue) => issue.path)
|
|
.join(", ")})`,
|
|
);
|
|
}
|
|
return Object.fromEntries(
|
|
Object.keys(PRODUCT_RUNTIME_CONFIG_FIELDS).flatMap((key) =>
|
|
Object.hasOwn(validated.data, key)
|
|
? [[key, Reflect.get(validated.data, key)]]
|
|
: [],
|
|
),
|
|
) as Pick<RuntimeConfig, ProductKey>;
|
|
}
|
|
|
|
/**
|
|
* 1103/09-02. The `RuntimeConfig` a template test composes with. Template
|
|
* tests used to write the whole type as a literal, so one product key with a
|
|
* `.default()` (a required key in the validated type) broke the types of
|
|
* every such test. A test writes the template's keys; the product's come from
|
|
* the real schema, with the defaults the product gave them.
|
|
*/
|
|
export function testRuntimeConfig(config: TemplateRuntimeConfig): RuntimeConfig {
|
|
return Object.freeze({ ...productDefaults(), ...config });
|
|
}
|