Skip to content

test: add unit tests for src/cost.ts - #71

Open
doitrous wants to merge 1 commit into
mrmps:mainfrom
doitrous:test/cost
Open

doitrous wants to merge 1 commit into
mrmps:mainfrom
doitrous:test/cost

Conversation

@doitrous

@doitrous doitrous commented Sep 20, 2026 •

Copy link
Copy Markdown

Adds test/cost.test.ts covering the four exports of src/cost.ts:

  • JEV_USD_PER_MTOK: matches the published rate
  • newMeter: starts at zero
  • addJevCost: correct token→USD math, accumulation, edge cases (NaN, Infinity, negative, zero, non-numbers, numeric strings), undefined meter safety
  • addUsd: exact addition, accumulation, same edge cases

12 tests, all pass under bun test.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added coverage for cost calculations, including token-to-USD conversion and accumulated totals.
    • Verified handling of numeric strings and invalid inputs.
    • Confirmed meter initialization and exact USD additions.

Cover newMeter, addJevCost, and addUsd: correct arithmetic, accumulation,
edge cases (NaN, Infinity, negative, zero, non-numbers, numeric strings),
and undefined meter safety.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 7a453d45-db57-4ae9-9186-368f509908b8

📥 Commits

Reviewing files that changed from the base of the PR and between 5c241af and abea66b.

📒 Files selected for processing (1)
  • test/cost.test.ts

Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The pull request adds test/cost.test.ts. The tests cover the exported JEV rate, meter initialization, JEV cost conversion, USD additions, accumulation, numeric strings, and invalid inputs.

Changes

Cost module tests

Layer / File(s) Summary
Cost meter behavior tests
test/cost.test.ts
Tests verify JEV_USD_PER_MTOK, newMeter(), addJevCost, and addUsd. The tests cover conversion, accumulation, numeric strings, invalid values, and an undefined meter.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding unit tests for src/cost.ts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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