문제 제품 확장 지점이 실행 경로에서는 동작했지만 타입 검사 경로에서 막혔다. (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
125 lines
4.2 KiB
TypeScript
125 lines
4.2 KiB
TypeScript
import { spawnSync } from "node:child_process";
|
|
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import { createRuntimeAdapters } from "../../src/bootstrap/runtime-adapters.ts";
|
|
import { COMPILED_PRODUCT_FEATURE_IDS } from "../../src/features/installed-product-manifest.ts";
|
|
import { generateRuntimeConfig } from "../../scripts/generate-runtime-config.ts";
|
|
import { testRuntimeConfig } from "../helpers/runtime-config.ts";
|
|
|
|
type Runtime = Parameters<typeof createRuntimeAdapters>[0]["runtime"];
|
|
|
|
// 09-09. An override key this build does not declare stays inert (one runtime
|
|
// document may serve several builds), but a misspelt kill switch used to leave
|
|
// the feature running without a trace.
|
|
const MISSPELT = "reference-featrue";
|
|
|
|
function runtimeWith(overrides: Readonly<Record<string, "DISABLED">>): Runtime {
|
|
return {
|
|
config: testRuntimeConfig({
|
|
APP_ENV: "local",
|
|
API_BASE_URL: "http://localhost:8080",
|
|
TELEMETRY_ENABLED: false,
|
|
AUTH_MODE: "demo",
|
|
REQUEST_TIMEOUT_MS: 1000,
|
|
MAX_RETRY_ATTEMPTS: 0,
|
|
RELEASE_MANIFEST_URL: "/release-manifest.json",
|
|
CONFIG_SCHEMA_VERSION: "2.0",
|
|
CAPABILITY_OVERRIDES: {
|
|
REALTIME: "DEFAULT",
|
|
WEB_WORKER: "DEFAULT",
|
|
SERVICE_WORKER: "DEFAULT",
|
|
OFFLINE_COMMANDS: "DEFAULT",
|
|
},
|
|
FEATURE_OVERRIDES: overrides,
|
|
}),
|
|
configSchema: "V2",
|
|
build: {
|
|
buildId: "build-a",
|
|
commitSha: "abc123",
|
|
routerBasePath: "/",
|
|
runtimeConfigUrl: "/config.json",
|
|
},
|
|
validationDurationMs: 0,
|
|
};
|
|
}
|
|
|
|
const release = {
|
|
schemaVersion: 2,
|
|
appVersion: "0.1.0",
|
|
buildId: "build-a",
|
|
commitSha: "abc123",
|
|
configSchemaVersion: "2.0",
|
|
contractSet: {
|
|
setAlgorithm: "CA_CONTRACT_SET_V1",
|
|
setDigest: `sha256:${"0".repeat(64)}`,
|
|
packages: [],
|
|
},
|
|
assetManifestHash: "hash-a",
|
|
releaseId: "release-a",
|
|
builtAt: "2026-07-25T00:00:00Z",
|
|
routeChunks: {},
|
|
} as Parameters<typeof createRuntimeAdapters>[0]["release"];
|
|
|
|
describe("unknown feature override keys (09-09)", () => {
|
|
it("records one diagnostic per key the build does not declare", async () => {
|
|
const declared = COMPILED_PRODUCT_FEATURE_IDS[0];
|
|
const adapters = await createRuntimeAdapters({
|
|
runtime: runtimeWith({
|
|
[MISSPELT]: "DISABLED",
|
|
...(declared === undefined ? {} : { [declared]: "DISABLED" }),
|
|
}),
|
|
release,
|
|
host: {},
|
|
});
|
|
try {
|
|
const unknown = adapters.outputPorts.diagnostics
|
|
.entries()
|
|
.filter((entry) => entry.eventId === "feature.override.unknown");
|
|
expect(unknown).toEqual([
|
|
expect.objectContaining({
|
|
level: "warn",
|
|
context: { feature_override_key: MISSPELT },
|
|
}),
|
|
]);
|
|
} finally {
|
|
adapters.infrastructure.dispose();
|
|
}
|
|
});
|
|
|
|
it("warns in the admission record without refusing the artifact", async () => {
|
|
const root = await mkdtemp(path.join(tmpdir(), "admission-override-"));
|
|
try {
|
|
const config = await generateRuntimeConfig("local", {});
|
|
await mkdir(path.join(root, "dist"), { recursive: true });
|
|
await writeFile(
|
|
path.join(root, "dist/config.json"),
|
|
JSON.stringify({ ...config, FEATURE_OVERRIDES: { [MISSPELT]: "DISABLED" } }),
|
|
);
|
|
const result = spawnSync(
|
|
process.execPath,
|
|
[path.resolve("scripts/check-release-admission.ts")],
|
|
{
|
|
cwd: root,
|
|
encoding: "utf8",
|
|
env: { ...process.env, APP_PROFILE: "local", RELEASE_TARGET: "local" },
|
|
},
|
|
);
|
|
expect(result.status, result.stderr).toBe(0);
|
|
expect(result.stderr).toContain(MISSPELT);
|
|
const record = JSON.parse(
|
|
await readFile(path.join(root, "artifacts/release/deployment-admission.json"), "utf8"),
|
|
) as { status: string; warnings: { field: string; reason: string }[] };
|
|
expect(record.status).toBe("ADMITTED");
|
|
expect(record.warnings).toEqual([
|
|
expect.objectContaining({ field: `FEATURE_OVERRIDES.${MISSPELT}` }),
|
|
]);
|
|
} finally {
|
|
await rm(root, { recursive: true, force: true });
|
|
}
|
|
});
|
|
});
|