Skip to content

test(usage-analysis): add unit tests for mergeUsageAnalysis, analyzeContextReferences, deriveConversationPatterns#600

Merged
rajbos merged 2 commits intomainfrom
test/usage-analysis-coverage
Apr 12, 2026
Merged

test(usage-analysis): add unit tests for mergeUsageAnalysis, analyzeContextReferences, deriveConversationPatterns#600
rajbos merged 2 commits intomainfrom
test/usage-analysis-coverage

Conversation

@rajbos
Copy link
Copy Markdown
Owner

@rajbos rajbos commented Apr 11, 2026

Summary

Adds 23 unit tests for the synchronous, pure-function core of usageAnalysis.ts -- the 1,974-line module driving the Usage Analysis dashboard that had zero test coverage.

What's tested

mergeUsageAnalysis (7 tests)

  • Tool call counts accumulate correctly across multiple sessions (including per-tool byTool map)
  • Mode usage (ask/edit/agent/plan/customAgent) accumulates correctly
  • Context reference fields (file, workspace, codebase) accumulate correctly
  • MCP tool counts accumulate by server and by tool
  • Mixed-tier session tracking: sessions with modelCount > 0 update mixedTierSessions, standardModels, premiumModels, request counts
  • Sessions with modelCount = 0 are correctly excluded from switching stats
  • byKind context reference counts accumulate correctly

analyzeContextReferences (13 tests)

  • Each of the 13 reference types detected: #file, #selection, @workspace, @Terminal, #codebase, #changes, #clipboard, #terminalLastCommand, #outputPanel, #problemsPanel
  • Accumulates on top of existing counts
  • Empty text produces no counts
  • Matching is case-insensitive

deriveConversationPatterns (3 tests)

  • 0 requests: singleTurn=0, multiTurn=0, avgTurns=0
  • 1 request: produces single-turn session with avgTurns=1
  • 3 requests: produces multi-turn session with correct avgTurns and maxTurns

Approach

Scoped to the purely synchronous functions only. analyzeSessionUsage and calculateModelSwitching are async with wide dependency interfaces and are left for a follow-up. Tests use inline object construction -- no mocks, no file I/O.

rajbos and others added 2 commits April 12, 2026 00:34
…ontextReferences, deriveConversationPatterns

Add 23 unit tests covering the three synchronous/pure-function layers of
usageAnalysis.ts: mergeUsageAnalysis (period accumulation, MCP tool merging,
model-switching stats, byKind context tracking), analyzeContextReferences (all
13 reference type patterns, accumulation, case-insensitivity), and
deriveConversationPatterns (0/1/multi-request session patterns). Tests use
inline object construction with no mocks or external dependencies.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rajbos rajbos enabled auto-merge (squash) April 12, 2026 08:32
@rajbos rajbos merged commit 78bfd77 into main Apr 12, 2026
17 checks passed
@rajbos rajbos deleted the test/usage-analysis-coverage branch April 12, 2026 08:34
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