Skip to content

test(worker): 场景 F 等 dialog_pending 更正通知后再让假人回答,消除与 hold 轮询的竞态 - #3026

Merged
deepcoldy merged 1 commit into
masterfrom
fix/startup-switch-confirm-hook-dialog-flake
Nov 7, 2026
Merged

deepcoldy merged 1 commit into
masterfrom
fix/startup-switch-confirm-hook-dialog-flake

Conversation

@deepcoldy

Copy link
Copy Markdown
Owner

背景

#2996 的 CI(run 42355456340,shard 3/4)上 test/worker-claude-startup-switch-confirm.integration.test.ts:349 失败:场景 F(late hook dialog)只收到 worker.startup_command_unconfirmed,缺 worker.startup_command_dialog_pending。该测试由 #2981 引入。

根因

纯测试夹具竞态,产品代码不需要改:

  • 场景 F 的假 CLI 在启动命令提交后 24s 才渲染 hook 确认框(dialogDelayMs: 24_000,晚于 20s 的 hold);旧夹具在收到第一条 hold 通知 4s 后就让假人回答。
  • CI 日志时间线:hold 建立于 09:13:42.487(unconfirmed 通知),假人随即在 ~46.5s 按 Enter;确认框只存在约 0.4s,而 worker 只在 hold 轮询(STARTUP_CMD_HOLD_POLL_MS = 1s)里读屏。忙 runner 上这一拍轮询错过确认框,onScreen 始终不是 leave,更正通知不发;命令在 47.04s 被记录,hold 解除,最终断言缺第二条通知。日志中全程没有 left for a person。
  • 真人做选择远多于 1 秒;人若真在同一秒内答完,也确实不再需要更正通知。旧夹具的定时回答只是在和 worker 的轮询抢跑。

改了什么(只改测试)

  • 场景 F 不再用「收到 hold 通知后固定 4s 回答」,而是等测试侧真正观测到 worker.startup_command_dialog_pending 更正通知后才放行假人回答(假 CLI 的确认框本来就一直挂着,直到 personFile 出现)。确认框因此必然覆盖至少一次 hold 轮询,断言不再依赖调度时序;其余场景 A–E 行为不变。

影响面

只改一个测试文件,生产代码不变。场景 F 时长约 25–30s,仍在 180s 用例超时内。

验证

  • npx vitest run --project unit test/worker-claude-startup-switch-confirm.integration.test.ts:1/1 通过(55 个断言),多次。
  • bun test --timeout=180000 ./test/worker-claude-startup-switch-confirm.integration.test.ts:1/1 通过。
  • 变异:把 worker 在 hold 轮询中补发 dialog_pending 的守卫置为不可达(src/worker.ts 中 hold.confirmation.onScreen === 'leave' 的补发分支),新测试确定性失败(等待更正通知 60s 超时,275 行);还原后通过。
  • 加压稳定性:isolate-run(2 CPU + 2 个满载进程模拟忙 shard)连跑 3 轮全绿。
  • 失败归因证据:CI 日志该 worker 时间线为 not confirmed within 20000ms(42.487)→ confirmed late(47.040),中间没有 left for a person。

#2996 CI shard 3/4 上 worker-claude-startup-switch-confirm 场景 F 失败:假人在
hold 通知后固定 4s 回答,而确认框在忙 runner 上只存在约 0.4s,worker 的 1s
hold 轮询没读到对话框,dialog_pending 更正通知不发。改为测试侧观测到更正
通知后才放行假人回答,确认框必然覆盖轮询;摘掉 worker 补发守卫时该用例确定性
超时变红。

Co-Authored-By: Claude Code <[email protected]>
@deepcoldy
deepcoldy merged commit b6346d8 into master Nov 7, 2026
15 checks passed
deepcoldy pushed a commit that referenced this pull request Nov 7, 2026
deepcoldy pushed a commit that referenced this pull request Nov 7, 2026
@github-actions

Copy link
Copy Markdown

🚀 Released in v3.59.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