refactor(electron): extract main process boundaries - #7532
Conversation
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
UX Review (Fable 5) — ✅ PASSUX-level review of All user-facing surfaces (dialogs, tray menu, status strings, permission prompts, update notification) survived the extraction byte-for-byte — only rewrapped across lines — and UX-Verdict: PASS Pure main-process boundary extraction: every dialog, tray label, status string, and permission prompt moves verbatim; no rendered surface or flow changes. [UX-REVIEWED] 3ee74e3 |
First Principles Review (Fable 5) — 🟡 CONCERNSPremise-level review of All mechanical checks are done: IPC channel sets, env vars, store keys, and timing values are identical between the base First-Principles-Verdict: CONCERNS The extraction is real and earns its place, but it ships fallback branches for callers that do not exist — a "transitional alias" with zero providers. What this change shipsIntent: make the 4,246-line Electron main process reviewable and directly testable by splitting it into three injected modules. ADDITION (structure-only move; no fix claimed).
Behavior preservation verified mechanically: 37 IPC channels, all store keys, env vars, and the 250/1500/400ms timing values match the base byte-for-byte; Watch
Subtractions
[FIRST-PRINCIPLES-REVIEWED] 3ee74e3 |
Design Review (Fable 5) — ✅ PASSDesign-level review of The extraction maps cleanly: security hardening hooks, quit ordering, and IPC surfaces carry over 1:1, the base's module-load Design-Verdict: PASS A real maintainability harm, fixed at the root with a proportionate, behavior-preserving decomposition — DI seams tested, docs and packaging updated in-commit. [DESIGN-REVIEWED] 3ee74e3 |
Opus 4.8 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
7dd4c2e to
9c8ef4e
Compare
9c8ef4e to
cc02b33
Compare
cc02b33 to
3ee74e3
Compare
chenmingwei23
left a comment
There was a problem hiding this comment.
Approved: PR Readiness passed, all review lanes green.
Open PR relationship auditThis is a consolidated, point-in-time code-level audit note. It compares complete merge-base diffs and current/merged code; it does not treat a shared topic as duplication or partial coverage as completion. Relationship findings
No PR, Issue, label, branch, or review state was changed by the relationship-note portion of this audit. |
Problem / Motivation
website/electron/main.jshad grown to 4,246 lines and jointly owned gateway supervision, IPC registration, window/security lifecycle, browser control, and recovery. That concentration made lifecycle ordering and cleanup ownership difficult to review or test safely.Why it matters
The desktop shell coordinates child-process ownership, single-instance behavior, hardened Electron sessions, navigation policy, updater handoff, and cross-platform window state. Keeping those responsibilities in one module made an otherwise local change more likely to disturb an unrelated security, startup, or shutdown invariant.
What changed (motivation → approach → change)
This is an intended behavior-preserving boundary extraction.
main.jsis now a 431-line composition root that retains application-level ordering, while three dependency-injected sibling modules own cohesive runtime state:gateway-supervisor.jsowns gateway discovery, start/stop, liveness, recovery, token flow, child-process cleanup, and updater handoff.window-lifecycle.jsowns dashboard/tray/browser windows, browser-control ownership, session and navigation hardening, diagnostics, and window cleanup.ipc-registrar.jsowns shell, updater, hotkey, memory-sampling, and WSL-detection IPC registration.The extraction keeps existing IPC channel names and payload shapes, single-instance behavior, app/window/process lifecycle order, partition/session hardening, external-navigation policy, browser-control sender ownership, and platform-specific branches. Timing and security WHY comments stay with their owning boundaries; obsolete historical/code-restatement comments were removed. Direct Electron tests now exercise the injected modules and their composition seams, and the owning desktop/i18n/update docs describe the new ownership boundary.
website/electron/package.jsonchanges only electron-builder's existingfilesallowlist so the three new sibling modules are packaged. No dependency, script, version, or lockfile changed.The base sync carries the chat copy-link menu wiring that landed on
mainwhile this branch was open: the dashboard'sattachContextMenucall now receives{ getAppOrigin: () => windowBackendUrl }at its new home inwindow-lifecycle.js, and the embedded browser panel still passes no origin. A source contract inwindow-lifecycle.test.jslocks that split so a later move cannot silently drop either half.Tests
npm run test:electron: the 19 electron test files this PR adds or changes, pluscontext-menu.test.js, pass together — 225 tests, 0 failed. The remaining reds in a full local run (packaging,build-config-schema,store-rename-migration,auto-update*,petOverlays, and thegateway-stophang) reproduce identically onorigin/mainwith the same missing-module / ENOENT causes, so they are host setup, not this diff.main.js, all three extracted modules, andwsl-detection.js.npx tsc -b, production Vite build, analyze build, and bundle-size gate passed (6,915 modules; 738 chunks within budget).DevFleetPageCoverageandImeEnterClaimRatchet); one unchangedMarkdownRendererworker also timed out during termination. Because Vitest exited red, it did not emit the coverage report. After syncing the latest base, a targeted run of both timeout files plusMarkdownRendererpassed all 202 tests without the worker warning.website/srcis identical toorigin/mainin this branch.npx eslint src/ --max-warnings 603) is inherited unchanged:website/srcis byte-identical toorigin/mainon this branch, so this diff can neither add nor remove a warning.website/electron/**has no eslint rules configured, so lint over the extracted modules only proves they parse;node --testis their real coverage. The default Python 3.13 launcher also lacks some gate dependencies, so equivalent installed Python 3.12 checks were used where noted; the docs self-test's symlink probe cannot run without the Windows symlink privilege, while the real docs lint passed.Manual verification
Related Issues
no linked issue: this is a self-directed maintainability refactor of the Electron main process, not a fix for a reported defect.
Checklist
feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)