Skip to content

test: extract 3 modules from extension.ts + 38 new tests (194 → 232)#29

Merged
dmartinochoa merged 1 commit into
mainfrom
test/expand-coverage-2
May 19, 2026
Merged

test: extract 3 modules from extension.ts + 38 new tests (194 → 232)#29
dmartinochoa merged 1 commit into
mainfrom
test/expand-coverage-2

Conversation

@dmartinochoa
Copy link
Copy Markdown
Member

Summary

Three thin extractions out of activate() so the behaviour they encapsulate can be exercised in unit tests rather than waiting for the @vscode/test-electron integration run, plus a few gaps in the existing CodeLens provider tests.

Extractions

Module What it owns Why extracted
src/lspStart.ts Bounded-time client.start() (was inline in extension.ts) Timeout race semantics need unit tests; also restructured internally from Promise.race([start, timeout]) to a single deferred with a settled flag — Promise.race plus vitest's fake timers leaked PromiseRejectionHandledWarning because race attaches its handler one microtask after the timer rejects
src/middleware.ts transformDiagnostics(uri, diagnostics, config) — pure composition of disabledProviders blanket-drop + severityThreshold filter The two stages were each tested separately, but the user-visible behaviour is the composition (disable wins, then severity filters survivors)
src/scanOnSave.ts createScanOnSaveHandler(deps) — save handler with closure-scoped busy flag Locks down cheap-gates-first ordering (isEnabled → isPipelineFile → busy); per-instance busy flag so two windows don't share a lock

extension.ts gets shorter at every site:

extension.ts: 481 → 460 lines

Test coverage (194 → 232, +38)

File Tests Surface
lspStart.test.ts 12 timeout race, stop-on-timeout, settled-flag idempotence, message rounding, copy invariants
middleware.test.ts 13 disable stage (blanket drop, empty-array shape, lowercase Dockerfile), severity stage (threshold filtering, missing-data passthrough), composition (disable wins, no-provider bypass)
scanOnSave.test.ts 9 cheap-gates-first, busy guard collapses storms, lock releases on rejection, per-instance lock, live config re-read
codeLens.test.ts (+4) +4 lens anchored at line 0 col 0, command target is pipelineCheck.findings.focus, live count (not cached), per-document scope

Test plan

  • npm test — 232/232 vitest assertions pass
  • npm run typecheck — clean
  • npm run lint — clean
  • npm run bundle:dev — bundle builds (808.5 kB, unchanged ±0.5 kB)
  • CI integration suite passes (end-to-end VS Code activation; no behaviour change so should be a no-op)

🤖 Generated with Claude Code

Three thin extractions out of the activate() closure so the behaviour
they encapsulate can be exercised in unit tests rather than waiting
for the @vscode/test-electron integration run:

- lspStart.ts: bounded-time client.start(). Internally restructured
  from Promise.race([start, timeout]) to a single deferred with a
  settled flag — Promise.race plus vitest's fake timers triggered
  "rejection handled asynchronously" warnings because Promise.race
  attaches its handler one microtask after the timer fires the
  rejection. The deferred avoids the two-promise dance.
- middleware.ts: pure transformDiagnostics(uri, diagnostics, config)
  composing the disabledProviders blanket-drop and the
  severityThreshold filter. extension.ts now plumbs the config in
  via deps; the composition (which the user sees) is testable in
  isolation.
- scanOnSave.ts: createScanOnSaveHandler(deps) returns a save handler
  that closes over a busy flag. Cheap-gates-first ordering
  (isEnabled → isPipelineFile → busy) is pinned; each handler
  instance has its own busy flag so two windows don't share a lock.

CodeLens provider class gets four new tests pinning the lens range
(line 0 col 0), the click target (pipelineCheck.findings.focus), the
"reads live counts each call" contract (so a future cache-once-at-
construction refactor trips), and the per-document scope (lens
reflects only this document's diagnostics, not the workspace total).

Tests breakdown:
- lspStart: 12 tests (timeout race, stop-on-timeout, settled-flag, copy)
- middleware: 13 tests (disabled stage, severity stage, composition)
- scanOnSave: 9 tests (gates, busy guard, per-instance lock)
- codeLens: +4 tests on the existing file

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

coderabbitai Bot commented May 19, 2026

Warning

Rate limit exceeded

@dmartinochoa has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 25 minutes and 49 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0492f358-def8-4960-9390-24de9188ae71

📥 Commits

Reviewing files that changed from the base of the PR and between f9b5a8f and c33d271.

📒 Files selected for processing (8)
  • src/codeLens.test.ts
  • src/extension.ts
  • src/lspStart.test.ts
  • src/lspStart.ts
  • src/middleware.test.ts
  • src/middleware.ts
  • src/scanOnSave.test.ts
  • src/scanOnSave.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/expand-coverage-2

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

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

@dmartinochoa dmartinochoa merged commit 6014c69 into main May 19, 2026
12 checks passed
@dmartinochoa dmartinochoa deleted the test/expand-coverage-2 branch May 19, 2026 18:07
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