#71

test: add unit tests for src/cost.ts

Opendoitrouswants to merge intofrom

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.

Activity

2
coderabbitai[bot]1mo ago

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 5c241afbb44e01f9e60a2d6184b6ce3621c83b36 and abea66b0c5ba48757997e7d4c7b8e3fa03c5cd06.

📒 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 nameStatusExplanation
Description Check✅ PassedCheck skipped - CodeRabbit’s high-level summary is enabled.
Title check✅ PassedThe title clearly and concisely describes the main change: adding unit tests for src/cost.ts.
Docstring Coverage✅ PassedNo 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✅ PassedCheck skipped because no linked issues were found for this pull request.
Out of Scope Changes check✅ PassedCheck 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.