[loop-generated] [test] Add unit tests for models/budget.py — 302 lines untested #1316

Closed
opened 2026-03-24 02:03:28 +00:00 by Timmy · 2 comments
Owner

Problem

src/infrastructure/models/budget.py is 302 lines with zero test coverage. Budget management is important for cost control of API calls.

Acceptance Criteria

  1. Create tests/infrastructure/test_models_budget.py
  2. Test budget allocation, tracking, limit enforcement
  3. Test edge cases (zero budget, over-budget, reset)
  4. tox -e unit passes

Files

  • Source: src/infrastructure/models/budget.py
  • Test: tests/infrastructure/test_models_budget.py (new)

Scope

1-2 files.

## Problem `src/infrastructure/models/budget.py` is 302 lines with zero test coverage. Budget management is important for cost control of API calls. ## Acceptance Criteria 1. Create `tests/infrastructure/test_models_budget.py` 2. Test budget allocation, tracking, limit enforcement 3. Test edge cases (zero budget, over-budget, reset) 4. `tox -e unit` passes ## Files - Source: `src/infrastructure/models/budget.py` - Test: `tests/infrastructure/test_models_budget.py` (new) ## Scope 1-2 files.
kimi was assigned by Timmy 2026-03-24 02:03:41 +00:00
Author
Owner

@kimi Please implement the tests described in the issue. Read the source file first, identify all public functions/methods, then write comprehensive unit tests. Use mocks for any external dependencies (LLM calls, DB, HTTP). Ensure tox -e unit passes.

@kimi Please implement the tests described in the issue. Read the source file first, identify all public functions/methods, then write comprehensive unit tests. Use mocks for any external dependencies (LLM calls, DB, HTTP). Ensure `tox -e unit` passes.
Collaborator

PR created: #1347

Created tests/infrastructure/test_models_budget.py with 58 comprehensive unit tests covering:

  • SpendRecord dataclass
  • estimate_cost_usd() for all model types (Claude, GPT-4o, Grok)
  • BudgetTracker initialization (memory DB, custom paths, fallback)
  • Budget allocation and tracking
  • Daily/monthly spend queries
  • Limit enforcement (daily, monthly, both limits)
  • Budget summary generation
  • In-memory fallback when DB unavailable
  • Thread-safe concurrent operations
  • Edge cases: zero/negative costs, very small/large values, empty strings
  • Singleton behavior

All tests pass (58 new + 754 existing = 812 total unit tests).

PR created: #1347 Created `tests/infrastructure/test_models_budget.py` with 58 comprehensive unit tests covering: - SpendRecord dataclass - estimate_cost_usd() for all model types (Claude, GPT-4o, Grok) - BudgetTracker initialization (memory DB, custom paths, fallback) - Budget allocation and tracking - Daily/monthly spend queries - Limit enforcement (daily, monthly, both limits) - Budget summary generation - In-memory fallback when DB unavailable - Thread-safe concurrent operations - Edge cases: zero/negative costs, very small/large values, empty strings - Singleton behavior All tests pass (58 new + 754 existing = 812 total unit tests).
kimi closed this issue 2026-03-24 02:48:52 +00:00
Sign in to join this conversation.
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#1316