fix: KEEP-1331 decode billing subscription response (overageCharges array + usage keys) - #113
Merged
Merged
Conversation
The server returns overageCharges as an array of recent overage billing line-items, but the CLI typed it as float64, so kh billing status and kh billing usage crashed on response decoding. Type it as a slice of OverageCharge and render the summed line-item total as the dollar figure.
… keys The CLI struct tagged usage as executions/limit, but the server sends executionsUsed/executionLimit, so Go silently decoded both to zero and kh billing status/usage reported "0 / 0" regardless of real usage. Align the JSON tags with the server and guard it with a decode test.
…owed TotalOverageDollars summed every recent overage record, including ones already pushed to a provider invoice or in a non-pending status, so the CLI overstated the bill (re-billing settled charges). Match the billing UI: sum only records with providerInvoiceId==nil and status=="pending".
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
kh billing status(andkh billing usage) crashed while decodingGET /api/billing/subscription:Root cause: the server returns
overageChargesas an array of up to five recent overage line-items (a.limit(5)select inapp/api/billing/subscription/route.ts), but the CLI typed the field asfloat64.While fixing that, a second silent mismatch surfaced in the same response: the CLI read
usage.executions/usage.limit, but the server sendsusage.executionsUsed/usage.executionLimit, so both decoded to0and the command reportedExecutions: 0 / 0regardless of real usage.Changes
SubscriptionResponse.OverageChargesis now[]OverageCharge, a struct mirroring the server element shape (periodStart,periodEnd,overageCount,totalChargeCents,status,createdAt, nullableproviderInvoiceId). The existing singleOverage: $X.XXline is now fed byTotalOverageDollars(), which sums the line-itemtotalChargeCents.usageJSON tags corrected toexecutionsUsed/executionLimitso the quota line renders real numbers.Overage: $4.75and non-zero usage.Verification
go test ./cmd/billing/...,go build ./...,go vet ./cmd/billing/...all pass (run ingolang:1.25; host has no Go).Out of scope (flagged for follow-up)
--jsonmode re-serializes only the modelled fields, so it still drops server-only fields (gasCredits,gasCreditCaps,trial, richersubscription). Pre-existing; not addressed here.