Skip to content

chore(pm2): 清理迁移后零调用方的 PM2 spawn 命令构造 - #1302

Open
deepcoldy wants to merge 1 commit into
masterfrom
chore/pm2-orphan-cleanup
Open

chore(pm2): 清理迁移后零调用方的 PM2 spawn 命令构造#1302
deepcoldy wants to merge 1 commit into
masterfrom
chore/pm2-orphan-cleanup

Conversation

@deepcoldy

Copy link
Copy Markdown
Owner

改了什么

插件服务迁到内置 supervisor(#1254)之后的收尾清理,删掉三样已经没人用的东西:

  • src/cli/pm2-command.tsbuildPm2SpawnCommand
  • test/pm2-command.test.ts(它的专测)
  • tsconfig.test-mocks.json 里指向已删除文件 test/plugin-pm2-env.test.ts 的 include 条目

为什么

#1254 删掉了 src/core/plugins/pm2.ts,而它是 buildPm2SpawnCommand 在主干上唯一的生产调用方。现在全仓已经没有任何代码路径会 spawn PM2,这个函数(以及它那套 Windows 引号处理、绝对 Node 路径解析的逻辑)就成了纯粹的死代码。

tsconfig.test-mocks.json 那条 include 指向的文件已随 #1254 删除。tsc 对匹配不到的 include 条目是静默容忍的(typecheck:test-mocks 照样 exit 0),所以它不会让 CI 变红,只是一条陈旧配置。

⚠️ 有意保留 src/cli/pm2-env.ts

它同样没有生产调用方,但不能删——它是 test/child-env.test.ts参照基准

scrubExternalMemberEnv(viaExternal);
scrubPm2CallerEnv(viaPm2);
expect(viaExternal).toEqual(viaPm2);

这条用例(strips exactly what the whole pm2 plugin boundary stripped)拿旧的 PM2 边界当基准,证明迁移后的 scrubExternalMemberEnv 剥离的环境变量与旧路径一模一样。删掉 pm2-env.ts 等于让这条对照消失,迁移可能静默降低防护而没有任何测试会红。用例注释里也写明了这个意图("a migration must not quietly reduce protection")。

影响面

只碰 PM2 spawn 命令行构造这一处。以下几个名字带 pm2 但仍在服役的模块都没动

模块 为什么留
core/legacy-pm2-reaper.ts 给从 PM2 版升级上来的老机器清残留 God,#1254 的 fail-closed 迁移逻辑在调它
pm2-graceful-exit.ts 退出码哨兵,5 处在用(daemon / dashboard / workflow v3 等),早已与 PM2 解耦
cli/pm2-readonly-client.ts ⚠️ grep 看着像孤儿,实际由 desktop/main/pm2-apps.ts:68 拼磁盘路径起子进程调用
core/pm2-lifecycle-owner.ts / desktop/main/pm2-apps.ts 桌面端读取旧 PM2 应用状态,另一条线

不涉及跨平台差异(删掉的是 Windows 分支逻辑,但整个函数已无调用方);不涉及其它 CLI 适配器;不涉及 PtyBackend / TmuxBackend 或任何会话类型。

实测验证

npx tsc --noEmit                        → exit 0,0 行输出
npx tsc -p tsconfig.test-mocks.json     → exit 0,0 行输出
bun run build                           → exit 0
npx vitest run <6 文件>                 → Test Files 6 passed (6) / Tests 115 passed (115)

跑的 6 个文件是整个 PM2 面 + supervisor 面:child-envpm2-graceful-exitlegacy-pm2-reaperdesktop/desktop-pm2-appsplugin-supervisor-stateplugin-supervisor.integration

另外单独确认了参照基准那条用例确实在执行(不是被 vitest 静默跳过):

✓ |unit| test/child-env.test.ts > scrubExternalMemberEnv (external fleet members)
  > strips exactly what the whole pm2 plugin boundary stripped

删除前也核过全仓对 pm2-command / buildPm2SpawnCommand 的引用数为 0src / test / scripts / 配置文件全搜过;src/worker.ts 里的 capturedSpawnCommandcopySpawnCommand 是同名无关标识符)。

插件服务改走内置 supervisor(#1254)后,`src/core/plugins/pm2.ts` 被删除,
`buildPm2SpawnCommand` 随之在全仓零调用方——已无任何代码路径 spawn PM2。
一并移除它的专测,并清掉 `tsconfig.test-mocks.json` 里指向已删除
`test/plugin-pm2-env.test.ts` 的 include 条目(tsc 对匹配不到的条目静默
容忍,不报错但是陈旧配置)。

有意保留 `src/cli/pm2-env.ts`:它虽然同样没有生产调用方,却是
`test/child-env.test.ts` 的**参照基准**——
`expect(viaExternal).toEqual(viaPm2)` 用旧 PM2 边界证明新的
`scrubExternalMemberEnv` 剥离的东西一模一样,删掉它等于让迁移
静默降低防护。

影响面:仅 PM2 spawn 命令行构造(Windows 引号/绝对 Node 路径那套)。
`legacy-pm2-reaper`(升级机清残留 God)、`pm2-graceful-exit`(退出码哨兵,
5 处在用)、`pm2-readonly-client`(桌面端按磁盘路径起子进程)均不受影响。

验证:tsc ✅ / typecheck:test-mocks ✅ / build ✅ /
6 文件 115 用例全通过;已确认参照基准用例
「strips exactly what the whole pm2 plugin boundary stripped」仍在执行。
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.

1 participant