문제 설정 키 금지 조각 검사(assertSafeConfigNames: TOKEN, COOKIE, SECRET 등)는 부팅 때 한 곳에서만 돈다. ece944d가 연 제품 키 경로로 PRODUCT_COOKIE_NOTICE 같은 키를 zod 필드·FE-REG-ENV 행·config/runtime 값으로 더하면 generateRuntimeConfig, 범위 테스트, check:registries가 모두 통과한다. 그 config.json으로 배포하면 모든 사용자가 부팅 실패 화면을 보고, 오류 코드 CONFIG_SECRET_NAME_REJECTED에는 키 이름이 없다(실험 E-4). 고른 방법 env-registry-coverage에 사례 하나를 더한다. V2 스키마가 읽는 키와 FE-REG-ENV 런타임 행 키 전부로, 값은 스키마 기본값(CAPABILITY_OVERRIDES의 중첩 키 포함)으로 문서를 만들어 assertSafeConfigNames에 넣는다. 실패 메시지가 키 이름을 말한다. 규칙은 매뉴얼 03 C절의 product-contracts.ts 항목에 적었다. 버린 대안 - product-contracts.ts 주석에 규칙 적기: 이 파일은 제품 소유이고 템플릿이 복사 뒤에 고치지 않는다고 약속한 파일이다. 동기화 때 충돌을 만든다. - generate-runtime-config에서도 검사: 스키마가 strict라 제품 키는 스키마 필드여야 들어가고, 그 키는 이 테스트가 먼저 잡는다. 같은 검사를 한 곳 더 두지 않았다. 위험·한계 - 부팅 오류 CONFIG_SECRET_NAME_REJECTED에 거절한 키 이름을 싣는 것은 하지 않았다(src/bootstrap/load-runtime-config.ts, 다른 작업 범위). - 제품 record 필드의 임의 중첩 키(값으로만 생기는 키)는 기본값에 없으면 이 테스트가 보지 못한다. 부팅 검사가 여전히 막는다. 검증 - E-4 재실행: PRODUCT_COOKIE_NOTICE를 제품 zod 필드와 행으로 더하면 이 사례가 "Forbidden client configuration key: PRODUCT_COOKIE_NOTICE"로 실패한다. 되돌리면 4건 통과. - eslint, verify:documentation 통과. Refs: docs/reviews/2026-11-03-maturity-review/07-contracts.md 07-04
85 lines
3.2 KiB
TypeScript
85 lines
3.2 KiB
TypeScript
import { isDeepStrictEqual } from "node:util";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
assertSafeConfigNames,
|
|
ENV_REGISTRY,
|
|
type EnvironmentDefinition,
|
|
} from "../../src/contracts/env.ts";
|
|
import { runtimeConfigV2ArtifactSchema } from "../../src/contracts/release-artifacts.ts";
|
|
|
|
const rows: Readonly<Record<string, EnvironmentDefinition>> = ENV_REGISTRY;
|
|
const shape = runtimeConfigV2ArtifactSchema.shape as Readonly<
|
|
Record<string, { safeParse(value: unknown): { success: boolean; data?: unknown } }>
|
|
>;
|
|
|
|
/**
|
|
* What the schema field says when the key is left out of config.json: a field
|
|
* that fails on `undefined` is required and has no default; one that passes
|
|
* has the parsed value as its default (`null` when it stays absent).
|
|
*/
|
|
function schemaDeclaration(key: string) {
|
|
const result = shape[key]!.safeParse(undefined);
|
|
return result.success
|
|
? { required: false, defaultValue: result.data ?? null }
|
|
: { required: true, defaultValue: null };
|
|
}
|
|
|
|
// 09-02. A key the deployed config.json may carry needs an FE-REG-ENV row, so
|
|
// check:registries sees it. A product key added to
|
|
// PRODUCT_RUNTIME_CONFIG_FIELDS without a PRODUCT_ENV_REGISTRY row fails here.
|
|
describe("FE-REG-ENV coverage", () => {
|
|
it("has a runtime row for every V2 runtime config key", () => {
|
|
const missing = Object.keys(shape).filter(
|
|
(key) => !Object.hasOwn(rows, key) || rows[key]!.phase !== "runtime",
|
|
);
|
|
|
|
expect(missing).toEqual([]);
|
|
});
|
|
|
|
// 1103/13-04, 0929/P-07-05. The other direction: a runtime row names a key
|
|
// the schema reads, and states its required flag and default as the schema
|
|
// field does, so the governed snapshot does not describe another document.
|
|
it("has no runtime row the V2 schema does not read", () => {
|
|
const extra = Object.keys(rows).filter(
|
|
(key) => rows[key]!.phase === "runtime" && !Object.hasOwn(shape, key),
|
|
);
|
|
|
|
expect(extra).toEqual([]);
|
|
});
|
|
|
|
it("states each runtime row's required flag and default as its schema field does", () => {
|
|
const differences = Object.keys(shape).flatMap((key) => {
|
|
const row = rows[key];
|
|
if (!row) return [];
|
|
const declared = { required: row.required, defaultValue: row.defaultValue };
|
|
const expected = schemaDeclaration(key);
|
|
return isDeepStrictEqual(declared, expected)
|
|
? []
|
|
: [`${key}: row ${JSON.stringify(declared)}, schema ${JSON.stringify(expected)}`];
|
|
});
|
|
|
|
expect(differences).toEqual([]);
|
|
});
|
|
|
|
// 1103/07-04. The boot refuses a config.json key with a credential-like
|
|
// name (`assertSafeConfigNames`). Checking every key the schema reads, with
|
|
// the nested keys of its defaults, fails here instead of at the first boot,
|
|
// and the error names the key.
|
|
it("names no runtime config key the boot would refuse", () => {
|
|
const keys = new Set([
|
|
...Object.keys(shape),
|
|
...Object.keys(rows).filter((key) => rows[key]!.phase === "runtime"),
|
|
]);
|
|
const document = Object.fromEntries(
|
|
[...keys].map((key) => [
|
|
key,
|
|
Object.hasOwn(shape, key) ? schemaDeclaration(key).defaultValue : null,
|
|
]),
|
|
);
|
|
|
|
expect(() => assertSafeConfigNames(document)).not.toThrow();
|
|
});
|
|
});
|