Skip to content

test(ai): add contract tests for resolveUsedFraction#3326

Open
oldschoola wants to merge 1 commit into
can1357:mainfrom
oldschoola:test/resolveUsedFraction-coverage
Open

test(ai): add contract tests for resolveUsedFraction#3326
oldschoola wants to merge 1 commit into
can1357:mainfrom
oldschoola:test/resolveUsedFraction-coverage

Conversation

@oldschoola

Copy link
Copy Markdown
Contributor

Problem

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 (via PR #3317), and the credential ranking strategy — but had zero dedicated test coverage.

Changes

Added 12 contract tests covering:

Tests

  • 12/12 pass

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)
@github-actions github-actions Bot added the vouched Passed the vouch gate label Jun 23, 2026

@roboomp roboomp left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm — incremental, well-scoped test addition.

  • Pins all four resolveUsedFraction resolution paths (usage.ts:94-103), the precedence order, and the edge cases (limit=0, overage, remainingFraction=0, clamp at 0, unresolvable input).
  • Local makeLimit helper, contract-level assertions on the return value, no mock.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants