From d904b843710f1ca8590b77a7b840a61350f66e9d Mon Sep 17 00:00:00 2001 From: Dante Date: Tue, 4 Aug 2026 19:58:13 -0400 Subject: [PATCH] FE-1251 feat: add flagged payment recovery UI (#14701) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Adds the independently flagged frontend slice for Payment Recovery US1 and US3: unattended renewal-failure visibility and role-safe paused-workspace run recovery, without depending on #14091. ### Root cause and why this is needed Payment recovery states were coupled to `billing_control_enabled`, which is the rollout control for existing out-of-credits and subscription-ending notices. Paused workspaces also fell through the generic inactive path, replacing the entire queue group with `Subscribe to Run`. This hid batch/queue controls and exposed generic subscription/payment language to members instead of the required role-safe recovery UX. ### How this changes - Adds the authenticated server flag key `v1_payment_recovery`, exposed as `flags.v1PaymentRecovery` with the normal `ff:v1_payment_recovery` local override. - Gates only `payment_failed` and `paused` banners/run-lock behavior with the new flag; existing out-of-credits, ending, and generic inactive behavior remain on their existing paths. - Shows billing managers a non-dismissible `Payment failed` banner with `Update payment`; returning focus refetches status/balance while that banner is visible. - Keeps the queue group mounted when paused. Existing auto-run mode is reset and the visible dropdown is locked so no queued execution bypasses recovery. - Gives owners a gold `Update payment to run` action and portal recovery dialog; members see a gray locked `Run` action and a billing-private `Subscription paused` explainer with `Ok, got it`. - Uses the existing billing portal action, which opens Stripe Billing Portal in a new tab. ### API / backend boundary This PR consumes existing `billing_status` values (`payment_failed`, `paused`) and the existing payment-portal endpoint. Backend/remote config must deliver `v1_payment_recovery`. It does not implement dunning, recovery state transitions, or server mechanics. PR #14091 remains separate transactional-decline work; this PR has no dependency on its dialog or implementation. ## Changes - **What**: Flag wiring, payment recovery banner derivation/focus refresh, paused queue lock, owner/member recovery dialog, focused unit/component coverage. ## Review Focus - Recovery states are independent from `billing_control_enabled` while unrelated states preserve existing gates. - Paused owner/member flows cannot submit via primary action or Run-on-Change, but batch/dropdown controls stay mounted. - Members receive no payment-declined, card, or payment-method details. ## Screenshots Captured in the real cloud application with billing/workspace endpoints mocked through the repository's Playwright fixtures; no Storybook state was used. ### AS IS — paused owner uses generic inactive replacement ![AS IS - Subscribe to Run replaces queue controls](https://ampcode.com/user-content/artifacts/0155ae74ced7c0007eea1a6abc671182050e09385e5a9202c6f9dbba7cff5949-file.png) ### TO BE — paused owner queue lock and recovery ![TO BE - owner queue lock](https://ampcode.com/user-content/artifacts/2c012c3fe5cd3a59baccac620c00fc86439f3bd98453a974d77af94ca3339ffe-file.png) ![TO BE - owner payment recovery dialog](https://ampcode.com/user-content/artifacts/30fbef1ba90077c83cb9a84cba857953082efe391b4836e8cf4b20eba9247631-file.png) ### TO BE — paused member privacy-safe explainer ![TO BE - member paused explainer](https://ampcode.com/user-content/artifacts/fd523269fa8472b7d79cf32cf6abc34f25ab4075c488246b64d65d42905cc316-file.png) ## Validation - `pnpm typecheck` - `pnpm lint:unstaged` - 101 focused unit/component tests - 2 real-app Playwright cloud scenarios (paused owner/member) - `pnpm exec oxfmt --check` on touched files - `git diff --check` `pnpm typecheck:browser` is currently blocked by pre-existing `BillingStatusResponse` fixture drift on `main` (existing fixtures are missing newly required seat fields); the added Playwright fixture itself was exercised successfully before being kept out of this focused diff. --------- Co-authored-by: Amp --- .../CloudRunButtonWrapper.test.ts | 239 +++++++++++++++++- .../ComfyRunButton/CloudRunButtonWrapper.vue | 108 +++++++- .../ComfyRunButton/ComfyQueueButton.test.ts | 42 ++- .../ComfyRunButton/ComfyQueueButton.vue | 62 ++++- src/composables/useFeatureFlags.test.ts | 20 +- src/composables/useFeatureFlags.ts | 9 + src/locales/en/main.json | 18 +- .../remoteConfig/refreshRemoteConfig.ts | 2 + src/platform/remoteConfig/remoteConfig.ts | 5 + src/platform/remoteConfig/types.ts | 1 + .../SubscriptionPausedDialog.test.ts | 84 ++++++ .../components/SubscriptionPausedDialog.vue | 70 +++++ .../settings/BillingStatusBanner.test.ts | 46 ++-- .../dialogs/settings/BillingStatusBanner.vue | 4 +- .../composables/deriveBillingBanner.test.ts | 20 +- .../composables/useBillingBanner.test.ts | 42 ++- .../workspace/composables/useBillingBanner.ts | 42 +-- src/storybook/mocks/useFeatureFlags.ts | 6 +- 18 files changed, 753 insertions(+), 67 deletions(-) create mode 100644 src/platform/workspace/components/SubscriptionPausedDialog.test.ts create mode 100644 src/platform/workspace/components/SubscriptionPausedDialog.vue diff --git a/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts b/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts index 65dce0c9c8a..accd895a849 100644 --- a/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts +++ b/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.test.ts @@ -1,21 +1,77 @@ -import { render, screen } from '@testing-library/vue' +import userEvent from '@testing-library/user-event' +import { render, screen, waitFor } from '@testing-library/vue' import { beforeEach, describe, expect, it, vi } from 'vitest' import { nextTick, ref } from 'vue' import CloudRunButtonWrapper from './CloudRunButtonWrapper.vue' const mockCanRunWorkflows = ref(true) +const mockBillingStatus = ref('paid') +const state = vi.hoisted(() => ({ + v1PaymentRecovery: true, + canManageSubscription: true, + manageSubscription: vi.fn(), + fetchStatus: vi.fn(), + fetchBalance: vi.fn(), + toastErrorHandler: vi.fn(), + showLayoutDialog: vi.fn(), + closeDialog: vi.fn(), + updateDialog: vi.fn() +})) vi.mock('@/composables/billing/useBillingContext', () => ({ useBillingContext: () => ({ - canRunWorkflows: mockCanRunWorkflows + canRunWorkflows: mockCanRunWorkflows, + billingStatus: mockBillingStatus, + manageSubscription: state.manageSubscription, + fetchStatus: state.fetchStatus, + fetchBalance: state.fetchBalance + }) +})) + +vi.mock('@/composables/useFeatureFlags', () => ({ + useFeatureFlags: () => ({ + flags: { + get v1PaymentRecovery() { + return state.v1PaymentRecovery + } + } + }) +})) + +vi.mock('@/composables/useErrorHandling', () => ({ + useErrorHandling: () => ({ toastErrorHandler: state.toastErrorHandler }) +})) + +vi.mock('@/platform/workspace/composables/useWorkspaceUI', async () => { + const { computed } = await import('vue') + return { + useWorkspaceUI: () => ({ + permissions: computed(() => ({ + canManageSubscription: state.canManageSubscription + })) + }) + } +}) + +vi.mock('@/services/dialogService', () => ({ + useDialogService: () => ({ showLayoutDialog: state.showLayoutDialog }) +})) + +vi.mock('@/stores/dialogStore', () => ({ + useDialogStore: () => ({ + closeDialog: state.closeDialog, + updateDialog: state.updateDialog }) })) vi.mock('@/components/actionbar/ComfyRunButton/ComfyQueueButton.vue', () => ({ default: { name: 'ComfyQueueButton', - template: '
' + props: ['paymentRecoveryLock'], + emits: ['paymentRecoveryClick'], + template: + '
' } })) @@ -33,6 +89,10 @@ function renderWrapper() { describe('CloudRunButtonWrapper', () => { beforeEach(() => { mockCanRunWorkflows.value = true + mockBillingStatus.value = 'paid' + state.v1PaymentRecovery = true + state.canManageSubscription = true + vi.clearAllMocks() }) it('renders the runnable queue button when the subscription is active', () => { @@ -66,4 +126,177 @@ describe('CloudRunButtonWrapper', () => { screen.queryByTestId('subscribe-to-run-button') ).not.toBeInTheDocument() }) + + it('preserves queue controls and opens the owner recovery flow when paused', async () => { + mockCanRunWorkflows.value = false + mockBillingStatus.value = 'paused' + renderWrapper() + + expect(screen.getByTestId('batch-count')).toBeInTheDocument() + expect(screen.getByTestId('queue-dropdown')).toBeInTheDocument() + expect(screen.getByTestId('queue-button')).toHaveTextContent( + 'Update payment to run' + ) + expect( + screen.queryByTestId('subscribe-to-run-button') + ).not.toBeInTheDocument() + + await userEvent.click( + screen.getByRole('button', { name: 'Update payment to run' }) + ) + const dialogOptions = state.showLayoutDialog.mock.calls[0][0] + expect(dialogOptions.props.canManage).toBe(true) + + await dialogOptions.props.onUpdatePayment() + expect(state.closeDialog).toHaveBeenCalledWith({ + key: 'subscription-paused' + }) + expect(state.manageSubscription).toHaveBeenCalledOnce() + }) + + it('keeps recovery open and surfaces portal failures', async () => { + const error = new Error('Portal unavailable') + state.manageSubscription.mockRejectedValueOnce(error) + mockCanRunWorkflows.value = false + mockBillingStatus.value = 'paused' + renderWrapper() + + await userEvent.click(screen.getByTestId('queue-button')) + const dialogOptions = state.showLayoutDialog.mock.calls[0][0] + await dialogOptions.props.onUpdatePayment() + + expect(state.toastErrorHandler).toHaveBeenCalledWith(error) + expect(state.closeDialog).not.toHaveBeenCalled() + }) + + it('refreshes billing once on focus after returning from the portal', async () => { + mockCanRunWorkflows.value = false + mockBillingStatus.value = 'paused' + state.fetchStatus.mockImplementationOnce(() => { + mockBillingStatus.value = 'paid' + mockCanRunWorkflows.value = true + }) + renderWrapper() + + await userEvent.click( + screen.getByRole('button', { name: 'Update payment to run' }) + ) + const dialog = state.showLayoutDialog.mock.calls[0][0] + await dialog.props.onUpdatePayment() + + window.dispatchEvent(new Event('focus')) + await waitFor(() => { + expect(state.fetchStatus).toHaveBeenCalledOnce() + expect(state.fetchBalance).toHaveBeenCalledOnce() + expect(screen.getByRole('button', { name: 'Run' })).toBeInTheDocument() + }) + + window.dispatchEvent(new Event('focus')) + expect(state.fetchStatus).toHaveBeenCalledOnce() + expect(state.fetchBalance).toHaveBeenCalledOnce() + }) + + it('reuses a pending portal request across rapid clicks and reopen', async () => { + let resolvePortal!: () => void + state.manageSubscription.mockImplementationOnce( + () => + new Promise((resolve) => { + resolvePortal = resolve + }) + ) + mockCanRunWorkflows.value = false + mockBillingStatus.value = 'paused' + renderWrapper() + + await userEvent.click( + screen.getByRole('button', { name: 'Update payment to run' }) + ) + const firstDialog = state.showLayoutDialog.mock.calls[0][0] + const firstRequest = firstDialog.props.onUpdatePayment() + const repeatedRequest = firstDialog.props.onUpdatePayment() + expect(state.manageSubscription).toHaveBeenCalledOnce() + + firstDialog.props.onClose() + await userEvent.click( + screen.getByRole('button', { name: 'Update payment to run' }) + ) + const reopenedDialog = state.showLayoutDialog.mock.calls.at(-1)?.[0] + expect(reopenedDialog.props.isUpdatingPayment).toBe(true) + expect(reopenedDialog.props.onUpdatePayment()).toBe(firstRequest) + expect(repeatedRequest).toBe(firstRequest) + expect(state.manageSubscription).toHaveBeenCalledOnce() + + resolvePortal() + await firstRequest + expect(state.updateDialog).toHaveBeenLastCalledWith({ + key: 'subscription-paused', + contentProps: { isUpdatingPayment: false } + }) + }) + + it('does not update a replacement dialog after unmount', async () => { + let resolvePortal!: () => void + state.manageSubscription.mockImplementationOnce( + () => + new Promise((resolve) => { + resolvePortal = resolve + }) + ) + mockCanRunWorkflows.value = false + mockBillingStatus.value = 'paused' + const { unmount } = renderWrapper() + + await userEvent.click( + screen.getByRole('button', { name: 'Update payment to run' }) + ) + const dialog = state.showLayoutDialog.mock.calls[0][0] + const portalRequest = dialog.props.onUpdatePayment() + unmount() + + resolvePortal() + await portalRequest + expect(state.closeDialog).not.toHaveBeenCalled() + expect(state.updateDialog).toHaveBeenCalledTimes(1) + expect(state.updateDialog).toHaveBeenCalledWith({ + key: 'subscription-paused', + contentProps: { isUpdatingPayment: true } + }) + }) + + it('opens member-safe recovery copy without a payment action', async () => { + mockCanRunWorkflows.value = false + mockBillingStatus.value = 'paused' + state.canManageSubscription = false + renderWrapper() + + expect(screen.getByTestId('queue-button')).toHaveTextContent('Run') + await userEvent.click(screen.getByTestId('queue-button')) + + const dialogOptions = state.showLayoutDialog.mock.calls[0][0] + expect(dialogOptions.props.canManage).toBe(false) + dialogOptions.props.onClose() + expect(state.closeDialog).toHaveBeenCalledWith({ + key: 'subscription-paused' + }) + expect(state.manageSubscription).not.toHaveBeenCalled() + }) + + it('keeps generic inactive behavior when payment recovery is disabled', () => { + mockCanRunWorkflows.value = false + mockBillingStatus.value = 'paused' + state.v1PaymentRecovery = false + renderWrapper() + + expect(screen.getByTestId('subscribe-to-run-button')).toBeInTheDocument() + expect(screen.queryByTestId('queue-group')).not.toBeInTheDocument() + }) + + it('keeps generic inactive behavior for non-paused statuses', () => { + mockCanRunWorkflows.value = false + mockBillingStatus.value = 'inactive' + renderWrapper() + + expect(screen.getByTestId('subscribe-to-run-button')).toBeInTheDocument() + expect(screen.queryByTestId('queue-group')).not.toBeInTheDocument() + }) }) diff --git a/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.vue b/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.vue index e5e8922a94a..e0fba1aa9d0 100644 --- a/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.vue +++ b/src/components/actionbar/ComfyRunButton/CloudRunButtonWrapper.vue @@ -1,19 +1,113 @@ diff --git a/src/components/actionbar/ComfyRunButton/ComfyQueueButton.test.ts b/src/components/actionbar/ComfyRunButton/ComfyQueueButton.test.ts index e4d940a850b..0aa8155658e 100644 --- a/src/components/actionbar/ComfyRunButton/ComfyQueueButton.test.ts +++ b/src/components/actionbar/ComfyRunButton/ComfyQueueButton.test.ts @@ -56,6 +56,15 @@ const i18n = createI18n({ runWorkflow: 'Run workflow', runWorkflowFront: 'Run workflow front', runWorkflowMissingResources: 'Workflow contains missing resources' + }, + subscription: { + paymentRecovery: { + ownerRunLabel: 'Update payment to run', + memberRunLabel: 'Run', + ownerRunTooltip: 'Update payment to restore this subscription', + memberRunTooltip: + 'Ask your workspace owner to restore this subscription' + } } } } @@ -136,7 +145,9 @@ const stubs = { DropdownMenuItem: { template: '
' } } -function renderQueueButton() { +function renderQueueButton( + props: { paymentRecoveryLock?: 'owner' | 'member' } = {} +) { const pinia = createTestingPinia({ createSpy: vi.fn, stubActions: (actionName) => actionName !== 'recordPromptError' @@ -144,6 +155,7 @@ function renderQueueButton() { const user = userEvent.setup() const result = render(ComfyQueueButton, { + props, global: { plugins: [pinia, i18n], directives: { @@ -165,6 +177,34 @@ describe('ComfyQueueButton', () => { expect(controls[1]).toHaveAttribute('data-testid', 'queue-button') }) + it.for([ + { + paymentRecoveryLock: 'owner', + label: 'Update payment to run', + variant: 'subscribe' + }, + { paymentRecoveryLock: 'member', label: 'Run', variant: 'secondary' } + ] as const)( + 'keeps the queue group mounted for a paused $paymentRecoveryLock and blocks execution', + async ({ paymentRecoveryLock, label, variant }) => { + useQueueSettingsStore().mode = 'change' + const { user, emitted } = renderQueueButton({ paymentRecoveryLock }) + const commandStore = useCommandStore() + + expect(screen.getByTestId('batch-count-edit')).toBeInTheDocument() + expect(screen.getByTestId('queue-mode-menu-trigger')).toBeDisabled() + expect(useQueueSettingsStore().mode).toBe('disabled') + const button = screen.getByTestId('queue-button') + expect(button).toHaveTextContent(label) + expect(button).toHaveAttribute('data-variant', variant) + + await user.click(button) + + expect(commandStore.execute).not.toHaveBeenCalled() + expect(emitted()).toHaveProperty('paymentRecoveryClick') + } + ) + it.for(missingResourceCases)( 'clears the warning icon when missing $label are resolved', async ({ setMissing, clearMissing }) => { diff --git a/src/components/actionbar/ComfyRunButton/ComfyQueueButton.vue b/src/components/actionbar/ComfyRunButton/ComfyQueueButton.vue index 2b156f70fe0..467673423ed 100644 --- a/src/components/actionbar/ComfyRunButton/ComfyQueueButton.vue +++ b/src/components/actionbar/ComfyRunButton/ComfyQueueButton.vue @@ -10,7 +10,12 @@ }" :variant="queueButtonVariant" size="unset" - :class="queueActionButtonClass" + :class=" + cn( + 'h-full gap-1.5 rounded-lg px-4', + paymentRecoveryLock ? 'font-medium' : 'font-light' + ) + " data-testid="queue-button" :data-variant="queueButtonVariant" @click="queuePrompt" @@ -24,6 +29,7 @@