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 4: simple-git で git sync 移植 + コンフリクト解決ウィンドウ by ymnao · Pull Request #14 · ymnao/scripta Conversation
Owner
概要旧 Tauri 版 scripta 関連 Issueなし 移行 Stage
変更内容git IPC 12 コマンドの本実装(
|
| Commit | 指摘内容 | 修正 |
|---|---|---|
d0830ed |
(高) handleComplete の git add -A が解消対象以外の未ステージ変更まで巻き込み(中) git:conflict-resolved 全 BrowserWindow broadcast で別 workspace の paused 状態が誤クリア |
gitAddAll 削除(個別 file は resolveConflictImpl 時点で stage 済)emit に workspacePath payload、受信側で workspacePath !== resolved なら早期 return |
3bf3d42 |
(高) git rebase --continue が default で commit message editor を起動 → ユーザーの GIT_EDITOR=vim 等でハング |
git-env.ts の env override に GIT_EDITOR=":" / EDITOR=":" / VISUAL=":" / GIT_PAGER="cat" 等を追加(POSIX shell no-op builtin) |
f43a200 |
(中) BrowserWindow.fromId(webContents.id) の型ミスマッチで親解決が常に undefined(中) loadURL 失敗時に Map / allowedRoots がリーク |
getAllWindows().find(w => w.webContents.id === parentSenderId) に変更load を try/catch で囲み、失敗時に conflictWindows.delete / setActiveWorkspaceForWindow(null) / win.destroy() を明示実行 |
pnpm format / pnpm lint / pnpm typecheck / pnpm test 全 passGIT_EDITOR="sleep 30" pnpm test -t "rebase --continue" でローカル再現確認 → 修正後 0.7 秒で passpnpm dev でリモート設定済 workspace を開いて:
UI 変更なし(ConflictWindow.tsx 等のフロント側は Stage 0b で取り込み済み)。
🤖 Generated with Claude Code
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Stage 4 (Git Sync) の準備段階。 - [email protected] を dependencies に追加 - electron/main/utils/git-validators.ts: validateRelativePath / validateRefName / isStageNotFound / MAX_CONFLICT_CONTENT_SIZE を旧 Rust git_sync.rs から 1:1 port - electron/main/utils/git-env.ts: createGit() / createGitNoCwd() / extractGitErrorMessage() - LC_ALL=C / GIT_TERMINAL_PROMPT=0 / GIT_ASKPASS="" / SSH_ASKPASS="" / GIT_LITERAL_PATHSPECS=1 + core.hooksPath=NULL を共通化 - .env({...process.env, ...overrides}) で PATH/HOME を温存 - validator は旧 Rust 5 件 + 拡張で 14 ケースをテスト Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
- electron/main/ipc/git.ts を全 no-op スタブから本実装に置換
- check-available / check-repo / status / add-all / commit / pull / push
- get-conflicted-files / get-conflict-content / resolve-conflict
- finish-conflict-resolution / get-last-commit-time
- emit-conflict-resolved(broadcast は既存実装を維持)
- assertPathAllowed で canonical を取得し I/O は canonical に揃える
(fs.ts / search.ts と同方針)
- pull の "no tracking information" / push の "no upstream" は旧 Rust 互換で
自動ハンドリング("" return / -u origin <branch> 自動付与)
- get-conflict-content は git show :2:/:3: を raw で実行、modify/delete
conflict の missing stage は isStageNotFound で empty 文字列 fallback
- resolve-conflict modify は 旧 Rust safe_write_in_repo を 1:1 port
(親ディレクトリ bounds 再確認 + target が symlink なら拒否)
- finish-conflict-resolution は .git/{rebase-merge,rebase-apply,MERGE_HEAD}
で rebase --continue / commit --no-edit を分岐
- commit は simple-git の "stderr が空だと success 扱い" を回避するため、
stdout の "nothing to commit" パターンを明示的に throw(旧 Tauri Err 経路再現)
simple-git 3.x の vulnerability ガードは process.env 由来の GIT_EDITOR /
GIT_ASKPASS / hooksPath を default で reject するため、対応する unsafe
フラグを git-env.ts でまとめて opt-in した。
テスト: 実 git バイナリ + mkdtemp で 35 ケース(merge/rebase/modify-delete
conflict、no-upstream auto-retry、symlink 拒否、path-guard 横断)。
全テスト 1465 passed (+35)。
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
- electron/main/utils/window-lifecycle.ts を新設
- 親 / 子 共通の close handler (stopWatcherForWindow / clearSearchForWindow /
unregisterWindow) を helper に切り出し、追加 cleanup を注入できる onCleanup
フックを提供
- electron/main/index.ts の close handler を attachWindowLifecycle に置換
- electron/main/ipc/window.ts の window:open-conflict を本実装
- Map<canonical workspacePath, BrowserWindow> で単一インスタンス管理
(旧 Tauri WebviewWindow.getByLabel 互換、複数 workspace 並列にも対応)
- parent の allowedRoots に登録された workspace のみ開かせる
(renderer 引数を信頼せず main 側で再検証)
- 子 webContents.id 向けに setActiveWorkspaceForWindow で path-guard 委譲
(ConflictWindow.tsx は workspaceSet を呼ばないため必須)
- dev: ELECTRON_RENDERER_URL?conflict=true&workspacePath=<encoded>
prod: loadFile(..., { search }) で query 構築
- electron/main/ipc/window.test.ts を新規(vi.hoisted + Proxy で BrowserWindow
をモック化、6 ケース:未承認 path 拒否 / workspace 登録 / URL 構築(dev/prod)/
単一インスタンス / minimized 復帰)
全テスト 1471 passed (+6)。
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Stage 4 (Git Sync) 完了に伴い、L86-90 の `[ ]` を `[x]` に更新。 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
simplify レビューで指摘された逐次 await を並列化。git CLI spawn が逐次 だとレイテンシが累積するため、独立コマンドはまとめて投げる。 - statusImpl: rev-parse / status --porcelain / remote の 3 cmd を並列化 (useGitSync の refresh で頻繁に呼ばれるホットパス) - getConflictContentImpl: stage 2 / 3 の git show を並列化 (conflict resolver 起動直前のブロッキング処理、UX 改善に直結) - finishConflictResolutionImpl: rebase-merge / rebase-apply / MERGE_HEAD の fsp.access を並列化 - pushImpl: no-upstream 再試行で branch / remote 取得を並列化、入れ子の try/catch を平坦化(外側の catch を変数 firstError に詰めて単段に) 挙動変更なし。全 1471 テスト pass。 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
simplify レビュー後にユーザーから指摘された 2 件の実害バグを修正。
1. (高) 完了ボタンで `git add -A` を呼んでいたため、解消対象以外の
未ステージ変更まで `git rebase --continue` / `git commit --no-edit`
に巻き込んでいた。各ファイルは resolveConflict 時点で
`git add -- <file>` / `git rm -- <file>` 済みのため、handleComplete
の gitAddAll 呼び出しは不要かつ有害。削除。
2. (中) `git:conflict-resolved` を全 BrowserWindow に無差別 broadcast
しており、別 workspace で未解決 conflict 中の useGitSync が
`pausedRef.current = false` を先に実行してしまい、refreshStatus
完了前に自動 commit/pull/push が paused 突破で走り得た。
- main: emit に workspacePath payload を載せて broadcast
- preload / commands.ts: emitConflictResolved / onConflictResolved
のシグネチャを (workspacePath: string) で型付け
- ConflictWindow: handleComplete / auto-close の両経路で
emitConflictResolved(workspacePath) を呼ぶ
- useGitSync: 受信時に `resolvedWorkspacePath !== workspacePath`
なら早期 return(自分の workspace の event のみ paused をクリア)
回帰テスト追加: 別 workspace の broadcast を ignore し、自 workspace の
broadcast のみ refreshStatus を走らせることを確認(useGitSync.test.ts に
1 件追加、合計 1472 件 pass)。
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
`git rebase --continue` は default で commit message のエディタを起動する
ため、GIT_ENV_OVERRIDES に GIT_EDITOR / EDITOR / VISUAL の上書きがないと、
ユーザーの普段使い(vim / nano / VS Code 等)が呼ばれてプロセスが
ハングする。`commit --no-edit` 経路は明示 flag のため影響なし。
修正:
- git-env.ts に GIT_EDITOR=":" / GIT_SEQUENCE_EDITOR=":" / EDITOR=":" /
VISUAL=":" を追加(POSIX shell の no-op builtin、git は
`/bin/sh -c "<editor> <file>"` で起動するため即 exit 0)
- 同じ理由で GIT_PAGER="cat" / PAGER="cat" も追加(pager 起因の
ハングを将来 防ぐ defensive override)
回帰テスト: `vi.stubEnv("GIT_EDITOR", "sleep 60")` で hostile な editor を
強制しても rebase --continue が即完走することを担保。
ローカル再現: 修正前は `GIT_EDITOR="sleep 30" pnpm test -t "rebase --continue"`
で `Please supply the message using either -m or -F option` でテスト失敗。
修正後は 0.7 秒で pass。
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
simplify レビューで指摘された 2 件の中程度バグを修正。 1. (中) parent BrowserWindow が解決できておらず親子関連付けが効いていな かった。`event.sender.id` は webContents.id だが、 `BrowserWindow.fromId()` は BrowserWindow.id を期待するため、常に null が返って parent === undefined になっていた。結果として「親 close で 子も追従して close」が成立しない。 → `BrowserWindow.getAllWindows().find(w => w.webContents.id === parentSenderId)` で線形探索に変更。`window:close` ハンドラ既存の `BrowserWindow.fromWebContents()` パターンと同じ意図で、senderId 経路 をそのまま渡せる。 2. (中) loadURL / loadFile が失敗すると Map と allowedRoots に状態が 残り、次回 openConflictWindow が壊れた window を focus し続ける状態 リークがあった。 → loadURL/File を try/catch で囲み、失敗時に conflictWindows.delete / setActiveWorkspaceForWindow(null) / win.destroy() を明示実行してから rethrow。real Electron では destroy が closed event を発火し attachWindowLifecycle 経由でも cleanup が走るが、両者とも冪等なため explicit に書く(mock 環境では closed event が発火しないため)。 回帰テスト追加 (window.test.ts): - "resolves parent BrowserWindow via webContents.id (not BrowserWindow.id)": 親 window を先に作って webContents.id を senderId に渡し、子 window の opts.parent が親 window object を指すことを確認。fromId() ベースの 旧実装ではこのテストは fail する。 - "cleans up Map and allowedRoots when load fails": loadURL を reject させ、Map / allowedRoots / window の destroy が すべて行われ、再 open で新しい window が作られることを確認。 FakeWindow に destroy 追加、`simulateLoadFailure` で次回 load を一時的に fail させるフラグを vi.hoisted に追加。 全テスト 1475 件 pass (+2)。 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
旧 Tauri 版の Git Sync 実装を Electron main(simple-git ベース)へ 1:1 移植し、コンフリクト解決 UI を独立した BrowserWindow として開けるようにする PR です。Stage 4(Git Sync)の移行を完了させ、旧版相当の UX を Electron で再現することを目的としています。
Changes:
simple-git を導入し、Git Sync の IPC 12 コマンド(status / pull / push / conflict 解決等)を Electron main に実装workspacePath payload を載せ、renderer 側で workspace を照合して誤クリアを防止(テスト追加)Copilot reviewed 18 out of 19 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/lib/commands.ts | conflict 解消イベント API を workspacePath payload 付きに更新 |
| src/hooks/useGitSync.ts | conflict 解消 broadcast を workspace 単位でフィルタして paused 誤クリアを防止 |
| src/hooks/useGitSync.test.ts | conflict 解消 broadcast の workspace フィルタ動作をテスト追加 |
| src/components/conflict/ConflictWindow.tsx | git add -A の巻き込み回避+emit に workspacePath を付与、依存配列調整 |
| src/components/conflict/ConflictWindow.test.tsx | emit の引数(workspacePath)を検証するように更新 |
| package.json | simple-git 依存を追加 |
| pnpm-lock.yaml | simple-git および関連依存の lock 追加 |
| electron/preload/index.ts | emitConflictResolved / onConflictResolved を payload 付き IPC に更新 |
| electron/preload/api.ts | preload API 型を payload 付きに更新 |
| electron/main/utils/window-lifecycle.ts | window close 時の per-window 状態 cleanup を共通化 |
| electron/main/utils/git-validators.ts | Git 用 validator / 定数(path/ref/stage 判定)を追加 |
| electron/main/utils/git-validators.test.ts | validator のユニットテスト追加 |
| electron/main/utils/git-env.ts | Git 実行時の env/config/unsafe 設定を集約(hooks/editor/pager 等を制御) |
| electron/main/ipc/window.ts | conflict resolver window の単一インスタンス生成・権限委譲・load 失敗 cleanup を実装 |
| electron/main/ipc/window.test.ts | conflict window の single instance / parent 解決 / load 失敗 cleanup をテスト追加 |
| electron/main/ipc/git.ts | Git Sync IPC を simple-git + raw 呼び出し中心で本実装、conflict resolved broadcast payload 化 |
| electron/main/ipc/git.test.ts | Git IPC 実装の統合テスト(repo/remote/conflict/rebase 等)を追加 |
| electron/main/index.ts | main window の close cleanup を attachWindowLifecycle に移譲 |
| docs/migration-plan.md | Stage 4 完了チェックを更新 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Copilot レビューで指摘された認可漏れを修正。 `git:emit-conflict-resolved` ハンドラは renderer から渡される workspacePath を検証せず全 BrowserWindow に broadcast していたため、 不正な / 別 workspace の renderer が任意の path を流して他 workspace の `pausedRef` を解除できる経路があった。renderer は信頼できない前提で 他 IPC は `assertPathAllowed` を通しているのに、この emit だけ漏れていた。 修正: - `emitConflictResolvedImpl(senderId, workspacePath)` を切り出し、冒頭で `assertPathAllowed(senderId, workspacePath)` を実行 - 正規の conflict window は createConflictWindow 内で `setActiveWorkspaceForWindow(childId, canonical)` 済みなので pass、 偽装 emit は Permission denied で reject される - destroyed window への send 防止に `!win.isDestroyed()` ガードも追加 回帰テスト追加 (git.test.ts): - 正規 sender が自 workspace の path を emit → success - 別 workspace の path を emit → Permission denied - 何も登録されていない window から emit → Permission denied 全テスト 1478 件 pass (+3)。 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 18 out of 19 changed files in this pull request and generated 2 comments.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Copilot レビュー指摘 2 件に対応。
1. (must) resolveConflictImpl の modify 経路で canonical I/O されていない
`assertPathAllowed(senderId, dirname(target))` の戻り値(canonical な親)
を捨てて raw な target で mkdir/writeFile していたため、fs.ts の
「判定に使った canonical をそのまま I/O に使う」TOCTOU 最小化方針から
外れていた。
→ canonical な親を `canonicalParent` として保持し、`canonicalTarget =
join(canonicalParent, basename(target))` で組み直して I/O する形に修正。
symlink lstat は canonical 化前の `target` で実行する必要があるため
順序は変えない(lstat は symlink 自身を検査)。`git add -- filePath`
は repo-relative path で動作するため変更不要。
2. (recommend) UNSAFE_FLAGS が一律 true で前提とコメントがズレていた
フラグの分類をコメントで明記し、不要なものを削除:
- (A) 我々が env / config[] で安全な値に固定しているもの:
hooksPath / editor / askPass / pager
- (B) ユーザーの普段の git 環境(.gitconfig / 環境変数)を意図的に
尊重するもの: credentialHelper / configPaths / sshCommand
旧 Tauri 版が std::process::Command で process.env を継承していたのと
同じ UX を維持するため。攻撃者制御値の流入は IPC 認可で workspace
単位に閉じ込めて防ぐ。
- 削除: allowUnsafeProtocolOverride(-c で設定しておらず、env 経路でも
継承する必要がない)
回帰なし。全テスト 1478 件 pass。
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 18 out of 19 changed files in this pull request and generated no new comments.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
@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 を適用。
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.