Skip to content

test: add 31 unit tests for estimate_cost helpers#285

Open
TerminalGravity wants to merge 1 commit intomainfrom
test/estimate-cost-tests-v2
Open

test: add 31 unit tests for estimate_cost helpers#285
TerminalGravity wants to merge 1 commit intomainfrom
test/estimate-cost-tests-v2

Conversation

@TerminalGravity
Copy link
Collaborator

Adds comprehensive unit tests for the estimate_cost tool's pure helper functions.

Changes

  • Export 7 pure helpers from estimate-cost.ts for testability
  • Add tests/tools/estimate-cost.test.ts with 31 tests covering:
    • estimateTokens: empty, short, long strings
    • extractText: string, block arrays, null/undefined/number/object
    • extractToolNames: tool_use blocks, missing names, non-arrays
    • formatTokens: raw numbers, k, M formats
    • formatCost: normal, sub-cent, zero
    • formatDuration: minutes, hours+minutes, zero
    • analyzeSessionFile: prompt counting, corrections, tool calls, preflight detection, timestamps, empty files, malformed JSON

Test results

Test Files  6 passed (6)
     Tests  74 passed (74)  ← up from 43

Closes no issue — pure test coverage improvement.

Export pure helper functions (estimateTokens, extractText, extractToolNames,
formatTokens, formatCost, formatDuration, analyzeSessionFile) and add
comprehensive tests covering:

- Token estimation (empty, short, long strings)
- Content extraction from string, block arrays, null/undefined
- Tool name extraction from content blocks
- Token/cost/duration formatting with edge cases
- Session file analysis: prompt counting, correction detection,
  tool call counting, preflight detection, timestamp tracking,
  empty files, and malformed JSON resilience

Brings test count from 43 to 74.
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