Repository navigation
fix: show Extra Usage Utilization before the month's first charge - #668
Open
eric-engberg wants to merge 2 commits into
Open
eric-engberg wants to merge 2 commits into
eric-engberg wants to merge 2 commits into
Conversation
Until the first extra-usage charge of the month, the usage API reports `utilization: null` alongside the monthly limit and the amount spent ($0). The widget treated the missing utilization as no data and rendered nothing, so it looked broken on every account with extra usage enabled until the first charge. When the API reports no utilization, work it out from the amount spent and the monthly limit. An API-reported value still wins, and accounts without a monthly limit render nothing, as before.
# Conflicts: # src/widgets/ExtraUsageUtilization.ts
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.
What
Extra Usage Utilization now shows
0.0%(and an empty bar) when extra usage is enabled but nothing has been charged yet this month. Before, it rendered nothing at all.Why
Until the first extra-usage charge of the month, the usage API reports
utilization: nullwhile still reporting the monthly limit and the amount spent ($0):The widget treated the missing utilization as no data and rendered nothing. Extra Usage Used and Extra Usage Remaining showed
$0.00and the full limit next to it, so the empty slot looked broken on every account with extra usage turned on. This shows up on a Max account right after turning extra usage on, and the Enterprise response inusage-fetch.test.ts, which mirrors a real account, has the same shape.How
When the API reports no utilization, the widget works it out from the amount spent and the monthly limit (spent 梅 limit 脳 100), the same ratio the API reports once there's a charge. The API's own value still wins whenever it's present. Without a monthly limit (or with a limit of 0) the widget renders nothing, as before (#413). No extra fetches: the spent and limit fields come in the same response and are already cached, and the existing rule that treats missing extra-usage detail fields as conclusive is unchanged.
Demo
The same line rendered from a fake usage cache (no login, no API call): first at $0 spent with no utilization from the API, then at $12.50 of a $50 limit, which is unchanged.
Powerline: before
Powerline: after
Plain: before
Plain: after
Testing
main(with docs: explain an empty status line in one folder (workspace trust)聽#606 and feat(git-is-fork): render forks as an editable glyph聽#617 merged in locally):bun testgives 2785 pass, 0 fail (Bun 1.4.2), andbun run lintpasses.mainonly by the added Utilization output. The TUI opens and exits cleanly under both.mainrenders no Utilization widgets, this branch rendersOverage: 0.0%. With an API-reported utilization the output is unchanged.