Repository navigation
test(worker): strict-env 探针报告等内容可解析再读,消除 CI flake - #2386
Merged
Merged
Conversation
test/strict-env-worker.integration.test.ts 的假 CLI 用 fs.writeFileSync 一次性写 report,测试却只 vi.waitFor(existsSync) 就立刻同步 JSON.parse(readFileSync(report))。writeFileSync 先 truncate-create 文件、字节后落盘,CI 高负载下轮询会命中「文件已存在但为空」的窗口, 随即 parse 空文件报 `JSON Parse error: Unexpected EOF`(2026-10-26 bun-test 首跑在 codex thread 用例撞上,同批另四个用例全过)。 这正是 #1934(7cfa759b7)修过的同一类竞态:当时 commit message 写 「credential/strict-env 两处」,实际 diff 只改了 credential-only-send-authority.test.ts,本文件这处漏修至今。 修法与 #1934 对齐并更严:新增 waitForJsonReport,轮询到「文件内容 JSON.parse 成功」才返回(非空但半截的写入同样继续等),超时返回 null 由调用方带 diagnostics 失败而不是挂死;字段级断言保持原样, 错误/泄漏的报告内容仍确定性失败,只骑过空/半截窗口。restore 分支 对 env-policy 只判存在、不读内容,原 existsSync 等待保留。 复现与变异证据(真 worker + 真 init IPC 的临时探针,跑完已删): 把假 CLI 改成先 open('w') 建空文件、500ms 后才写完整 report 以放大 create-vs-write 窗口——旧读取逻辑(existsSync 即 parse)100% 失败, 报错为空 JSON parse(与 CI 同形);新 waitForJsonReport 通过;5 个 原用例 vitest 5/5 绿,tsc 0 错。
deepcoldy
requested review from
47seek,
LucasIcarus,
xiaoxueSunn and
xiongz-c
as code owners
October 26, 2026 13:13
This was referenced Oct 26, 2026
|
🚀 Released in v3.53.0 |
This was referenced Oct 29, 2026
deepcoldy
pushed a commit
that referenced
this pull request
Nov 5, 2026
复审 P3:条目原写「新建 helper」会催生第三份逐字拷贝——strict-env-worker.integration.test.ts:30 与 session-env-worker.integration.test.ts:26 已有相同的 waitForJsonReport(注释引 #1934/#2386),credential-only-send-authority.test.ts:336 有纯文本变体 waitForFile;改为要求抽公共件时收编这三处并统一超时语义(null 返回 vs undefined/抛错)。补入同形竞态的 CI 咬红史对照(config-dir 注释、#1934、#2386)。校准三处行号:kimi 注释 46-51、worker-tmux-pane-launch 注释 71、kimi 竞态注释 16-17;补记已闭合的 codex-actor-launcher 85-86。仅文档。 Co-Authored-By: Claude Code <[email protected]>
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.
背景
bun-test首跑在test/strict-env-worker.integration.test.ts的codex ... thread用例上偶发失败:报告文件已
existsSync为真,但紧接着同步JSON.parse(readFileSync(report))读到 0 字节。根因
假 CLI 用
fs.writeFileSync(report, JSON.stringify(...))一次性写报告,测试的等待条件却是:writeFileSync先 truncate-create 文件、字节随后落盘;CI 高负载、首个用例冷启 worker 最慢的窗口里,轮询会在「文件已创建但内容未写完」之间返回,下一行同步读到空文件 → parse EOF。同批另外 4 个用例都过,是低频时序竞态,不是逻辑回归。这与 #1934(7cfa759b7)修过的是同一类竞态——但那次 commit message 写「消除 credential/strict-env 两处 CI flake」,实际 diff 只改了
credential-only-send-authority.test.ts,本文件这处漏修,一直留到现在。改动(仅测试,1 文件)
waitForJsonReport(path, timeoutMs):轮询直到文件内容JSON.parse成功才返回;非空但半截的写入同样继续等;超时返回null,由调用方带diagnostics失败而不是挂死。env-policy文件只判存在、不读内容,原existsSync等待保留。与 #1934 对 credential 的修法(等非空内容)对齐,并按 JSON 场景收紧到「可解析」。
复现与变异证据
用真 worker + 真 init IPC 的临时探针(验证后已删除,未入库):把假 CLI 改成先
open(report,'w')建空文件、延迟 500ms 后才写完整报告,确定性放大 create-vs-write 窗口——existsSync即readFileSync+parse):100% 失败,报错为空 JSON 解析(与 CI 的 Unexpected EOF 同形);waitForJsonReport:通过(骑过 500ms 窗口读到完整报告,全部字段断言通过)。修复后 5 个原用例 vitest 5/5 绿;
tsc --noEmit0 错。影响面
仅测试文件,无 src 改动。该 flake 在多个互不相关 PR 的
bun-test上以不同 integration 文件偶发出现(runner 高负载时序),本 PR 根治其中已定位到 #1934 漏修的这一处。Co-Authored-By: Claude Code [email protected]