문제: fixture spec 여섯(old-tab-chunk-recovery, generated-feature, preload-use, boot-module-failure, service-worker-update·recovery)이 beforeAll에서 저장소를 복사해 vite build를 동기로 돈다. chromium· firefox·webkit project가 그 hook을 따로 돌아, e2e 한 번에 같은 build를 세 번(약 9 build × 3) 만든다. 그 build는 옆 worker의 브라우저와 CPU를 다툰다. FE-GATE-008이 가끔 떨어진 firefox 시험(runner run 127, desktop p5·fea-v8: `old-tab-chunk-recovery`·`app-shell`·`accessibility`의 첫 goto 뒤 요소 없음)은 이 build가 도는 구간과 겹쳤다. 다만 아래 6회 실행에서 고치기 전·후 모두 재현되지 않아, 이것이 원인이라고는 확정하지 못했다. 고른 방법: e2e 설정의 global setup이 run마다 공유 폴더를 만들고 (`SHARED_FIXTURE_BUILD_ROOT`), `prepareFixtureBuilds`와 `prepareServiceWorkerBuilds`가 key마다 처음 닿은 worker만 build한다. 나머지 worker는 그 결과를 기다려 쓴다(`mkdir` 잠금, 결과 JSON을 rename으로 공개, 실패는 `.failed`로 전한다). 같은 key를 다른 정의로 부르면 거절한다. build는 엔진과 무관하고 시험이 build 폴더에 쓰는 곳은 없다(edit는 build 전에만 돈다). global teardown이 폴더를 지운다. - old-tab spec은 edit 안에서 정하던 기능 목록을 build 뒤에 root에서도 읽는다. 다른 project의 build를 쓴 worker는 edit를 돌지 않는다. - 공유 폴더가 없으면(Vitest 시험, 다른 Playwright 설정) 예전처럼 호출마다 자기 사본을 만든다. - 버린 대안: expect timeout 늘리기·worker 줄이기(규칙 밖), fixture spec을 한 브라우저만 돌리기(브라우저별 계약이 줄어든다). 위험·한계: build를 기다리는 worker는 자기 hook timeout(180~300초) 안에서 기다린다. build한 worker가 죽으면 기다리는 쪽은 그 timeout으로 실패한다. 2026-11-01 리뷰의 R-1(두 helper 중복 정리)은 하지 않았다. 검증(desktop, `taskset -c 0-5` + worker 6으로 runner 모양, 같은 세션에서 고치기 전·후 번갈아 3회): e2e 전체 벽시계 172/150/141 → 123/141/113초 (중앙값 150 → 123초), 6회 모두 183개 통과. 공유 시험 6개 통과, check:types·eslint rc=0. 로그 /tmp/claude-gates/w2fe2-e2eab/, w2fe2-shared1/.
116 lines
4.1 KiB
TypeScript
116 lines
4.1 KiB
TypeScript
import { access, mkdtemp, rm, writeFile } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
SHARED_FIXTURE_BUILD_ROOT_VARIABLE,
|
|
sharedFixtureBuild,
|
|
startSharedFixtureBuilds,
|
|
} from "../e2e/support/shared-fixture-builds.ts";
|
|
|
|
const roots: string[] = [];
|
|
|
|
afterEach(async () => {
|
|
await Promise.all(
|
|
roots.splice(0).map((root) => rm(root, { recursive: true, force: true })),
|
|
);
|
|
});
|
|
|
|
async function sharedEnvironment(): Promise<NodeJS.ProcessEnv> {
|
|
const root = await mkdtemp(path.join(tmpdir(), "shared-builds-test-"));
|
|
roots.push(root);
|
|
return { [SHARED_FIXTURE_BUILD_ROOT_VARIABLE]: root };
|
|
}
|
|
|
|
describe("one fixture build per e2e run", () => {
|
|
it("builds a key once and hands every caller the same copy", async () => {
|
|
const environment = await sharedEnvironment();
|
|
let builds = 0;
|
|
const create = async (root: string) => {
|
|
builds += 1;
|
|
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
await writeFile(path.join(root, "dist.txt"), "built");
|
|
return { dist: path.join(root, "dist.txt") };
|
|
};
|
|
|
|
const results = await Promise.all(
|
|
[1, 2, 3].map(() => sharedFixtureBuild("fixture-a", "same", create, environment)),
|
|
);
|
|
|
|
expect(builds).toBe(1);
|
|
expect(new Set(results.map((result) => result.root)).size).toBe(1);
|
|
for (const result of results) {
|
|
expect(result.shared).toBe(true);
|
|
expect(result.value).toEqual({ dist: path.join(result.root, "dist.txt") });
|
|
}
|
|
await access(results[0]!.value.dist);
|
|
});
|
|
|
|
it("refuses a second definition under the same key", async () => {
|
|
const environment = await sharedEnvironment();
|
|
await sharedFixtureBuild("fixture-b", "first", async () => ({}), environment);
|
|
|
|
await expect(
|
|
sharedFixtureBuild("fixture-b", "second", async () => ({}), environment),
|
|
).rejects.toThrow(/fixture-b was built from another definition/u);
|
|
});
|
|
|
|
it("fails the waiting callers with the builder's failure", async () => {
|
|
const environment = await sharedEnvironment();
|
|
const owner = sharedFixtureBuild(
|
|
"fixture-c",
|
|
"same",
|
|
async () => {
|
|
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
throw new Error("vite build exited 1");
|
|
},
|
|
environment,
|
|
);
|
|
const waiter = sharedFixtureBuild("fixture-c", "same", async () => ({}), environment);
|
|
|
|
await expect(owner).rejects.toThrow(/vite build exited 1/u);
|
|
await expect(waiter).rejects.toThrow(
|
|
/fixture-c failed in another worker:[\s\S]*vite build exited 1/u,
|
|
);
|
|
});
|
|
|
|
it("builds a private copy and removes it on failure without a shared root", async () => {
|
|
const result = await sharedFixtureBuild("fixture-d", "x", async (root) => root, {});
|
|
roots.push(result.root);
|
|
expect(result).toMatchObject({ shared: false, value: result.root });
|
|
expect(path.dirname(result.root)).toBe(tmpdir());
|
|
|
|
let failedRoot = "";
|
|
await expect(
|
|
sharedFixtureBuild("fixture-d", "x", async (root) => {
|
|
failedRoot = root;
|
|
throw new Error("broken copy");
|
|
}, {}),
|
|
).rejects.toThrow(/broken copy/u);
|
|
await expect(access(failedRoot)).rejects.toMatchObject({ code: "ENOENT" });
|
|
});
|
|
|
|
it("refuses a key that is not one lower-case path segment", async () => {
|
|
for (const key of ["", "../x", "a/b", "Fixture", `a${"b".repeat(64)}`]) {
|
|
await expect(sharedFixtureBuild(key, "x", async () => ({}), {})).rejects.toThrow(
|
|
/Invalid fixture build key/u,
|
|
);
|
|
}
|
|
});
|
|
|
|
it("gives the run a root and removes it with the teardown", async () => {
|
|
const environment: NodeJS.ProcessEnv = {};
|
|
const teardown = await startSharedFixtureBuilds(environment);
|
|
const root = environment[SHARED_FIXTURE_BUILD_ROOT_VARIABLE];
|
|
expect(root).toBeTruthy();
|
|
await sharedFixtureBuild("fixture-e", "x", async () => ({}), environment);
|
|
|
|
await teardown();
|
|
|
|
expect(environment[SHARED_FIXTURE_BUILD_ROOT_VARIABLE]).toBeUndefined();
|
|
await expect(access(root!)).rejects.toMatchObject({ code: "ENOENT" });
|
|
});
|
|
});
|