fix(build): render product index before every script that loads it (R-0)

The first R-0 pass prefixed only the tsc/vite/test entry points. 36 more
package scripts run node entry files that import src and therefore the
gitignored index, including ci:gate (the CI runner) and check:ci, so they
still failed on a fresh checkout.

- prefix those scripts with the index generator
- update the CI contract's canonical check:artifact-schemas command
- the guard test now walks relative imports from every node entry and
  fails if a script reaches src/.generated without rendering it first

Verified from a fresh state: check:registries, check:ci, check:i18n,
check:design-system, check:diagnostics, check:realtime-boundaries,
check:artifact-schemas, verify:compatibility, ci:gate FE-GATE-001 pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DongHyeonka
2026-09-24 12:44:50 +09:00
co-authored by Claude Opus 5.5
parent 7022a1efd0
commit 7dfb89f894
3 changed files with 84 additions and 50 deletions
+36 -36
View File
@@ -12,19 +12,19 @@
"dev": "node scripts/generate-product-feature-index.ts && vite",
"build": "node scripts/generate-product-feature-index.ts && node scripts/build-frontend.ts",
"build:profile": "node scripts/generate-runtime-config.ts",
"build:release-candidate": "corepack pnpm build && corepack pnpm generate:supply-chain && corepack pnpm scan:security && corepack pnpm verify:release && node scripts/verify-supply-chain-artifacts.ts && node scripts/create-release-candidate.ts",
"build:release-candidate": "node scripts/generate-product-feature-index.ts && corepack pnpm build && corepack pnpm generate:supply-chain && corepack pnpm scan:security && corepack pnpm verify:release && node scripts/verify-supply-chain-artifacts.ts && node scripts/create-release-candidate.ts",
"preview": "vite preview",
"lint": "eslint src scripts tests recipes .storybook vite.config.ts vitest.config.ts playwright*.config.ts --max-warnings=0",
"check:architecture": "node scripts/generate-product-feature-index.ts && node scripts/check-architecture.ts",
"check:design-system": "node scripts/check-design-system.ts",
"check:design-system:fixture": "node scripts/check-design-system.ts --fixture",
"check:i18n": "node scripts/check-i18n.ts",
"check:i18n:fixture": "node scripts/check-i18n.ts --fixture",
"check:design-system": "node scripts/generate-product-feature-index.ts && node scripts/check-design-system.ts",
"check:design-system:fixture": "node scripts/generate-product-feature-index.ts && node scripts/check-design-system.ts --fixture",
"check:i18n": "node scripts/generate-product-feature-index.ts && node scripts/check-i18n.ts",
"check:i18n:fixture": "node scripts/generate-product-feature-index.ts && node scripts/check-i18n.ts --fixture",
"check:adapter-inventory": "node scripts/check-adapter-inventory.ts",
"check:remediation-ledger": "node scripts/check-remediation-ledger.ts",
"check:release-admission": "node scripts/check-release-admission.ts",
"check:diagnostics": "node scripts/check-diagnostics.ts",
"check:diagnostics:fixture": "node scripts/check-diagnostics.ts --fixture",
"check:diagnostics": "node scripts/generate-product-feature-index.ts && node scripts/check-diagnostics.ts",
"check:diagnostics:fixture": "node scripts/generate-product-feature-index.ts && node scripts/check-diagnostics.ts --fixture",
"check:types": "corepack pnpm check:types:app && corepack pnpm check:types:node && corepack pnpm check:types:test && corepack pnpm check:types:recipes && corepack pnpm check:types:web-worker && corepack pnpm check:types:service-worker",
"check:types:app": "node scripts/generate-product-feature-index.ts && tsc --project tsconfig.app.json",
"check:types:node": "node scripts/generate-product-feature-index.ts && tsc --project tsconfig.node.json",
@@ -70,8 +70,8 @@
"check:http-scenario-evidence:fixture": "node scripts/check-test-evidence.ts --scenario-only --source-root tests/fixtures/test-evidence/scenarios/source --policy tests/fixtures/test-evidence/scenarios/policy.json --catalog tests/fixtures/test-evidence/scenarios/catalog.json --receipt tests/fixtures/test-evidence/scenarios/receipt.json --artifact artifacts/quality/http-scenario-evidence-fixture.json",
"check:test-evidence:source": "node scripts/check-test-evidence.ts --source-only --artifact artifacts/quality/test-evidence-source.json",
"check:test-evidence:fixture": "node scripts/check-test-evidence.ts --source-root tests/fixtures/test-evidence/forbidden --artifact artifacts/quality/test-evidence-fixture.json",
"test:a11y": "playwright test --grep @a11y && node scripts/write-a11y-report.ts",
"review:a11y-manual": "node scripts/verify-a11y-manual.ts",
"test:a11y": "node scripts/generate-product-feature-index.ts && playwright test --grep @a11y && node scripts/write-a11y-report.ts",
"review:a11y-manual": "node scripts/generate-product-feature-index.ts && node scripts/verify-a11y-manual.ts",
"test:sample-removal": "node scripts/test-sample-removal.ts",
"test:optional-recipe-removal": "node scripts/test-optional-recipe-removal.ts",
"test:browser-file-storage-removal": "node scripts/test-browser-file-storage-runtime-removal.ts",
@@ -83,46 +83,46 @@
"test:all": "corepack pnpm test:runtime-schema && corepack pnpm test:unit && corepack pnpm test:contract && corepack pnpm test:component && corepack pnpm test:integration && corepack pnpm test:reference-feature && corepack pnpm test:platform && corepack pnpm check:release-coherence && corepack pnpm test:recipes",
"verify:lockfile": "corepack pnpm install --frozen-lockfile --ignore-scripts",
"check:frozen-lockfile:fixture": "node scripts/check-frozen-lockfile-fixture.ts",
"generate:artifact-schemas": "node scripts/generate-artifact-schemas.ts",
"check:artifact-schemas": "node scripts/generate-artifact-schemas.ts --check",
"generate:supply-chain": "node scripts/generate-supply-chain.ts",
"verify:local-evidence": "node scripts/verify-release-candidate.ts && node scripts/verify-release.ts && node scripts/verify-supply-chain-artifacts.ts && node scripts/verify-archived-local-evidence.ts && node scripts/verify-release-candidate.ts",
"verify:promotion": "node scripts/verify-exact-promotion-bundle.ts",
"generate:artifact-schemas": "node scripts/generate-product-feature-index.ts && node scripts/generate-artifact-schemas.ts",
"check:artifact-schemas": "node scripts/generate-product-feature-index.ts && node scripts/generate-artifact-schemas.ts --check",
"generate:supply-chain": "node scripts/generate-product-feature-index.ts && node scripts/generate-supply-chain.ts",
"verify:local-evidence": "node scripts/generate-product-feature-index.ts && node scripts/verify-release-candidate.ts && node scripts/verify-release.ts && node scripts/verify-supply-chain-artifacts.ts && node scripts/verify-archived-local-evidence.ts && node scripts/verify-release-candidate.ts",
"verify:promotion": "node scripts/generate-product-feature-index.ts && node scripts/verify-exact-promotion-bundle.ts",
"update:dependency-baseline": "node scripts/update-dependency-baseline.ts",
"check:supply-chain:fixtures": "node scripts/check-supply-chain-fixtures.ts",
"check:supply-chain:provider-fixtures": "node scripts/check-supply-chain-provider-fixtures.ts",
"verify:reproducible-build": "node scripts/verify-reproducible-build.ts",
"check:supply-chain:fixtures": "node scripts/generate-product-feature-index.ts && node scripts/check-supply-chain-fixtures.ts",
"check:supply-chain:provider-fixtures": "node scripts/generate-product-feature-index.ts && node scripts/check-supply-chain-provider-fixtures.ts",
"verify:reproducible-build": "node scripts/generate-product-feature-index.ts && node scripts/verify-reproducible-build.ts",
"scan:security": "node scripts/security-scan.ts",
"scan:security:fixture": "node scripts/security-scan.ts --policy tests/fixtures/security/secret-detection/forbidden-policy.json --artifact artifacts/security/scan-fixture.sarif",
"check:security:fixtures": "node scripts/check-security-fixtures.ts",
"check:browser-security": "node scripts/check-browser-security.ts",
"check:browser-file-storage-boundaries": "node scripts/check-browser-file-storage-boundaries.ts",
"check:realtime-boundaries": "node scripts/check-realtime-boundaries.ts",
"check:realtime-boundaries": "node scripts/generate-product-feature-index.ts && node scripts/check-realtime-boundaries.ts",
"check:realtime-boundaries:fixture": "node scripts/check-realtime-boundary-fixtures.ts",
"check:optional-recipes": "node scripts/check-optional-recipes.ts --require-dist",
"check:optional-recipes:source": "node scripts/check-optional-recipes.ts",
"check:optional-recipe-fixtures": "node scripts/check-optional-recipe-fixtures.ts",
"check:registries": "node scripts/check-registries.ts",
"check:registries:structure": "node scripts/check-registries.ts --no-baseline",
"check:registries:compatibility-fixtures": "node scripts/check-registry-compatibility-fixtures.ts",
"check:registries:baseline-fixture": "node scripts/check-registries.ts --approval tests/fixtures/registry/compatibility/tampered-approval.json --artifact artifacts/quality/registry-baseline-fixture.json",
"check:registries:fixture": "node scripts/check-registries.ts --governance tests/fixtures/registry/forbidden/governance.json --artifact artifacts/quality/registry-fixture.json",
"check:routes:fixture": "node scripts/check-registries.ts --governance tests/fixtures/registry/routes/governance.json --artifact artifacts/quality/route-registry-fixture.json",
"verify:compatibility": "node scripts/check-compatibility.ts",
"verify:release": "node scripts/verify-release.ts",
"verify:hosting-headers": "node scripts/verify-hosting-headers.ts",
"check:bundle": "node scripts/generate-supply-chain.ts && node scripts/check-bundle.ts",
"test:performance": "node scripts/test-performance.ts",
"collect:web-vitals-evidence": "node scripts/collect-web-vitals-evidence.ts",
"drill:runbook": "node scripts/drill-runbook.ts",
"check:optional-recipes": "node scripts/generate-product-feature-index.ts && node scripts/check-optional-recipes.ts --require-dist",
"check:optional-recipes:source": "node scripts/generate-product-feature-index.ts && node scripts/check-optional-recipes.ts",
"check:optional-recipe-fixtures": "node scripts/generate-product-feature-index.ts && node scripts/check-optional-recipe-fixtures.ts",
"check:registries": "node scripts/generate-product-feature-index.ts && node scripts/check-registries.ts",
"check:registries:structure": "node scripts/generate-product-feature-index.ts && node scripts/check-registries.ts --no-baseline",
"check:registries:compatibility-fixtures": "node scripts/generate-product-feature-index.ts && node scripts/check-registry-compatibility-fixtures.ts",
"check:registries:baseline-fixture": "node scripts/generate-product-feature-index.ts && node scripts/check-registries.ts --approval tests/fixtures/registry/compatibility/tampered-approval.json --artifact artifacts/quality/registry-baseline-fixture.json",
"check:registries:fixture": "node scripts/generate-product-feature-index.ts && node scripts/check-registries.ts --governance tests/fixtures/registry/forbidden/governance.json --artifact artifacts/quality/registry-fixture.json",
"check:routes:fixture": "node scripts/generate-product-feature-index.ts && node scripts/check-registries.ts --governance tests/fixtures/registry/routes/governance.json --artifact artifacts/quality/route-registry-fixture.json",
"verify:compatibility": "node scripts/generate-product-feature-index.ts && node scripts/check-compatibility.ts",
"verify:release": "node scripts/generate-product-feature-index.ts && node scripts/verify-release.ts",
"verify:hosting-headers": "node scripts/generate-product-feature-index.ts && node scripts/verify-hosting-headers.ts",
"check:bundle": "node scripts/generate-product-feature-index.ts && node scripts/generate-supply-chain.ts && node scripts/check-bundle.ts",
"test:performance": "node scripts/generate-product-feature-index.ts && node scripts/test-performance.ts",
"collect:web-vitals-evidence": "node scripts/generate-product-feature-index.ts && node scripts/collect-web-vitals-evidence.ts",
"drill:runbook": "node scripts/generate-product-feature-index.ts && node scripts/drill-runbook.ts",
"drill:runbooks": "corepack pnpm drill:runbook -- FE-RB-001 && corepack pnpm drill:runbook -- FE-RB-002 && corepack pnpm drill:runbook -- FE-RB-003 && corepack pnpm drill:runbook -- FE-RB-004 && corepack pnpm drill:runbook -- FE-RB-005",
"ci:gate": "node scripts/run-ci-gate.ts",
"ci:gate": "node scripts/generate-product-feature-index.ts && node scripts/run-ci-gate.ts",
"generate:ci-workflow": "node scripts/generate-ci-workflow.ts",
"check:ci-workflow": "node scripts/generate-ci-workflow.ts --check",
"check:ci": "corepack pnpm check:artifact-schemas && node scripts/check-ci-contract.ts && corepack pnpm check:ci-workflow",
"verify:documentation": "node scripts/generate-product-feature-index.ts && node scripts/verify-documentation-readiness.ts",
"build:app-only": "node scripts/generate-product-feature-index.ts && vite build && node scripts/generate-build-manifest.ts",
"generate:contract-set": "node scripts/generate-contract-set.ts",
"generate:contract-set": "node scripts/generate-product-feature-index.ts && node scripts/generate-contract-set.ts",
"check:types:web-worker": "tsc --project tsconfig.web-worker.json",
"check:types:service-worker": "tsc --project tsconfig.service-worker.json",
"check:types:fixture:http-operation-input": "tsc -p tests/fixtures/typecheck/tsconfig.http-operation-input.json",
+4 -1
View File
@@ -573,7 +573,10 @@ export async function loadCiGateContract(
throw new TypeError("check:ci must use the exact canonical non-recursive orchestration");
}
const canonicalCheckCiDependencies = {
"check:artifact-schemas": "node scripts/generate-artifact-schemas.ts --check",
// R-0. The schema generator imports src, which loads the gitignored
// product index, so the index is rendered first.
"check:artifact-schemas":
"node scripts/generate-product-feature-index.ts && node scripts/generate-artifact-schemas.ts --check",
"check:ci-workflow": mode === "canonical"
? "node scripts/generate-ci-workflow.ts --check"
: "node scripts/generate-ci-workflow.ts --check --reduced-removal-fixture",
+44 -13
View File
@@ -1,17 +1,17 @@
import { readFile } from "node:fs/promises";
import { existsSync, readFileSync } from "node:fs";
import path from "node:path";
import { describe, expect, it } from "vitest";
// src/.generated is gitignored (R-0): every entry point that loads the product
// index must render it first, or a fresh checkout cannot run the gates.
const GENERATE = "node scripts/generate-product-feature-index.ts && ";
const ENTRY_SCRIPTS = [
// Entry points the import walk below cannot see (tsc, vite, storybook).
const NON_NODE_ENTRY_SCRIPTS = [
"dev",
"build",
"build:app-only",
"storybook",
"build:storybook",
"check:architecture",
"check:types:app",
"check:types:node",
"check:types:test",
@@ -20,21 +20,52 @@ const ENTRY_SCRIPTS = [
"check:types:fixture:icon-button",
"check:types:fixture:i18n-key",
"check:types:fixture:i18n-params",
"verify:documentation",
] as const;
const ROOT = process.cwd();
const GENERATED_DIR = path.join(ROOT, "src/.generated");
const RELATIVE_IMPORT =
/(?:import|export)\s[^'"]*?from\s+["'](\.{1,2}\/[^"']+)["']|import\(\s*["'](\.{1,2}\/[^"']+)["']\s*\)/gu;
function reachesGeneratedIndex(file: string, seen = new Set<string>()): boolean {
if (seen.has(file) || !existsSync(file)) return false;
seen.add(file);
for (const match of readFileSync(file, "utf8").matchAll(RELATIVE_IMPORT)) {
const resolved = path.resolve(path.dirname(file), match[1] ?? match[2] ?? "");
if (resolved.startsWith(GENERATED_DIR)) return true;
if (reachesGeneratedIndex(resolved, seen)) return true;
}
return false;
}
function packageScripts(): Record<string, string> {
return (JSON.parse(readFileSync("package.json", "utf8")) as { scripts: Record<string, string> })
.scripts;
}
describe("product index entry points", () => {
it("renders the generated index before scripts that load src", async () => {
const { scripts } = JSON.parse(await readFile("package.json", "utf8")) as {
scripts: Record<string, string>;
};
for (const name of ENTRY_SCRIPTS) {
expect(scripts[name], name).toMatch(new RegExp(`^${GENERATE.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`));
it("renders the generated index before tsc, vite and storybook entry points", () => {
const scripts = packageScripts();
for (const name of NON_NODE_ENTRY_SCRIPTS) {
expect(scripts[name]?.startsWith(GENERATE), name).toBe(true);
}
});
it("renders the generated index before every Vitest run", async () => {
const runner = await readFile("scripts/run-vitest.ts", "utf8");
it("renders the generated index before every node script that imports it", () => {
const missing = Object.entries(packageScripts())
.filter(([, command]) => !command.startsWith(GENERATE))
.filter(([, command]) =>
[...command.matchAll(/node\s+(scripts\/[\w./-]+\.ts)/gu)]
.map((match) => match[1] ?? "")
.filter((entry) => entry !== "scripts/run-vitest.ts")
.some((entry) => reachesGeneratedIndex(path.join(ROOT, entry))),
)
.map(([name]) => name);
expect(missing).toEqual([]);
});
it("renders the generated index before every Vitest run", () => {
const runner = readFileSync("scripts/run-vitest.ts", "utf8");
expect(runner.indexOf("generate-product-feature-index.ts")).toBeGreaterThan(-1);
expect(runner.indexOf("generate-product-feature-index.ts")).toBeLessThan(
runner.indexOf("vitestEntry, ...process.argv"),