Skip to content

test: stop integration runs failing on teardown console race#6702

Draft
macko911 wants to merge 1 commit into
masterfrom
matej/fix-flaky-integration-teardown
Draft

test: stop integration runs failing on teardown console race#6702
macko911 wants to merge 1 commit into
masterfrom
matej/fix-flaky-integration-teardown

Conversation

@macko911

@macko911 macko911 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Problem

Integration CI can fail even when every test passes. Under Vitest 4, worker console output is intercepted and shipped to the main process over an RPC. Handlers in these tests do fire-and-forget logging that outlives the request (e.g. the proxy's enrichOperation in a finally block), so a stray log can fire as the worker tears down and race the closing RPC. The run then fails with EnvironmentTeardownError: Closing rpc while "onUserConsoleLog" was pending, attributed to allProxy.integration.test.ts — the most recent occurrence passed all 317 tests but still exited 1.

Solution

  • Set disableConsoleIntercept: true in vite.integration.config.ts so worker console writes go straight to stdout/stderr, removing the RPC the stray log was racing.

This is a class of flake — any integration test whose handler logs asynchronously can trip it, not just the proxy suite. No test relies on Vitest's console interception.

Trade-offs

Pros

  • Removes the whole onUserConsoleLog teardown-race flake class, not just the proxy case.
  • No production or test-logic change; a genuine failure still prints its test name and assertion stack (that comes from the test result, not console interception).
  • Safer than the alternatives: dangerouslyIgnoreUnhandledErrors would swallow real unhandled errors, and fixing it at the source would mean blocking HTTP responses on fire-and-forget logging.

Cons

  • Log lines lose their stdout | file > test prefix, so free-floating logs are no longer attributable to a specific test in CI output.
  • Console output can interleave more messily (low impact here — this config runs maxWorkers: 1 + fileParallelism: false, so logs stay serial).
  • Applies to all integration tests — the option is project-level, can't be scoped to one file.

Testing

  • Ran allProxy.integration.test.ts against the fix: 7/7 pass, no Errors line and no EnvironmentTeardownError.

Vitest 4 intercepts worker console output and ships it to the main
process over an RPC. Handlers in these tests do fire-and-forget logging
that outlives the request (e.g. the proxy's enrichOperation in a finally
block), so a stray log can fire as the worker tears down and race the
closing RPC, failing the whole run with "EnvironmentTeardownError:
Closing rpc while onUserConsoleLog was pending" even when every test
passed.

Set disableConsoleIntercept so worker console writes go straight to
stdout/stderr, removing the RPC entirely. No test relies on console
interception.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 1 file

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

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