Skip to content

[WRONG BRANCH] test(ws-upstream): avoid unsupported fake timer advance - #267

Draft
luvs01 wants to merge 1 commit into
mainfrom
codex/fix-test-only-fake-timer-failure
Draft

[WRONG BRANCH] test(ws-upstream): avoid unsupported fake timer advance#267
luvs01 wants to merge 1 commit into
mainfrom
codex/fix-test-only-fake-timer-failure

Conversation

@luvs01

@luvs01 luvs01 commented Aug 13, 2026

Copy link
Copy Markdown
Owner

Motivation

  • A newly added timeout test relied on jest.advanceTimersByTime, which is not exported by the jest helper in the Bun test runtime and caused a TypeError in CI.
  • The change keeps the test coverage for the 10s WebSocket upgrade deadline and HTTP fallback behavior while making the test compatible with Bun's bun:test environment.

Description

  • Replace the jest import with spyOn from bun:test and remove calls to jest.useFakeTimers() / jest.advanceTimersByTime in the failing test.
  • Install a scoped spy on globalThis.setTimeout that captures the upgrade-deadline callback, asserts the expected 10_000 delay, invokes the callback to simulate the deadline, and then restores the spy in finally to avoid test pollution.

Testing

  • Ran the targeted test with bun test tests/ws-upstream.test.ts -t 'upgrade deadline elapses' and it passed.
  • Ran bun run typecheck and bun run privacy:scan, both completed successfully.
  • Exercised the repository test runner (bun run test) during verification; the modified ws-upstream test passed, but unrelated existing failures and external GUI build/network issues prevented a fully green full-suite run in this environment.

Codex Task

Summary by CodeRabbit

  • Tests
    • Improved timeout test reliability by explicitly controlling and restoring the timer behavior during test execution.

@github-actions

Copy link
Copy Markdown

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the chore label Aug 13, 2026
@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The WebSocket upstream timeout test replaces Jest fake timers with a Bun setTimeout spy. The test captures the deadline callback, invokes it directly, verifies the 10-second delay, and restores the spy during cleanup.

Changes

WebSocket timeout test

Layer / File(s) Summary
Replace fake timers with a setTimeout spy
tests/ws-upstream.test.ts
The test imports Bun’s spyOn, captures the 10-second timeout callback, invokes it directly, and restores the spy in finally.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Mergeability Score: 🔵 Low · up to 28812

The test-only change may allow the upgrade-deadline scenario to pass without confirming that the timeout callback was installed, leaving the 10-second fallback behavior insufficiently verified. The PR is mergeable with explicit owner follow-up to assert the callback was captured.

Suggested reviewers: wibias

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the WebSocket upstream test change and the replacement of unsupported fake-timer advancement.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-test-only-fake-timer-failure

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown

⏳ DRAFT

  • wrong target branch (main); retarget to dev.

What to do

  • Retarget this PR to dev — all contributions go to dev.

Its title has been prefixed with [WRONG BRANCH].
This pull request was already a draft. Its draft status will be preserved after every issue above is resolved.

@github-actions github-actions Bot changed the title test(ws-upstream): avoid unsupported fake timer advance [WRONG BRANCH] test(ws-upstream): avoid unsupported fake timer advance Aug 13, 2026
@github-actions
github-actions Bot marked this pull request as draft August 13, 2026 01:01

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/ws-upstream.test.ts`:
- Around line 210-217: Update the test around the deadline invocation to assert
that deadline was captured before calling it, ensuring the test fails when
setTimeout does not register the fallback callback. Keep the existing response,
fallbackCalls, and socket-closed assertions unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 028b1c28-74af-4fb5-9b62-4b1747bd18f6

📥 Commits

Reviewing files that changed from the base of the PR and between 1193075 and 288126d.

📒 Files selected for processing (1)
  • tests/ws-upstream.test.ts

Comment thread tests/ws-upstream.test.ts
Comment on lines +210 to +217
deadline?.();
const response = await responsePromise;

expect(response).toBe(sentinel);
expect(fallbackCalls).toBe(1);
expect(FakeWebSocket.instances[0].closed).toBe(true);
} finally {
jest.useRealTimers();
setTimeoutSpy.mockRestore();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert that the timeout callback was captured.

In tests/ws-upstream.test.ts, Line 210 skips the callback when deadline is undefined. The assertion at Line 195 does not detect a missing timer because it runs only when setTimeout is called. The test can then hang or complete through a different close path without testing the 10-second fallback.

Assert the callback before invoking it.

Proposed fix
-      deadline?.();
+      expect(deadline).toBeDefined();
+      deadline!();
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
deadline?.();
const response = await responsePromise;
expect(response).toBe(sentinel);
expect(fallbackCalls).toBe(1);
expect(FakeWebSocket.instances[0].closed).toBe(true);
} finally {
jest.useRealTimers();
setTimeoutSpy.mockRestore();
expect(deadline).toBeDefined();
deadline!();
const response = await responsePromise;
expect(response).toBe(sentinel);
expect(fallbackCalls).toBe(1);
expect(FakeWebSocket.instances[0].closed).toBe(true);
} finally {
setTimeoutSpy.mockRestore();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/ws-upstream.test.ts` around lines 210 - 217, Update the test around the
deadline invocation to assert that deadline was captured before calling it,
ensuring the test fails when setTimeout does not register the fallback callback.
Keep the existing response, fallbackCalls, and socket-closed assertions
unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant