Skip to content

test: add 22 unit tests for estimate-cost helpers - #82

Closed
TerminalGravity wants to merge 6 commits into
mainfrom
test/estimate-cost-coverage
Closed

test: add 22 unit tests for estimate-cost helpers#82
TerminalGravity wants to merge 6 commits into
mainfrom
test/estimate-cost-coverage

Conversation

@TerminalGravity

Copy link
Copy Markdown
Collaborator

Exports pure helper functions from estimate-cost.ts and adds comprehensive unit tests covering token estimation, content extraction, formatting, session analysis, and malformed input handling.

Test coverage goes from 1/24 tools to 2/24. More to come.

- Export scorePrompt function for testability
- Add 17 tests covering all 4 scoring dimensions (specificity, scope, actionability, done-condition)
- Test grade assignment boundaries (A+ through F)
- Test feedback generation for both high and low scores
- Verify total is sum of dimensions
Export pure helper functions from estimate-cost.ts and add
comprehensive test coverage for:
- estimateTokens, extractText, extractToolNames
- formatTokens, formatCost, formatDuration
- analyzeSessionFile (prompts, corrections, tool calls, timestamps, edge cases)
ESLint 10 uses util.styleText which was added in Node 20.
This has been failing the Node 18 CI check on every PR, blocking
all merges (28 open PRs affected).

- CI matrix: [18, 20] → [20, 22]
- engines: >=18 → >=20
sharp (transitive dep from @xenova/transformers) frequently fails to
install in CI due to network issues downloading libvips. Since preflight
only uses text embeddings (not image processing), sharp is not required
at runtime. This adds a fallback so CI doesn't fail on transient network
errors.
- Export scorePrompt for testability
- Add 12 tests covering specificity, scope, actionability, done condition
- Tests cover high/low scores, edge cases, grade boundaries
- All 55 tests pass (43 existing + 12 new)
Export pure helper functions (estimateTokens, extractText, extractToolNames,
formatTokens, formatCost, formatDuration, analyzeSessionFile) and add
comprehensive tests covering:
- Token estimation math
- Content extraction from various formats
- Tool name extraction from content blocks
- Number/cost/duration formatting edge cases
- Session file analysis (prompts, corrections, preflight calls, timestamps)
- Malformed JSONL handling
@TerminalGravity

Copy link
Copy Markdown
Collaborator Author

22 tests for estimate-cost — solid coverage. CI green. ✅

@TerminalGravity TerminalGravity left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good test coverage for estimate-cost. Exporting the helpers is the right call — makes them testable without reaching into internals. One note: the CI matrix bump from Node 18→20 and the npm ci || npm ci --ignore-optional fallback look like they belong in PR #80 rather than here. Consider splitting those out to keep the PR focused, or at least note the CI changes in the PR description. The actual tests are solid though. ✅

@TerminalGravity

Copy link
Copy Markdown
Collaborator Author

Superseded by newer, more comprehensive test PRs.

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