Repository navigation
test(worker): session-env 报告轮询到完整 JSON,修 tmux 下 create-then-write 空窗 flake - #2509
Merged
Merged
Conversation
…flake 假 CLI 用 writeFileSync 写报告时,truncate-create 让路径在字节落盘前就存在; 旧断言 vi.waitFor(existsSync(report)) 后立即同步 JSON.parse(readFileSync()), 在 tmux 后端调度更碎时会命中「文件已创建但为空」的窗口,报 JSON Parse error: Unexpected EOF,真正的 env overlay 断言尚未执行。 - 套用 #2386 为 strict-env-worker 引入的 waitForJsonReport:轮询直到读到 非空且可解析的 JSON,空窗/部分写入都继续等(同一竞态同一修法)。 - 假 CLI 支持 PROBE_REPORT_DELAY_MS:先 truncate-create 空文件、延迟再写正文, 确定性放大 create-vs-write 窗口;新增 pty 守卫用例(延迟 400ms)。 - 回退成 existsSync-then-parse 后,该守卫在 vitest 与 bun 双引擎都稳定报 与 CI 同形的 Unexpected EOF;恢复新写法后双引擎 3/3 绿。 关联 #2386(同族修法)、#2396(同类读取竞态守卫沉淀)。纯测试改动。 Co-Authored-By: Claude Code <[email protected]>
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 29, 2026 08:07
复审指出守卫两处保真度缺口: - PROBE_REPORT_DELAY_MS 注入若被误删,空文件不再被预创建,守卫会对照即时 写好的报告假绿。pick 增加该键,放大窗口用例断言它确实等于注入值, 把「延迟真的经 env overlay 到达假 CLI」也钉住。 - 原生产 flake 发生在 tmux,守卫却只跑 pty。改为 it.each(backends), pty/tmux 各跑一条放大窗口用例。 变异双引擎(私有 TMPDIR/TMUX_TMPDIR):删注入 → 两后端守卫均红; 读取回退成 existsSync-then-parse → 两后端守卫均报同形 Unexpected EOF; 正常路径两条始终绿。修复态 4/4 双引擎绿,tsc/test-hygiene 通过。 Co-Authored-By: Claude Code <[email protected]>
Owner
Author
|
补充一组同根因的确定性对照(来自已关闭的 #2512,它用写侧「临时文件 + rename」修同一问题,按 #2386 的既有修法改以本 PR 为准):
问题记录在 #2510(与本 PR 描述一致),本 PR 合入时可一并关联。 |
This was referenced Oct 29, 2026
|
🚀 Released in v3.56.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.
背景
#2475 合入 master(d0adf0e27)后的 push CI run 40833799368,bun-test 腿 1808 个文件中 1 个失败:
同一份代码树(落地树 eb338ad2dc 与 PR head 树逐字同一)在 PR CI run 40816006666 的 bun-test attempt 1 全绿,master push 仅这一条 tmux 用例红——概率性时序,非确定性回归,与 #2475 的 dsh 改动零文件、零代码路径交集。
根因
测试的假 CLI 用
fs.writeFileSync(report, …)写报告:open(O_CREAT|O_TRUNC)让路径在字节落盘前就存在。旧断言vi.waitFor(() => existsSync(report))只等文件存在,紧接着同步JSON.parse(readFileSync(report))。tmux 后端下 CLI 经 server/pane 启动、调度更碎,轮询命中「文件已 truncate-create、内容尚未写入」的零字节窗口,JSON.parse('')抛Unexpected EOF。真正的 env overlay 断言(其后若干行)还没执行到,失败发生在测试读自己假 CLI 写的文件,不是生产逻辑。这是仓库里已记录的同族竞态:#2386 已为
test/strict-env-worker.integration.test.ts修过逐字相同的问题,#2396 跟踪把该守卫沉淀推广。session-env-worker是当时漏掉、未套用修法的文件。改动(纯测试,单文件)
waitForJsonReport:轮询直到读到非空且可解析的 JSON,未创建/空窗/部分写入都继续等,超时返回 null。runOverlayCheck(backendType, reportDelayMs);假 CLI 新增PROBE_REPORT_DELAY_MS开关——非零时先 truncate-create 空文件、延迟 N 毫秒再写正文,确定性放大 create-vs-write 窗口(不再靠 CI 高并发偶发命中)。验证(A/B,双引擎,均在私有 TMPDIR/TMUX_TMPDIR 隔离,未触线上 tmux)
bun test3 pass / 0 fail(pty、tmux 正常路径 + 放大窗口守卫)。vi.waitFor(existsSync)+ 立即JSON.parse):放大窗口守卫在 vitest 与 bun 下都稳定失败,报与 CI 同形的JSON Parse error: Unexpected EOF;两条不放大的正常用例仍绿——守卫精确区分新旧谓词,回退即红。变异已逐字节恢复。bun run build通过、tsc --noEmit干净、test-hygiene26 项通过。影响面
仅测试文件,无 src 改动,无生产行为/配置/持久化变化。修后 master bun-test 不再被这条已知 flake 偶发拖红。#2396 设想的「共享 fixture 统一收口 strict-env 与本文件的 helper」仍留给该 issue 统一做,本 PR 保持与 #2386 一致的文件内 helper 形态,范围最小。
部分推进 #2396(仅解决 session-env-worker 这一处漏修;strict-env 守卫自证、共享 helper 等其余诉求仍在 #2396 跟踪);关联 #2386。
🤖 Generated with Claude Code