From f81dda49134096bed2a7949f4a642efaad24f0c1 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 13 Nov 2026 18:04:31 +0900 Subject: [PATCH 1/2] =?UTF-8?q?test(e2e):=20Firefox=20=EB=B8=8C=EB=9D=BC?= =?UTF-8?q?=EC=9A=B0=EC=A0=80=20=ED=94=84=EB=A1=9C=ED=95=84=EC=9D=84=20RAM?= =?UTF-8?q?=20=ED=8C=8C=EC=9D=BC=EC=8B=9C=EC=8A=A4=ED=85=9C=EC=97=90=20?= =?UTF-8?q?=EB=91=94=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FE-GATE-008의 Firefox 시험이 가끔 첫 화면 5초 대기에서 실패한다 (old-tab-chunk-recovery.spec.ts, preload-use.spec.ts, platform-overview.spec.ts). runner run 127과 desktop merge 검증에서 실패했고, 다시 돌리면 통과해 묻혔다. Playwright는 Firefox 프로필을 os.tmpdir()에 만든다. desktop과 CI job 모두 /tmp가 같은 SATA SSD 위에 있다. Firefox는 시험 context의 localStorage·IndexedDB를 그 프로필(디스크)에 둔다. 그래서 디스크가 붐비면 context마다 첫 localStorage 접근이 디스크 일을 기다린다. Chromium·WebKit은 시험 context 저장소를 메모리에 둔다. 앱은 첫 렌더 전에 색 구성 설정을 localStorage에서 읽어, 그 대기가 첫 화면 대기에 들어간다. desktop e2e 전체 8회(2026-11-13)에서 Firefox 앱 부팅 463회 중 19회가 0.7~3.8초 멈췄고, Chromium·WebKit은 16 ms를 넘지 않았다. tests/support/browser/browser-test.ts가 Firefox worker의 프로필을 RAM 파일시스템에 둔다. os.tmpdir()가 이미 tmpfs면 그대로 쓴다. 아니면 /dev/shm에 worker 수 x 64 MB 자리가 있을 때 그 안에 폴더를 만든다. Playwright의 browser fixture가 launch하는 동안만 TMPDIR를 그 폴더로 돌리고 바로 되돌린다. 그래서 fixture build 같은 다른 임시 파일은 디스크에 그대로 남는다. 프로필이 그 폴더에 생기지 않으면 시험을 실패시킨다. 자리가 없으면 이유를 한 줄 알리고 디스크에 둔다. strict fixture와 strict를 쓰지 않는 spec 둘(preload-use, chunk-load-error)이 이 test를 바탕으로 쓴다. docs/work/reference/testing.md 5절 표에 원인을 적었다. 버린 대안: - worker마다 localStorage를 미리 한 번 건드리는 예열: 브라우저 프로세스당 한 번 드는 준비 비용으로 봤다. 예열 뒤에도 19/463이 멈췄다. 예열 context를 바로 닫는 판은 21/464로 더 나빴다. - toolkit.storage.synchronous=0(SQLite fsync 끔): 15/224로 그대로였다. - 첫 화면 대기 timeout 늘리기, worker 줄이기: 원인을 덮는다. - 시험 실행 전체에 TMPDIR 걸기: fixture build까지 RAM에 들어간다. 위험·한계: - CI job 컨테이너는 /dev/shm이 64 MB다(2026-11-13 runner 확인). /tmp는 같은 SSD 위에 있다. 그래서 CI에서는 프로필이 디스크에 남고 로그에 이유가 한 줄 찍힌다. CI까지 고치려면 runner가 job 컨테이너에 RAM 자리를 줘야 한다(--shm-size 또는 --tmpfs /tmp). runner 설정이라 이 커밋에 넣지 않았다. - 64 MB/worker는 Firefox worker 6개 프로필 합이 가장 컸을 때 211 MB(1개 35 MB)인 것을 보고 잡은 여유다. - Playwright의 두 동작에 기댄다. fixture 의존성을 적힌 순서로 준비하는 것과, launch할 때 os.tmpdir()를 읽는 것이다. 어느 쪽이 바뀌어도 폴더가 비므로 시험이 실패해 알린다. 검증(desktop): - 재현: Firefox 6개를 동시에 띄우고 context 8개씩 localStorage 첫 접근을 쟀다. 프로필 /tmp에서 최대 8,157 ms(384회), /dev/shm에서 최대 17 ms (384회). - 수정본 e2e 전체 10회: 매번 189 passed. Firefox 부팅 576회 중 0.5초를 넘는 멈춤 0회(최대 36 ms), 부하 15.9~31.2. 프로필은 매번 /dev/shm에 5~6개, 디스크 0개, 끝난 뒤 남은 폴더 0개. - 변이: launch 전에 TMPDIR를 돌리지 않게 하면 theme.spec.ts(firefox)가 2 failed, 안전장치 메시지로 실패한다. - check:types:test, eslint(바뀐 파일), check:test-evidence:source 통과. - scripts/verify.sh gate FE-GATE-008(CI=true, main ee95573f 위): rc=0 205초, e2e 189 passed, browser-capabilities 69, storybook 11, visual 7. - scripts/verify.sh docs, desktop verify:documentation 통과. --- docs/work/reference/testing.md | 1 + .../chunk-load-error.spec.ts | 2 +- tests/e2e/preload-use.spec.ts | 5 +- tests/support/browser/browser-test.ts | 117 ++++++++++++++++++ tests/support/browser/strict-browser-test.ts | 8 +- 5 files changed, 125 insertions(+), 8 deletions(-) create mode 100644 tests/support/browser/browser-test.ts diff --git a/docs/work/reference/testing.md b/docs/work/reference/testing.md index bd739ff0..c4f5943c 100644 --- a/docs/work/reference/testing.md +++ b/docs/work/reference/testing.md @@ -101,6 +101,7 @@ | 그리는 중인 화면을 누른다 | 앱 뒤에 붙인 버튼이 렌더링 중 12 px 밀려 클릭이 닿지 않았다 | 테스트가 붙이는 조작 요소는 앱 레이아웃과 무관한 고정 층에 둔다. "다 그려질 때까지 기다리기"는 신호가 없어 쓰지 않는다(결함 패턴 T5) | | 짧은 상태를 폴링으로 잡는다 | 500 ms만 이어지는 `BLOCKED` 상태를 폴링으로 잡으려다 두 엔진에서 실패 | 상태 변화를 이벤트·기록으로 받는다 | | 고정 상한과 첫 실행 비용 | provider 테스트 10개가 10초 상한에 묶이고, 하나만 고르면 첫 테스트가 fixture 빌드를 떠안아 실패 | 무거운 준비는 suite 준비 단계로 옮기고 suite가 자기 timeout을 선언한다 | +| 브라우저가 붐비는 디스크를 기다린다 | Firefox는 시험 context의 localStorage를 디스크의 프로필에 둔다. runner와 같이 쓰는 desktop SSD에서 context마다 첫 접근이 최대 8.2초 멈췄고, 첫 화면 5초 대기 안에서 실패했다. 프로필을 `/dev/shm`에 두면 최대 17 ms | Firefox 프로필은 RAM 파일시스템에 둔다(`tests/support/browser/browser-test.ts`). 자리가 없으면 그 사실과 이유를 한 줄로 알린다 | ## 6. 테스트 실행 비용 diff --git a/tests/browser-capabilities/chunk-load-error.spec.ts b/tests/browser-capabilities/chunk-load-error.spec.ts index 41e638fb..5929a857 100644 --- a/tests/browser-capabilities/chunk-load-error.spec.ts +++ b/tests/browser-capabilities/chunk-load-error.spec.ts @@ -1,4 +1,4 @@ -import { expect, test } from "@playwright/test"; +import { expect, test } from "../support/browser/browser-test.ts"; // R3-7. The chunk-recovery classifier matches engine error wording. Run the // app's own classifier (served by the dev server) against the error each real diff --git a/tests/e2e/preload-use.spec.ts b/tests/e2e/preload-use.spec.ts index 3652cf11..7f614f83 100644 --- a/tests/e2e/preload-use.spec.ts +++ b/tests/e2e/preload-use.spec.ts @@ -1,10 +1,13 @@ import { readFile } from "node:fs/promises"; import path from "node:path"; -import { expect, test, type Page } from "@playwright/test"; +import type { Page } from "@playwright/test"; import { addGeneratedFeature } from "../../scripts/lib/generated-feature.ts"; import { testRunPath } from "../../scripts/lib/run-isolation.ts"; +// The tracker's own tests run without the strict verdict, on the same +// browser set-up as every other spec. +import { expect, test } from "../support/browser/browser-test.ts"; import { trackPreloadUse } from "../support/browser/preload-use.ts"; import { test as strictTest } from "../support/browser/strict-browser-test.ts"; import { diff --git a/tests/support/browser/browser-test.ts b/tests/support/browser/browser-test.ts new file mode 100644 index 00000000..eee1e26a --- /dev/null +++ b/tests/support/browser/browser-test.ts @@ -0,0 +1,117 @@ +import { mkdtemp, readdir, rm, statfs } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import path from "node:path"; + +import { test as base } from "@playwright/test"; + +export { expect } from "@playwright/test"; + +/** + * The browser tests' base `test`: Playwright's, with each Firefox worker's + * browser profile on a RAM filesystem. Every browser spec reaches it, through + * tests/support/browser/strict-browser-test.ts or directly. + * + * Firefox keeps a test context's localStorage and IndexedDB in the profile on + * disk (Chromium and WebKit keep them in memory), and the first localStorage + * access of each context waits for that disk work. On desktop, whose SSD the + * CI runner shares with every other job, that access took up to 8.2 s with + * the profile in /tmp and never more than 17 ms with it in /dev/shm + * (2026-11-13, six browsers at a time, 384 accesses each way). The app reads + * the colour scheme preference before it renders, so a Firefox test spent the + * wait inside its 5 s wait for the first screen: 19 of 463 Firefox app boots + * took 0.7 to 3.8 s in eight full FE-GATE-008 runs, and none of 174 took more + * than 14 ms in three Firefox runs with the profiles in RAM. The failures it + * caused before were in `old-tab-chunk-recovery.spec.ts`, + * `preload-use.spec.ts` and `platform-overview.spec.ts`. + */ + +/** `f_type` of a tmpfs in statfs(2). */ +const TMPFS_MAGIC = 0x0102_1994; + +/** The RAM filesystem of Linux, the desktop and the CI job containers included. */ +const SHARED_MEMORY = "/dev/shm"; + +/** + * Room for one Firefox profile. Six Firefox workers' profiles held 211 MB + * together at their largest in a Firefox FE-GATE-008 run (2026-11-13). + */ +const PROFILE_ROOM_BYTES = 64 * 1024 * 1024; + +type ProfileRoot = Readonly<{ + /** The directory for the profile when it is not the temp directory. */ + root?: string; + /** Why the profile stays on disk. */ + note?: string; +}>; + +/** + * Where this worker's Firefox makes its profile: the temp directory when it is + * already in RAM, else a new directory in /dev/shm when that has room for + * every worker's profile, else the temp directory on disk, with the reason. + */ +async function firefoxProfileRoot(workers: number): Promise { + const needed = workers * PROFILE_ROOM_BYTES; + const notes: string[] = []; + for (const candidate of [tmpdir(), SHARED_MEMORY]) { + const space = await statfs(candidate).catch(() => undefined); + if (space === undefined) { + notes.push(`${candidate} is missing`); + } else if (space.type !== TMPFS_MAGIC) { + notes.push(`${candidate} is on disk`); + } else if (space.bavail * space.bsize < needed) { + notes.push( + `${candidate} has ${Math.floor((space.bavail * space.bsize) / 2 ** 20)} MB free, ` + + `${workers} workers need ${needed / 2 ** 20} MB`, + ); + } else { + return candidate === tmpdir() + ? {} + : { root: await mkdtemp(path.join(candidate, "playwright-firefox-")) }; + } + } + return { note: `Firefox profiles stay on disk in ${tmpdir()}: ${notes.join("; ")}.` }; +} + +/** TMPDIR as the worker started, put back once the browser has launched. */ +const workerTmpdir = process.env.TMPDIR; + +function restoreTmpdir() { + if (workerTmpdir === undefined) delete process.env.TMPDIR; + else process.env.TMPDIR = workerTmpdir; +} + +export const test = base.extend({ + firefoxProfileRoot: [ + async ({ browserName }, use, workerInfo) => { + const choice = + browserName === "firefox" ? await firefoxProfileRoot(workerInfo.config.workers) : {}; + if (choice.note !== undefined) console.warn(choice.note); + if (choice.root !== undefined) process.env.TMPDIR = choice.root; + try { + await use(choice); + } finally { + restoreTmpdir(); + if (choice.root !== undefined) await rm(choice.root, { recursive: true, force: true }); + } + }, + { scope: "worker" }, + ], + // Playwright sets up a fixture's dependencies in the order they are named, + // so the root is chosen before Playwright's own `browser` launches and + // makes its profile under os.tmpdir(). TMPDIR points at the root only until + // then: nothing else the worker puts in the temp directory goes to RAM. + browser: [ + async ({ firefoxProfileRoot, browser }, use) => { + restoreTmpdir(); + const { root } = firefoxProfileRoot; + if (root !== undefined && (await readdir(root)).length === 0) { + throw new Error( + `Firefox did not make its profile in ${root}: Playwright no longer reads ` + + "os.tmpdir() when it launches a browser (or the browser was connected, not launched).", + ); + } + await use(browser); + }, + { scope: "worker" }, + ], +}); diff --git a/tests/support/browser/strict-browser-test.ts b/tests/support/browser/strict-browser-test.ts index 0f144bee..1c0b5a94 100644 --- a/tests/support/browser/strict-browser-test.ts +++ b/tests/support/browser/strict-browser-test.ts @@ -1,10 +1,6 @@ -import { - expect, - test as base, - type ConsoleMessage, - type Page, -} from "@playwright/test"; +import type { ConsoleMessage, Page } from "@playwright/test"; +import { expect, test as base } from "./browser-test.ts"; import { trackPreloadUse } from "./preload-use.ts"; /** -- 2.54.0 From c239bdf4d50a148d043fd4fd1e2cada13dc12c78 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Fri, 13 Nov 2026 19:34:18 +0900 Subject: [PATCH 2/2] =?UTF-8?q?ci(gates):=20browser=20job=20=EC=BB=A8?= =?UTF-8?q?=ED=85=8C=EC=9D=B4=EB=84=88=EC=9D=98=20/dev/shm=EC=9D=84=202=20?= =?UTF-8?q?GB=EB=A1=9C=20=EC=97=B0=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CI job 컨테이너의 /dev/shm은 Docker 기본값 64 MB다. 그래서 앞 커밋의 Firefox RAM 프로필이 CI에서는 켜지지 않는다. 프로필은 runner 디스크에 남고, 이유가 한 줄 찍힌다. main run 266(ee95573f)도 같은 꼴로 빨갛다. FE-GATE-009 [firefox] generated-feature.spec.ts:380에서 첫 화면(로그인 heading) 5초 대기를 넘겼다. 생성기가 Playwright 이미지를 쓰는 job 컨테이너에 `options: "--shm-size=2g"`를 붙인다(BROWSER_JOB_SHARED_MEMORY). 2 GB는 Firefox worker 6개 프로필 합 최대 211 MB와 fixture가 요구하는 worker당 64 MB에 여유를 둔 값이다. job 메모리 상한 10 GB 안에서 쓴다. ci-quality-gates.md에 한 줄을 적었다. 버린 대안: runner 설정 `container.options`에 같은 값을 두는 안(계획 D-4 (가))은 운영 설정이라 소유자 실행 묶음에 있다. 그것이 적용되면 이 줄은 지워도 된다. 위험·한계: runner는 `privileged: false`다. act_runner가 workflow의 이 옵션을 무시하면 프로필은 그대로 디스크에 남고, FE-GATE-008·009 로그에 「Firefox profiles stay on disk」 줄이 남는다. runner run에서 그 줄이 없는지로 확인한다. 검증(desktop): generate:ci-workflow로 workflow와 snapshot 갱신, ci-browser-image·ci-workflow-generation 시험 449 passed, check:ci-workflow, check:types:node, eslint, scripts/verify.sh docs, verify:documentation 통과. --- .gitea/workflows/quality-gates.yml | 1 + docs/operations/ci-quality-gates.md | 5 ++++- scripts/generate-ci-workflow.ts | 18 +++++++++++++++++- .../ci-workflow-generation.test.ts.snap | 1 + tests/unit/ci-browser-image.test.ts | 6 ++++-- 5 files changed, 27 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/quality-gates.yml b/.gitea/workflows/quality-gates.yml index 2c76e9eb..4bf9eb16 100644 --- a/.gitea/workflows/quality-gates.yml +++ b/.gitea/workflows/quality-gates.yml @@ -175,6 +175,7 @@ jobs: timeout-minutes: 45 container: image: "mcr.microsoft.com/playwright:v1.62.0-noble@sha256:baed2032d533817f3dbe6425de795788430ba345e819a1201337009ba17c9d07" + options: "--shm-size=2g" env: CI_RUNNER_IMAGE: "mcr.microsoft.com/playwright:v1.62.0-noble@sha256:baed2032d533817f3dbe6425de795788430ba345e819a1201337009ba17c9d07" steps: diff --git a/docs/operations/ci-quality-gates.md b/docs/operations/ci-quality-gates.md index 5be5aff5..ae54a31d 100644 --- a/docs/operations/ci-quality-gates.md +++ b/docs/operations/ci-quality-gates.md @@ -8,7 +8,10 @@ 출력을 거절한다. `corepack pnpm check:ci`는 산출물 schema 검사, 타입이 있는 계약 검사기, 이 workflow drift 검사를 돈다. merge 단계는 job 셋(`merge_static`, `merge_test`, `merge_browser`)으로 돌고 job마다 설치를 한 번 한다. 게이트마다 ID 이름의 step이 하나씩 -있고, 실패한 게이트가 다음 게이트를 건너뛰게 하지 않는다. +있고, 실패한 게이트가 다음 게이트를 건너뛰게 하지 않는다. `merge_browser` 컨테이너는 `/dev/shm`을 +2 GB로 연다(`--shm-size=2g`). Firefox 시험 프로필을 RAM에 두기 위해서다 +(`tests/support/browser/browser-test.ts`). Docker 기본값 64 MB면 프로필이 runner 디스크에 남아 +Firefox의 첫 localStorage 접근이 수 초씩 기다렸다. merge job 셋만 의존성 캐시를 쓴다(권하는 안으로 정함 2026-11-13, 총괄). setup-node 앞에서 Node toolcache, corepack이 받은 pnpm, pnpm store와 메타데이터 캐시를 `.nvmrc`와 diff --git a/scripts/generate-ci-workflow.ts b/scripts/generate-ci-workflow.ts index dd1a400a..85860be5 100644 --- a/scripts/generate-ci-workflow.ts +++ b/scripts/generate-ci-workflow.ts @@ -210,7 +210,13 @@ function renderJob( ` timeout-minutes: ${job.timeoutMinutes}`, ); const image = jobImage(job); - if (image) lines.push(" container:", ` image: ${yamlScalar(image)}`); + if (image) { + lines.push( + " container:", + ` image: ${yamlScalar(image)}`, + ` options: ${yamlScalar(`--shm-size=${BROWSER_JOB_SHARED_MEMORY}`)}`, + ); + } if (job.kind === "immutable") { const archive = job.steps.find((step) => step.kind === "archive-candidate"); if (!archive || archive.kind !== "archive-candidate") throw new TypeError("immutable job lacks archive step"); @@ -291,6 +297,16 @@ function gateHostPrefix(gate: Readonly<{ hostEnvironment?: "system-container" | return gate?.hostEnvironment === "system-container" ? "scripts/run-in-system-container.sh " : ""; } +/** + * /dev/shm of a browser job's container. Firefox's test profiles go there when + * it has room for every worker (tests/support/browser/browser-test.ts): with a + * profile on the runner's shared disk, Firefox's first localStorage access in + * a context waited up to 8.2 s and failed first-screen waits (FE-GATE-008 and + * FE-GATE-009, runs 127 and 266). Docker's default of 64 MB holds none; six + * Firefox workers' profiles peaked at 211 MB together (2026-11-13). + */ +export const BROWSER_JOB_SHARED_MEMORY = "2g"; + /** The Playwright image a browser job runs in (`browser-install.image`), if any. */ function jobImage(job: CiWorkflowJob): string | undefined { for (const step of job.steps) { diff --git a/tests/unit/__snapshots__/ci-workflow-generation.test.ts.snap b/tests/unit/__snapshots__/ci-workflow-generation.test.ts.snap index 4f08cf2c..cbb87091 100644 --- a/tests/unit/__snapshots__/ci-workflow-generation.test.ts.snap +++ b/tests/unit/__snapshots__/ci-workflow-generation.test.ts.snap @@ -178,6 +178,7 @@ jobs: timeout-minutes: 45 container: image: "mcr.microsoft.com/playwright:v1.62.0-noble@sha256:baed2032d533817f3dbe6425de795788430ba345e819a1201337009ba17c9d07" + options: "--shm-size=2g" env: CI_RUNNER_IMAGE: "mcr.microsoft.com/playwright:v1.62.0-noble@sha256:baed2032d533817f3dbe6425de795788430ba345e819a1201337009ba17c9d07" steps: diff --git a/tests/unit/ci-browser-image.test.ts b/tests/unit/ci-browser-image.test.ts index 127c9b1c..6cadc273 100644 --- a/tests/unit/ci-browser-image.test.ts +++ b/tests/unit/ci-browser-image.test.ts @@ -3,7 +3,7 @@ import { readFileSync } from "node:fs"; import { describe, expect, it } from "vitest"; import { loadCiGateContract, PLAYWRIGHT_JOB_IMAGE_PATTERN } from "../../scripts/contracts/ci-gates.ts"; -import { renderCiWorkflow } from "../../scripts/generate-ci-workflow.ts"; +import { BROWSER_JOB_SHARED_MEMORY, renderCiWorkflow } from "../../scripts/generate-ci-workflow.ts"; /** * merge_browser runs in Playwright's own image so it does not download the @@ -36,7 +36,9 @@ describe("browser job image", () => { const job = workflow.slice(workflow.indexOf(" merge_browser:\n"), workflow.indexOf(" release_gate:\n")); expect(image?.kind === "browser-install" && image.image).toBeTruthy(); const ref = image?.kind === "browser-install" ? image.image! : ""; - expect(job).toContain(` container:\n image: "${ref}"\n`); + expect(job).toContain( + ` container:\n image: "${ref}"\n options: "--shm-size=${BROWSER_JOB_SHARED_MEMORY}"\n`, + ); expect(job).toContain(` env:\n CI_RUNNER_IMAGE: "${ref}"\n`); expect(job).not.toContain("playwright install"); }); -- 2.54.0