frontend-quality-gates / merge / static checks (pull_request) Successful in 1m15s
frontend-quality-gates / merge / tests (pull_request) Successful in 13m20s
frontend-quality-gates / merge / browser tests (pull_request) Successful in 5m16s
frontend-quality-gates / FE-GATE-017 / diagram-review (pull_request) Skipped
frontend-quality-gates / FE-GATE-015 / immutable-release-candidate (pull_request) Skipped
frontend-quality-gates / external-provenance-provider (pull_request) Skipped
frontend-quality-gates / main / self-tests and removal drills (pull_request) Skipped
frontend-quality-gates / FE-GATE-014 / config-compatibility (pull_request) Skipped
frontend-quality-gates / FE-GATE-028 / manual-accessibility-review (pull_request) Skipped
frontend-quality-gates / FE-GATE-026 / lab-performance (pull_request) Skipped
frontend-quality-gates / external-vulnerability-provider (pull_request) Skipped
frontend-quality-gates / promote-verified-immutable-candidate (pull_request) Skipped
frontend-quality-gates / deploy-promoted-release (pull_request) Skipped
frontend-quality-gates / FE-GATE-019 / hosting-header (pull_request) Skipped
frontend-quality-gates / FE-GATE-021 / runbook-boot-config (pull_request) Skipped
frontend-quality-gates / FE-GATE-022 / runbook-chunk-mismatch (pull_request) Skipped
frontend-quality-gates / FE-GATE-023 / runbook-api-degradation (pull_request) Skipped
frontend-quality-gates / FE-GATE-024 / runbook-telemetry (pull_request) Skipped
frontend-quality-gates / FE-GATE-025 / runbook-release-rollback (pull_request) Skipped
frontend-quality-gates / FE-GATE-018 / field-web-vitals (pull_request) Skipped
스크립트 22곳이 argv[1]로 직접 실행을 판정해서, checkout 경로에 공백·한글이 있거나 symlink 절대 경로로 부르면 18곳이 검사 없이 rc=0으로 끝날 수 있다. merge 게이트 명령 셋이 여기 걸린다. isEntryModule(import.meta) 하나로 바꾸고, process.argv 둘째 값 읽기와 helper 밖 판정은 시험으로 막는다. 맨 import.meta.main은 그 값이 없는 Node에서 같은 거짓 통과가 나서 버렸다. realpath 비교는 같은 판정의 사본 22개가 남고, argv 값의 쓰임을 따라가는 시험은 return·대입으로 피할 수 있어 버렸다. 위험·한계: 건너뛰던 검사가 실패하기 시작할 수 있고, 실행 판정이 아닌 process.argv[1] 읽기도 실패한다. import.meta.main이 없는 Node에서 직접 실행하거나 import하면 실패한다. verify-extreme-scale도 그 Node에서는 rc=2보다 먼저 rc=1로 끝나고, 이전 기록(passed일 수 있다)이 그대로 남아 종료 code로 본다. 코드로 읽은 것이고 그 Node로 돌려 보지 않았다. 막는 시험은 process·argv 별칭과 계산한 index를 따라가지 않는다. 검증(노트북, main으로 옮기기 전 트리 a806088b): 새 시험 고치기 전 실패, 고친 뒤 통과. test:unit 3707개, types, lint, check:ci, verify:documentation rc=0. desktop merge 단계는 따로 확인한다. Refs: REV-FE-0040
153 lines
6.1 KiB
TypeScript
153 lines
6.1 KiB
TypeScript
import { readFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
|
|
import {
|
|
createFileSystemDeclarationSource,
|
|
type TopologyDeclarationSource,
|
|
} from "./generate-product-feature-index.ts";
|
|
import { isEntryModule } from "./lib/entry-module.ts";
|
|
import { checkoutBuildReadFailure } from "./lib/run-isolation.ts";
|
|
|
|
/**
|
|
* scale-architecture.md §3 / §37. Build-input regression gate for deployable-app isolation.
|
|
*
|
|
* The app being built is the one recorded in `src/.generated/product-app.ts`.
|
|
* Its allowed features are exactly those owned (via their context) by that
|
|
* app's declarations. The gate fails when
|
|
* - a generated index imports a feature or declares a context outside that
|
|
* ownership set (e.g. a regression back to "import every src/features"),
|
|
* - the production bundle's module inventory contains a module of a feature
|
|
* the app does not own.
|
|
*/
|
|
export type AppBuildInputReport = Readonly<{
|
|
appId: string;
|
|
ownedContexts: readonly string[];
|
|
ownedFeatureDirectories: readonly string[];
|
|
generatedFeatureImports: readonly string[];
|
|
generatedContexts: readonly string[];
|
|
bundle: Readonly<{ checked: boolean; featureDirectories: readonly string[] }>;
|
|
violations: readonly string[];
|
|
}>;
|
|
|
|
const GENERATED = [
|
|
"src/.generated/product-feature-index.ts",
|
|
"src/.generated/product-context-index.ts",
|
|
"src/.generated/product-app.ts",
|
|
] as const;
|
|
|
|
function unique(values: Iterable<string>): string[] {
|
|
return [...new Set(values)].sort();
|
|
}
|
|
|
|
export async function inspectAppBuildInput(
|
|
root: string,
|
|
options: Readonly<{
|
|
source?: TopologyDeclarationSource;
|
|
bundleInventory?: string | null;
|
|
}> = {},
|
|
): Promise<AppBuildInputReport> {
|
|
const source = options.source ?? (await createFileSystemDeclarationSource(root));
|
|
const [featureIndex, contextIndex, appIndex] = await Promise.all(
|
|
GENERATED.map((file) => readFile(path.join(root, file), "utf8")),
|
|
);
|
|
const appId = /id:\s*"([^"]+)"/u.exec(appIndex ?? "")?.[1];
|
|
const violations: string[] = [];
|
|
if (!appId || !source.app(appId)) {
|
|
violations.push(`generated app ${appId ?? "<missing>"} is not a declared deployable app`);
|
|
}
|
|
const ownedContexts = appId ? source.contextsOf(appId).map((context) => context.id) : [];
|
|
const ownedFeatureDirectories = unique(
|
|
ownedContexts.flatMap((contextId) => source.featuresOf(contextId).map((feature) => feature.directory)),
|
|
);
|
|
const owned = new Set(ownedFeatureDirectories);
|
|
|
|
const featureDirectoriesIn = (text: string) =>
|
|
unique([...text.matchAll(/\.\.\/features\/([^/"']+)\//gu)].map((match) => match[1] as string));
|
|
const generatedFeatureImports = unique([
|
|
...featureDirectoriesIn(featureIndex ?? ""),
|
|
...featureDirectoriesIn(contextIndex ?? ""),
|
|
]);
|
|
for (const directory of generatedFeatureImports) {
|
|
if (!owned.has(directory)) {
|
|
violations.push(`generated index imports feature "${directory}" not owned by app ${appId}`);
|
|
}
|
|
}
|
|
const generatedContexts = unique(
|
|
[...(contextIndex ?? "").matchAll(/defineBoundedContextModule\(\{\s*id:\s*"([^"]+)"/gu)].map(
|
|
(match) => match[1] as string,
|
|
),
|
|
);
|
|
const ownedContextSet = new Set(ownedContexts);
|
|
for (const contextId of generatedContexts) {
|
|
if (!ownedContextSet.has(contextId)) {
|
|
violations.push(`generated index declares context "${contextId}" not owned by app ${appId}`);
|
|
}
|
|
}
|
|
|
|
let bundle: AppBuildInputReport["bundle"] = { checked: false, featureDirectories: [] };
|
|
const inventoryPath =
|
|
options.bundleInventory === undefined
|
|
? path.join(root, "artifacts/quality/vite-module-inventory.json")
|
|
: options.bundleInventory;
|
|
if (inventoryPath) {
|
|
const raw = await readFile(inventoryPath, "utf8").catch(() => null);
|
|
if (raw !== null) {
|
|
const inventory = JSON.parse(raw) as { chunks?: { modules?: string[] }[] };
|
|
const modules = (inventory.chunks ?? []).flatMap((chunk) => chunk.modules ?? []);
|
|
const featureDirectories = unique(
|
|
modules.flatMap((module) => {
|
|
const match = /^src\/features\/([^/]+)\//u.exec(module);
|
|
return match ? [match[1] as string] : [];
|
|
}),
|
|
);
|
|
bundle = { checked: true, featureDirectories };
|
|
for (const directory of featureDirectories) {
|
|
if (!owned.has(directory)) {
|
|
violations.push(`production bundle contains feature "${directory}" not owned by app ${appId}`);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return Object.freeze({
|
|
appId: appId ?? "",
|
|
ownedContexts: unique(ownedContexts),
|
|
ownedFeatureDirectories,
|
|
generatedFeatureImports,
|
|
generatedContexts,
|
|
bundle,
|
|
violations,
|
|
});
|
|
}
|
|
|
|
async function main(): Promise<void> {
|
|
// The bundle inventory is only meaningful right after a build of this tree;
|
|
// without `--require-bundle` the gate checks the generated indexes only, so a
|
|
// stale inventory from another build can never pass or fail it.
|
|
const requireBundle = process.argv.includes("--require-bundle");
|
|
// 1106/12-02. The inventory is read where the checkout keeps it; under
|
|
// RUN_OUTPUT_ROOT the build wrote elsewhere and this would judge an earlier one.
|
|
const outputRootFailure = requireBundle ? checkoutBuildReadFailure("scripts/check-app-build-input.ts") : undefined;
|
|
if (outputRootFailure !== undefined) {
|
|
process.stderr.write(`${outputRootFailure}\n`);
|
|
process.exit(1);
|
|
}
|
|
const report = await inspectAppBuildInput(process.cwd(), requireBundle ? {} : { bundleInventory: null });
|
|
if (requireBundle && !report.bundle.checked) {
|
|
process.stderr.write("app build input: no production module inventory; run the build first\n");
|
|
process.exit(1);
|
|
}
|
|
for (const violation of report.violations) process.stderr.write(`FAIL ${violation}\n`);
|
|
process.stdout.write(
|
|
`app build input: app=${report.appId} contexts=${report.ownedContexts.length} ` +
|
|
`features=${report.ownedFeatureDirectories.length} generatedImports=${report.generatedFeatureImports.length} ` +
|
|
`bundle=${report.bundle.checked ? `${report.bundle.featureDirectories.length} feature dirs` : "not checked"} ` +
|
|
`${report.violations.length === 0 ? "PASS" : "FAIL"}\n`,
|
|
);
|
|
if (report.violations.length > 0) process.exitCode = 1;
|
|
}
|
|
|
|
if (isEntryModule(import.meta)) {
|
|
await main();
|
|
}
|