[kimi] Add comprehensive unit tests for models/budget.py (#1316) #1347

Merged
kimi merged 1 commits from kimi/issue-1316 into main 2026-03-24 02:48:51 +00:00
Collaborator

Fixes #1316

Summary

Adds comprehensive unit test coverage for src/infrastructure/models/budget.py (302 lines).

Changes

  • Created tests/infrastructure/test_models_budget.py with 58 unit tests

Coverage

  • SpendRecord dataclass: Creation and field access
  • estimate_cost_usd(): All model types (Claude Haiku/Sonnet/Opus, GPT-4o/GPT-4o-mini, Grok), cost calculations, case-insensitive matching
  • BudgetTracker initialization: Memory DB, custom paths, directory creation, fallback
  • record_spend(): Returns cost, explicit cost, accumulation, provider/model tracking, zero/negative costs
  • Spend queries: Daily/monthly isolation, empty state
  • cloud_allowed(): Limit enforcement (daily, monthly, both), zero budget, exact limit, below limit
  • get_summary(): All keys present, status flags, rounding, disabled limits
  • In-memory fallback: Records persistence, query spend, old record filtering
  • Thread safety: Concurrent spend recording
  • Edge cases: Very small/large costs, many records, empty strings
  • Singleton: get_budget_tracker() behavior

Test Results

All 58 new tests pass:

pytest tests/infrastructure/test_models_budget.py -v
58 passed

Full unit test suite:

tox -e unit
812 passed, 15 warnings
Fixes #1316 ## Summary Adds comprehensive unit test coverage for `src/infrastructure/models/budget.py` (302 lines). ## Changes - Created `tests/infrastructure/test_models_budget.py` with 58 unit tests ## Coverage - **SpendRecord dataclass**: Creation and field access - **estimate_cost_usd()**: All model types (Claude Haiku/Sonnet/Opus, GPT-4o/GPT-4o-mini, Grok), cost calculations, case-insensitive matching - **BudgetTracker initialization**: Memory DB, custom paths, directory creation, fallback - **record_spend()**: Returns cost, explicit cost, accumulation, provider/model tracking, zero/negative costs - **Spend queries**: Daily/monthly isolation, empty state - **cloud_allowed()**: Limit enforcement (daily, monthly, both), zero budget, exact limit, below limit - **get_summary()**: All keys present, status flags, rounding, disabled limits - **In-memory fallback**: Records persistence, query spend, old record filtering - **Thread safety**: Concurrent spend recording - **Edge cases**: Very small/large costs, many records, empty strings - **Singleton**: get_budget_tracker() behavior ## Test Results All 58 new tests pass: ``` pytest tests/infrastructure/test_models_budget.py -v 58 passed ``` Full unit test suite: ``` tox -e unit 812 passed, 15 warnings ```
kimi added 1 commit 2026-03-24 02:48:20 +00:00
test: Add comprehensive unit tests for models/budget.py (#1316)
Some checks failed
Tests / lint (pull_request) Failing after 39s
Tests / test (pull_request) Has been skipped
a7da45e788
Fixes #1316

Adds 58 unit tests covering:
- SpendRecord dataclass functionality
- estimate_cost_usd() for all model types (Claude, GPT-4o, Grok)
- BudgetTracker initialization with memory/file DB
- Budget tracking and accumulation
- Daily/monthly spend queries and isolation
- Cloud budget limit enforcement (daily, monthly, both)
- Budget summary generation with all status flags
- In-memory fallback when DB is unavailable
- Thread-safe concurrent spend recording
- Edge cases: zero/negative costs, empty names, very small/large values
- Singleton get_budget_tracker() behavior
kimi merged commit e09082a8a8 into main 2026-03-24 02:48:51 +00:00
kimi deleted branch kimi/issue-1316 2026-03-24 02:48:52 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#1347