GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Stage 6: e2e テスト基盤(Playwright + window.api モック)を追加 by ymnao · Pull Request #17 · ymnao/scripta Conversation
Owner
概要Stage 6 の「e2e テスト整備」項目として、Playwright + 関連 Issueなし 移行 Stage
変更内容採用した方針
追加ファイル
変更ファイル
Api 型固定
動作確認
スクリーンショットUI 変更なし(テスト基盤のみ)。
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsStage 6 の「e2e テスト整備」項目に着手。旧 Tauri 版が `tauri-mock.ts` で `window.__TAURI__` をモックしてブラウザ Chromium で軽量 e2e を回していた戦略を 踏襲し、Electron では実機を起動せず renderer-only Vite dev サーバーを叩いて `window.api` を `addInitScript` 経由で注入する構造に置き換える。 ## 採用した方針 - renderer-only(Playwright `_electron` 実機モードは不採用) - 旧 24 spec の移植コストを最小化 - CI で xvfb-run / display 設定が不要 - 実 IPC / main プロセスのテストは Vitest 側 (`electron/main/**/*.test.ts`) で網羅済み - port は 5174 固定(`electron-vite dev` の 5173 と衝突回避、`strictPort: true`) - `tsconfig.e2e.json` は既定 `pnpm typecheck` には含めず `typecheck:e2e` を独立配線(旧版踏襲) ## 追加ファイル - `vite.config.e2e.ts` — renderer-only の素 Vite config(react + tailwindcss) - `playwright.config.ts` — Chromium プロジェクト + `webServer: pnpm dev:e2e` - `tsconfig.e2e.json` — DOM + node 型の e2e 専用 tsconfig - `e2e/helpers/electron-api-mock.ts` — `ElectronApiMock` クラス。`addInitScript` で `window.api` の全 50+ メソッドを stateful にモック注入。検索 / wikilink スキャン / fs watcher / メニューイベント / ダイアログまで対応 - `e2e/smoke.spec.ts` — 起動 smoke テスト 2 ケース - `e2e/sidebar-toggle.spec.ts` — 旧版から移植(Cmd+B でサイドバー開閉) ## 変更ファイル - `package.json` — `@playwright/test@^1.59.1` を devDeps に追加。 `dev:e2e` / `typecheck:e2e` / `test:e2e` / `test:e2e:ui` スクリプトを追加 - `tsconfig.json` — references に `tsconfig.e2e.json` を追加 - `.github/workflows/ci.yml` — typecheck job に `pnpm typecheck:e2e` を追加。 新 `e2e` job を追加(Playwright ブラウザを `~/.cache/ms-playwright` で バージョン pin キャッシュ、failure 時は `playwright-report/` と `test-results/` を artifact upload。retention 7 days) ## ローカル検証 - biome check / tsc node + web / vitest run まで実施。0 errors、1640 passed + 1 既知フレーク(`git.test.ts > pushImpl > propagates network error stderr`、 Stage 5 から継続)+ 2 skipped。 - `pnpm test:e2e` は `pnpm install` 後にユーザー側で実施が必要 (サンドボックス制約で本セッションでは未実行)。 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> 3 エージェント(reuse / quality / efficiency)のレビューを反映。
- `MenuEventName` を `electron/preload/api.ts` から import して使う。
`emitMenuEvent` のリテラル union 重複と `onMenuEvent` モックの string 緩和を解消
- `tsconfig.e2e.json` の include に `electron/preload/api.ts` を追加(上記 import 用)
- `scanUnresolvedWikilinks` のソートを `localeCompare` → バイト比較に変更し、
実装側 `electron/main/ipc/search.ts` と同じ順序にする
- `TextEncoder` インスタンスを scanUnresolvedWikilinks のループ外に hoist
- `renameEntry` の `.map((e) => ({ ...e, path: ... }))` 重複を local `remap` 関数に抽出
- `electron-api-mock.ts` / `playwright.config.ts` / `vite.config.e2e.ts` の
ファイルヘッダ説明を WHY のみに圧縮(What を narrative する文を削除)
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
レビュー指摘で本番 `electron/main/ipc/search.ts` と e2e モックの 3 点の挙動差を
解消。このまま放置すると検索系の e2e が本番では起きない結果で通ったり、
逆に落ちたりする。
## 修正点
1. `collectMdFiles`: `.` 始まりのエントリ(`.git` / `.scripta` 等)を早期 skip。
隠しディレクトリの中身を再帰しない(本番 search.ts:19 と一致)。
2. `searchFiles`: ファイルリストを byte 比較で sort してから走査。検索結果の
順序が決定的になる(本番 search.ts:104-106 と一致)。`split("\n")` も
`split(/\r?\n/)` に変更し改行コード差を吸収(本番 search.ts:124)。
3. `searchFilenames`: フルパスではなく `basename(p)` に対して fuzzy match。
`basename` 抽出も byte sort も含め本番 search.ts:158-160 と完全一致。
ついでに本番 `fuzzyMatch` (search.ts:45-57) と同じ two-pointer 走査の
ヘルパを内側に定義し、char-iteration の挙動も揃える。
## 副次的整理
- `byteCmp` / `fuzzyMatch` を `installApiMock` のスコープに helper 化。
`searchFiles` / `searchFilenames` / `scanUnresolvedWikilinks` の sort 比較を
すべて `byteCmp` に統一。
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
レビュー指摘の追加 2 点:
1. (中) searchFiles の case-insensitive matchStart / matchEnd が
`line.toLowerCase()` 上の position をそのまま返しており、
`İ` (U+0130) → `i\u{0307}` のように長さが変わる Unicode 行で
位置がズレていた。本番 `electron/main/ipc/search.ts:127-135` と同じく
`buildLowerToOrigUtf16Map` で lowercase 文字列上 offset を元行の
UTF-16 offset に逆引きする処理を導入。
`electron/main/utils/search-pure.ts` の `isAsciiOnly` /
`buildLowerToOrigUtf16Map` を `installApiMock` 内に inline コピー
(addInitScript 制約で import 不可)。
2. (低) scanUnresolvedWikilinks の行分割が `split("\n")` のまま
だった。本番 `search.ts:210` と同じく `split(/\r?\n/)` に変更し、
CRLF Markdown で `\r` が lineContent / contextBefore / contextAfter
に残る差異を解消。
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
レビュー指摘 4 点をまとめて修正。
## 1. (高) pnpm-lock.yaml に @playwright/test を追加
`feat:` commit で package.json に追加した `@playwright/test@^1.59.1` が
lockfile に反映されていなかった。CI の
`pnpm install --frozen-lockfile` (.github/actions/setup-node-pnpm) は
package.json と lockfile の不整合で落ちるため、lockfile を同梱する。
## 2. (中) workspaceSet mock に settings の永続化を追加
本番 `electron/main/ipc/workspace.ts:104` → `settings.ts:170`
`persistWorkspacePath(path)` で `settings.workspacePath` まで永続化する
(path === null は delete、それ以外は set)が、mock は activeWorkspace
を更新するだけだった。起動時 `src/lib/store.ts:54` と
`AppLayout.tsx:199` は `settings.workspacePath` を読んで workspace を
復元するため、reload / 再起動系の e2e で本番と違う遷移になっていた。
mock 側も settings.workspacePath を同期更新するよう修正。
## 3. (中) window.api mock を Api 型に固定
`const api = { ... }` で推論任せになっており、preload `Api` 契約と
乖離しても typecheck が通っていた。`import type { Api }` して
`const api: Api = { ... }` に固定。あわせて 7 箇所の loose な型を
preload と一致させた:
- `showSaveDialog opts: unknown` → `SaveDialogOptions`
- `searchFiles return: Promise<unknown[]>` → `Promise<SearchResult[]>`
- `scanUnresolvedWikilinks return: Promise<unknown[]>` → `Promise<UnresolvedWikilink[]>`
- `fetchOgp return: Promise<unknown>` → `Promise<OgpData>`
- `checkForUpdate return: Promise<unknown>` → `Promise<UpdateInfo>`
- `gitStatus return: Promise<unknown>` → `Promise<GitStatus>`
- `gitGetConflictContent return: Promise<unknown>` → `Promise<ConflictContent>`
- `gitPull syncMethod: string` → `SyncMethod`
これで preload `Api` のシグネチャが変わると mock 側も typecheck が
落ちて気付ける。
## 4. (低) CI の Playwright reporter に HTML を追加
CI mode の reporter が `[["dot"], ["github"]]` で HTML report を
生成していなかったが、`.github/workflows/ci.yml:81` は
`playwright-report/` を artifact 化していた。失敗時の解析パスが
切れていた状態。`["html", { open: "never" }]` を追加して
playwright-report/ が確実に生成されるようにする。
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsUh oh!
There was an error while loading. Please reload this page.
3 of 11 tasks
4 of 6 tasks
ymnao
added a commit
that referenced
this pull request
@electron/get / jsdom 経由の undici 7.25.0 と node-gyp 経由の 6.25.0 を それぞれ patched 版 (^7.28.0 / ^6.27.0) に固定して open alert を解消する。 対象 alert (9 件): - #10 GHSA-pr7r-676h-xcf6 (medium) — cross-user info disclosure via shared cache whitespace bypass (7.x) - #11 GHSA-vmh5-mc38-953g (high) — TLS certificate validation bypass via dropped requestTls in SOCKS5 ProxyAgent (7.x) - #12 GHSA-35p6-xmwp-9g52 (low) — HTTP response queue poisoning via keep-alive socket reuse (6.x) - #13 GHSA-35p6-xmwp-9g52 (low) — 同上 (7.x) - #14 GHSA-hm92-r4w5-c3mj (high) — cross-origin request routing via SOCKS5 proxy pool reuse (7.x) - #17 GHSA-p88m-4jfj-68fv (medium) — HTTP header injection via Set-Cookie percent-decoding (6.x) - #18 GHSA-p88m-4jfj-68fv (medium) — 同上 (7.x) - #19 GHSA-g8m3-5g58-fq7m (low) — Set-Cookie SameSite downgrade via permissive substring matching (6.x) - #20 GHSA-g8m3-5g58-fq7m (low) — 同上 (7.x) parent 特定: - `@electron/[email protected]` (electron の devDep transitive) が optionalDep として undici 7.25.0 - `[email protected]` (Vitest の DOM 環境用 devDep) が undici 7.25.0 - `[email protected]` (@electron/rebuild → electron-builder 経由) が undici 6.25.0 実害評価: いずれも build/test time の transitive で本リポ runtime は触らない。 SOCKS5 ProxyAgent / shared cache / 攻撃者制御 Set-Cookie 等の前提を満たさないが、 alert closed 化が目的で patch を適用。
This was referenced
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reviewers
Copilot code review
Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Uh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later. |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |