test(research): 终态等待改为墙钟预算,避免慢环境下误报未收敛 - #157
Merged
Merged
Conversation
ResearchService 测试里的 waitForTerminal 用固定 100 次 × 5ms 的轮询预算, 实际只有约 500–700ms 墙钟时间;而 run 本身需要落盘后再轮询回读,在慢机器或 满载 CI 上完整跑完所需时间会超过这个预算,于是健康的 run 被判定为 "did not reach a terminal status"。 - waitForTerminal 改为基于墙钟 deadline(TERMINAL_WAIT_MS = 5000ms)轮询 - 新增回归用例:模拟 800ms 后才收敛的流水线,旧实现必然超时失败 影响:消除 Full unit tests (advisory) 因该等待窗口过短产生的偶发红灯 (如 PR helsome#138 的 advisory 作业 106589165526,2 fail / 1605 pass)。 范围:仅测试辅助函数与新增用例,无生产代码改动。
helsome
approved these changes
Sep 22, 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 #156
复现
在干净
main(7c9b550)上运行:连跑 3 次,稳定出现失败(详见 issue #156):
失败项:
ResearchService > runs a report end-to-end and persists it、ResearchService > lists runs newest-first、ResearchService > plans from the strategy and persists strategyId onto the report,报错均为error: run research-<uuid> did not reach a terminal status,耗时 709–769ms。同一问题在 GitHub Actions 上也出现过:PR #138 的
Full unit tests (advisory)(run35678224696/ job106589165526)结果为 1605 pass / 2 fail,两个失败项即ResearchService > lists runs newest-first与ResearchService > plans from the strategy and persists strategyId onto the report。根因
waitForTerminal()用固定 100 次迭代表达等待预算:每次迭代的实际墙钟成本 = 一次
service.getRun()(回读磁盘上的 run 存储)+setTimeout(5),实测约 7ms/次,因此 100 次只覆盖约 500–700ms。流水线在慢机器 / 满载 CI 上跑完需要 700ms 以上,于是健康的 run 尚未收敛预算就已耗尽,被抛成did not reach a terminal status。这是等待窗口的表达方式问题(迭代次数 vs 墙钟时间),不是被测行为的问题——run 最终确实会收敛。
修复
waitForTerminal()改为墙钟 deadline 驱动:TERMINAL_WAIT_MS = 5_000,do { ... } while (Date.now() < deadline)。ResearchService > keeps polling past the old fixed 500ms budget when the pipeline is slow:包装service.getRun,模拟一条 800ms 后才收敛的流水线,断言waitForTerminal仍返回completed。回归用例在旧实现下确实失败(把循环改回固定 100 次后单独跑该用例):
预期 / 实际
waitForTerminal()返回终态;测试只因行为不对而失败。范围
仅
packages/shared/src/research/service.test.ts(waitForTerminal辅助函数 + 1 条新增用例,+33 / −2)。无生产代码改动,无可见 UI 变化。验证
环境:Windows 11(本机),Bun 1.4.2,分支基于
origin/main7c9b550。bun test packages/shared/src/research/service.test.ts --isolatebun test packages/shared/src/research --isolatebun run typecheckgit diff --check基线说明:上述失败在干净
main(7c9b550)上同样复现,属 main 既有问题,本 PR 不夹带其他修复;修复后packages/shared的 research 目录全绿。