From f0b7b49dc44bf281f266f8b757e14f50c9ffb913 Mon Sep 17 00:00:00 2001 From: Dante Date: Wed, 4 Nov 2026 16:36:16 +0000 Subject: [PATCH] M4 fix(billing): keep auto_top_up_setup in the SDK capabilities projection (#22907) ## Summary On the billing SDK rail, the Add credits dialog never shows the "Running low on credits? Turn on auto top-up." row with **Set up**, even for an owner whose auto top-up is off and whose setup is `ready` (QA plan case C10, testcloud `012eef04`; C11 is blocked by it). ## Why The 1.60 M4 QA found the row missing on testcloud. Capabilities served `auto_top_up_enabled: true`, `can_manage_auto_top_up: true` and `auto_top_up_setup.state: "ready"`, and the Billing tab showed auto top-up as Off. The dialog never requested `/api/billing/auto-reload`. ## Root cause `projectBillingCapabilities` (`src/platform/billing/sdk/billingCapabilitiesView.ts`) maps the SDK's capabilities snapshot back to the read the capabilities composable holds. It copied every field except `auto_top_up_setup`, which the SDK reader decodes into `autoTopUpSetup`. So on the SDK rail `useBillingCapabilities().autoTopUpSetup` was always `null`, and `TopUpAutoTopUpCard` returns hidden for a `null` setup before it reads the auto top-up status. The Billing tab card still worked because it only hides on `state: 'unavailable'`. This has been the case since the row shipped in #22421. ## How Copy `auto_top_up_setup` into the projection when the snapshot has it, the same way `auto_top_up_enabled` is copied. The other snapshot fields were already copied. ## Verification - Tests: `billingCapabilitiesView.test.ts` passes `ready`, `frozen` and `unavailable` setups through. The test commit fails on its own (3 failures) and passes with the fix. The billing SDK, auto top-up card and top-up dialog suites pass (15 files, 291 tests). - A temporary test that mounted the real card with the real composables on both rails also failed on the SDK rail before the fix and passed after it. ## AS IS / TO BE | AS IS | TO BE | | --- | --- | | AS IS | TO BE | --- .../billing/sdk/billingCapabilitiesView.test.ts | 14 ++++++++++++++ .../billing/sdk/billingCapabilitiesView.ts | 3 +++ 2 files changed, 17 insertions(+) diff --git a/src/platform/billing/sdk/billingCapabilitiesView.test.ts b/src/platform/billing/sdk/billingCapabilitiesView.test.ts index f68dfbd9c89..e2d6e64f7f0 100644 --- a/src/platform/billing/sdk/billingCapabilitiesView.test.ts +++ b/src/platform/billing/sdk/billingCapabilitiesView.test.ts @@ -57,6 +57,20 @@ describe('projectBillingCapabilities', () => { } ) + it.for([ + { state: 'ready' }, + { state: 'frozen', reason: 'payment_past_due' }, + { state: 'unavailable' } + ] as const)( + 'passes auto_top_up_setup $state through to the capabilities read', + (served) => { + expect( + projectBillingCapabilities({ ...SNAPSHOT, autoTopUpSetup: served }) + .auto_top_up_setup + ).toStrictEqual(served) + } + ) + it('reads the snapshot back as the response the composable holds', () => { expect(projectBillingCapabilities(SNAPSHOT)).toStrictEqual({ capabilities: SNAPSHOT.capabilities, diff --git a/src/platform/billing/sdk/billingCapabilitiesView.ts b/src/platform/billing/sdk/billingCapabilitiesView.ts index 9e4f9ada6b8..4566b3d1bfa 100644 --- a/src/platform/billing/sdk/billingCapabilitiesView.ts +++ b/src/platform/billing/sdk/billingCapabilitiesView.ts @@ -14,6 +14,9 @@ export function projectBillingCapabilities( ...(snapshot.autoTopUpEnabled === undefined ? {} : { auto_top_up_enabled: snapshot.autoTopUpEnabled }), + ...(snapshot.autoTopUpSetup === undefined + ? {} + : { auto_top_up_setup: snapshot.autoTopUpSetup }), capabilities: snapshot.capabilities, denied_reasons: snapshot.denials, expires_at: new Date(snapshot.freshUntil).toISOString(),