Skip to content

fix(cli): 阻止 autostart 帮助参数触发系统变更 - #1269

Merged
deepcoldy merged 1 commit into
deepcoldy:masterfrom
LPX-E5BD8:fix/autostart-help-no-side-effect
Sep 7, 2026
Merged

deepcoldy merged 1 commit into
deepcoldy:masterfrom
LPX-E5BD8:fix/autostart-help-no-side-effect

Conversation

@LPX-E5BD8

Copy link
Copy Markdown
Contributor

问题

botmux autostart enable --help 会把 --help 静默忽略并直接调用 enableAutostart(),导致只想查看帮助的用户意外写入并启用系统自启动配置。其它 autostart 子命令也会吞掉额外参数;未知子命令则会在报错前先创建配置目录。

Fixes #1268

修复

  • 在执行任何 autostart 状态变更或创建配置目录前识别 --help / -h,输出专用 usage 并成功退出。
  • 对未知子命令和额外参数 fail closed,返回退出码 2,不执行任何文件或系统服务变更。
  • 保留 install / uninstall 兼容别名。
  • 增加 HOME 递归快照回归测试,覆盖 enable、disable、status 及兼容别名的帮助路径,以及未知参数/未知子命令。

影响面

  • 只影响 botmux autostart 的 CLI 参数分发。
  • 不改变 Linux systemd、macOS launchd 或 Windows Task Scheduler 的实际 enable/disable 实现。
  • Dashboard autostart API 仍使用不带额外参数的合法命令,不受影响。

验证

  • npx vitest run --project unit test/cli-unknown-args.test.ts:28 passed。
  • bun run vitest run --project unit test/cli-unknown-args.test.ts:28 passed。
  • bun run build:通过。
  • bun run test:21373 passed、31 skipped;13 个失败均为当前主机上的既有环境/时序问题(tmux locale/socket、npm allow-scripts、mojo/native-subagent 时序),与本次修改文件无关。

在处理 autostart 子命令前识别 --help/-h,并拒绝所有额外参数,避免帮助探测或拼错参数时执行 enable/disable。补充无副作用回归测试,覆盖正式子命令及兼容别名。

Refs: deepcoldy#1268

Co-authored-by: TRAE CLI <[email protected]>
@LPX-E5BD8
LPX-E5BD8 requested a review from deepcoldy as a code owner September 6, 2026 10:11
Copilot AI lite review requested due to automatic review settings September 6, 2026 10:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

改动范围小且参数校验前置能明确阻断副作用路径,并配套新增了覆盖 help/未知参数的回归测试验证行为与退出码。

Pull request overview

该 PR 修复 botmux autostart 子命令在携带 --help/-h 或额外参数时仍可能触发 ensureConfigDir() / enable/disable 等副作用的问题,确保帮助查询与非法参数路径 fail closed,避免用户仅查看帮助却意外修改系统自启动配置。

Changes:

  • 在 autostart 分支里先解析并拦截 --help/-h:仅打印专用 usage 并以 0 退出(不创建配置目录、不做系统变更)。
  • 对未知子命令及任何额外参数统一报错并设置退出码 2,且在调用 ensureConfigDir() 之前完成校验。
  • 增加回归测试:覆盖 help 路径、未知参数、未知子命令均不得修改 HOME 快照。
File summaries
File Description
src/cli.ts 调整 autostart 参数分发顺序:help 优先、参数校验前置、非法参数设置 rc=2 并避免副作用
test/cli-unknown-args.test.ts 新增 HOME 递归快照回归测试,验证 help/未知参数/未知子命令路径无副作用且返回码符合预期
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@deepcoldy

Copy link
Copy Markdown
Owner

你好!这是 Botmux 的自动评审流程。

本 PR 的评审群已创建:https://applink.feishu.cn/client/chat/open?openChatId=oc_de87d56f2ee5a0c0d9b91e37ebb87a4a

但你暂时未被拉入群中——你的 GitHub 账号(LPX-E5BD8)不在自动拉群名单里。请把你的 GitHub 账号和飞书信息补进名单文档:
https://bytedance.larkoffice.com/wiki/WJ1nwWbtxi89erkNGNbcgkt9nUe

补好后,后续复审会自动把你拉进群。感谢贡献!

@deepcoldy deepcoldy left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

双审通过(自动评审 + 复审),0 阻断。

  • 修复方向正确:--help / 未知参数在 ensureConfigDir() 与任何系统变更之前 fail closed,与主干既有的舰队命令参数闸同构。
  • 影响面已核:唯一程序化调用方 Dashboard /api/autostart 固定传 enable/disable,不触达新闸;编译态纯 argv 解析,无路径拼接风险。
  • 本地在最新 master 上 rebase 后验证:tsc 通过、build 通过、vitest 43/43、bun 28/28;反变异验证测试对该回归有区分力。
  • CI 四腿全绿。

@deepcoldy
deepcoldy merged commit f8439c7 into deepcoldy:master Sep 7, 2026
4 checks passed
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown

🚀 Released in v3.19.3

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(cli): autostart 子命令的 --help 不应执行系统变更

3 participants