Skip to content

e2e: 平台专属的 Electron 二进制路径与 POSIX shell 清理,让 harness 在 Windows 上无法运行 #223

Open

Description

@wxrbyte

问题与复现

apps/electron/e2e/ 下的 harness 脚本假定了宿主平台,导致在 Windows 上完全无法启动。

1. Electron 二进制路径按平台写死(11 个文件)

10 个脚本把二进制指向 macOS 专属的 bundle 路径(run.mjs:26-29、interactions.mjs、skills-interactions.mjs、dom-audit.mjs、v5.mjs、visual.mjs、product-flows.mjs、v9-verify.mjs、typed-blocks.mjs 以及 electron-harness.mjs 的候选表):

const electronBinary = join(
  repoRoot,
  'node_modules/.bun/[email protected]/node_modules/electron/dist/Electron.app/Contents/MacOS/Electron'
);

citation-acceptance.mjs:28 是镜像问题——写死了 Windows 专属路径:

const electronBinary = join(appRoot, 'node_modules/electron/dist/electron.exe');

每个脚本都在 main() 开头用 existsSync(electronBinary) 守卫,所以症状不是「用错二进制」而是直接硬失败。实际输出(Windows 11,main ba5dcdfd):

$ node apps/electron/e2e/run.mjs
Electron binary not found: E:\Work\Code\代码\folio\node_modules\.bun\[email protected]\node_modules\electron\dist\Electron.app\Contents\MacOS\Electron

值得注意的是,同一个目录里 electron-harness.mjs 已经导出了正确的共享解析器 resolveElectronBinary(appRoot, repoRoot)(走 require(join(appRoot, 'node_modules/electron')),由 electron 包自己的 path.txt 决定真实二进制),并且 stream-replay.mjs / trace-showcase.mjs / ux-audit.mjs / research-recovery.mjs 已经在用它。也就是说这是「部分脚本漏改」,不是缺少能力。

2. 用 POSIX shell 清理 userData(3 个文件)

run.mjs:101-102、interactions.mjs:199-200、skills-interactions.mjs:99-100:

execSync(`rm -rf "${userDataDir}"`);
execSync(`mkdir -p "${userDataDir}"`);

win32 下 execSync 的默认 shell 是 cmd.exe,其中没有 rm / mkdir -p,命令返回非 0 → execSync 抛错。即使二进制路径修好,也会立刻卡在这一步。

3. 顺带:citation-acceptance.mjs 的 repoRoot 少一层

:26 写作 join(here, '../..'),here 是 apps/electron/e2e,于是 repoRoot 得到 apps/;同目录其余脚本都是 '../../..'。该值既作 spawn 的 cwd(:90)又用于定位 .pi/extensions/finagent/index.ts(:84),因此本来就指向了错误目录——修二进制解析时必须一并修正,否则新的解析器会拿到错误的回退根。

回归测试

新增 apps/electron/e2e/platform-portability.test.ts,把上述三类假设钉死(纯静态扫描,无平台分支):

  • 禁止出现 Electron.app(macOS bundle)与 node_modules/electron/dist/(按平台写死的 dist 路径)
  • 禁止出现 execSync(\rm -rf与execSync(`mkdir -p`
  • 引用 electronBinary 的脚本必须从 ./electron-harness.mjs 导入解析器;除 electron-harness.mjs 自身外不得再实现 resolveElectronBinary

对纯净 main ba5dcdfd 运行该测试:0 pass / 2 fail,逐条列出 11 个文件 24 处违规;修复后 2 pass / 0 fail。

预期与修复方向

  1. 11 个脚本改用 resolveElectronBinary(appRoot, repoRoot),并删除随之失效的 existsSync 守卫(解析器自身在找不到时会抛出带完整候选清单的错误,信息量更大)。
  2. electron-harness.mjs 候选表的第三项由 macOS 路径改为 tryResolve(join(repoRoot, 'node_modules/electron'))。
  3. 3 处 rm -rf / mkdir -p 改用 rmSync(dir, { recursive: true, force: true }) / mkdirSync(dir, { recursive: true })。
  4. typed-blocks.mjs 删除本地重复实现的 resolveElectronBinary(),改用共享版本。
  5. citation-acceptance.mjs 的 repoRoot 修正为 '../../..'。

不改任何断言、步骤编号、CDP 端口或产物路径;无可见 UI 变化。

复现证据

  • 环境:Windows 11 (10.0.26200) + Node v22.22.2 + Bun 1.4.2;上游 main ba5dcdfd(干净检出)
  • 新守卫测试(纯净 main):bun test apps/electron/e2e/platform-portability.test.ts → 0 pass / 2 fail
  • 新守卫测试(修复后):2 pass / 0 fail
  • node apps/electron/e2e/run.mjs:修复前在二进制守卫处退出(见上);修复后越过该检查,推进到 :90 的 execSync('bun run build:preload')
  • node --check 全部 e2e/*.mjs:0 失败
  • bun test apps/electron --isolate:32 pass / 0 fail(6 文件)
  • bun run typecheck:五个工作区全部 exit 0

范围

改动 11 个 apps/electron/e2e/*.mjs + 新增 1 个测试文件(platform-portability.test.ts)。

明确不在本次范围(各自独立,可另行处理):

  • fresh-install.mjs:30 指向的是打包产物 dist/electron/mac-arm64/Folio.app/Contents/MacOS/Folio——这是打包脚本的产物命名问题,不是开发态二进制解析
  • 13 个脚本用 pkill -f 'remote-debugging-port=…' 清理残留进程。Windows 没有 pkill;多数调用包在 try/catch 里,所以只是静默失效(残留进程占住 CDP 端口会影响后续运行)。跨平台杀进程需要新的辅助函数,故单列
  • dom-audit.mjs / product-flows.mjs / v9-verify.mjs 中 main 即已存在的未使用 existsSync 导入——与本次问题无关,保持不动以免扩散

相关先例:issue #68([DevEx] Fix unit test failures on Windows)属同类跨平台 DevEx 问题,但范围是单元测试,不覆盖 e2e harness。

Activity

  1. wxrbyte commented on Sep 26, 2026

    @wxrbyte
    ContributorAuthor

    /claim

  2. github-actions commented on Sep 26, 2026

    @github-actions

    @wxrbyte 已认领该 Issue,并已自动设为 Assignee。提交 PR 时请在描述中写 Closes #223。

  3. added
    claimed
    on Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

claimed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions