fix(build): checkout 빌드를 읽는 스크립트 넷이 다른 RUN_OUTPUT_ROOT를 거절한다

문제: `RUN_OUTPUT_ROOT`가 다른 폴더를 가리키면 빌드는 그 아래에 쓰는데,
`verify-reproducible-build.ts`, `check-optional-recipes.ts`,
`check-app-build-input.ts --require-bundle`, `create-release-candidate.ts`는
checkout의 `dist/`·`artifacts/`를 읽고 스스로 거절하지 않았다. 게이트
안에서는 앞 단계가 거절해 거짓 PASS가 없었지만, 단독 실행은
`verify:reproducible-build`가 이전 빌드를 두 번 재서 `passed: true`를 쓸 수
있었다.

고친 것: 넷이 시작할 때 `checkoutBuildReadFailure`(check-bundle.ts와 같다)를
부르고 변수 이름·값을 적으며 exit 1. `check-optional-recipes.ts`는
`--dist-root`를 받았으면 그 폴더를 읽으므로 묻지 않는다.

검증: desktop `node scripts/run-vitest.ts run tests/unit/run-isolation.test.ts`
통과. 넷을 `RUN_OUTPUT_ROOT=.tmp/run-output-refusal`로 띄워 rc=1과 메시지를
본다(가장 긴 실행 499 ms). 기준 커밋에서는 넷 다 실패한다(RED).

Refs: 1106/12-02
This commit is contained in:
DongHyeonka
2026-11-13 23:29:13 +09:00
parent 86b4a328c0
commit e657d00fbe
5 changed files with 60 additions and 0 deletions
+8
View File
@@ -5,6 +5,7 @@ import {
createFileSystemDeclarationSource,
type TopologyDeclarationSource,
} from "./generate-product-feature-index.ts";
import { checkoutBuildReadFailure } from "./lib/run-isolation.ts";
/**
* scale-architecture.md §3 / §37. Build-input regression gate for deployable-app isolation.
@@ -123,6 +124,13 @@ async function main(): Promise<void> {
// 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");
+10
View File
@@ -11,6 +11,7 @@ import {
validateRecipeCatalog,
} from "./lib/optional-recipes.ts";
import { assertMatchesJsonSchema } from "./lib/json-schema.ts";
import { checkoutBuildReadFailure } from "./lib/run-isolation.ts";
import { writeValidatedJsonArtifact } from "./lib/validated-json-artifact.ts";
type GateViolation = Readonly<{
@@ -36,6 +37,15 @@ const catalogPath = argument(
);
const sourceRoot = argument("--source-root", "src");
const distRoot = argument("--dist-root", "dist");
// 1106/12-02. Without --dist-root this scans the checkout's dist; under
// RUN_OUTPUT_ROOT the build wrote elsewhere, so it would judge an earlier build.
const outputRootFailure = process.argv.includes("--dist-root")
? undefined
: checkoutBuildReadFailure("scripts/check-optional-recipes.ts");
if (outputRootFailure !== undefined) {
process.stderr.write(`${outputRootFailure}\n`);
process.exit(1);
}
const artifactPath = argument(
"--artifact",
"artifacts/quality/optional-recipes.json",
+10
View File
@@ -1,5 +1,6 @@
import { mkdir } from "node:fs/promises";
import { checkoutBuildReadFailure } from "./lib/run-isolation.ts";
import { writeValidatedJsonArtifact } from "./lib/validated-json-artifact.ts";
import { localEvidenceAssessmentArtifactSchema } from "./contracts/release-artifacts.ts";
import { createLocalEvidenceAssessment } from "./lib/local-release-evidence.ts";
@@ -10,6 +11,15 @@ import {
releaseCandidateManifestSchema,
} from "./lib/release-candidate.ts";
// 1106/12-02. This digests dist and the evidence under artifacts/ where the
// checkout keeps them (scripts/lib/release-candidate.ts). Under RUN_OUTPUT_ROOT
// the build wrote elsewhere, so the candidate would package an earlier build.
const outputRootFailure = checkoutBuildReadFailure("scripts/create-release-candidate.ts");
if (outputRootFailure !== undefined) {
process.stderr.write(`${outputRootFailure}\n`);
process.exit(1);
}
const assessment = await createLocalEvidenceAssessment();
await mkdir("artifacts/security", { recursive: true });
await writeValidatedJsonArtifact({
+8
View File
@@ -4,10 +4,18 @@ import path from "node:path";
import { reproducibleBuildArtifactSchema } from "./contracts/release-artifacts.ts";
import { assertCiBuildEnvironment } from "./lib/build-environment.ts";
import { checkoutBuildReadFailure } from "./lib/run-isolation.ts";
import { supplyChainDigest } from "./lib/supply-chain.ts";
import { writeValidatedJsonArtifact } from "./lib/validated-json-artifact.ts";
assertCiBuildEnvironment(process.env);
// 1106/12-02. This builds twice and digests dist where the checkout keeps it. Under RUN_OUTPUT_ROOT the build wrote elsewhere, so
// this would judge the earlier build the checkout still holds.
const outputRootFailure = checkoutBuildReadFailure("scripts/verify-reproducible-build.ts");
if (outputRootFailure !== undefined) {
process.stderr.write(`${outputRootFailure}\n`);
process.exit(1);
}
async function filesWithin(directory: string): Promise<string[]> {
const entries = await readdir(directory, { withFileTypes: true });
+24
View File
@@ -1,3 +1,4 @@
import { spawnSync } from "node:child_process";
import { createServer, type Server } from "node:net";
import { afterEach, describe, expect, it, vi } from "vitest";
@@ -12,6 +13,7 @@ import {
testRunPath,
testRunRoot,
} from "../../scripts/lib/run-isolation.ts";
import { childProcessTimeout } from "../helpers/child-process-timeout.ts";
const servers: Server[] = [];
@@ -110,6 +112,28 @@ describe("build output root (RUN_OUTPUT_ROOT)", () => {
/^check-bundle: RUN_OUTPUT_ROOT must be/u,
);
});
// 1106/12-02, the part the gates did not cover. Run alone, these four read
// the checkout's dist/ or artifacts/ and did not refuse another root:
// `RUN_OUTPUT_ROOT=.tmp/x corepack pnpm verify:reproducible-build` wrote
// `passed: true` about the earlier build.
it.each([
["scripts/verify-reproducible-build.ts"],
["scripts/check-optional-recipes.ts", "--require-dist"],
["scripts/check-app-build-input.ts", "--require-bundle"],
["scripts/create-release-candidate.ts"],
])("%s refuses to read the checkout's build under another RUN_OUTPUT_ROOT", (script, ...args) => {
const { CI: _ci, ...environment } = process.env;
const result = spawnSync(process.execPath, [script, ...args], {
encoding: "utf8",
env: { ...environment, RUN_OUTPUT_ROOT: ".tmp/run-output-refusal" },
});
expect(result.status, result.stderr).toBe(1);
expect(result.stderr).toContain(
`${script} reads the build at this checkout's paths (dist/, artifacts/), but RUN_OUTPUT_ROOT=.tmp/run-output-refusal`,
);
}, childProcessTimeout(499));
});
describe("server ports", () => {