test: add 22 unit tests for estimate-cost helpers - #82
Closed
TerminalGravity wants to merge 6 commits into
Closed
Conversation
- 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
Collaborator
Author
|
22 tests for estimate-cost — solid coverage. CI green. ✅ |
TerminalGravity
commented
Mar 4, 2026
TerminalGravity
left a comment
Collaborator
Author
There was a problem hiding this comment.
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. ✅
Collaborator
Author
|
Superseded by newer, more comprehensive test PRs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Exports pure helper functions from
estimate-cost.tsand 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.