Repository navigation
Conversation
假 CLI 用 writeFileSync 原地写报告,文件先以截断方式创建、再写入内容;用例只等 文件存在就解析,落在两步之间就读到空串而报 JSON Parse error(#2510)。改成写 临时文件后 rename 到位:同目录 rename 是原子的,「存在」即「写完」,读侧不变。 Co-Authored-By: Claude Opus 5.5 <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 29, 2026 09:10
Owner
Author
|
自动评审的初步意见(最终以维护者审阅为准)。 结论修法正确,建议补一个确定性回归守卫、并处理与 #2509 的重复后合入。 核实与验证
P2:缺少回退即可见的确定性回归守卫本 PR 只改假 CLI 的写序,没有新增用例;不注入延迟时,新旧写法在自然调度下都通过(issue 里 8 并发 × 8 轮 × 修复前后各 64 次全过也印证了窗口只有微秒级)。也就是说将来若有人把这三行改回原地写,测试不会确定性地红。 建议并入一个延迟守卫(约十几行):假 CLI 支持
旧写法在同一用例下会稳定复现 流程项:与 #2509 二选一#2509 是同根因的另一种修法(读侧轮询到可解析 JSON,已含延迟注入开关、额外 pty 守卫用例),两个 PR 改的是同一段假 CLI 脚本、互斥,不能都合。个人倾向本 PR 的写侧原子化:同目录 rename 原子,「存在即完整」,用例原有等待语义保持成立,改动也更小;但建议把 #2509 的守卫思路移植过来,然后关闭另一个。 P3(可不改)
|
Owner
Author
This was referenced Oct 29, 2026
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.
Closes #2510。
现象
master
d0adf0e27(#2475 合入)首跑 run 40833799368 / bun-test:test/session-env-worker.integration.test.ts的session env overlay reaches the CLI through a real worker > tmux,2.4s 失败,SyntaxError: JSON Parse error: Unexpected EOF,位置在第 69 行JSON.parse(readFileSync(report))。根因
报告由测试自己写的假 CLI(
fake-cli.cjs)用fs.writeFileSync原地写出:文件先以截断方式创建(O_CREAT|O_TRUNC),再写入内容。用例第 68 行只等文件「存在」,第 69 行马上解析;落在两步之间就读到''。读写两侧都是测试代码。修法:写的一侧先写临时文件再 rename
假 CLI 先把报告写到同目录的
report.json.<pid>.tmp,再renameSync到report.json。读的一侧不变。二选一的理由:
rename是原子的,「文件存在」就等于「内容写完」,用例原本的等待语义因此成立,读侧逻辑一行不用改;影响面
只改这一个测试文件(假 CLI 的脚本文本和一句注释),
src/零改动。验证
isolate-run,把写报告的「创建」与「写入」之间拉开 300ms):pty、tmux两例都失败,报错与 CI 逐字相同;isolate-run,4 核 + 6 个空转进程,8 并发 × 8 轮,不拉长窗口):修复前后各 64 次全过。窗口只有微秒级,自然负载很难碰上;能确定复现的是上面的对照。test-hygiene28 例全绿;bun test --timeout=180000跑本文件 2 例全绿。🤖 Generated with Claude Code