문제 제품 확장 지점이 실행 경로에서는 동작했지만 타입 검사 경로에서 막혔다. (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
251 lines
6.8 KiB
TypeScript
251 lines
6.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
loadReleaseManifest,
|
|
ReleaseManifestError,
|
|
} from "../../src/bootstrap/load-release-manifest.ts";
|
|
import { computeContractSetDigest } from "../../src/contracts/contract-set-canonical.ts";
|
|
import { EXPECTED_CONTRACT_SET_PACKAGES } from "../../src/features/installed-contract-contributions.ts";
|
|
import { testRuntimeConfig } from "../helpers/runtime-config.ts";
|
|
|
|
const EMPTY_SET_DIGEST = await computeContractSetDigest([]);
|
|
// 16-02. The build compiles the installed features' packages, so a coherent
|
|
// manifest carries exactly that set, whatever is installed.
|
|
const INSTALLED_SET_DIGEST = await computeContractSetDigest(
|
|
EXPECTED_CONTRACT_SET_PACKAGES,
|
|
);
|
|
|
|
const runtime: Parameters<typeof loadReleaseManifest>[0] = {
|
|
build: {
|
|
buildId: "build-a",
|
|
commitSha: "abc123",
|
|
routerBasePath: "/",
|
|
runtimeConfigUrl: "/config.json",
|
|
},
|
|
config: testRuntimeConfig({
|
|
APP_ENV: "local",
|
|
API_BASE_URL: "https://api.test",
|
|
REQUEST_TIMEOUT_MS: 10_000,
|
|
MAX_RETRY_ATTEMPTS: 2,
|
|
TELEMETRY_ENABLED: false,
|
|
AUTH_MODE: "external",
|
|
RELEASE_MANIFEST_URL: "/release-manifest.json",
|
|
BUILD_ID: "build-a",
|
|
RELEASE_ID: "release-a",
|
|
CONFIG_SCHEMA_VERSION: "2.0",
|
|
CAPABILITY_OVERRIDES: {
|
|
REALTIME: "DEFAULT",
|
|
WEB_WORKER: "DEFAULT",
|
|
SERVICE_WORKER: "DEFAULT",
|
|
OFFLINE_COMMANDS: "DEFAULT",
|
|
},
|
|
FEATURE_OVERRIDES: {},
|
|
}),
|
|
configSchema: "V2",
|
|
validationDurationMs: 0,
|
|
};
|
|
const manifest = {
|
|
schemaVersion: 2,
|
|
appVersion: "0.1.0",
|
|
buildId: "build-a",
|
|
commitSha: "abc123",
|
|
configSchemaVersion: "2.0",
|
|
assetManifestHash: "hash-a",
|
|
releaseId: "release-a",
|
|
builtAt: "2026-07-25T00:00:00Z",
|
|
routeChunks: { "route-home": "assets/home.js" },
|
|
contractSet: {
|
|
setAlgorithm: "CA_CONTRACT_SET_V1",
|
|
setDigest: INSTALLED_SET_DIGEST,
|
|
packages: EXPECTED_CONTRACT_SET_PACKAGES,
|
|
},
|
|
};
|
|
|
|
const runtimeV1: Parameters<typeof loadReleaseManifest>[0] = {
|
|
...runtime,
|
|
config: {
|
|
...runtime.config,
|
|
CONFIG_SCHEMA_VERSION: "1",
|
|
LEGACY_API_CONTRACT_VERSION: "1",
|
|
},
|
|
configSchema: "V1",
|
|
};
|
|
|
|
const manifestV1 = {
|
|
schemaVersion: 1,
|
|
appVersion: "0.1.0",
|
|
buildId: "build-a",
|
|
commitSha: "abc123",
|
|
configSchemaVersion: "1",
|
|
apiContractVersion: "1",
|
|
assetManifestHash: "hash-a",
|
|
releaseId: "release-a",
|
|
builtAt: "2026-07-25T00:00:00Z",
|
|
routeChunks: { "route-home": "assets/home.js" },
|
|
};
|
|
|
|
function jsonResponse(body: unknown): Response {
|
|
return new Response(JSON.stringify(body), {
|
|
headers: { "content-type": "application/json" },
|
|
});
|
|
}
|
|
|
|
describe("release manifest boot boundary", () => {
|
|
it("loads a coherent release tuple", async () => {
|
|
await expect(
|
|
loadReleaseManifest(
|
|
runtime,
|
|
{ fetcher: async () => jsonResponse(manifest) },
|
|
),
|
|
).resolves.toMatchObject({ releaseId: "release-a" });
|
|
});
|
|
|
|
it("fails before mount when release and runtime differ", async () => {
|
|
await expect(
|
|
loadReleaseManifest(
|
|
runtime,
|
|
{
|
|
fetcher: async () =>
|
|
jsonResponse({ ...manifest, buildId: "build-b" }),
|
|
},
|
|
),
|
|
).rejects.toMatchObject({
|
|
kind: "BUILD_MISMATCH",
|
|
code: "MANIFEST_BUILD_MISMATCH",
|
|
});
|
|
});
|
|
|
|
it.each([
|
|
[
|
|
{ releaseId: "release-b" },
|
|
{},
|
|
"RELEASE_MISMATCH",
|
|
"MANIFEST_RELEASE_MISMATCH",
|
|
],
|
|
[
|
|
{},
|
|
{ expectedAssetManifestHash: "different" },
|
|
"ASSET_MISMATCH",
|
|
"MANIFEST_ASSET_MISMATCH",
|
|
],
|
|
])(
|
|
"classifies tuple mismatch %# without a generic deploy error",
|
|
async (manifestOverride, options, kind, code) => {
|
|
await expect(
|
|
loadReleaseManifest(
|
|
runtime,
|
|
{
|
|
fetcher: async () =>
|
|
jsonResponse({ ...manifest, ...manifestOverride }),
|
|
...options,
|
|
},
|
|
),
|
|
).rejects.toMatchObject({ kind, code });
|
|
},
|
|
);
|
|
|
|
it.each(["3.0", "9.0"])(
|
|
"rejects unsupported V2 manifest config version %s at the schema boundary",
|
|
async (configSchemaVersion) => {
|
|
await expect(
|
|
loadReleaseManifest(runtime, {
|
|
fetcher: async () =>
|
|
jsonResponse({ ...manifest, configSchemaVersion }),
|
|
}),
|
|
).rejects.toMatchObject({
|
|
kind: "RELEASE_MANIFEST_FAILURE",
|
|
code: "MANIFEST_SCHEMA_INVALID",
|
|
});
|
|
},
|
|
);
|
|
|
|
it("rejects a contract set the build did not compile", async () => {
|
|
await expect(
|
|
loadReleaseManifest(runtime, {
|
|
fetcher: async () =>
|
|
jsonResponse({
|
|
...manifest,
|
|
contractSet: {
|
|
setAlgorithm: "CA_CONTRACT_SET_V1",
|
|
setDigest: EMPTY_SET_DIGEST,
|
|
packages: [
|
|
{
|
|
packageId: "@org-contracts/worklog",
|
|
version: "1.2.3",
|
|
digest: `sha256:${"a".repeat(64)}`,
|
|
runtimeProtocolVersion: 1,
|
|
sourceRevision: "abc1234",
|
|
},
|
|
],
|
|
},
|
|
}),
|
|
}),
|
|
).rejects.toMatchObject({
|
|
kind: "CONTRACT_SET_MISMATCH",
|
|
code: "CONTRACT_SET_PACKAGE_UNEXPECTED",
|
|
});
|
|
});
|
|
|
|
it("still reads a V1 manifest during the compatibility window", async () => {
|
|
await expect(
|
|
loadReleaseManifest(
|
|
runtimeV1,
|
|
{
|
|
fetcher: async () => jsonResponse(manifestV1),
|
|
},
|
|
),
|
|
).resolves.toMatchObject({ schemaVersion: 1, contractSet: null });
|
|
});
|
|
|
|
it("rejects a V2 runtime paired with a V1 manifest", async () => {
|
|
await expect(
|
|
loadReleaseManifest(runtime, {
|
|
fetcher: async () => jsonResponse({
|
|
...manifestV1,
|
|
configSchemaVersion: "2.0",
|
|
}),
|
|
}),
|
|
).rejects.toMatchObject({
|
|
kind: "PROTOCOL_PAIR_MISMATCH",
|
|
code: "MANIFEST_PROTOCOL_PAIR_MISMATCH",
|
|
});
|
|
});
|
|
|
|
it("rejects a V1 runtime paired with a V2 manifest", async () => {
|
|
await expect(
|
|
loadReleaseManifest(runtimeV1, {
|
|
fetcher: async () => jsonResponse(manifest),
|
|
}),
|
|
).rejects.toMatchObject({
|
|
kind: "PROTOCOL_PAIR_MISMATCH",
|
|
code: "MANIFEST_PROTOCOL_PAIR_MISMATCH",
|
|
});
|
|
});
|
|
|
|
it("requires matching legacy scalar versions for a V1 pair", async () => {
|
|
await expect(
|
|
loadReleaseManifest(runtimeV1, {
|
|
fetcher: async () => jsonResponse({
|
|
...manifestV1,
|
|
apiContractVersion: "2",
|
|
}),
|
|
}),
|
|
).rejects.toMatchObject({
|
|
kind: "API_CONTRACT_MISMATCH",
|
|
code: "MANIFEST_API_CONTRACT_MISMATCH",
|
|
});
|
|
});
|
|
|
|
it("rejects a manifest without a complete route chunk map", async () => {
|
|
const malformed = Object.fromEntries(
|
|
Object.entries(manifest).filter(([key]) => key !== "routeChunks"),
|
|
);
|
|
await expect(
|
|
loadReleaseManifest(
|
|
runtime,
|
|
{ fetcher: async () => jsonResponse(malformed) },
|
|
),
|
|
).rejects.toBeInstanceOf(ReleaseManifestError);
|
|
});
|
|
});
|