From 9987bee64a2f430fe2068b83d972ad70753ea046 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Sat, 3 Oct 2026 18:09:57 -0400 Subject: [PATCH 1/2] test(billing): cancel and resubscribe must reject when routing times out --- .../dialogs/cancelSubscriptionDialog.spec.ts | 16 ++++++--- .../billing/useBillingContext.test.ts | 35 +++++++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/browser_tests/tests/dialogs/cancelSubscriptionDialog.spec.ts b/browser_tests/tests/dialogs/cancelSubscriptionDialog.spec.ts index 4962bb6308d..7d1babaa84f 100644 --- a/browser_tests/tests/dialogs/cancelSubscriptionDialog.spec.ts +++ b/browser_tests/tests/dialogs/cancelSubscriptionDialog.spec.ts @@ -32,9 +32,9 @@ test.describe('CancelSubscription dialog', { tag: '@ui' }, () => { }) // No billing workspace loads in this environment, so the cancellation waits - // for routing, times out and reports an error instead of cancelling. The - // success path is covered in cancelSubscriptionSdkRail. - test('"Cancel subscription" button reports an error when billing is unavailable', async ({ + // for routing, times out and fails instead of cancelling. The success path + // is covered in cancelSubscriptionSdkRail. + test('"Cancel subscription" button fails without claiming success when billing is unavailable', async ({ comfyPage }) => { test.setTimeout(45_000) @@ -44,8 +44,16 @@ test.describe('CancelSubscription dialog', { tag: '@ui' }, () => { await dialog.confirmCancelButton.click() - await expect(comfyPage.toast.toastErrors.first()).toBeVisible({ + await expect(comfyPage.toast.toastErrors).toHaveCount(1, { timeout: 20_000 }) + await expect(comfyPage.toast.toastErrors).toContainText( + 'Failed to cancel subscription' + ) + await expect(comfyPage.toast.toastErrors).toContainText( + "We couldn't reach your account. Try again in a moment." + ) + await expect(comfyPage.toast.toastSuccesses).toHaveCount(0) + await expect(dialog.root).toBeVisible() }) }) diff --git a/src/composables/billing/useBillingContext.test.ts b/src/composables/billing/useBillingContext.test.ts index 2347681fa16..3b03c9d4537 100644 --- a/src/composables/billing/useBillingContext.test.ts +++ b/src/composables/billing/useBillingContext.test.ts @@ -694,6 +694,41 @@ describe('useBillingContext', () => { expect(workspaceApi.createTopup).not.toHaveBeenCalled() }) + it.for([ + { + name: 'cancelSubscription', + run: (context: ReturnType) => + context.cancelSubscription() + }, + { + name: 'resubscribe', + run: (context: ReturnType) => + context.resubscribe() + } + ])( + 'rejects $name for its caller to show if the workspace never loads', + async ({ run }) => { + vi.useFakeTimers() + onTestFinished(() => { + vi.useRealTimers() + }) + holdWorkspaceUnloaded('team') + const context = useBillingContext() + vi.clearAllMocks() + + const outcome = run(context).then( + () => 'resolved', + (error: unknown) => error + ) + await vi.advanceTimersByTimeAsync(10_000) + + expect(await outcome).toMatchObject({ + message: "We couldn't reach your account. Try again in a moment." + }) + expect(useErrorHandling().toastErrorHandler).not.toHaveBeenCalled() + } + ) + it('drops an action silently when the workspace changed during the wait', async () => { const current = ref<{ id: string; type?: 'team' }>({ id: 'ws-a' }) const workspaceStore = useTeamWorkspaceStore() From 9e2bf1587d6bcfe7e1ae928cb4b1ea97eebe205a Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Sat, 3 Oct 2026 18:21:16 -0400 Subject: [PATCH 2/2] fix(billing): reject cancel and resubscribe when the workspace type never loads --- src/composables/billing/useBillingContext.ts | 35 ++++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/composables/billing/useBillingContext.ts b/src/composables/billing/useBillingContext.ts index c85e0a2bfe0..c69a45bfa72 100644 --- a/src/composables/billing/useBillingContext.ts +++ b/src/composables/billing/useBillingContext.ts @@ -37,6 +37,8 @@ import { useWorkspaceBilling } from '@/platform/workspace/composables/useWorkspa const LEGACY_TEAM_PLAN_SLUG_PREFIX = 'team-' const PER_CREDIT_TEAM_PLAN_SLUG_PREFIX = 'team_per_credit_' +const ROUTING_WAIT_TIMEOUT_MS = 10_000 + class BillingRoutingUnavailableError extends Error {} function isTeamPlanSlug(planSlug: string | null | undefined): boolean { @@ -265,12 +267,9 @@ function useBillingContextInternal(): BillingContext { { immediate: true } ) - const ROUTING_WAIT_TIMEOUT_MS = 10_000 - - // Resolves false so the caller stops: after reporting once on timeout (as - // legacy actions did on failure), or silently when the user switched - // workspace during the wait. - async function whenRoutingKnown(): Promise { + // Rejects on timeout. Resolves false when the user switched workspace during + // the wait, so the caller stops silently. + async function waitForRouting(): Promise { if (type.value !== 'unknown') return true const workspaceId = store.activeWorkspace?.id try { @@ -278,14 +277,22 @@ function useBillingContextInternal(): BillingContext { timeout: ROUTING_WAIT_TIMEOUT_MS, throwOnTimeout: true }) - const currentId = store.activeWorkspace?.id - return !workspaceId || currentId === workspaceId } catch { - useErrorHandling().toastErrorHandler( - new BillingRoutingUnavailableError( - t('auth.webSession.token.unavailable') - ) + throw new BillingRoutingUnavailableError( + t('auth.webSession.token.unavailable') ) + } + const currentId = store.activeWorkspace?.id + return !workspaceId || currentId === workspaceId + } + + // For actions whose caller shows no outcome: reports a timeout once, as + // legacy actions did on failure, and resolves false so the caller stops. + async function whenRoutingKnown(): Promise { + try { + return await waitForRouting() + } catch (err) { + useErrorHandling().toastErrorHandler(err) return false } } @@ -370,14 +377,14 @@ function useBillingContextInternal(): BillingContext { } async function cancelSubscription(isScopeCurrent?: () => boolean) { - if (!(await whenRoutingKnown())) return + if (!(await waitForRouting())) return return activeContext.value.cancelSubscription(isScopeCurrent) } async function resubscribe( options?: Parameters[0] ) { - if (!(await whenRoutingKnown())) return + if (!(await waitForRouting())) return return activeContext.value.resubscribe(options) }