Skip to content

fix(compiled): zmx attach 与 zellij 探针在编译态下不再落到 help - #3058

Merged
deepcoldy merged 1 commit into
masterfrom
fix/compiled-zmx-attach-zellij-probe
Nov 7, 2026
Merged

deepcoldy merged 1 commit into
masterfrom
fix/compiled-zmx-attach-zellij-probe

Conversation

@deepcoldy

Copy link
Copy Markdown
Owner

Fixes #1120

只修 issue 列为该修的第 1、2 处(zmx attach 谎报成功、zellij adopt 静默丢会话);第 3、4 处 issue 已标为可延后(fail-closed),顺带的 connector-store flake 不在本 PR 范围。

现象

编译版单文件二进制把首个参数当子命令,<binary> <脚本路径> … 会打印 help 并 exit 0:

  1. zmx 会话「本地打开」生成的 shell 命令是 exec <execPath> <cli.js> __zmx-attach-managed …,attach 没发生却返回成功;
  2. findServerPid 用 <execPath> <zellij-socket-probe.js> <sock> <pids> 跑探针,拿到 help 文本 Number() 为 NaN,恒返回 null,已有 zellij adopt 会话被判为不存在而关闭。

根因

这两处仍是 Node 形态的硬编码 argv,没有走 core/self-spawn.ts 里已有的形态感知助手。

修复

  • zmx attach:用 resolveCliSpawn(CLI_ENTRYPOINT, ['__zmx-attach-managed', …]) 生成 argv,再对每一项 shellQuote。编译态不再拼脚本路径,也就不会把 /$bunfs/… 交给 shell 展开;Node 形态命令不变(仅子命令 token 也加了引号)。
  • zellij 探针:注册为隐藏入口 __zellij-socket-probe(BotmuxEntry + cli.ts 分发),findServerPid 改用 resolveEntrySpawn('zellij-socket-probe', distDir);Node 形态仍执行同一个 dist/adapters/backend/zellij-socket-probe.js。探针模块的「直接执行」判定在编译态跳过:编译产物里所有模块共用二进制的 URL,该判定对任何 import 都成立,会用错位的参数再跑一份探针并 exit 1(真机二进制实测发现)。

验证

  • 回归测试(编译态用 process.argv[1] = '/$bunfs/…' 走真实的 isStandaloneBinary() 分支):
    • test/local-cli-opener.test.ts:编译态 zmx attach 为 exec '<execPath>' '__zmx-attach-managed' …,不含 cli.js / $bunfs
    • test/zellij-server-pid-compiled.test.ts:编译态 findServerPid 以 <execPath> __zellij-socket-probe <sock> <pids> 启动探针;Node 形态仍是探针脚本
    • test/zellij-backend-helpers.test.ts:经 src/cli.ts 真实分发 __zellij-socket-probe,对另一个进程监听的 unix socket 归因出该进程 pid;缺参 exit 64
  • 上述用例在未修改的 master 上均红。变异验证(均变红):findServerPid 恢复脚本路径;去掉 cli.ts 分发分支;分发参数错位;zmx 恢复脚本路径;去掉逐项引号。
  • 真实编译二进制(scripts/build-bun-binary.mjs,临时 HOME):
    • 旧形态 <binary> <probe.js> <sock> <pid> → help + exit 0(Number(stdout)=NaN);新形态 <binary> __zellij-socket-probe <sock> <pid> → exit 0,输出监听进程 pid
    • 旧形态 <binary> //root/cli.js __zmx-attach-managed … → help + exit 0;新形态 <binary> __zmx-attach-managed … → 进入真实 helper,对不存在的会话拒绝 attach(exit 1)
  • tsc --noEmit、npm run build 通过;相关 6 个测试文件 vitest 104/104 通过;bun 腿中 zellij-backend-helpers、local-cli-opener 等通过,zellij-server-pid-compiled 与既有的 card-handler-open-local-cli 使用 importOriginal,按 bun-leg-selectors 不在 bun 腿运行。

编译版单文件二进制把首个参数当子命令,<binary> <脚本路径> … 会打印 help
并 exit 0:zmx 本地 attach 没发生却报成功,findServerPid 恒为 null 导致
已有 zellij adopt 会话被关闭。

zmx attach 改用 resolveCliSpawn 生成 argv 并逐项引号;zellij 探针注册为隐藏
入口 __zellij-socket-probe,由 resolveEntrySpawn 启动,其直接执行判定在编译态
跳过。

Fixes #1120
// The socket owner must be another process: spawnSync below blocks this
// event loop, so a server here would never accept() the probe's connections.
const server = spawn(process.execPath, ['-e',
`require('node:net').createServer(c => c.on('error', () => {})).listen(${JSON.stringify(sock)}, () => console.log('ready'))`,
@github-actions

Copy link
Copy Markdown

🚀 Released in v3.59.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(compiled): 4 处「execPath + 脚本路径」在编译态失效,其中 zmx attach 谎报成功、zellij adopt 静默丢会话

2 participants