Skip to content

test: replace real timeout waits with fake timers in the slowest suites - #878

Merged
BytePioneer-AI merged 2 commits into
mainfrom
perf/speed-slow-tests
Nov 16, 2026
Merged

BytePioneer-AI merged 2 commits into
mainfrom
perf/speed-slow-tests

Conversation

@BytePioneer-AI

Copy link
Copy Markdown
Owner

Purpose

Seven test files spent 4–17 seconds each waiting for real 10-second timeouts and rate-limit refills. remote-relay alone took 56 seconds of CI test time across 12 files.

Changes

The slow cases advance Vitest fake timers instead of waiting in real time. Socket and filesystem I/O stay real, and each timeout case now also checks the boundary: still open just before the deadline, closed at it. No production code changed and no assertions were removed.

File Cause Local time before → after
packages/remote-relay/test/limits.test.ts real rate limiting and 10 s timeout 17.19s → 0.48s
packages/remote-relay/test/operations.test.ts real registration timeout and rate limit 12.51s → 0.82s
packages/remote-relay/test/relay.test.ts real registration timeout 12.20s → 2.24s
packages/host-runtime/test/remote-official-socket-link.test.ts real startup timeout (fakes Date only) 10.38s → 0.42s
packages/remote-relay/test/client-hello.test.ts real handshake timeout 10.13s → 0.16s
packages/host-runtime/test/installed-harness-plugins.test.ts registry reloaded for each of 16 cases; now loaded once 9.19s → 6.68s
packages/adapters/zcode/test/transport.test.ts child-process sleep and request timeout 4.05s → 1.73s

tests/release/host-bundle.test.mjs was also slow but has no safely shareable setup, so it is unchanged.

Validation

  • Each changed file was run on its own before and after on macOS: all pass.
  • ESLint and Prettier on the changed files: pass.
  • Linux and Windows were not run locally. The remote-relay cases mix real socket I/O with fake timers, so the CI platform lanes are the check for flakiness.

Seven files spent most of their CI time waiting for real 10-second
timeouts and rate-limit refills. They now advance fake timers instead,
keep real socket and filesystem I/O, and assert each deadline boundary
(still open just before it, closed at it). The installed-plugin test
loads the registry once for its 16 explicit-command cases.

No production code changed and no assertions were removed.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T07:09:22.062223Z d7d1283 PR opened
🔒 Security Review ✅ Completed 2026-11-16T07:08:55.856934Z d7d1283 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • 测试
    • 改进了连接超时、传输限速及适配器安装状态相关检查的稳定性与准确性。
    • 完善测试资源清理,减少计时器和连接状态对其他测试的影响。

测试套件改用假计时器验证请求和连接的超时边界,并通过虚拟时间推进限速传输。Harness 注册表测试改为集中初始化和关闭。

Changes: 计时器驱动的超时与传输测试

Layer / File(s) Summary
:--- :---
协议请求超时
packages/adapters/zcode/test/transport.test.ts, packages/remote-relay/test/client-hello.test.ts
测试使用假计时器检查请求在超时前后的结果。清理钩子会恢复真实计时器。
连接超时与清理
packages/host-runtime/test/remote-official-socket-link.test.ts, packages/remote-relay/test/operations.test.ts, packages/remote-relay/test/relay.test.ts, packages/remote-relay/test/limits.test.ts
测试使用假计时器检查连接超时前后的状态、关闭代码和后续注册行为。清理流程会恢复真实计时器。
限速传输计时
packages/remote-relay/test/limits.test.ts, packages/remote-relay/test/operations.test.ts
测试以小步推进虚拟时间并让出事件循环,等待传输结果;超过虚拟时间上限时,测试会失败。

Harness 注册表测试

Layer / File(s) Summary
:--- :---
注册表初始化与适配器断言
packages/host-runtime/test/installed-harness-plugins.test.ts
测试在套件开始时加载注册表,并为 Harness 配置缺失命令路径。测试逐项验证适配器结果,并在套件结束时关闭注册表。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Other

Suggested reviewers: gy212, mouzhi

Merge Risk: Minimal · up to f52f0

This change only speeds up tests by replacing real waits with fake timers, and production behavior is unchanged. The CI platform runs on Linux and Windows should confirm the socket-based timeout tests are stable.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed 标题“test: replace real timeout waits with fake timers in the slowest suites”准确描述了主要变更:将慢速测试中的真实超时等待替换为 Vitest 假计时器。原始摘要和 PR 目标都确认该变更覆盖七个测试文件,且未修改生产代码。标题简洁,符合 conventional commit 格式。
Description check Passed 描述与变更集高度相关。它说明了问题来源(真实的 10 秒超时和限速等待)、受影响的七个文件及其耗时变化、保留真实 I/O 与边界检查的做法,以及验证方式。这些内容与原始摘要中各文件的改动一致。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between d7d1283 and f52f050.

Files selected for processing: 1

  • packages/host-runtime/test/installed-harness-plugins.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 2 remain after this review.

Recent review details

Context from checks skipped due to timeout: 4

  • GitHub Check: Check windows-latest
  • GitHub Check: Check Linux ARM64
  • GitHub Check: Check ubuntu-22.04
  • GitHub Check: Check macos-26
Additional context used

Code guidelines: 2

CLAUDE.md — auto-discovered
AGENTS.md — auto-discovered
Path-based instructions: 1

Source excerpt: Host Runtime loads installed plugins through public contracts, not direct imports of concrete Adapter packages.

CodeRabbit inference engine (CLAUDE.md)

Files:

  • packages/host-runtime/test/installed-harness-plugins.test.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d7d1283df4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +101 to +103
Object.fromEntries(
commands.map(([id, variable]) => [variable, path.resolve(".missing-fixture", id)]),
),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Isolate each explicit-command override

Populating every CODEXHOST_*_COMMAND variable in the shared registry weakens the mapping check: if an Adapter is accidentally wired to another Harness's variable, it still receives a nonexistent path and returns the expected notInstalled result. Previously, only the variable under test was set, so this mistake was exposed whenever normal discovery found that Adapter locally—the exact scenario these cases are intended to cover. Preserve per-case environments, or independently assert which configured path each Adapter selected.

Useful? React with 👍 / 👎.

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