Files
clean-architecture-frontend…/tests/unit/playwright-run-isolation.test.ts
DongHyeonka ede99cb9b9 fix(test-run): FE-GATE-009와 test:e2e:dev가 e2e 결과를 덮지 않는다
문제: `test:a11y`(FE-GATE-009)가 `playwright.config.ts`를 그대로 써서
e2e의 결과 폴더·HTML report·`results.xml`에 쓴다. merge browser job은
한 checkout에서 FE-GATE-008 다음 FE-GATE-009를 돌고 `artifacts/`를
올리므로, 올린 e2e 증거는 a11y 실행의 것이다. FE-GATE-009에는 자기
JUnit·report 증거가 없다. 게이트 밖 `test:e2e:dev`도 e2e 설정을 펼쳐
같은 경로에 쓰므로, 로컬 실행이 FE-GATE-008 결과를 지운다
(Playwright는 시작할 때 결과 폴더를 비운다).

고른 방법:
- `playwright.a11y.config.ts`가 e2e 설정을 펼치고 결과 경로만
  `artifacts/tests/a11y/`로 바꾼다. `forbidOnly: true`는 글자로 둔다
  (`check-test-evidence.ts`가 등록 설정마다 그 글자를 찾는다).
  `test:a11y`는 `--config playwright.a11y.config.ts --grep @a11y`.
- `playwright.dev.config.ts`도 결과 경로를 `artifacts/tests/e2e-dev/`로
  둔다.
- `config/ci/gates.json`: a11y `results.xml`·`report/index.html`
  증거(producer `test-a11y`)를 더하고 FE-GATE-009 증거에 넣는다.
- 새 시험 `tests/unit/playwright-result-paths.test.ts`: package script가
  부르는 Playwright 설정을 run ID 없이 불러 결과 경로를 모은다.
  (1) 서로 다른 설정 둘이 같은 경로(또는 한쪽 안의 경로)에 쓰면 실패,
  (2) 게이트 명령 둘이 같은 경로에 쓰면 실패, (3) 게이트 명령이 쓰는
  JUnit·report가 그 게이트의 증거이고 producer가 그 명령이 아니면 실패.
- FE-6 시험의 Playwright 쪽(`test:e2e`·`test:a11y`의 `playwright test`
  두 줄과 「같은 설정이라 project가 같다」)을
  `ci-workflow-generation.test.ts`에서 새 시험으로 옮긴다. 글자로 보던
  것을, 같은 포트로 두 설정을 불러 결과 경로 밖 설정 전체가 같은지 보는
  단언으로 바꾼다. gate 계약 쪽(008·009의 commandIds, merge browser
  job)은 그 자리에 둔다.
- 제거 fixture 사본(FE-GATE-013·020)은 `artifacts/`에서 재생성 트리만
  빼고 복사한다. 결과 경로를 옮기면 a11y·dev 결과와 report(실패하면
  trace까지)가 사본에 들어가므로, `scripts/lib/removal-fixture.ts`의
  목록에 `artifacts/tests/a11y`·`artifacts/tests/e2e-dev`를 더한다.
  새 시험 (4): 각 Playwright 설정의 results·report 폴더가 그 목록 안에
  있다. `a11y.json`·`a11y-data-state/`는 계속 복사되는지 fixture 시험이
  본다.
- `playwright.a11y.config.ts`가 `testDir: "./tests/e2e"`를 글자로 둔다.
  FE-GATE-029는 게이트 명령이 부르는 설정 파일 본문에서 `testDir:`를
  찾으므로, 펼치기만 하면 `test:a11y`가 게이트하는 폴더가 0개다.
  새 시험(`ungated-tests.test.ts`): 게이트 명령이 닿는
  `playwright test`마다 testDir을 찾는다.
- decisions.md FE-6 행은 옮긴 단언의 자리
  `tests/unit/playwright-result-paths.test.ts`를 백틱으로 적는다.
  샘플 제거 드릴(FE-GATE-020)은 사본에서 `ci-workflow-generation.test.ts`를
  지우고, 사본의 `verify:documentation`은 살아 있는 문서의 백틱 경로를
  대조한다. 그 시험 경로를 백틱으로 적은 첫 판은 020에서 실패했다.
  버린 안: 경로를 백틱 없이 적기. `.claude/rules/docs.md`가 「검사를
  피하려고 백틱을 빼지 않는다」고 정한다(1105/14-03). 드릴 쪽(문서
  검사에 예외 경로 넘기기, 그 시험을 지우지 않기)은 b6bfc9b7에서 버린
  안이라 손대지 않는다. 다른 살아 있는 문서에는 드릴이 지우는 네
  파일을 백틱으로 적은 곳이 없다(`git grep`).
