chore(credits): retire getGrantExpiresAt and the expires_at it feeds
Follow-on cleanup for recoupable/chat#1960. Row 6 of that issue's PR matrix.
Merge after api#837 (the refill-is-a-floor fix). Branched from main independently — there is no file overlap with #837, only a logical dependency: until the refill can no longer reduce a balance, a grant genuinely does expire and removing the field would be a lie in the other direction.
getGrantExpiresAt.ts exists only to tell an admin when the monthly reset will destroy a grant. It is 14 lines of code under 20 lines of comment explaining which direction its month-clamping errs in, all of it reasoning about an overwrite that no longer happens once the refill is a floor. Worse than dead: it tells admins to re-grant credits that do not need re-granting.
What changes
Deleted: lib/credits/getGrantExpiresAt.ts and lib/credits/__tests__/getGrantExpiresAt.test.ts.
POST /api/admins/credits no longer returns expires_at. Response goes from 9 fields to 8:
{
"status": "success",
"grant_id": "...",
"account_id": "...",
"remaining_credits": 9999,
"previous_credits": 12,
"reason": "Trial headroom for the Aug 12 label demo",
"granted_by": "...",
"granted_at": "2026-08-06T23:00:00.000Z"
}
Breaking for admin callers reading expires_at. This is an internal, admin-only surface. The postAdminCreditsHandler JSDoc now states that the grant holds until it is spent, replacing the "including when it expires" line.
Verification
TDD, red before green. Added it("no longer reports an expires_at, because a grant cannot be reduced by a refill") and removed expires_at from the documented-response-shape assertion. Ran it: RED, 2 failed (expected { status: 'success', …(8) } to not have property "expires_at", and the shape test showing + "expires_at": "2026-09-06T23:00:00.000Z"). Implemented, then GREEN.
| Check | Result |
|---|---|
vitest run lib/admins/credits lib/credits | 18 files / 128 tests passed |
eslint lib/admins lib/credits | clean |
tsc --noEmit | 202 errors, identical to baseline, zero in any file this PR touches |
grep -rn getGrantExpiresAt lib app | no matches |
The remaining 6 tests in postAdminCreditsHandler.test.ts (atomic write pass-through, null previous_credits, 401/403/400 pass-through, 404 unknown account, 500 on write failure, no error-message leak) pass unmodified.
Not yet done: hitting POST /api/admins/credits on the preview to confirm the live response carries 8 fields and no expires_at. Flagging rather than implying it.
Merge order
api#837 → this PR → docs#300, which removes expires_at from AdminGrantCreditsResponse and rewrites the grant-expiry paragraph. The docs PR is the one surface that must not land before both api PRs are on prod.
Summary by cubic
Removes grant-expiry logic and stops returning expires_at from POST /api/admins/credits, because the monthly refill is now a floor. Previously the endpoint returned expires_at and implied grants expire; now the field is omitted and grants persist until spent.
- Deletes
lib/credits/getGrantExpiresAt.tsand its test; removes its usage and updatespostAdminCreditsHandlerJSDoc to the present-tense grant contract. - Updates tests to assert the response no longer includes
expires_at. - Merge after
api#837(refill-is-a-floor). - Required: admin callers must stop reading
expires_atfromPOST /api/admins/credits.