Skip to content

test: fix flaky tests and speed up slow test suite#242

Merged
anandgupta42 merged 1 commit intomainfrom
worktree-fix-flaky-slow-tests
Mar 18, 2026
Merged

test: fix flaky tests and speed up slow test suite#242
anandgupta42 merged 1 commit intomainfrom
worktree-fix-flaky-slow-tests

Conversation

@anandgupta42
Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes 4 failing tests, eliminates flakiness, and speeds up the 9 slowest test files by 4.6x (62s → 14s).

Failures fixed (4 → 0):

  • Mock DuckDB driver in adversarial.test.ts and dbt-first-execution.test.ts
  • describe.skipIf with synchronous require.resolve("duckdb") in connections.test.ts
  • Fingerprint.reset() to fix cross-test cache pollution in skill.test.ts
  • Replace cowsay npm dep with local module in registry.test.ts
  • Add retry: 2 for flaky PTY Bus event delivery under parallel load

Speed improvements:

Test File Before After Speedup
session/retry.test.ts 8.3s 0.3s 28x
tracing-adversarial.test.ts 5.7s 0.5s 11x
config/config.test.ts 7.1s 0.7s 10x
tool/project-scan.test.ts 16.0s 3.2s 5x
tracing-adversarial-snapshot.test.ts 4.2s 1.1s 3.8x
mcp/oauth-browser.test.ts 6.4s 1.8s 3.6x
tracing-display-crash.test.ts 2.6s 0.8s 3.3x
tracing-adversarial-final.test.ts 2.3s 0.8s 2.9x
tool/registry.test.ts 9.6s 4.7s 2x
Totals 62.2s 13.6s 4.6x

Production code change: Added Fingerprint.reset() export (5 LOC) for test cache isolation.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Refactor (no functional changes)

Issue for this PR

Follow-up issue for tracing test consolidation: Closes #241

How did you verify your code works?

  • Full test suite passes: 3262 pass, 174 skip, 0 fail
  • Verified stability across 2 consecutive full suite runs
  • Type check passes (bun run typecheck)
  • Individual file timing verified before/after

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • New and existing unit tests pass locally with my changes

- Fix 4 failing tests: mock DuckDB driver in `adversarial.test.ts` and
  `dbt-first-execution.test.ts`, use `describe.skipIf` with synchronous
  `require.resolve("duckdb")` in `connections.test.ts`, add
  `Fingerprint.reset()` to fix cross-test cache pollution in `skill.test.ts`
- Fix `registry.test.ts` timeout by replacing `cowsay` npm dep with local
  module import and adding `git: true` fixture flag
- Fix flaky `pty-session.test.ts` by adding `retry: 2` for Bus event
  delivery under parallel load
- Speed up `retry.test.ts` 28x (8.3s → 0.3s) by replacing 10s
  `Bun.serve` idle timeout with raw TCP socket destroy
- Speed up `config.test.ts` 10x (7.1s → 0.7s) by mocking `BunProc.run`
  to prevent real `bun install` during tests
- Speed up `tracing-adversarial.test.ts` 11x (5.7s → 0.5s) by replacing
  5s exporter timeout with 200ms auto-resolve
- Speed up `project-scan.test.ts` 5x (16s → 3.2s) by caching
  `detectDataTools`/`detectGit` results in `beforeAll`
- Speed up `oauth-browser.test.ts` 3.6x (6.4s → 1.8s) by reducing sleep
  durations to match actual detection window timing
- Speed up 3 tracing snapshot/display tests 3-4x by reducing settle waits
  from 200-500ms to 50-100ms
- Add `Fingerprint.reset()` export for test isolation (5 LOC production change)
- Result: 0 failures (was 4), 62s → 14s on targeted files, full suite stable

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@claude
Copy link
Copy Markdown

claude bot commented Mar 18, 2026

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review.

@anandgupta42 anandgupta42 merged commit e4f3471 into main Mar 18, 2026
6 of 7 checks passed
@anandgupta42 anandgupta42 deleted the worktree-fix-flaky-slow-tests branch March 25, 2026 02:14
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.

chore: consolidate redundant tracing test files (~5,000 LOC savings)

1 participant