- 시험 helper(설정 찾기·경로 겹침)에 거절 입력 시험을 둔다.
- 버린 안: `test:a11y`에 `--output`·`--reporter` 인자를 붙이기. 결과
  경로가 설정과 script 두 곳에 나뉘고, run ID 격리(`testRunPath`)를
  다시 만들어야 한다.
- 막지 않은 것: `test:visual:update`는 `test:visual`과 같은 설정이라 같은
  경로에 쓴다. 같은 시험을 골든 갱신으로 도는 것이라 그 결과가 visual
  결과다. 시험 (1)은 설정 단위라 이것을 막지 않는다.

위험·한계: FE-GATE-009의 증거가 둘 늘어 그 게이트가 JUnit·report 없이
끝나면 실패한다. 하류 프로젝트가 `test:a11y`를 고쳐 `--config` 없이 쓰면
새 시험이 실패한다(CHANGELOG 「먼저 할 일」). 결과 경로를 script 인자로
바꾸는 설정(`--output` 등)은 새 시험이 읽지 않는다. FE-GATE-029
파서는 `--grep-invert @a11y`를 읽지 않아 `@a11y` 시험을 008이 도는
것으로 센다(FE-6부터 있던 것, 이 커밋 밖).

검증(desktop `scripts/verify.sh exec`):
- RED(트리 1e2c4a8f, 고치기 전): 새 시험 3개 모두 실패. dev 설정이 e2e
  경로 셋, test-e2e·test-a11y가 같은 경로 셋, test-a11y의 JUnit·report가
  FE-GATE-009 증거가 아니고 producer가 test-e2e.
- GREEN: 새 시험, playwright-run-isolation, ci-workflow-generation,
  repository-layout, test-evidence-repository-configs 503개 통과.
- 변이: a11y 결과 경로를 e2e로 → 새 시험 3개와 a11y 결과 폴더 시험
  실패. dev 설정의 결과 경로 빼기 → 새 시험 (1)과 dev 결과 폴더 시험
  실패. a11y 설정에 `workers: 1` → FE-6 시험 실패.
- `check:types`·바꾼 파일 eslint·`check:ci` rc=0.
- 리뷰 반영 RED(트리 a36e8676, 시험만 더함): 새 시험 (4)가 a11y·dev의
  results·report 4개로, testDir 시험이 `test:a11y` 한 줄로 실패.
  거절 입력 시험 둘과 fixture 형제 경로 단언은 통과.
- 리뷰 반영 GREEN(트리 155a93de): 위 시험과 removal-fixture,
  ungated-tests, documentation-readiness 7파일 549개 통과,
  `check:types`·바꾼 파일 eslint rc=0.
- FE-GATE-020: 첫 판(트리 ac0ea6d7)의 desktop merge에서 rc=1
  (「decisions.md names paths that do not exist」).
- FE-6 단언 옮김 RED(트리 eed3c87f): a11y 설정에 `retries: 7` 변이 →
  옮긴 단언이 새 시험에서 실패(1 failed, 6 passed). 옛 자리에 그 단언이
  없다(`ci-workflow-generation.test.ts`에서 `loadConfigFile`·
  `withoutResultPaths`·`playwrightRuns` grep 0건).
- GREEN(트리 d2d941c3): 새 시험, ci-workflow-generation, ungated-tests,
  removal-fixture 4파일 485개 통과, `check:types`·바꾼 파일 eslint rc=0.

Refs: 1106 리뷰 11 영역 3.2 (3) 증거 읽기 주의
2026-11-20 22:20:28 +09:00

135 lines
5.5 KiB
TypeScript

