문제 제품 확장 지점이 실행 경로에서는 동작했지만 타입 검사 경로에서 막혔다. (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
329 lines
10 KiB
TypeScript
329 lines
10 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { verifyRollbackReleaseCoherence } from "../../scripts/drill-runbook.ts";
|
|
import { verifyReleaseArtifactsCoherence } from "../../scripts/verify-release.ts";
|
|
import type { InstalledContractPackageIdentity } from "../../src/contracts/external-contract-runtime.ts";
|
|
import { computeContractSetDigest } from "../../src/contracts/contract-set-canonical.ts";
|
|
import type {
|
|
ReleaseArtifact,
|
|
runtimeConfigArtifactSchema,
|
|
} from "../../src/contracts/release-artifacts.ts";
|
|
import type { z } from "../../src/contracts/zod.ts";
|
|
import {
|
|
compareReleaseToRuntime,
|
|
RELEASE_TOKEN_REGISTRY,
|
|
} from "../../src/contracts/release-tokens.ts";
|
|
|
|
const contractPackages = [
|
|
{
|
|
packageId: "@example/accounts",
|
|
version: "1.2.3",
|
|
digest: `sha256:${"1".repeat(64)}`,
|
|
runtimeProtocolVersion: 1,
|
|
sourceRevision: "a".repeat(40),
|
|
},
|
|
{
|
|
packageId: "@example/billing",
|
|
version: "2.3.4",
|
|
digest: `sha256:${"2".repeat(64)}`,
|
|
runtimeProtocolVersion: 1,
|
|
sourceRevision: "b".repeat(40),
|
|
},
|
|
] as const satisfies readonly InstalledContractPackageIdentity[];
|
|
|
|
const releaseV1 = {
|
|
schemaVersion: 1,
|
|
appVersion: "1.0.0",
|
|
buildId: "build-a",
|
|
commitSha: "abc1234",
|
|
configSchemaVersion: "1",
|
|
apiContractVersion: "1.4.0",
|
|
assetManifestHash: "assets-a",
|
|
releaseId: "release-a",
|
|
builtAt: "2026-08-01T00:00:00.000Z",
|
|
routeChunks: {},
|
|
} as const satisfies ReleaseArtifact;
|
|
|
|
/**
|
|
* 1103/09-02. A runtime config document as written, before validation: a
|
|
* product key with a `.default()` may be left out of it.
|
|
*/
|
|
type RuntimeConfigDocument = z.input<typeof runtimeConfigArtifactSchema>;
|
|
|
|
const runtimeV1 = {
|
|
APP_ENV: "local",
|
|
API_BASE_URL: "http://localhost:8080/",
|
|
REQUEST_TIMEOUT_MS: 10_000,
|
|
MAX_RETRY_ATTEMPTS: 2,
|
|
TELEMETRY_ENABLED: false,
|
|
AUTH_MODE: "external",
|
|
CONFIG_SCHEMA_VERSION: "1",
|
|
API_CONTRACT_VERSION: "1.6.0",
|
|
RELEASE_MANIFEST_URL: "/release-manifest.json",
|
|
BUILD_ID: "build-a",
|
|
RELEASE_ID: "release-a",
|
|
} as const satisfies RuntimeConfigDocument;
|
|
|
|
const runtimeV2 = {
|
|
APP_ENV: "local",
|
|
API_BASE_URL: "http://localhost:8080/",
|
|
REQUEST_TIMEOUT_MS: 10_000,
|
|
MAX_RETRY_ATTEMPTS: 2,
|
|
TELEMETRY_ENABLED: false,
|
|
AUTH_MODE: "external",
|
|
CONFIG_SCHEMA_VERSION: "2.0",
|
|
RELEASE_MANIFEST_URL: "/release-manifest.json",
|
|
BUILD_ID: "build-a",
|
|
RELEASE_ID: "release-a",
|
|
CAPABILITY_OVERRIDES: {
|
|
REALTIME: "DEFAULT",
|
|
WEB_WORKER: "DEFAULT",
|
|
SERVICE_WORKER: "DEFAULT",
|
|
OFFLINE_COMMANDS: "DEFAULT",
|
|
},
|
|
FEATURE_OVERRIDES: {},
|
|
} as const satisfies RuntimeConfigDocument;
|
|
|
|
async function releaseV2With(
|
|
packages: readonly InstalledContractPackageIdentity[],
|
|
setDigest?: `sha256:${string}`,
|
|
): Promise<ReleaseArtifact> {
|
|
return {
|
|
schemaVersion: 2,
|
|
appVersion: "1.0.0",
|
|
buildId: "build-a",
|
|
commitSha: "abc1234",
|
|
configSchemaVersion: "2.0",
|
|
assetManifestHash: "assets-a",
|
|
releaseId: "release-a",
|
|
builtAt: "2026-08-01T00:00:00.000Z",
|
|
routeChunks: {},
|
|
contractSet: {
|
|
setAlgorithm: "CA_CONTRACT_SET_V1",
|
|
setDigest: setDigest ?? (await computeContractSetDigest(packages)),
|
|
packages: [...packages],
|
|
},
|
|
};
|
|
}
|
|
|
|
function artifactReader(
|
|
entries: Readonly<Record<string, unknown | Error>>,
|
|
reads: string[] = [],
|
|
): (path: string) => Promise<unknown> {
|
|
return async (path) => {
|
|
reads.push(path);
|
|
const value = entries[path];
|
|
if (value === undefined) {
|
|
throw Object.assign(new Error(`missing ${path}`), { code: "ENOENT" });
|
|
}
|
|
if (value instanceof Error) throw value;
|
|
return value;
|
|
};
|
|
}
|
|
|
|
describe("release coherence", () => {
|
|
it("owns all nine release tokens and keeps builtAt diagnostic-only", () => {
|
|
// §5.2 adds contractSetDigest beside the legacy apiContractVersion scalar.
|
|
expect(Object.keys(RELEASE_TOKEN_REGISTRY)).toHaveLength(9);
|
|
expect(RELEASE_TOKEN_REGISTRY.contractSetDigest.compatibilityRole).toContain(
|
|
"multi-package",
|
|
);
|
|
expect(RELEASE_TOKEN_REGISTRY.builtAt.compatibilityRole).toContain(
|
|
"never cache identity",
|
|
);
|
|
});
|
|
|
|
it("compares the runtime config to the release structurally", () => {
|
|
const release = {
|
|
buildId: "build-a",
|
|
configSchemaVersion: "1.0",
|
|
apiContractVersion: "1.0",
|
|
assetManifestHash: "assets-a",
|
|
releaseId: "release-a",
|
|
};
|
|
expect(
|
|
compareReleaseToRuntime(release, {
|
|
BUILD_ID: "build-a",
|
|
CONFIG_SCHEMA_VERSION: "1.2",
|
|
API_CONTRACT_VERSION: "1.1",
|
|
RELEASE_ID: "release-a",
|
|
}),
|
|
).toMatchObject({ compatible: true, mismatches: [] });
|
|
});
|
|
|
|
it("rejects HTML-only rollback against a newer runtime config", () => {
|
|
const oldRelease = {
|
|
buildId: "build-old",
|
|
configSchemaVersion: "1.0",
|
|
apiContractVersion: "1.0",
|
|
assetManifestHash: "assets-old",
|
|
releaseId: "release-old",
|
|
};
|
|
expect(
|
|
compareReleaseToRuntime(oldRelease, {
|
|
BUILD_ID: "build-new",
|
|
CONFIG_SCHEMA_VERSION: "2.0",
|
|
API_CONTRACT_VERSION: "2.0",
|
|
RELEASE_ID: "release-new",
|
|
}),
|
|
).toMatchObject({
|
|
compatible: false,
|
|
mismatches: ["buildId", "configSchemaVersion", "apiContractVersion"],
|
|
});
|
|
});
|
|
|
|
it("gives release verification and rollback drills the same V1/V2 tamper verdicts", async () => {
|
|
const packageAdded = [
|
|
...contractPackages,
|
|
{
|
|
packageId: "@example/notifications",
|
|
version: "3.0.0",
|
|
digest: `sha256:${"3".repeat(64)}`,
|
|
runtimeProtocolVersion: 1,
|
|
sourceRevision: "c".repeat(40),
|
|
},
|
|
] as const satisfies readonly InstalledContractPackageIdentity[];
|
|
const packageRemoved = contractPackages.slice(0, 1);
|
|
const versionChanged = [
|
|
{ ...contractPackages[0], version: "1.2.4" },
|
|
contractPackages[1],
|
|
] as const satisfies readonly InstalledContractPackageIdentity[];
|
|
const packageDigestChanged = [
|
|
{
|
|
...contractPackages[0],
|
|
digest: `sha256:${"f".repeat(64)}`,
|
|
},
|
|
contractPackages[1],
|
|
] as const satisfies readonly InstalledContractPackageIdentity[];
|
|
const exactV2 = await releaseV2With(contractPackages);
|
|
const matrix = [
|
|
{
|
|
name: "V1 scalar success",
|
|
release: releaseV1,
|
|
runtime: runtimeV1,
|
|
expectedCompatible: true,
|
|
},
|
|
{
|
|
name: "V1 scalar mismatch",
|
|
release: releaseV1,
|
|
runtime: { ...runtimeV1, API_CONTRACT_VERSION: "2.0.0" },
|
|
expectedCompatible: false,
|
|
},
|
|
{
|
|
name: "V2 exact package set",
|
|
release: exactV2,
|
|
runtime: runtimeV2,
|
|
expectedCompatible: true,
|
|
},
|
|
{
|
|
name: "V2 exact package set in non-canonical manifest order",
|
|
release: await releaseV2With([...contractPackages].reverse()),
|
|
runtime: runtimeV2,
|
|
expectedCompatible: true,
|
|
},
|
|
{
|
|
name: "V2 package added",
|
|
release: await releaseV2With(packageAdded),
|
|
runtime: runtimeV2,
|
|
expectedCompatible: false,
|
|
},
|
|
{
|
|
name: "V2 package removed",
|
|
release: await releaseV2With(packageRemoved),
|
|
runtime: runtimeV2,
|
|
expectedCompatible: false,
|
|
},
|
|
{
|
|
name: "V2 package version tampered",
|
|
release: await releaseV2With(versionChanged),
|
|
runtime: runtimeV2,
|
|
expectedCompatible: false,
|
|
},
|
|
{
|
|
name: "V2 package digest tampered",
|
|
release: await releaseV2With(packageDigestChanged),
|
|
runtime: runtimeV2,
|
|
expectedCompatible: false,
|
|
},
|
|
{
|
|
name: "V2 set digest tampered",
|
|
release: await releaseV2With(
|
|
contractPackages,
|
|
`sha256:${"0".repeat(64)}`,
|
|
),
|
|
runtime: runtimeV2,
|
|
expectedCompatible: false,
|
|
},
|
|
];
|
|
|
|
for (const fixture of matrix) {
|
|
const input = { release: fixture.release, runtime: fixture.runtime };
|
|
const verifierVerdict = (
|
|
await verifyReleaseArtifactsCoherence({
|
|
readArtifact: artifactReader({
|
|
"dist/release-manifest.json": input.release,
|
|
"dist/config.json": input.runtime,
|
|
}),
|
|
contractPackages,
|
|
})
|
|
).coherence.compatible;
|
|
const rollbackDrillVerdict = (
|
|
await verifyRollbackReleaseCoherence({
|
|
readArtifact: artifactReader({
|
|
"dist/release-manifest.json": fixture.release,
|
|
"dist/config.json": fixture.runtime,
|
|
}),
|
|
contractPackages,
|
|
})
|
|
).coherence.compatible;
|
|
expect(verifierVerdict, `${fixture.name}: verifier`).toBe(
|
|
fixture.expectedCompatible,
|
|
);
|
|
expect(rollbackDrillVerdict, `${fixture.name}: rollback drill`).toBe(
|
|
fixture.expectedCompatible,
|
|
);
|
|
expect(rollbackDrillVerdict, `${fixture.name}: identical verdict`).toBe(
|
|
verifierVerdict,
|
|
);
|
|
}
|
|
});
|
|
|
|
// 13-03: the rollback drill checks the built release only. Reading the
|
|
// public/ placeholders when dist was absent let it pass without any build.
|
|
it("reads only the built dist pair and never falls back to public placeholders", async () => {
|
|
const exactV2 = await releaseV2With(contractPackages);
|
|
const validPublic = {
|
|
"public/release-manifest.json": exactV2,
|
|
"public/config.json": runtimeV2,
|
|
};
|
|
for (const primary of [
|
|
{},
|
|
{ "dist/config.json": runtimeV2 },
|
|
{ "dist/release-manifest.json": exactV2 },
|
|
{ "dist/release-manifest.json": new SyntaxError("invalid primary JSON"), "dist/config.json": runtimeV2 },
|
|
{ "dist/release-manifest.json": { ...exactV2, unexpected: "tampered" }, "dist/config.json": runtimeV2 },
|
|
]) {
|
|
const reads: string[] = [];
|
|
await expect(
|
|
verifyRollbackReleaseCoherence({
|
|
readArtifact: artifactReader({ ...primary, ...validPublic }, reads),
|
|
contractPackages,
|
|
}),
|
|
).rejects.toBeDefined();
|
|
expect(reads.some((read) => read.startsWith("public/"))).toBe(false);
|
|
}
|
|
|
|
const tamperedPrimary = await releaseV2With(contractPackages.slice(0, 1));
|
|
await expect(
|
|
verifyRollbackReleaseCoherence({
|
|
readArtifact: artifactReader({
|
|
"dist/release-manifest.json": tamperedPrimary,
|
|
"dist/config.json": runtimeV2,
|
|
...validPublic,
|
|
}),
|
|
contractPackages,
|
|
}),
|
|
).resolves.toMatchObject({ coherence: { compatible: false } });
|
|
});
|
|
});
|