Repository navigation
test(riff): bootstrap 测试改用临时 HOME 和隔离 PATH,不再覆盖宿主 botmux - #3060
Merged
Merged
Conversation
症状:在 botmux 会话里跑 test/riff-host-bootstrap.test.ts,会把宿主 ~/.botmux/bin/botmux 覆盖成测试用的假 CLI,宿主上的 botmux 命令随即失效; 同一次运行里 10 个执行 bootstrap 的用例失败。 根因:测试 spawn bash 执行生成的 bootstrap 时继承了宿主的 PATH、HOME 和 BASH_ENV。botmux 会话的 BASH_ENV 在 bash 启动时把 ~/.botmux/bin 插回 PATH 最前面,排在测试的 bin 之前,bootstrap 的 `command -v botmux` 于是解析到 宿主 launcher,哈希不匹配后 `mv -f` 把下载产物写到了它上面。 修法:两处 bootstrap spawn 的环境统一由 bootstrapEnv 生成:HOME 指向用例 临时目录,继承的 PATH 去掉所有位于 .botmux 目录下的条目,删除 BASH_ENV。 文件首个 import 改为 require-fenced-data-dir,测试围栏未生效时直接拒跑。 验证:用诱饵 .botmux/bin 和会把它插回 PATH 的诱饵 BASH_ENV 跑该文件, 旧代码诱饵 launcher 被覆盖、10 个用例失败;新代码诱饵不动、37 个用例全过。 分别去掉删除 BASH_ENV、PATH 过滤、临时 HOME,对应的泄漏各自重现;绕过 setupFiles 运行时文件在导入阶段拒跑。
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
November 7, 2026 12:33
Owner
Author
|
已合入 master(squash 评审中记录的可选后续项(均不阻断,供后续 PR 处理):
|
|
🚀 Released in v3.59.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
症状
在 botmux 会话的 shell 里跑
test/riff-host-bootstrap.test.ts,宿主的~/.botmux/bin/botmux会被覆盖成测试里的假 CLI(FAKE_CLI/ artifact 内容),此后宿主上所有botmux命令失效,只能手动恢复 launcher。同一次运行里 10 个执行 bootstrap 的用例失败(curl-argsENOENT、riff_host_cli_download_failed等)。根因
测试用
spawnSync('bash', ['-c', ...])执行生成的 bootstrap,env 是{ ...process.env, PATH: \${bin}:${process.env.PATH}` }`:BASH_ENV。botmux 会话的BASH_ENV在 bash 启动时把~/.botmux/bin重新插到 PATH 最前面,排在测试的bin之前;command -v botmux定位安装目标,于是解析到宿主 launcher;哈希不匹配后走下载分支,mv -f "$artifact" "$target"写到宿主 launcher 上。vitest 的测试围栏只改 HOME 和数据目录,不动 PATH 和
BASH_ENV,所以拦不住这条路径。修法
只改这一个测试文件,不动产品代码:
bootstrapEnv(root, bin, extra),两处 bootstrap spawn 都用它:HOME指向用例临时目录下的home;继承的 PATH 去掉所有位于.botmux目录下的条目,再把测试bin放在最前;删除BASH_ENV。./helpers/require-fenced-data-dir.js(与 test(fence): 四个写数据目录的测试文件在围栏外直接拒跑 #3047 相同做法),测试围栏未生效(例如绕过 setupFiles)时在导入阶段拒跑。验证
复现和验证都在
scripts/fenced-run.ts里进行,外层 PATH 已去掉所有.botmux条目,不会碰到宿主 launcher。另放一个诱饵/tmp/.../riff-decoy/.botmux/bin/botmux,诱饵BASH_ENV模仿会话脚本把它插回 PATH,诱饵sha256sum记录 bootstrap shell 实际看到的 HOME 和 PATH。每次运行前后比对宿主 launcher 的哈希,均未变化。.botmux目录BASH_ENVrefusing to run: data-dir fence not active.botmux,都是 postinstall 用例自己的<root>/home/.botmux/bin,不是继承来的。BASH_ENV是直接止血的那一项;PATH 过滤保证继承的 PATH 里没有宿主.botmux目录。现有用例的bin里都放了botmux,所以过滤不改变用例结果,它防的是以后bin里没有botmux时解析到宿主 launcher。bin里不放botmux的用例,bootstrap 会走npm prefix -g兜底,需要另外把npm_config_prefix指向临时目录。当前所有用例都走不到这一步,本 PR 不处理。bun run build(含tsc)通过;单独对该测试文件做类型检查无报错。