From 5f85ce3f4c556a9da9db9d88becb116d7ccfe065 Mon Sep 17 00:00:00 2001
From: dante01yoon
Date: Sun, 1 Nov 2026 19:34:16 -0500
Subject: [PATCH 1/3] [backport core/1.59] FRONT-3621 fix(billing): read auto
top-up visibility from billing capabilities so local follows the server
(#22405)
Backport of #22405 to core/1.59. Adds the served auto_top_up_enabled field
to the core/1.59 ingest types as optional, so the capabilities read can use
it without the full ingest-types sync; a missing field reads as false.
(cherry picked from commit fbac2166fb1d5b599bff65c8b05146a07205232e)
---
packages/ingest-types/src/types.gen.ts | 9 +++++++++
packages/ingest-types/src/zod.gen.ts | 1 +
src/composables/__mocks__/useFeatureFlags.ts | 1 -
src/composables/useFeatureFlags.test.ts | 3 +--
src/composables/useFeatureFlags.ts | 9 ---------
.../billingTab/BillingAutoTopUpCard.test.ts | 9 +++++----
.../components/billingTab/BillingTab.test.ts | 18 +++++++++++-------
.../components/billingTab/BillingTab.vue | 4 +---
.../__mocks__/useBillingCapabilities.ts | 7 +++++++
.../composables/useAutoTopUpBannerKind.test.ts | 12 ++++++------
.../composables/useAutoTopUpBannerKind.ts | 8 +++-----
.../composables/useBillingCapabilities.test.ts | 18 ++++++++++++++++++
.../composables/useBillingCapabilities.ts | 7 +++++++
src/platform/remoteConfig/serverFeatureFlag.ts | 1 -
src/platform/remoteConfig/types.ts | 1 -
15 files changed, 69 insertions(+), 39 deletions(-)
diff --git a/packages/ingest-types/src/types.gen.ts b/packages/ingest-types/src/types.gen.ts
index b90bfd251fa..ee47483720d 100644
--- a/packages/ingest-types/src/types.gen.ts
+++ b/packages/ingest-types/src/types.gen.ts
@@ -6178,6 +6178,15 @@ export type BillingCapabilityDenialParams = {
* Effective billing UI guidance for one authenticated user and workspace.
*/
export type BillingCapabilitiesResponse = {
+ /**
+ * Whether auto top-up is rolled out to this user: the auto_top_up_enabled
+ * rollout flag, evaluated by ingest the same way GET /api/features
+ * evaluates it. Any evaluation failure reads as false. It gates
+ * visibility only; capabilities.can_manage_auto_top_up still decides
+ * who may manage auto top-up.
+ *
+ */
+ auto_top_up_enabled?: boolean
auto_top_up_setup?: AutoTopUpSetup
capabilities: BillingCapabilities
denied_reason_params?: BillingCapabilityDenialParams
diff --git a/packages/ingest-types/src/zod.gen.ts b/packages/ingest-types/src/zod.gen.ts
index 9e1264aa1f6..8ea10d41138 100644
--- a/packages/ingest-types/src/zod.gen.ts
+++ b/packages/ingest-types/src/zod.gen.ts
@@ -3832,6 +3832,7 @@ export const zAutoTopUpSetup = z.object({
* Effective billing UI guidance for one authenticated user and workspace.
*/
export const zBillingCapabilitiesResponse = z.object({
+ auto_top_up_enabled: z.boolean().optional(),
auto_top_up_setup: zAutoTopUpSetup.optional(),
capabilities: zBillingCapabilities,
denied_reason_params: zBillingCapabilityDenialParams.optional(),
diff --git a/src/composables/__mocks__/useFeatureFlags.ts b/src/composables/__mocks__/useFeatureFlags.ts
index 6b073c731bc..ec04e4bbc55 100644
--- a/src/composables/__mocks__/useFeatureFlags.ts
+++ b/src/composables/__mocks__/useFeatureFlags.ts
@@ -41,7 +41,6 @@ const defaultFlags: FeatureFlags = {
billingSdkTopupRailEnabled: false,
billingSdkSubscriptionEnabled: false,
unifiedBillingSettingsEnabled: false,
- autoTopUpEnabled: false,
billingSdkSubscriptionRailEnabled: false,
v1PaymentRecovery: false,
signupTurnstileMode: 'off',
diff --git a/src/composables/useFeatureFlags.test.ts b/src/composables/useFeatureFlags.test.ts
index 22f82306bd5..e6352feaa7f 100644
--- a/src/composables/useFeatureFlags.test.ts
+++ b/src/composables/useFeatureFlags.test.ts
@@ -391,8 +391,7 @@ describe('useFeatureFlags', () => {
{
flag: 'unifiedBillingSettingsEnabled' as const,
offCloudTrue: true
- },
- { flag: 'autoTopUpEnabled' as const, offCloudTrue: false }
+ }
])('$flag', ({ flag, offCloudTrue }) => {
afterEach(() => {
vi.mocked(distributionTypes).isCloud = false
diff --git a/src/composables/useFeatureFlags.ts b/src/composables/useFeatureFlags.ts
index bc390270ec8..489ce05e9ec 100644
--- a/src/composables/useFeatureFlags.ts
+++ b/src/composables/useFeatureFlags.ts
@@ -334,14 +334,6 @@ export function useFeatureFlags() {
remoteConfig.value.unified_billing_settings
)
},
- get autoTopUpEnabled() {
- if (!isCloud) return false
-
- return resolveStrictBooleanFlag(
- ServerFeatureFlag.AUTO_TOP_UP_ENABLED,
- remoteConfig.value.auto_top_up_enabled
- )
- },
get v1PaymentRecovery() {
return resolveAuthGatedFlag(
ServerFeatureFlag.V1_PAYMENT_RECOVERY,
@@ -432,7 +424,6 @@ export function startFeatureFlagTelemetry() {
flags.billingSdkSubscriptionEnabled,
[ServerFeatureFlag.UNIFIED_BILLING_SETTINGS]:
flags.unifiedBillingSettingsEnabled,
- [ServerFeatureFlag.AUTO_TOP_UP_ENABLED]: flags.autoTopUpEnabled,
[ServerFeatureFlag.V1_PAYMENT_RECOVERY]: flags.v1PaymentRecovery,
[ServerFeatureFlag.SIGNUP_TURNSTILE]: flags.signupTurnstileMode,
[ServerFeatureFlag.SUPPORTS_MODEL_TYPE_TAGS]: flags.supportsModelTypeTags,
diff --git a/src/platform/billing/components/billingTab/BillingAutoTopUpCard.test.ts b/src/platform/billing/components/billingTab/BillingAutoTopUpCard.test.ts
index 09a24718226..48a629f72ce 100644
--- a/src/platform/billing/components/billingTab/BillingAutoTopUpCard.test.ts
+++ b/src/platform/billing/components/billingTab/BillingAutoTopUpCard.test.ts
@@ -14,9 +14,11 @@ import {
WorkspaceApiError,
workspaceApi
} from '@/platform/workspace/api/workspaceApi'
-import { useFeatureFlags } from '@/composables/useFeatureFlags'
import { activateBillingScope } from '@/platform/billing/composables/activateBillingScope.testUtils'
-import { canManageAutoTopUpFact } from '@/platform/billing/composables/__mocks__/useBillingCapabilities'
+import {
+ autoTopUpEnabledFact,
+ canManageAutoTopUpFact
+} from '@/platform/billing/composables/__mocks__/useBillingCapabilities'
import { usePausedBanner } from '@/platform/billing/composables/usePausedBanner'
import { useBillingCapabilities } from '@/platform/billing/composables/useBillingCapabilities'
@@ -26,7 +28,6 @@ import BillingLocalCreditBanner from './BillingLocalCreditBanner.vue'
vi.mock(import('firebase/auth'), { spy: true })
vi.mock(import('@/platform/billing/composables/useBillingContext'))
vi.mock(import('@/platform/billing/composables/useBillingDialogs'))
-vi.mock(import('@/composables/useFeatureFlags'))
vi.mock(import('@/platform/billing/composables/usePausedBanner'))
vi.mock(import('@/platform/workspace/composables/useWorkspaceUI'))
vi.mock(import('@/platform/workspace/api/workspaceApi'))
@@ -138,7 +139,7 @@ describe('BillingAutoTopUpCard', () => {
vi.mocked(usePausedBanner).mockReturnValue({
isPaused: computed(() => false)
})
- vi.mocked(useFeatureFlags().flags).autoTopUpEnabled = true
+ useBillingCapabilities().autoTopUpEnabled = autoTopUpEnabledFact(true)
useBillingCapabilities().canManageAutoTopUp = canManageAutoTopUpFact(true)
render(BillingLocalCreditBanner, i18nOptions())
await vi.waitFor(() =>
diff --git a/src/platform/billing/components/billingTab/BillingTab.test.ts b/src/platform/billing/components/billingTab/BillingTab.test.ts
index af7848bb2e4..d2eac2ff657 100644
--- a/src/platform/billing/components/billingTab/BillingTab.test.ts
+++ b/src/platform/billing/components/billingTab/BillingTab.test.ts
@@ -95,7 +95,7 @@ interface Scenario {
capabilitiesReady?: boolean
capabilitiesResolved?: boolean
balance?: BalanceInfo | null
- autoTopUpFlag?: boolean
+ autoTopUpEnabled?: boolean
canManageAutoTopUp?: boolean
canTopUp?: boolean
topUpDenial?: string
@@ -205,6 +205,12 @@ function arrange(scenario: Scenario = {}) {
scenario.canManageAutoTopUp ?? true
)
),
+ autoTopUpEnabled: computed(() =>
+ receiveServerFact(
+ 'auto_top_up_enabled',
+ scenario.autoTopUpEnabled ?? true
+ )
+ ),
autoTopUpSetup: computed(() => null),
isReady: computed(() => scenario.capabilitiesReady ?? true),
hasResolvedCapabilities: computed(
@@ -214,8 +220,6 @@ function arrange(scenario: Scenario = {}) {
refresh
})
)
- vi.mocked(useFeatureFlags().flags).autoTopUpEnabled =
- scenario.autoTopUpFlag ?? true
vi.mocked(useFreeTierQuota).mockReturnValue(
fromPartial({
quotaEnabled: computed(() => false),
@@ -1335,7 +1339,7 @@ describe('BillingTab', () => {
settleDetail.push(resolve)
})
)
- arrange({ autoTopUpFlag: false })
+ arrange({ autoTopUpEnabled: false })
await vi.waitFor(() => expect(settleDetail).toHaveLength(1))
settleDetail[0](checkout('credits_applying', { session_id: 'cs_1' }))
@@ -1381,7 +1385,7 @@ describe('BillingTab', () => {
settleDetail.push(resolve)
})
)
- arrange({ autoTopUpFlag: false })
+ arrange({ autoTopUpEnabled: false })
await vi.waitFor(() => expect(settleDetail).toHaveLength(1))
const visibility = vi.spyOn(document, 'visibilityState', 'get')
@@ -1493,7 +1497,7 @@ describe('BillingTab', () => {
settleDetail.push(resolve)
})
)
- arrange({ autoTopUpFlag: false })
+ arrange({ autoTopUpEnabled: false })
await vi.waitFor(() => expect(settleDetail).toHaveLength(1))
vi.mocked(workspaceApi.listTopupCheckouts).mockClear()
@@ -1681,7 +1685,7 @@ describe('BillingTab', () => {
it.for<{ case: string; scenario: Scenario; reads: number }>([
{
case: 'the flag is off',
- scenario: { autoTopUpFlag: false },
+ scenario: { autoTopUpEnabled: false },
reads: 0
},
{
diff --git a/src/platform/billing/components/billingTab/BillingTab.vue b/src/platform/billing/components/billingTab/BillingTab.vue
index 523e6ba6d7f..4fff9426884 100644
--- a/src/platform/billing/components/billingTab/BillingTab.vue
+++ b/src/platform/billing/components/billingTab/BillingTab.vue
@@ -76,7 +76,7 @@
@retry="retryBalance"
@add-credits="addCredits('credits_panel')"
/>
-
+
@@ -160,7 +160,6 @@ import Button from '@/components/ui/button/Button.vue'
import Skeleton from '@/components/ui/skeleton/Skeleton.vue'
import { useBillingContext } from '@/platform/billing/composables/useBillingContext'
import { useBillingDialogs } from '@/platform/billing/composables/useBillingDialogs'
-import { useFeatureFlags } from '@/composables/useFeatureFlags'
import { useExternalLink } from '@/composables/useExternalLink'
import { useMessageSupport } from '@/platform/billing/subscription/composables/useSubscriptionActions'
import { useTelemetry } from '@/platform/telemetry'
@@ -203,7 +202,6 @@ const suppressCreditBanner = computed(
planCheckout.banner.value != null ||
topupCheckout.banner.value != null
)
-const { flags } = useFeatureFlags()
const { state: planRow } = useBillingPlanRow()
const { state: creditsCard } = useBillingCreditsCard(planRow)
const planCreditNote = useTopUpPlanCreditCopy()
diff --git a/src/platform/billing/composables/__mocks__/useBillingCapabilities.ts b/src/platform/billing/composables/__mocks__/useBillingCapabilities.ts
index 385b558e207..cc31fa73221 100644
--- a/src/platform/billing/composables/__mocks__/useBillingCapabilities.ts
+++ b/src/platform/billing/composables/__mocks__/useBillingCapabilities.ts
@@ -43,6 +43,9 @@ const defaults: ReturnType = {
canManageAutoTopUp: computed(() =>
receiveServerFact('can_manage_auto_top_up', false)
),
+ autoTopUpEnabled: computed(() =>
+ receiveServerFact('auto_top_up_enabled', false)
+ ),
autoTopUpSetup: computed(() => null),
canRunWorkflows: computed(() => false),
planKind: computed(() => receiveServerFact('plan_kind', null)),
@@ -71,6 +74,10 @@ export function canManageAutoTopUpFact(granted: boolean) {
return computed(() => receiveServerFact('can_manage_auto_top_up', granted))
}
+export function autoTopUpEnabledFact(enabled: boolean) {
+ return computed(() => receiveServerFact('auto_top_up_enabled', enabled))
+}
+
export function paymentRecoveryAvailableFact(
available: MaybeRefOrGetter
) {
diff --git a/src/platform/billing/composables/useAutoTopUpBannerKind.test.ts b/src/platform/billing/composables/useAutoTopUpBannerKind.test.ts
index d146215a4d0..95b33d4e3da 100644
--- a/src/platform/billing/composables/useAutoTopUpBannerKind.test.ts
+++ b/src/platform/billing/composables/useAutoTopUpBannerKind.test.ts
@@ -3,7 +3,6 @@ import { describe, expect, it, onTestFinished, vi } from 'vitest'
import { computed, effectScope } from 'vue'
import { useBillingContext } from '@/platform/billing/composables/useBillingContext'
-import { useFeatureFlags } from '@/composables/useFeatureFlags'
import { receiveServerFact } from '@/platform/serverFacts/serverFact'
import type { AutoReloadSettings } from '@/platform/workspace/api/workspaceApi'
@@ -20,7 +19,6 @@ vi.mock(import('@/platform/distribution/types'), () => ({
}
}))
vi.mock(import('@/platform/billing/composables/useBillingContext'))
-vi.mock(import('@/composables/useFeatureFlags'))
vi.mock(import('./useBillingCapabilities'))
vi.mock(import('./usePausedBanner'))
vi.mock(import('./useBillingAutoTopUpCard'))
@@ -31,13 +29,12 @@ interface Scenario {
isActive?: boolean
paused?: boolean
owner?: boolean
- flag?: boolean
+ enabled?: boolean
settings?: Pick
}
function arrange(scenario: Scenario) {
distribution.isCloud = scenario.isCloud ?? false
- vi.mocked(useFeatureFlags().flags).autoTopUpEnabled = scenario.flag ?? true
vi.mocked(useBillingContext).mockReturnValue(
fromPartial({
canAccessSubscriptionFeatures: computed(
@@ -50,6 +47,9 @@ function arrange(scenario: Scenario) {
)
})
)
+ useBillingCapabilities().autoTopUpEnabled = computed(() =>
+ receiveServerFact('auto_top_up_enabled', scenario.enabled ?? true)
+ )
useBillingCapabilities().canManageAutoTopUp = computed(() =>
receiveServerFact('can_manage_auto_top_up', scenario.owner ?? true)
)
@@ -120,8 +120,8 @@ describe('useAutoTopUpBannerKind', () => {
kind: null
},
{
- name: 'the flag off',
- scenario: { flag: false, settings: failed },
+ name: 'auto top-up not served for the account',
+ scenario: { enabled: false, settings: failed },
kind: null
},
{ name: 'a read still loading', scenario: {}, kind: null }
diff --git a/src/platform/billing/composables/useAutoTopUpBannerKind.ts b/src/platform/billing/composables/useAutoTopUpBannerKind.ts
index 9d66b1582ff..ccee70e43e6 100644
--- a/src/platform/billing/composables/useAutoTopUpBannerKind.ts
+++ b/src/platform/billing/composables/useAutoTopUpBannerKind.ts
@@ -1,7 +1,6 @@
import { computed, watch } from 'vue'
import { useBillingContext } from '@/platform/billing/composables/useBillingContext'
-import { useFeatureFlags } from '@/composables/useFeatureFlags'
import { isCloud } from '@/platform/distribution/types'
import { useBillingAutoTopUpCard } from '@/platform/billing/composables/useBillingAutoTopUpCard'
import { deriveAutoTopUpBanner } from '@/platform/billing/composables/deriveAutoTopUpBanner'
@@ -10,12 +9,11 @@ import { usePausedBanner } from '@/platform/billing/composables/usePausedBanner'
export function useAutoTopUpBannerKind() {
const billing = useBillingContext()
- const { flags } = useFeatureFlags()
- const { canManageAutoTopUp } = useBillingCapabilities()
+ const { autoTopUpEnabled, canManageAutoTopUp } = useBillingCapabilities()
const { isPaused } = usePausedBanner()
const readEnabled = computed(() => {
- if (!flags.autoTopUpEnabled) return false
+ if (!autoTopUpEnabled.value) return false
return canManageAutoTopUp.value
})
const { state, ensureRead } = useBillingAutoTopUpCard()
@@ -31,7 +29,7 @@ export function useAutoTopUpBannerKind() {
const read = state.value
const loaded = read.kind === 'loaded' ? read.settings : null
return deriveAutoTopUpBanner({
- enabled: flags.autoTopUpEnabled,
+ enabled: autoTopUpEnabled.value,
canManageAutoTopUp: canManageAutoTopUp.value,
isPaused: isPaused.value,
hasActivePlan: !isCloud || billing.subscription.value?.isActive === true,
diff --git a/src/platform/billing/composables/useBillingCapabilities.test.ts b/src/platform/billing/composables/useBillingCapabilities.test.ts
index cee772dd604..e93ec29146f 100644
--- a/src/platform/billing/composables/useBillingCapabilities.test.ts
+++ b/src/platform/billing/composables/useBillingCapabilities.test.ts
@@ -435,6 +435,24 @@ describe('useBillingCapabilities', () => {
}
)
+ it.for([
+ { served: true, expected: true },
+ { served: false, expected: false }
+ ])(
+ 'renders auto_top_up_enabled $served as $expected',
+ async ({ served, expected }) => {
+ const response = capabilitiesResponse(true, 'workspace-1', true)
+ response.auto_top_up_enabled = served
+ vi.mocked(workspaceApi.getBillingCapabilities).mockResolvedValueOnce(
+ response
+ )
+
+ await billingCapabilities.initialize()
+
+ expect(billingCapabilities.autoTopUpEnabled.value).toBe(expected)
+ }
+ )
+
it('offers workspace editing only when the server does', async () => {
vi.mocked(workspaceApi.getBillingCapabilities).mockResolvedValueOnce(
capabilitiesResponse(
diff --git a/src/platform/billing/composables/useBillingCapabilities.ts b/src/platform/billing/composables/useBillingCapabilities.ts
index 6e84d976c02..ba88c58e5b1 100644
--- a/src/platform/billing/composables/useBillingCapabilities.ts
+++ b/src/platform/billing/composables/useBillingCapabilities.ts
@@ -199,6 +199,12 @@ function useBillingCapabilitiesInternal() {
capabilities.value?.can_manage_auto_top_up ?? false
)
)
+ const autoTopUpEnabled = computed(() =>
+ receiveServerFact(
+ 'auto_top_up_enabled',
+ resolvedResponse.value?.auto_top_up_enabled ?? false
+ )
+ )
const autoTopUpSetup = computed(
() => resolvedResponse.value?.auto_top_up_setup ?? null
)
@@ -572,6 +578,7 @@ function useBillingCapabilitiesInternal() {
canManageSubscription,
canDowngradeToPersonal,
canManageAutoTopUp,
+ autoTopUpEnabled,
autoTopUpSetup,
canRunWorkflows,
planKind,
diff --git a/src/platform/remoteConfig/serverFeatureFlag.ts b/src/platform/remoteConfig/serverFeatureFlag.ts
index 8ee5a041aa8..adecb98283f 100644
--- a/src/platform/remoteConfig/serverFeatureFlag.ts
+++ b/src/platform/remoteConfig/serverFeatureFlag.ts
@@ -33,7 +33,6 @@ export enum ServerFeatureFlag {
BILLING_SDK_SUBSCRIPTION_ENABLED = 'billing_sdk_subscription_enabled',
V1_PAYMENT_RECOVERY = 'v1_payment_recovery',
UNIFIED_BILLING_SETTINGS = 'unified_billing_settings',
- AUTO_TOP_UP_ENABLED = 'auto_top_up_enabled',
SIGNUP_TURNSTILE = 'signup_turnstile',
SUPPORTS_MODEL_TYPE_TAGS = 'supports_model_type_tags',
ONBOARDING_TOUR_ENABLED = 'onboarding_tour_enabled',
diff --git a/src/platform/remoteConfig/types.ts b/src/platform/remoteConfig/types.ts
index b0d4ecbb077..00e2cfa68bb 100644
--- a/src/platform/remoteConfig/types.ts
+++ b/src/platform/remoteConfig/types.ts
@@ -140,7 +140,6 @@ export type RemoteConfig = Partial & {
member_credit_limits_enabled?: boolean
v1_payment_recovery?: boolean
unified_billing_settings?: boolean
- auto_top_up_enabled?: boolean
sentry_dsn?: string
turnstile_sitekey?: string
/** Absent when the backend has no key configured, not an empty string; always sanitize with the reader before trusting it. */
From 8e251b1ff3e15b526d16317f767c94490c290d28 Mon Sep 17 00:00:00 2001
From: dante01yoon
Date: Sun, 1 Nov 2026 20:39:57 -0500
Subject: [PATCH 2/3] test(billing): include auto_top_up_enabled in the
capabilities contract keys
---
.../core/billing/contracts/billingCapabilities.contract.test.ts | 1 +
1 file changed, 1 insertion(+)
diff --git a/packages/account-core/src/core/billing/contracts/billingCapabilities.contract.test.ts b/packages/account-core/src/core/billing/contracts/billingCapabilities.contract.test.ts
index 4c183c38747..568b9a99ad4 100644
--- a/packages/account-core/src/core/billing/contracts/billingCapabilities.contract.test.ts
+++ b/packages/account-core/src/core/billing/contracts/billingCapabilities.contract.test.ts
@@ -61,6 +61,7 @@ function capabilitiesBody(
}
expectTypeOf().toEqualTypeOf<
+ | 'auto_top_up_enabled'
| 'auto_top_up_setup'
| 'capabilities'
| 'denied_reason_params'
From 017d38e25bf3663705d84249ded86aebffa73419 Mon Sep 17 00:00:00 2001
From: Dante
Date: Mon, 2 Nov 2026 11:13:01 -0500
Subject: [PATCH 3/3] [backport core/1.59] FRONT-3734 feat(billing): auto
top-up card in the Add credits dialog (#22421) (#22712)
Backport of #22421 (FRONT-3734) to `core/1.59`. Stacked on #22672, which
brings the served `auto_top_up_enabled` fact to core/1.59.
## Why
Local ComfyUI users have no way into auto top-up from the app. On local
the unified Billing tab (where the auto top-up card and banners live) is
behind `unified_billing_settings`, which the local backend's `/features`
never serves, so local shows the legacy Plan & Credits panel. The Add
credits dialog is reachable on local, so the #22421 card is the entry
point local users actually see.
## Root cause
Same as #22421: no in-app path to auto top-up outside the unified
Billing tab.
## How
Cherry-pick of 620580eee5 with core/1.59 paths:
- `usePlatformHandoff` from
`@/platform/workspace/composables/usePlatformHandoff` (same signature as
main's `@/platform/billing/composables/`).
- `Button` from `@/components/ui/button/Button.vue`, telemetry from
`@/platform/telemetry`.
- Test mock types `AutoReloadSettings` from `workspaceApi` and uses
core/1.59's field set.
The card still renders served facts only: `auto_top_up_enabled`,
`can_manage_auto_top_up`, `auto_top_up_setup`, and status `off`.
## AS IS / TO BE
Add credits dialog opened from the user popover's **Add credits** button
on local (legacy dialog; `unified_billing_settings` left off, as the
local `/features` does not serve it). Same mocks on both builds:
signed-in user, Standard monthly plan, Cloud billing capabilities with
`auto_top_up_enabled: true`, `can_manage_auto_top_up: true`,
`auto_top_up_setup: { state: "ready" }`, plus balance and auto top-up
settings. Only the auto top-up status changes between rows.
| Auto top-up status | AS IS (`core/1.59`) | TO BE (this PR) |
| --- | --- | --- |
| `off` |
|
|
| `on` |
|
|
## Testing
- `TopUpAutoTopUpCard`, `TopUpCreditsDialogContentLegacy`,
`TopUpCreditsDialogContentWorkspace`: 149 tests pass on this branch.
---
src/locales/en/main.json | 4 +
.../components/TopUpAutoTopUpCard.test.ts | 127 ++++++++++++++++++
.../billing/components/TopUpAutoTopUpCard.vue | 63 +++++++++
.../TopUpCreditsDialogContentLegacy.test.ts | 34 ++++-
.../TopUpCreditsDialogContentLegacy.vue | 22 +--
...TopUpCreditsDialogContentWorkspace.test.ts | 56 ++++++++
.../TopUpCreditsDialogContentWorkspace.vue | 5 +
.../__mocks__/useBillingAutoTopUpCard.ts | 53 ++++++++
8 files changed, 354 insertions(+), 10 deletions(-)
create mode 100644 src/platform/billing/components/TopUpAutoTopUpCard.test.ts
create mode 100644 src/platform/billing/components/TopUpAutoTopUpCard.vue
create mode 100644 src/platform/billing/composables/__mocks__/useBillingAutoTopUpCard.ts
diff --git a/src/locales/en/main.json b/src/locales/en/main.json
index 7b40a93ece7..9c88ba23d30 100644
--- a/src/locales/en/main.json
+++ b/src/locales/en/main.json
@@ -3015,6 +3015,10 @@
"verifyTitle": "Verify your payment",
"startOver": "Start over",
"viewPricing": "View pricing details",
+ "autoTopUp": {
+ "prompt": "Running low on credits? Turn on auto top-up.",
+ "setUp": "Set up"
+ },
"youPay": "Amount (USD)",
"youGet": "Credits",
"buyCredits": "Continue to payment",
diff --git a/src/platform/billing/components/TopUpAutoTopUpCard.test.ts b/src/platform/billing/components/TopUpAutoTopUpCard.test.ts
new file mode 100644
index 00000000000..582490e9638
--- /dev/null
+++ b/src/platform/billing/components/TopUpAutoTopUpCard.test.ts
@@ -0,0 +1,127 @@
+import type { AutoTopUpSetup } from '@comfyorg/ingest-types'
+import { render, screen } from '@testing-library/vue'
+import userEvent from '@testing-library/user-event'
+import { describe, expect, it, vi } from 'vitest'
+import { computed } from 'vue'
+import { createI18n } from 'vue-i18n'
+
+import enMessages from '@/locales/en/main.json'
+import { useTelemetry } from '@/platform/telemetry'
+import {
+ autoTopUpCardState,
+ loadedAutoTopUp
+} from '@/platform/billing/composables/__mocks__/useBillingAutoTopUpCard'
+import {
+ autoTopUpEnabledFact,
+ canManageAutoTopUpFact
+} from '@/platform/billing/composables/__mocks__/useBillingCapabilities'
+import { useBillingAutoTopUpCard } from '@/platform/billing/composables/useBillingAutoTopUpCard'
+import { useBillingCapabilities } from '@/platform/billing/composables/useBillingCapabilities'
+
+import TopUpAutoTopUpCard from './TopUpAutoTopUpCard.vue'
+
+vi.mock(import('@/platform/billing/composables/useBillingCapabilities'))
+vi.mock(import('@/platform/billing/composables/useBillingAutoTopUpCard'))
+vi.mock(import('@/platform/telemetry'))
+vi.mock(import('@/platform/workspace/utils/platformLink'), () => ({
+ platformLink: (path: string, correlationId?: string) =>
+ `https://platform.test${path}?correlation_id=${correlationId}`
+}))
+
+const PROMPT = 'Running low on credits? Turn on auto top-up.'
+
+type Served = {
+ enabled: boolean
+ canManage: boolean
+ setup: AutoTopUpSetup | null
+ card: ReturnType | { kind: 'loading' | 'unavailable' }
+}
+
+const shown: Served = {
+ enabled: true,
+ canManage: true,
+ setup: { state: 'ready' },
+ card: loadedAutoTopUp('off')
+}
+
+function renderCard(served: Partial = {}) {
+ const { enabled, canManage, setup, card } = { ...shown, ...served }
+ const capabilities = useBillingCapabilities()
+ capabilities.autoTopUpEnabled = autoTopUpEnabledFact(enabled)
+ capabilities.canManageAutoTopUp = canManageAutoTopUpFact(canManage)
+ capabilities.autoTopUpSetup = computed(() => setup)
+ autoTopUpCardState.value = card
+ render(TopUpAutoTopUpCard, {
+ global: {
+ plugins: [
+ createI18n({
+ legacy: false,
+ locale: 'en',
+ messages: { en: enMessages }
+ })
+ ]
+ }
+ })
+}
+
+describe('TopUpAutoTopUpCard', () => {
+ it('offers a manager with auto top-up off to set it up on the billing site', () => {
+ renderCard()
+
+ expect(screen.getByText(PROMPT)).toBeInTheDocument()
+ expect(screen.getByRole('link', { name: 'Set up' })).toHaveAttribute(
+ 'href',
+ expect.stringContaining('https://platform.test/profile/billing')
+ )
+ })
+
+ it.for<{ name: string } & Partial>([
+ { name: 'auto top-up is not served', enabled: false },
+ { name: 'the viewer cannot manage it', canManage: false },
+ { name: 'no setup is served', setup: null },
+ {
+ name: 'setup is unavailable',
+ setup: { state: 'unavailable', reason: 'workspace_blocked' }
+ },
+ {
+ name: 'setup is frozen by a past-due payment',
+ setup: { state: 'frozen', reason: 'payment_past_due' }
+ },
+ { name: 'auto top-up is already on', card: loadedAutoTopUp('on') },
+ { name: 'auto top-up has failed', card: loadedAutoTopUp('failed') },
+ { name: 'the status is still loading', card: { kind: 'loading' } },
+ { name: 'the status read failed', card: { kind: 'unavailable' } }
+ ])('shows nothing when $name', ({ name: _, ...served }) => {
+ renderCard(served)
+
+ expect(screen.queryByText(PROMPT)).toBeNull()
+ })
+
+ it('stays shown while setup is frozen for another reason', () => {
+ renderCard({ setup: { state: 'frozen', reason: 'billing_paused' } })
+
+ expect(screen.getByText(PROMPT)).toBeInTheDocument()
+ })
+
+ it('reads the auto top-up status only when the served facts allow setup', () => {
+ renderCard({ canManage: false })
+ expect(useBillingAutoTopUpCard().ensureRead).not.toHaveBeenCalled()
+
+ renderCard()
+ expect(useBillingAutoTopUpCard().ensureRead).toHaveBeenCalledOnce()
+ })
+
+ it('reports the hand-off to the billing site', async () => {
+ renderCard()
+
+ await userEvent.click(screen.getByRole('link', { name: 'Set up' }))
+
+ expect(useTelemetry()?.trackBillingEvent).toHaveBeenCalledWith(
+ expect.objectContaining({
+ operation: 'platform_handoff',
+ target: 'auto_top_up',
+ action: 'turn_on'
+ })
+ )
+ })
+})
diff --git a/src/platform/billing/components/TopUpAutoTopUpCard.vue b/src/platform/billing/components/TopUpAutoTopUpCard.vue
new file mode 100644
index 00000000000..6053b42dfdf
--- /dev/null
+++ b/src/platform/billing/components/TopUpAutoTopUpCard.vue
@@ -0,0 +1,63 @@
+
+
+
+ {{ $t('credits.topUp.autoTopUp.prompt') }}
+
+
+
+
+
+
diff --git a/src/platform/billing/components/TopUpCreditsDialogContentLegacy.test.ts b/src/platform/billing/components/TopUpCreditsDialogContentLegacy.test.ts
index 720fd98dd6b..164befb3876 100644
--- a/src/platform/billing/components/TopUpCreditsDialogContentLegacy.test.ts
+++ b/src/platform/billing/components/TopUpCreditsDialogContentLegacy.test.ts
@@ -7,6 +7,15 @@ import { createI18n } from 'vue-i18n'
import enMessages from '@/locales/en/main.json'
import { useToast } from '@/components/ui/toast/toastStore'
+import {
+ autoTopUpCardState,
+ loadedAutoTopUp
+} from '@/platform/billing/composables/__mocks__/useBillingAutoTopUpCard'
+import {
+ autoTopUpEnabledFact,
+ canManageAutoTopUpFact
+} from '@/platform/billing/composables/__mocks__/useBillingCapabilities'
+import { useBillingCapabilities } from '@/platform/billing/composables/useBillingCapabilities'
import { useBillingContext } from '@/platform/billing/composables/useBillingContext'
import { useBillingRouting } from '@/platform/billing/composables/useBillingRouting'
import { useSubscription } from '@/platform/billing/subscription/composables/useSubscription'
@@ -26,6 +35,8 @@ vi.mock(import('@/platform/billing/composables/useBillingContext'))
vi.mock(import('@/platform/billing/composables/useBillingCapabilities'))
+vi.mock(import('@/platform/billing/composables/useBillingAutoTopUpCard'))
+
vi.mock(import('@/platform/distribution/types'), () => ({
isCloud: true,
isDesktop: false
@@ -68,7 +79,8 @@ const i18n = createI18n({
contactUs: 'Contact us',
viewPricing: 'View pricing',
insufficientWorkflowMessage: 'Insufficient credits',
- buyCredits: 'Continue to payment'
+ buyCredits: 'Continue to payment',
+ autoTopUp: enMessages.credits.topUp.autoTopUp
}
}
}
@@ -237,6 +249,26 @@ describe('TopUpCreditsDialogContentLegacy', () => {
}
)
+ it('offers auto top-up set-up above Continue to payment when every served fact allows it', () => {
+ const capabilities = useBillingCapabilities()
+ capabilities.autoTopUpEnabled = autoTopUpEnabledFact(true)
+ capabilities.canManageAutoTopUp = canManageAutoTopUpFact(true)
+ capabilities.autoTopUpSetup = computed(() => ({ state: 'ready' as const }))
+ autoTopUpCardState.value = loadedAutoTopUp('off')
+
+ renderDialog()
+
+ const setUp = screen.getByRole('link', { name: 'Set up' })
+ expect(
+ screen.getByText('Running low on credits? Turn on auto top-up.')
+ ).toBeInTheDocument()
+ expect(
+ setUp.compareDocumentPosition(
+ screen.getByRole('button', { name: 'Continue to payment' })
+ ) & Node.DOCUMENT_POSITION_FOLLOWING
+ ).toBeTruthy()
+ })
+
it('shows Plan & Credits after a successful Cloud purchase', async () => {
renderDialog()
await clickBuyCredits()
diff --git a/src/platform/billing/components/TopUpCreditsDialogContentLegacy.vue b/src/platform/billing/components/TopUpCreditsDialogContentLegacy.vue
index b615a39fa35..28cdf61a9c9 100644
--- a/src/platform/billing/components/TopUpCreditsDialogContentLegacy.vue
+++ b/src/platform/billing/components/TopUpCreditsDialogContentLegacy.vue
@@ -138,15 +138,18 @@
-
+
+
+
+
{
})
}
+ describe('the auto top-up card', () => {
+ const AUTO_TOP_UP_PROMPT = 'Running low on credits? Turn on auto top-up.'
+
+ beforeEach(() => {
+ const capabilities = useBillingCapabilities()
+ capabilities.autoTopUpEnabled = autoTopUpEnabledFact(true)
+ capabilities.canManageAutoTopUp = canManageAutoTopUpFact(true)
+ capabilities.autoTopUpSetup = computed(() => ({
+ state: 'ready' as const
+ }))
+ autoTopUpCardState.value = loadedAutoTopUp('off')
+ })
+
+ it('sits above Add credits on the amount step', () => {
+ renderDialog()
+
+ const setUp = screen.getByRole('link', { name: 'Set up' })
+ expect(screen.getByText(AUTO_TOP_UP_PROMPT)).toBeInTheDocument()
+ expect(
+ setUp.compareDocumentPosition(
+ screen.getByRole('button', { name: 'Add credits' })
+ ) & Node.DOCUMENT_POSITION_FOLLOWING
+ ).toBeTruthy()
+ })
+
+ it('is gone on the payment step', async () => {
+ renderDialog()
+
+ await clickAddCredits()
+
+ expect(
+ screen.getByRole('button', { name: 'Pay $50.00' })
+ ).toBeInTheDocument()
+ expect(screen.queryByText(AUTO_TOP_UP_PROMPT)).not.toBeInTheDocument()
+ })
+
+ it('gives way to the payment processing notice', async () => {
+ vi.mocked(useFeatureFlags().flags).unifiedBillingSettingsEnabled = true
+ serveProcessingCheckout(2500)
+ renderDialog()
+
+ await screen.findByRole('status')
+ expect(screen.queryByText(AUTO_TOP_UP_PROMPT)).not.toBeInTheDocument()
+ })
+ })
+
describe('a top-up payment still processing', () => {
it('keeps add credits available and names the served amount', async () => {
vi.mocked(useFeatureFlags().flags).unifiedBillingSettingsEnabled = true
diff --git a/src/platform/billing/components/TopUpCreditsDialogContentWorkspace.vue b/src/platform/billing/components/TopUpCreditsDialogContentWorkspace.vue
index 48bccf2e777..9c39afbb8c5 100644
--- a/src/platform/billing/components/TopUpCreditsDialogContentWorkspace.vue
+++ b/src/platform/billing/components/TopUpCreditsDialogContentWorkspace.vue
@@ -363,6 +363,10 @@
{{ $t('credits.topUp.paymentProcessingBody') }}
+