문제: 1105/12-04 뒤 빌드는 `RUN_OUTPUT_ROOT` 아래에 쓰는데, check:bundle의 두 단계(`generate-supply-chain.ts`, `check-bundle.ts`)는 이 변수를 읽지 않고 checkout의 `dist`와 `artifacts/`를 읽는다. 셸에 이 변수를 둔 채 빌드와 check:bundle을 돌리면 예산을 3,504 B 넘는 새 빌드 대신 이전 빌드를 재서 PASS한다(리뷰 12-R2). ci:gate의 신선도 검사도 bundle.json을 check:bundle이 다시 쓰므로 막지 못한다. 고른 방법: `scripts/lib/run-isolation.ts`에 `checkoutBuildReadFailure`를 두고, 두 스크립트가 무엇을 읽기 전에 부른다. 출력 루트가 `.`이 아니면 변수 값과 이유를 적고 exit 1로 멈춘다. `.`(Playwright 설정이 run ID 없이 web server에 넘기는 값)과 빈 값은 그대로 돈다. 그래서 `RUN_OUTPUT_ROOT=.tmp/x corepack pnpm ci:gate -- FE-GATE-012`도 check-bundle 단계에서 변수 이름을 적고 실패한다. 버린 대안: ci:gate가 시작 전에 거절하기(리뷰 문서 (b)). 12-R2처럼 check:bundle을 직접 돌리는 경우를 막지 못한다. 두 스크립트가 같은 루트를 읽게 하기(c)는 supply-chain 산출물 전부와 CI upload 경로를 함께 옮겨야 한다. 위험·한계: - FE-GATE-012는 빌드 단계를 끝까지 돈 뒤 check-bundle에서 실패한다. 빌드 시간만큼 늦게 알린다. - 같은 모양일 수 있는 `check:app-build-input:bundle`, `check:optional-recipes --require-dist`, release candidate 조립은 보지 않았다. FE-GATE-012에서는 check-bundle이 먼저 실패해 거기까지 가지 않는다. - 디버깅으로 변수를 둔 사람은 check:bundle 전에 지워야 한다(문서에 적음). - 이 노트북에서는 실행하지 못했다. 검증: desktop batch에서 확인. node scripts/run-vitest.ts run tests/unit/check-bundle-output.test.ts tests/unit/run-isolation.test.ts 리뷰 12-R2 명령(stale-bundle-rc=1, stderr에 RUN_OUTPUT_ROOT), check:types, lint, verify:documentation, ci:gate FE-GATE-012 Refs: 1106/12-02
167 lines
6.4 KiB
TypeScript
167 lines
6.4 KiB
TypeScript
import { createServer, type Server } from "node:net";
|
|
|
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
|
|
import {
|
|
checkoutBuildReadFailure,
|
|
findFreePort,
|
|
moduleSpecifier,
|
|
reservePort,
|
|
runOutputPath,
|
|
runOutputRoot,
|
|
testRunPath,
|
|
testRunRoot,
|
|
} from "../../scripts/lib/run-isolation.ts";
|
|
|
|
const servers: Server[] = [];
|
|
|
|
afterEach(async () => {
|
|
await Promise.all(
|
|
servers.splice(0).map((server) => new Promise<void>((resolve) => server.close(() => resolve()))),
|
|
);
|
|
});
|
|
|
|
async function listen(port: number): Promise<number> {
|
|
const server = createServer();
|
|
servers.push(server);
|
|
await new Promise<void>((resolve, reject) => {
|
|
server.once("error", reject);
|
|
server.listen(port, "127.0.0.1", () => resolve());
|
|
});
|
|
const address = server.address();
|
|
return typeof address === "object" && address !== null ? address.port : -1;
|
|
}
|
|
|
|
/**
|
|
* 1105/12-04. Builds and Playwright runs wrote to fixed paths (`dist`,
|
|
* `artifacts/tests/*`), so a second run in one checkout emptied the first
|
|
* one's dist and deleted its results. These are the path rules every config
|
|
* and build step uses.
|
|
*/
|
|
describe("test run paths (TEST_RUN_ID)", () => {
|
|
it("are the checkout's own paths without a run ID", () => {
|
|
for (const environment of [{}, { TEST_RUN_ID: "" }]) {
|
|
expect(testRunRoot(environment)).toBe(".");
|
|
expect(testRunPath("artifacts/tests/e2e/results", environment)).toBe(
|
|
"artifacts/tests/e2e/results",
|
|
);
|
|
expect(testRunPath("dist", environment)).toBe("dist");
|
|
}
|
|
});
|
|
|
|
it("give each run ID its own folder under .tmp/runs", () => {
|
|
const a = { TEST_RUN_ID: "gate-008.a" };
|
|
const b = { TEST_RUN_ID: "gate-008.b" };
|
|
expect(testRunRoot(a)).toBe(".tmp/runs/gate-008.a");
|
|
expect(testRunPath("artifacts/tests/e2e/results", a)).toBe(
|
|
".tmp/runs/gate-008.a/artifacts/tests/e2e/results",
|
|
);
|
|
expect(testRunPath("dist", b)).toBe(".tmp/runs/gate-008.b/dist");
|
|
expect(testRunPath("dist", a)).not.toBe(testRunPath("dist", b));
|
|
});
|
|
|
|
it("refuse a run ID that is not one folder name", () => {
|
|
for (const runId of ["../dist", "a/b", ".hidden", "-a", "a b", "x".repeat(65), "a\\b"]) {
|
|
expect(() => testRunRoot({ TEST_RUN_ID: runId }), runId).toThrow(/TEST_RUN_ID/u);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("build output root (RUN_OUTPUT_ROOT)", () => {
|
|
it("is the checkout without a root", () => {
|
|
for (const environment of [{}, { RUN_OUTPUT_ROOT: "" }, { RUN_OUTPUT_ROOT: "." }]) {
|
|
expect(runOutputRoot(environment)).toBe(".");
|
|
expect(runOutputPath("dist", environment)).toBe("dist");
|
|
expect(runOutputPath(".generated/frontend-runtime", environment)).toBe(
|
|
".generated/frontend-runtime",
|
|
);
|
|
}
|
|
});
|
|
|
|
it("puts every build output under a root in .tmp", () => {
|
|
const environment = { RUN_OUTPUT_ROOT: "./.tmp/runs/a/" };
|
|
expect(runOutputRoot(environment)).toBe(".tmp/runs/a");
|
|
expect(runOutputPath("dist/config.json", environment)).toBe(".tmp/runs/a/dist/config.json");
|
|
expect(runOutputPath("artifacts/release/build-manifest.json", environment)).toBe(
|
|
".tmp/runs/a/artifacts/release/build-manifest.json",
|
|
);
|
|
});
|
|
|
|
it("refuses a root outside .tmp, which git, Tailwind and the watchers do not ignore", () => {
|
|
for (const root of ["dist", "out/a", "/tmp/a", ".tmp", ".tmp/../dist", "../other", ".tmp\\a"]) {
|
|
expect(() => runOutputRoot({ RUN_OUTPUT_ROOT: root }), root).toThrow(/RUN_OUTPUT_ROOT/u);
|
|
}
|
|
});
|
|
|
|
// 1106/12-02. The steps after the build read the checkout's dist/ and
|
|
// artifacts/; under another root they judged an earlier build.
|
|
it("lets a step that reads the checkout's build run only when the build writes there", () => {
|
|
for (const environment of [{}, { RUN_OUTPUT_ROOT: "" }, { RUN_OUTPUT_ROOT: "." }, { RUN_OUTPUT_ROOT: "./" }]) {
|
|
expect(checkoutBuildReadFailure("check-bundle", environment), JSON.stringify(environment))
|
|
.toBeUndefined();
|
|
}
|
|
expect(checkoutBuildReadFailure("check-bundle", { RUN_OUTPUT_ROOT: "./.tmp/runs/a/" })).toBe(
|
|
"check-bundle reads the build at this checkout's paths (dist/, artifacts/), but " +
|
|
"RUN_OUTPUT_ROOT=.tmp/runs/a makes the build write under .tmp/runs/a/, so it would " +
|
|
"judge an earlier build. Unset RUN_OUTPUT_ROOT, build again and run check-bundle again.",
|
|
);
|
|
// A root the build itself refuses is no reason to read the checkout's.
|
|
expect(checkoutBuildReadFailure("check-bundle", { RUN_OUTPUT_ROOT: "dist" })).toMatch(
|
|
/^check-bundle: RUN_OUTPUT_ROOT must be/u,
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("server ports", () => {
|
|
it("finds a port a server can listen on right away", async () => {
|
|
const port = await findFreePort();
|
|
|
|
expect(port).toBeGreaterThan(0);
|
|
expect(await listen(port)).toBe(port);
|
|
});
|
|
|
|
it("never offers a port another run's server holds", async () => {
|
|
const taken = await listen(0);
|
|
|
|
for (let attempt = 0; attempt < 20; attempt += 1) {
|
|
expect(await findFreePort()).not.toBe(taken);
|
|
}
|
|
});
|
|
|
|
it("keeps the port it picked in the variable, so the next evaluation reuses it", async () => {
|
|
const environment: Record<string, string | undefined> = {};
|
|
const find = vi.fn(async () => 41_234);
|
|
|
|
expect(await reservePort("TEST_E2E_PORT", environment, find)).toBe(41_234);
|
|
expect(environment["TEST_E2E_PORT"]).toBe("41234");
|
|
// A Playwright worker: same config, the runner's environment.
|
|
expect(await reservePort("TEST_E2E_PORT", environment, find)).toBe(41_234);
|
|
expect(find).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it("uses a port the caller pinned and refuses one that is not a port", async () => {
|
|
const find = vi.fn(async () => 41_234);
|
|
|
|
expect(await reservePort("TEST_DEV_PORT", { TEST_DEV_PORT: "5173" }, find)).toBe(5173);
|
|
expect(find).not.toHaveBeenCalled();
|
|
for (const value of ["0", "65536", "-1", "4173x", "abc", "41.5"]) {
|
|
await expect(reservePort("TEST_DEV_PORT", { TEST_DEV_PORT: value }, find), value)
|
|
.rejects.toThrow(/TEST_DEV_PORT/u);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("generated module specifiers", () => {
|
|
it("keep today's specifier in .generated and reach src from a deeper root", () => {
|
|
expect(
|
|
moduleSpecifier(".generated/frontend-runtime/contract-set.ts", "src/contracts/contract-set.ts"),
|
|
).toBe("../../src/contracts/contract-set.ts");
|
|
expect(
|
|
moduleSpecifier(
|
|
".tmp/runs/a/.generated/frontend-runtime/contract-set.ts",
|
|
"src/contracts/contract-set.ts",
|
|
),
|
|
).toBe("../../../../../src/contracts/contract-set.ts");
|
|
});
|
|
});
|