Skip to content

refactor: extract cost-estimator lib + 31 tests - #25

Closed
TerminalGravity wants to merge 1 commit into
mainfrom
add-estimate-cost-tests
Closed

refactor: extract cost-estimator lib + 31 tests#25
TerminalGravity wants to merge 1 commit into
mainfrom
add-estimate-cost-tests

Conversation

@TerminalGravity

@TerminalGravity TerminalGravity commented Feb 27, 2026

Copy link
Copy Markdown
Collaborator

What

Extracts the cost estimation logic from tools/estimate-cost.ts into a dedicated lib/cost-estimator.ts module for testability and reuse.

Changes

  • New: src/lib/cost-estimator.ts — exported helpers: analyzeSessionContent, computeCost, estimateTokens, extractText, extractToolNames, formatting utils, pricing table, constants
  • Updated: src/tools/estimate-cost.ts — thin wrapper that imports from the lib (was monolithic)
  • New: tests/lib/cost-estimator.test.ts — 31 tests covering token estimation, text extraction, tool name parsing, formatting, correction detection, session analysis, and cost computation
  • Removed: old tests/lib/estimate-cost.test.ts (replaced with more comprehensive tests)

Why

The original tool file mixed business logic with MCP registration, making it untestable without mocking the full server. Now the core logic is independently importable and tested.

@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.

24 tests for estimate-cost — good coverage. LGTM 👍

@TerminalGravity
TerminalGravity force-pushed the add-estimate-cost-tests branch from dd3c0c2 to 36a1fe4 Compare March 3, 2026 06:17
@TerminalGravity TerminalGravity changed the title test: add 24 tests for estimate-cost tool refactor: extract cost-estimator lib + 31 tests Mar 3, 2026
- Export helper functions from estimate-cost.ts for testability
- Add comprehensive tests for estimateTokens, extractText, extractToolNames,
  formatTokens, formatCost, formatDuration, and analyzeSessionFile
- Restore prompt-score.test.ts (was missing from tracked files)
- Export scorePrompt from prompt-score.ts to fix test imports
- Total: 81 tests passing (was 60)
@TerminalGravity
TerminalGravity force-pushed the add-estimate-cost-tests branch from 36a1fe4 to f933152 Compare March 4, 2026 17:46
TerminalGravity added a commit that referenced this pull request Mar 5, 2026
Implements #5 — generates markdown reports from timeline data with:
- Weekly/monthly/custom date range summaries
- Daily activity breakdown with bar chart
- Commit log extraction
- Correction tracking and prompt quality indicators
- Optional save to ~/.preflight/reports/

Registered as tool #25 in the MCP server.
@TerminalGravity

Copy link
Copy Markdown
Collaborator Author

Superseded by newer 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