From 86b4a328c03dda07e1e785f06d6d0566d894af82 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 13 Nov 2026 18:46:44 +0900 Subject: [PATCH] =?UTF-8?q?fix(release):=20route=20=EC=B2=AD=ED=81=AC?= =?UTF-8?q?=EB=A5=BC=20=EC=B2=AD=ED=81=AC=20=EC=9D=B4=EB=A6=84=EC=9D=B4=20?= =?UTF-8?q?=EC=95=84=EB=8B=88=EB=9D=BC=20=ED=8E=98=EC=9D=B4=EC=A7=80=20?= =?UTF-8?q?=EC=86=8C=EC=8A=A4=20=ED=8C=8C=EC=9D=BC=EB=A1=9C=20=EC=B0=BE?= =?UTF-8?q?=EB=8A=94=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: build manifest 작성과 release 검사 둘은 route 청크를 Vite manifest `entry.name === moduleId`로 찾았다. 청크 이름이 선언 없이 계약이 되어, vite.config.ts가 route 청크에 이름을 붙이면(tech-log 방식) 빌드가 이유 없는 `Missing built route chunk: `로 멈췄다. 고친 것: `scripts/lib/build-manifest-outputs.ts`의 `findRouteChunk` 하나가 dynamic entry 중 소스 파일(manifest 키 또는 `src`) 이름이 route runtime의 `moduleId`인 것을 찾는다. 셋(build manifest, verify-release, local release evidence)이 그것을 쓴다. 새 파일을 두지 않은 것은 release 후보 archive의 검증기 소스 목록(`config/ci/gates.json` member 집합)을 바꾸지 않기 위해서다. 못 찾으면 규칙("moduleId는 그 라우트가 import하는 페이지 파일 이름")을, 둘이면 두 소스 경로를 적는다. 위험·한계: moduleId가 페이지 파일 이름이라는 규약은 그대로다(생성기와 `route-runtime.tsx`가 이미 그렇게 쓴다). 검증: desktop `node scripts/run-vitest.ts run tests/unit/route-chunks.test.ts` 통과(다른 청크 이름, 없음, 중복, 계약 없음, 세 사용처). Refs: 0929/13-03 --- scripts/generate-build-manifest.ts | 15 +++--- scripts/lib/build-manifest-outputs.ts | 49 ++++++++++++++++++ scripts/lib/local-release-evidence.ts | 13 +++-- scripts/verify-release.ts | 10 ++-- tests/unit/route-chunks.test.ts | 74 +++++++++++++++++++++++++++ 5 files changed, 142 insertions(+), 19 deletions(-) create mode 100644 tests/unit/route-chunks.test.ts diff --git a/scripts/generate-build-manifest.ts b/scripts/generate-build-manifest.ts index 2d47f7d7..58c1de8a 100644 --- a/scripts/generate-build-manifest.ts +++ b/scripts/generate-build-manifest.ts @@ -20,7 +20,7 @@ import { buildDate, } from "./lib/build-environment.ts"; import { writeValidatedJsonArtifact } from "./lib/validated-json-artifact.ts"; -import { CANONICAL_VITE_MANIFEST_PATH } from "./lib/build-manifest-outputs.ts"; +import { CANONICAL_VITE_MANIFEST_PATH, findRouteChunk } from "./lib/build-manifest-outputs.ts"; import { runOutputPath } from "./lib/run-isolation.ts"; assertCiBuildEnvironment(process.env); @@ -68,14 +68,13 @@ const routeChunks: Record = {}; const runtimeContracts: Readonly> = ROUTE_RUNTIME_CONTRACT; for (const definition of Object.values(ROUTE_REGISTRY)) { - const runtime = runtimeContracts[definition.routeId]; - const asset = Object.values(viteManifestObject).find( - (entry) => entry.name === runtime?.moduleId && entry.isDynamicEntry, + const chunk = findRouteChunk( + viteManifestObject, + definition.routeId, + runtimeContracts[definition.routeId]?.moduleId, ); - if (!runtime || !asset?.file) { - throw new Error(`Missing built route chunk: ${definition.routeId}`); - } - routeChunks[definition.chunkId] = asset.file; + if ("error" in chunk) throw new Error(chunk.error); + routeChunks[definition.chunkId] = chunk.file; } const runtimeConfigJsonSchema = z.toJSONSchema(runtimeConfigV2ArtifactSchema); diff --git a/scripts/lib/build-manifest-outputs.ts b/scripts/lib/build-manifest-outputs.ts index 0f7dea44..bdd8f268 100644 --- a/scripts/lib/build-manifest-outputs.ts +++ b/scripts/lib/build-manifest-outputs.ts @@ -186,3 +186,52 @@ export async function verifyBuildManifestOutputs( } return mismatches; } + +/** + * 0929/13-03. The built chunk of a route's lazy page, for the build manifest + * and the two release checks that compare its `routeChunks`. A route runtime's + * `moduleId` is the file name of the page it imports + * (`src/presentation/routes/route-runtime.tsx`, a generated feature's + * `-route-runtime.ts`), so the chunk is the dynamic entry whose source + * file — the Vite manifest key — has that name. The chunk's own `name` used to + * be matched instead, so a chunk-naming change in vite.config.ts stopped the + * build with a reason-less `Missing built route chunk`. + */ +export type RouteChunkLookup = Readonly<{ file: string }> | Readonly<{ error: string }>; + +const SOURCE_EXTENSION = /\.(?:tsx|ts|jsx|js)$/u; + +export function findRouteChunk( + manifest: Readonly>, + routeId: string, + moduleId: string | undefined, +): RouteChunkLookup { + if (moduleId === undefined) { + return { error: `Missing built route chunk: ${routeId} has no route runtime contract (ROUTE_RUNTIME_CONTRACT)` }; + } + const matches: { source: string; file: string }[] = []; + for (const [key, entry] of Object.entries(manifest)) { + if (!isManifestRecord(entry) || entry["isDynamicEntry"] !== true || typeof entry["file"] !== "string") continue; + const source = typeof entry["src"] === "string" ? entry["src"] : key; + if (path.posix.basename(source).replace(SOURCE_EXTENSION, "") === moduleId) { + matches.push({ source, file: entry["file"] }); + } + } + if (matches.length === 1) return { file: matches[0]!.file }; + if (matches.length === 0) { + return { + error: + `Missing built route chunk: ${routeId}: no lazily imported module in the Vite manifest has the source ` + + `file ${moduleId}.tsx (or .ts). A route runtime's moduleId must be the file name of the page it imports.`, + }; + } + return { + error: + `Ambiguous built route chunk: ${routeId}: the lazily imported modules ` + + `${matches.map(({ source }) => source).join(", ")} are all named ${moduleId}.`, + }; +} + +function isManifestRecord(value: unknown): value is Record { + return typeof value === "object" && value !== null && !Array.isArray(value); +} diff --git a/scripts/lib/local-release-evidence.ts b/scripts/lib/local-release-evidence.ts index 9149872e..3e1423c9 100644 --- a/scripts/lib/local-release-evidence.ts +++ b/scripts/lib/local-release-evidence.ts @@ -26,6 +26,7 @@ import { } from "../contracts/release-artifacts.ts"; import { CANONICAL_VITE_MANIFEST_PATH, + findRouteChunk, verifyBuildManifestOutputs, } from "./build-manifest-outputs.ts"; import { assertMatchesJsonSchema } from "./json-schema.ts"; @@ -1255,14 +1256,12 @@ async function verifyReleaseOutputs( const runtimeContracts: Readonly> = ROUTE_RUNTIME_CONTRACT; for (const definition of Object.values(ROUTE_REGISTRY)) { - const runtime = runtimeContracts[definition.routeId]; - const viteEntry = Object.values(viteManifest).find( - (entry) => - isRecord(entry) && - entry.name === runtime?.moduleId && - entry.isDynamicEntry === true, + const chunk = findRouteChunk( + viteManifest, + definition.routeId, + runtimeContracts[definition.routeId]?.moduleId, ); - const file = isRecord(viteEntry) ? viteEntry.file : null; + const file = "error" in chunk ? null : chunk.file; if ( typeof file !== "string" || release.routeChunks[definition.chunkId] !== file || diff --git a/scripts/verify-release.ts b/scripts/verify-release.ts index c4eb5a9f..c332cd69 100644 --- a/scripts/verify-release.ts +++ b/scripts/verify-release.ts @@ -24,6 +24,7 @@ import { import { assertMatchesJsonSchema } from "./lib/json-schema.ts"; import { CANONICAL_VITE_MANIFEST_PATH, + findRouteChunk, verifyBuildManifestOutputs, } from "./lib/build-manifest-outputs.ts"; import { verifyReleaseRuntimeCoherence } from "./lib/release-runtime-coherence.ts"; @@ -168,12 +169,13 @@ for (const chunkId of actualChunkIds) { const runtimeContracts: Readonly> = ROUTE_RUNTIME_CONTRACT; for (const definition of Object.values(ROUTE_REGISTRY)) { - const runtime = runtimeContracts[definition.routeId]; - const viteEntry = Object.values(viteManifestObject).find( - (entry) => entry.name === runtime?.moduleId && entry.isDynamicEntry, + const viteEntry = findRouteChunk( + viteManifestObject, + definition.routeId, + runtimeContracts[definition.routeId]?.moduleId, ); const routeAsset = release.routeChunks[definition.chunkId]; - if (!runtime || !viteEntry || routeAsset !== viteEntry.file) { + if ("error" in viteEntry || routeAsset !== viteEntry.file) { artifactMismatches.push(`routeChunk:mismatch:${definition.chunkId}`); continue; } diff --git a/tests/unit/route-chunks.test.ts b/tests/unit/route-chunks.test.ts new file mode 100644 index 00000000..99142cad --- /dev/null +++ b/tests/unit/route-chunks.test.ts @@ -0,0 +1,74 @@ +import { readFile } from "node:fs/promises"; + +import { describe, expect, it } from "vitest"; + +import { findRouteChunk } from "../../scripts/lib/build-manifest-outputs.ts"; + +// 0929/13-03. The route chunk was found by the chunk's `name`, so naming route +// chunks in vite.config.ts (the way tech-log did) stopped the build with +// `Missing built route chunk: APP_HOME` and no reason. It is found by the +// page's source file now, which is what the route runtime's moduleId names. +describe("route chunk lookup (0929/13-03)", () => { + const manifest = { + "index.html": { file: "assets/index-a.js", isEntry: true }, + "src/presentation/pages/home-page.tsx": { + file: "assets/route-home-page-b.js", + name: "route-home-page", + src: "src/presentation/pages/home-page.tsx", + isDynamicEntry: true, + }, + "src/features/order-feature/presentation/order-feature-list-page.tsx": { + file: "assets/order-feature-list-page-c.js", + name: "order-feature-list-page", + isDynamicEntry: true, + }, + "_home-page-shared.js": { file: "assets/home-page-d.js", name: "home-page" }, + }; + + it("finds the chunk by the page's source file even when the chunk has another name", () => { + expect(findRouteChunk(manifest, "APP_HOME", "home-page")).toEqual({ file: "assets/route-home-page-b.js" }); + expect(findRouteChunk(manifest, "ORDER_FEATURE_LIST", "order-feature-list-page")).toEqual({ + file: "assets/order-feature-list-page-c.js", + }); + }); + + it("names the reason and the rule when no lazily imported page has that file name", () => { + const lookup = findRouteChunk(manifest, "NOT_FOUND", "not-found-page"); + expect(lookup).toEqual({ + error: + "Missing built route chunk: NOT_FOUND: no lazily imported module in the Vite manifest has the source " + + "file not-found-page.tsx (or .ts). A route runtime's moduleId must be the file name of the page it imports.", + }); + }); + + it("refuses two lazily imported pages with the same file name", () => { + const lookup = findRouteChunk( + { ...manifest, "src/other/home-page.tsx": { file: "assets/home-page-e.js", isDynamicEntry: true } }, + "APP_HOME", + "home-page", + ); + expect(lookup).toEqual({ + error: + "Ambiguous built route chunk: APP_HOME: the lazily imported modules " + + "src/presentation/pages/home-page.tsx, src/other/home-page.tsx are all named home-page.", + }); + }); + + it("names a route without a runtime contract", () => { + expect(findRouteChunk(manifest, "GHOST", undefined)).toEqual({ + error: "Missing built route chunk: GHOST has no route runtime contract (ROUTE_RUNTIME_CONTRACT)", + }); + }); + + it("is the one lookup the manifest writer and both release checks use", async () => { + for (const file of [ + "scripts/generate-build-manifest.ts", + "scripts/verify-release.ts", + "scripts/lib/local-release-evidence.ts", + ]) { + const source = await readFile(file, "utf8"); + expect(source, file).toContain("findRouteChunk("); + expect(source, file).not.toMatch(/\.name === runtime\?\.moduleId/u); + } + }); +});