Repository navigation
fix(ci): disable vitest console intercept to eliminate teardown race - #14
Merged
Merged
Conversation
vitest 4.1.11 unconditionally replaces globalThis.console in the worker (setupConsoleLogSpy) and forwards every log via state().rpc.onUserConsoleLog. When a test leaves async console output in flight during worker teardown, the RPC close races with the pending onUserConsoleLog call and vitest fails with: EnvironmentTeardownError: [vitest-worker]: Closing rpc while onUserConsoleLog was pending. The origin is random (ClineProvider.flicker-free-cancel.spec.ts on windows, Task.throttle.test.ts on ubuntu), so it is a systemic flake, not a single file issue. Enabling disableConsoleIntercept keeps the native console, which writes straight to the process streams and completely bypasses the RPC. Also mock SkillsManager in ClineProvider.flicker-free-cancel.spec.ts (the only test that constructs ClineProvider directly). It was missing that mock, so the real SkillsManager.initialize() ran directory scans and emitted console.error, which was the most common trigger. Use a regular function for the constructor mock because arrow functions lack [[Construct]] and break new SkillsManager(this).
seeones
added a commit
that referenced
this pull request
Sep 23, 2026
…14) vitest 4.1.11 unconditionally replaces globalThis.console in the worker (setupConsoleLogSpy) and forwards every log via state().rpc.onUserConsoleLog. When a test leaves async console output in flight during worker teardown, the RPC close races with the pending onUserConsoleLog call and vitest fails with: EnvironmentTeardownError: [vitest-worker]: Closing rpc while onUserConsoleLog was pending. The origin is random (ClineProvider.flicker-free-cancel.spec.ts on windows, Task.throttle.test.ts on ubuntu), so it is a systemic flake, not a single file issue. Enabling disableConsoleIntercept keeps the native console, which writes straight to the process streams and completely bypasses the RPC. Also mock SkillsManager in ClineProvider.flicker-free-cancel.spec.ts (the only test that constructs ClineProvider directly). It was missing that mock, so the real SkillsManager.initialize() ran directory scans and emitted console.error, which was the most common trigger. Use a regular function for the constructor mock because arrow functions lack [[Construct]] and break new SkillsManager(this). Co-authored-by: seeones <seeones@163.com>
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.
背景
PR #12 合并后 main 上的 Code QA 在 ubuntu/windows 随机失败:
根因(源码级确认)
vitest 4.1.11 在 worker 侧无条件替换
globalThis.console(setupConsoleLogSpy),每次 console 输出经 microtask →state().rpc.onUserConsoleLog(...)转发到主进程。测试文件的异步 console 输出在 worker teardown 时在途,RPC 关闭与之竞争即报错。origin 是随机的:windows 落在
ClineProvider.flicker-free-cancel.spec.ts,ubuntu 落在Task.throttle.test.ts——系统性 flake,不是单文件问题。修复
src/vitest.config.ts:启用disableConsoleIntercept: true,console 保持原生直接写进程流,完全绕开onUserConsoleLogRPC。ClineProvider.flicker-free-cancel.spec.ts:补SkillsManagermock(唯一真实构造 ClineProvider 的测试),消除最常触发的 console.error 来源。验证