Skip to content

test(sandbox): bwrap 身份/存储握手轮询等待内容而非文件存在,消除 CI flake - #1926

Merged
deepcoldy merged 1 commit into
masterfrom
fix/bwrap-identity-flake
Oct 14, 2026
Merged

deepcoldy merged 1 commit into
masterfrom
fix/bwrap-identity-flake

Conversation

@deepcoldy

Copy link
Copy Markdown
Owner

改了什么 / 为什么

合入 #833 后的 master push CI 出现一例真实 bwrap 用例 flake:test/cli-identity-bwrap.test.ts > reads an atomically replaced identity through the production directory bind,现象 expected '' to contain 'token-second'(同分片前一次运行该用例刚通过)。

根因是测试握手的就绪判定,与被测生产代码无关:

  • 容器内发布结果用的是 cat identity > out(shell 重定向)——内核先截断/创建 out,稍后才把字节写入;
  • 宿主侧却用 pollFor(() => existsSync(out)) 判「读完了」。文件「存在」不等于「内容已写完」,CI 高负载下 50ms 轮询正好落在「已建空文件、cat 尚未写入」的窗口,读到空串。

修法(仅测试,零 src 改动):就绪判据从「文件存在」改为「所需内容就绪」。

  • cli-identity-bwrap.test.ts:轮询直到 out 含刷新后的 token-second;读到旧 token-first 永不满足、按超时失败,不会假绿。
  • test/session-store-bwrap.test.ts:同一 flake 形状(容器内 writeFileSync('out', …) 同样先建后写),轮询改为等 out 非空,最终 v2/ERR 断言不变。

测试验证

  • 变异对照(真实 bwrap,放大竞态窗口):把容器改成「先 : > out 截断建空文件 → sleep 0.5s → 再写内容」:
    • 旧 existsSync 判据:确定性复现 CI 失败(expected '' to contain 'token-second');
    • 新内容判据:通过(放大 0.5s 窗口仍稳)。
  • 两文件真实 bwrap 连跑 20/20 绿;tsc 0 错、bun run build 通过。
  • 本机另有 3 个真实 bwrap 集成文件(plugin-mcp-sandbox / plugin-registry-sandbox-read / sandbox-dispatch-routing)在这台共享机基线上本就红/skip(撤销本改动后同样失败,CI runner 上为绿),属本机环境基线,不在本 PR 范围。

影响面:仅 2 个 linux-only、bwrap 可用才运行的测试文件;不改任何生产代码、其它 CLI/后端/平台不受影响。

🤖 Generated with Claude Code

容器内 cat > out / writeFileSync 都是先截断建文件、稍后字节才落地;
宿主侧用 existsSync 判就绪在 CI 高负载下会读到建文件与写入之间的空窗,
cli-identity-bwrap 实测 flake(expected '' to contain 'token-second')。
两处真实 bwrap 握手改为轮询所需内容(刷新后的 token / 非空查询结果),
文件存在不再等价于内容就绪。

Co-Authored-By: Claude Code <[email protected]>
@deepcoldy
deepcoldy merged commit dece45d into master Oct 14, 2026
14 checks passed
@github-actions

Copy link
Copy Markdown

🚀 Released in v3.44.0

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.

1 participant