Skip to content

feat(testing): add deterministic token/cost accounting to MockLLMBackend#1596

Open
diiviikk5 wants to merge 1 commit intomofa-org:mainfrom
diiviikk5:feat/testing-mock-token-cost
Open

feat(testing): add deterministic token/cost accounting to MockLLMBackend#1596
diiviikk5 wants to merge 1 commit intomofa-org:mainfrom
diiviikk5:feat/testing-mock-token-cost

Conversation

@diiviikk5
Copy link
Copy Markdown
Contributor

Summary

closess #1595

Add deterministic token/cost accounting to MockLLMBackend so test suites can assert usage drift and cost-related regressions without relying on external providers.

newpr

What Changed

  • Added usage model types in tests/src/backend.rs:
    • InferenceUsage
    • UsageTotals
  • Added deterministic accounting state to MockLLMBackend:
    • token pricing config
    • per-call usage history for successful inferences
  • Added new APIs:
    • set_token_cost_rates(...)
    • reset_usage_accounting()
    • last_usage()
    • usage_history() / get_usage_history()
    • usage_totals() / get_usage_totals()
  • Integrated accounting into successful infer() path.
  • Added dedicated tests in tests/tests/backend_usage_tests.rs.

Why

This enables deterministic cost/usage assertions as part of the testing framework roadmap, which is important for regression testing, benchmark comparisons, and CI policy gating.

Testing

cargo test -p mofa-testing --test backend_usage_tests

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