import { readFileSync } from "node:fs";
import { afterEach, describe, expect, it } from "vitest";
import {
configRuns,
describeResultFolders,
describeServerPorts,
itExitsWhenItsPortIsTaken,
itKeepsTheViteCacheInTheRun,
hold,
releaseRuns,
webServer,
webServers,
} from "../helpers/playwright-run-isolation.ts";
/**
* 1105/12-04. Every Playwright config wrote its results, report and JUnit
* file, and the e2e and visual builds wrote `dist`, at fixed paths. A second
* run in one checkout deleted the first one's results (Playwright empties
* `outputDir` at start) and emptied the `dist` its preview was serving. Under
* TEST_RUN_ID each run gets its own paths; without it the paths stay where
* FE-GATE-008 and the CI upload read them.
*
* The servers listened on fixed ports (e2e 4173, visual and capabilities both
* 4174, storybook 6006, dev 5173), so the second run failed with "is already
* used", and the dev config reused whatever answered on 5173. Each now picks
* a free port, which the runner's environment hands to the workers.
*
* Each load evaluates the config again with the environment of one process.
*
* 1106/10-01. The capabilities config is checked in
* tests/unit/playwright-capabilities-run-isolation.test.ts: it goes with the
* browser file/storage runtime, and test:browser-file-storage-removal deletes
* the config and that file by name. This file has the five configs every
* project has; the a11y config spreads the e2e one.
*/
const runs = configRuns({
e2e: () => import("../../playwright.config.ts"),
a11y: () => import("../../playwright.a11y.config.ts"),
visual: () => import("../../playwright.visual.config.ts"),
storybook: () => import("../../playwright.storybook.config.ts"),
dev: () => import("../../playwright.dev.config.ts"),
});
afterEach(releaseRuns);
describeResultFolders(runs, [
["e2e", "e2e"],
["a11y", "a11y"],
["visual", "visual"],
["storybook", "storybook"],
["dev", "e2e-dev"],
]);
describe("the build a run serves", () => {
it.each(["e2e", "visual"] as const)(
"is the checkout's dist without a run ID, and the run's own with one (%s)",
async (name) => {
const checkout = webServer(await runs.load(name));
expect(checkout.env?.["RUN_OUTPUT_ROOT"]).toBe(".");
expect(checkout.command).toMatch(/ --outDir dist(?: |$)/u);
const run = webServer(await runs.load(name, { TEST_RUN_ID: "a" }));
// The build writes under RUN_OUTPUT_ROOT and the preview serves it.
expect(run.env?.["RUN_OUTPUT_ROOT"]).toBe(".tmp/runs/a");
expect(run.command).toMatch(/^corepack pnpm build && corepack pnpm preview /u);
expect(run.command).toMatch(/ --outDir \.tmp\/runs\/a\/dist(?: |$)/u);
},
);
itKeepsTheViteCacheInTheRun(runs, ["dev"]);
it("builds the workshop into the run's folder the way build:storybook does", async () => {
const checkout = webServer(await runs.load("storybook")).command;
expect(checkout).toMatch(
/^corepack pnpm build:storybook && node scripts\/serve-static\.ts artifacts\/storybook\/static /u,
);
const run = webServer(await runs.load("storybook", { TEST_RUN_ID: "a" })).command;
const script = (
JSON.parse(readFileSync("package.json", "utf8")) as { scripts: Record<string, string> }
).scripts["build:storybook"]!;
const sameStepsOtherFolder = script
.replace("&& storybook build", "&& corepack pnpm exec storybook build")
.replace("-o artifacts/storybook/static", "-o .tmp/runs/a/artifacts/storybook/static");
expect(sameStepsOtherFolder).not.toBe(script);
expect(run.startsWith(`${sameStepsOtherFolder} && `)).toBe(true);
expect(run).toMatch(/ node scripts\/serve-static\.ts \.tmp\/runs\/a\/artifacts\/storybook\/static /u);
});
});
describeServerPorts(runs, ["e2e", "visual", "storybook", "dev"]);
// The gallery goldens open workshop stories: the visual config starts the
// static workshop next to its preview, on a port of its own.
describe("the visual config's workshop server", () => {
const workshop = async (environment: Readonly<Record<string, string>> = {}) => {
const runner = await runs.loadProcess("visual", environment);
const servers = webServers(runner.config);
expect(servers).toHaveLength(2);
return { runner, server: servers[1]! };
};
it("is a free port of its own the runner hands to its workers", async () => {
const { runner, server } = await workshop();
const port = Number(runner.after["TEST_VISUAL_WORKSHOP_PORT"]);
expect(port).toBeGreaterThan(0);
expect(port).not.toBe(Number(runner.after["TEST_VISUAL_PORT"]));
expect(server.url).toBe(`http://127.0.0.1:${port}`);
expect(server.command).toMatch(new RegExp(` ${port}$`, "u"));
expect(server.reuseExistingServer).toBe(false);
});
it("moves for a second run while the first run's server holds its port", async () => {
const first = (await workshop()).server.url;
await hold(Number(new URL(String(first)).port));
expect((await workshop()).server.url).not.toBe(first);
});
it("serves the build the workshop config serves, in the run's folder", async () => {
const pinned = { TEST_VISUAL_WORKSHOP_PORT: "40124", TEST_STORYBOOK_PORT: "40124" };
for (const environment of [pinned, { ...pinned, TEST_RUN_ID: "a" }]) {
const { server } = await workshop(environment);
expect(server.command).toBe(webServer(await runs.load("storybook", environment)).command);
}
});
});
describe("vite servers", () => {
itExitsWhenItsPortIsTaken(runs, ["e2e", "visual", "dev"]);
});