From c4ab4083b604f4019e39d96990ce506084ea9e80 Mon Sep 17 00:00:00 2001 From: yo4e <59075346+yo4e@users.noreply.github.com> Date: Tue, 20 Oct 2026 16:12:18 +0900 Subject: [PATCH] Wait for Playwright directory listener installation before selection --- docs/VALIDATION.md | 2 ++ package.json | 2 +- scripts/prepare-browser-tests.mjs | 39 +++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 scripts/prepare-browser-tests.mjs diff --git a/docs/VALIDATION.md b/docs/VALIDATION.md index 040a68d..ca733c6 100644 --- a/docs/VALIDATION.md +++ b/docs/VALIDATION.md @@ -57,6 +57,8 @@ npm run test:ui 同じフォルダの再読込では、「本のフォルダを開く」から原稿を3版に書き換えて読み、各版のタイトル・原稿・画像・保存結果を確認する。変更のない同じフォルダについても本文DOMの入れ替えを確認し、前回の完了表示だけを見て成功としない。WebKitではこのシナリオを追加で5回繰り返し、失敗時のスクリーンショットとトレースをActionsのartifactに7日間残す。 +`npm run test:ui`は、固定したPlaywright 1.61.1のディレクトリ選択処理にテスト専用の補正を適用する(`scripts/prepare-browser-tests.mjs`)。元の処理は`input`監視の登録完了を待たずにネイティブ選択を開始するため、Ubuntu WebKitでイベントを取り逃がすことがある。保存トレースでは本が表示済みでも`setInputFiles`が30秒待機していた。補正は監視登録の完了を確認してから選択を実行する。タイムアウト延長・例外の握りつぶし・再試行・テスト省略は行わず、製品のparser/viewerには含めない。バージョンや対象コードが変わった場合は明示的に失敗するので、Playwright更新時に上流の修正を確認して削除または再評価する。2026-10-20時点の[公式v1.64.1実装](https://github.com/microsoft/playwright/blob/v1.64.1/packages/playwright-core/src/server/dom.ts#L770)にも同じ登録順序が残っている。 + 保存したスクリーンショットと`evidence/validation-summary.json`は上記macOSの初回記録であり、CIの毎回の結果へ自動で上書きコミットしない。CIが検証したコミットと実行結果はActionsで確認する。Ubuntu上のブラウザ検証が通っても、Linux全般の手動読書・フォント・支援技術の評価済みとは扱わない。 ## 既知の制限 diff --git a/package.json b/package.json index 4222f8f..5074e97 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "lint": "eslint .", "typecheck": "tsc --noEmit", "test": "node --test tests/*.test.mjs", - "test:ui": "npm run build && playwright test", + "test:ui": "npm run build && node scripts/prepare-browser-tests.mjs && playwright test", "validate": "node src/cli.mjs validate", "ast": "node src/cli.mjs ast" }, diff --git a/scripts/prepare-browser-tests.mjs b/scripts/prepare-browser-tests.mjs new file mode 100644 index 0000000..33099e7 --- /dev/null +++ b/scripts/prepare-browser-tests.mjs @@ -0,0 +1,39 @@ +// Test infrastructure only. Playwright 1.61.1 starts an evaluate() that installs +// an input listener, then sends the native file-selection command without an +// acknowledgement that the listener exists. Linux WebKit can dispatch first: +// the book loads, but setInputFiles never resolves. Wait for a JSHandle to an +// object containing the event promise before selecting files, then await it. +// Keep this narrowly guarded and remove it once the upstream race is fixed. +import { readFile, writeFile } from 'node:fs/promises'; +import { createRequire } from 'node:module'; +import { dirname, join } from 'node:path'; + +const require = createRequire(import.meta.url); +const packagePath = require.resolve('playwright-core/package.json'); +const { version } = JSON.parse(await readFile(packagePath, 'utf8')); +if (version !== '1.61.1') throw new Error('Reassess the directory-input race patch for this Playwright version.'); +const bundlePath = join(dirname(packagePath), 'lib/coreBundle.js'); +const source = await readFile(bundlePath, 'utf8'); +const original = ` const waitForInputEvent = localDirectory ? this.evaluate((node) => new Promise((fulfill) => { + node.addEventListener("input", fulfill, { once: true }); + })).catch(() => { + }) : Promise.resolve(); + await this._page.delegate.setInputFilePaths(progress2, retargeted, localPathsOrDirectory); + await progress2.race(waitForInputEvent);`; +const replacement = ` // YomPUB test harness: acknowledge listener installation before selection. + const inputEvent = localDirectory ? await progress2.race(this.evaluateHandle((node) => ({ + promise: new Promise((fulfill) => node.addEventListener("input", fulfill, { once: true })) + }))) : null; + try { + await this._page.delegate.setInputFilePaths(progress2, retargeted, localPathsOrDirectory); + if (inputEvent) await progress2.race(inputEvent.evaluate((event) => event.promise)); + } finally { + await inputEvent?.dispose(); + }`; +if (source.includes(replacement)) { + console.log('Playwright directory-input listener patch already applied.'); +} else { + if (source.split(original).length !== 2) throw new Error('Playwright upload implementation changed; refusing an unverified patch.'); + await writeFile(bundlePath, source.replace(original, replacement)); + console.log('Applied test-only Playwright directory-input listener patch.'); +}