test(ai): add contract tests for resolveUsedFraction#3326
Open
oldschoola wants to merge 1 commit into
Open
Conversation
resolveUsedFraction is the shared helper that resolves a used fraction (0..1) from whichever UsageAmount fields a provider populated. It's used by the CLI usage renderer, the TUI usage renderer, and the credential ranking strategy — but had zero dedicated test coverage. Added 12 contract tests covering: - All four resolution paths (explicit fraction, used/limit, percent+used, inverted remaining) - Precedence ordering (fraction > used/limit > percent > remaining) - Edge cases (limit=0, overage>1, remainingFraction=0, no fields) - The remainingFraction fallback that was missing from the TUI's local copy (fixed in PR can1357#3317)
roboomp
reviewed
Jun 23, 2026
roboomp
left a comment
Collaborator
There was a problem hiding this comment.
lgtm — incremental, well-scoped test addition.
- Pins all four
resolveUsedFractionresolution paths (usage.ts:94-103), the precedence order, and the edge cases (limit=0, overage,remainingFraction=0, clamp at 0, unresolvable input). - Local
makeLimithelper, contract-level assertions on the return value, nomock.module()/ globals — full-suite-safe. - CHANGELOG entry under
[Unreleased]; 12/12 pass locally.
resolveUsedFraction is consumed by usage-cli.ts (status, summary, render bar, history bucketing) and auth-storage.ts:2232; pinning the precedence is a useful regression net after the TUI's local copy missed the remainingFraction fallback in #3317. Thanks @oldschoola.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
resolveUsedFractionis the shared helper that resolves a used fraction (0..1) from whicheverUsageAmountfields a provider populated. It's used by the CLI usage renderer, the TUI usage renderer (via PR #3317), and the credential ranking strategy — but had zero dedicated test coverage.Changes
Added 12 contract tests covering:
usedFraction,used/limit,percent+used, invertedremainingFraction)usedFraction>used/limit>percent+used>remainingFraction)limit=0, overage (usedFraction > 1),remainingFraction=0, no resolvable fieldsremainingFractionfallback that was missing from the TUI's local copy (fixed in fix(usage): use shared resolveUsedFraction in TUI path, fixing missing remainingFraction fallback #3317)Tests