From 6b47b341b210753128669ea35e36caa796a16841 Mon Sep 17 00:00:00 2001 From: Wei Hai Date: Wed, 26 Aug 2026 09:59:00 -0700 Subject: [PATCH 1/2] fix(billing): align pricing-dialog reactivation with the centralized rail policy UnifiedPricingTable and handleResubscribe gated on isCloud plus the raw can_reactivate, ignoring the billing rail. A cancelled legacy_stripe customer therefore reached the pricing dialog with the reactivate CTA disabled, and the executor refused the action. --- .../components/UnifiedPricingTable.test.ts | 29 +++++++++++++++++-- .../components/UnifiedPricingTable.vue | 11 ++----- .../useSubscriptionCheckout.test.ts | 22 ++++++++++++++ .../composables/useSubscriptionCheckout.ts | 17 +++-------- 4 files changed, 56 insertions(+), 23 deletions(-) diff --git a/src/platform/workspace/components/UnifiedPricingTable.test.ts b/src/platform/workspace/components/UnifiedPricingTable.test.ts index 903d258d8d2..87595850f64 100644 --- a/src/platform/workspace/components/UnifiedPricingTable.test.ts +++ b/src/platform/workspace/components/UnifiedPricingTable.test.ts @@ -29,6 +29,10 @@ const mockCurrentTeamCreditStop = ref(null) const mockIsTeamPlan = ref(false) const mockCanManageSubscription = ref(true) const mockCanDowngradeToPersonal = ref(true) +const mockCanReactivatePlan = ref(true) +// the raw server capability, kept separate so a test can prove the component +// follows the derived policy rather than this value +const mockRawCanReactivate = ref(true) const mockPermissions = ref({ canManageSubscription: true, canManageSubscriptionLifecycle: true, @@ -53,7 +57,7 @@ vi.mock('@/platform/distribution/types', () => mockDistributionTypes) vi.mock('@/platform/workspace/composables/useBillingCapabilities', () => ({ useBillingCapabilities: () => ({ canSubscribeSelfServe: computed(() => mockCanManageSubscription.value), - canReactivate: computed(() => mockCanManageSubscription.value), + canReactivate: computed(() => mockRawCanReactivate.value), canChangeSeats: computed(() => mockCanManageSubscription.value), canDowngradeToPersonal: computed(() => mockCanDowngradeToPersonal.value) }) @@ -61,7 +65,8 @@ vi.mock('@/platform/workspace/composables/useBillingCapabilities', () => ({ vi.mock('@/platform/workspace/composables/useWorkspaceUI', () => ({ useWorkspaceUI: () => ({ - permissions: computed(() => mockPermissions.value) + permissions: computed(() => mockPermissions.value), + canReactivatePlan: computed(() => mockCanReactivatePlan.value) }) })) @@ -93,6 +98,8 @@ function renderComponent(props: Record = {}) { describe('UnifiedPricingTable plan CTA labels', () => { beforeEach(() => { + mockCanReactivatePlan.value = true + mockRawCanReactivate.value = true mockSubscription.value = null mockSubscriptionStatus.value = null mockCurrentPlanSlug.value = null @@ -222,6 +229,8 @@ describe('UnifiedPricingTable team plan CTA', () => { } beforeEach(() => { + mockCanReactivatePlan.value = true + mockRawCanReactivate.value = true mockSubscription.value = null mockSubscriptionStatus.value = null mockCurrentPlanSlug.value = null @@ -309,6 +318,20 @@ describe('UnifiedPricingTable team plan CTA', () => { expect(emitted().resubscribe).toBeTruthy() }) + it('disables Resubscribe when the workspace may not reactivate', () => { + mockSubscription.value = { + tier: 'TEAM', + duration: 'ANNUAL', + isCancelled: true + } + mockCurrentTeamCreditStop.value = TEAM_STOP + mockCanReactivatePlan.value = false + + renderComponent({ initialPlanMode: 'team' }) + + expect(screen.getByRole('button', { name: 'Resubscribe' })).toBeDisabled() + }) + it('lets a cancelled sub change to a different stop (not re-subscribe)', async () => { const user = userEvent.setup() mockSubscription.value = { @@ -368,6 +391,8 @@ describe('UnifiedPricingTable outside Cloud', () => { } beforeEach(() => { + mockCanReactivatePlan.value = true + mockRawCanReactivate.value = true mockSubscription.value = null mockSubscriptionStatus.value = null mockCurrentPlanSlug.value = null diff --git a/src/platform/workspace/components/UnifiedPricingTable.vue b/src/platform/workspace/components/UnifiedPricingTable.vue index 12f290dc164..fc4bf7b3226 100644 --- a/src/platform/workspace/components/UnifiedPricingTable.vue +++ b/src/platform/workspace/components/UnifiedPricingTable.vue @@ -469,18 +469,13 @@ const emit = defineEmits<{ const { t, n } = useI18n() const capabilities = useBillingCapabilities() -const { permissions } = useWorkspaceUI() +const { permissions, canReactivatePlan } = useWorkspaceUI() const canSubscribeSelfServe = computed(() => isCloud ? capabilities.canSubscribeSelfServe.value : permissions.value.canManageSubscription ) -const canReactivate = computed(() => - isCloud - ? capabilities.canReactivate.value - : permissions.value.canManageSubscriptionLifecycle -) const canChangeSeats = computed(() => isCloud ? capabilities.canChangeSeats.value @@ -770,7 +765,7 @@ const isTeamButtonDisabled = computed(() => { if (isLoading) return true if (!isTeamSubscribed.value) return !canSubscribeSelfServe.value if (isTeamCurrentPlanSelected.value) { - return !isCancelled.value || !canReactivate.value + return !isCancelled.value || !canReactivatePlan.value } return !canChangeSeats.value }) @@ -861,7 +856,7 @@ const canUsePersonalPlanAction = (tierKey: CheckoutTierKey): boolean => { if (!canSelectPersonalPlan.value) return false if (isTeamPlan.value) return canDowngradeToPersonal.value if (isCurrentPlan(tierKey)) { - return isCancelled.value && canReactivate.value + return isCancelled.value && canReactivatePlan.value } return hasActivePaidPlan(currentAccountTier.value) ? canChangeSeats.value diff --git a/src/platform/workspace/composables/useSubscriptionCheckout.test.ts b/src/platform/workspace/composables/useSubscriptionCheckout.test.ts index 4ac1258df5c..8721b1376a5 100644 --- a/src/platform/workspace/composables/useSubscriptionCheckout.test.ts +++ b/src/platform/workspace/composables/useSubscriptionCheckout.test.ts @@ -175,6 +175,7 @@ const { mockSetActiveWorkspaceIdImpl, mockSetActiveWorkspaceId, mockPermissions, + mockCanReactivatePlan, mockCapabilities, mockSubscription } = vi.hoisted(() => ({ @@ -218,6 +219,7 @@ const { canDowngradeToPersonal: true } }, + mockCanReactivatePlan: { value: true }, mockCapabilities: { value: { canSubscribeSelfServe: true, @@ -282,6 +284,11 @@ vi.mock('@/platform/workspace/composables/useWorkspaceUI', () => ({ get value() { return mockPermissions.value } + }, + canReactivatePlan: { + get value() { + return mockCanReactivatePlan.value + } } }) })) @@ -503,6 +510,7 @@ describe('useSubscriptionCheckout', () => { canChangeSeats: true, canDowngradeToPersonal: true } + mockCanReactivatePlan.value = true mockSubscription.value = null sessionStorage.clear() emit = vi.fn() @@ -3876,9 +3884,22 @@ describe('useSubscriptionCheckout', () => { }) }) + it('resubscribes on the legacy rail even though the server withholds can_reactivate', async () => { + // legacy_stripe workspaces have no capability projection row, so the + // raw capability is false while the workspace may still reactivate. + mockCapabilities.value.canReactivate = false + mockCanReactivatePlan.value = true + const checkout = await setup() + + await checkout.handleResubscribe() + + expect(mockResubscribe).toHaveBeenCalled() + }) + it('does not resubscribe for a member', async () => { mockPermissions.value.canManageSubscriptionLifecycle = false mockCapabilities.value.canReactivate = false + mockCanReactivatePlan.value = false const checkout = await setup() await checkout.handleResubscribe() @@ -3889,6 +3910,7 @@ describe('useSubscriptionCheckout', () => { it('does not resubscribe when the server denies reactivation to a client-side owner', async () => { mockCapabilities.value.canReactivate = false + mockCanReactivatePlan.value = false const checkout = await setup() await checkout.handleResubscribe() diff --git a/src/platform/workspace/composables/useSubscriptionCheckout.ts b/src/platform/workspace/composables/useSubscriptionCheckout.ts index 0a9ee5ab194..defd5fc4c4f 100644 --- a/src/platform/workspace/composables/useSubscriptionCheckout.ts +++ b/src/platform/workspace/composables/useSubscriptionCheckout.ts @@ -137,13 +137,9 @@ export function useSubscriptionCheckout( subscription } = useBillingContext() const { shouldUseWorkspaceBilling } = useBillingRouting() - const { - canSubscribeSelfServe, - canReactivate, - canChangeSeats, - canDowngradeToPersonal - } = useBillingCapabilities() - const { permissions } = useWorkspaceUI() + const { canSubscribeSelfServe, canChangeSeats, canDowngradeToPersonal } = + useBillingCapabilities() + const { permissions, canReactivatePlan } = useWorkspaceUI() const telemetry = useTelemetry() const billingOperationStore = useBillingOperationStore() const workspaceStore = useTeamWorkspaceStore() @@ -1459,12 +1455,7 @@ export function useSubscriptionCheckout( } async function handleResubscribe() { - if ( - !(isCloud - ? canReactivate.value - : permissions.value.canManageSubscriptionLifecycle) - ) - return + if (!canReactivatePlan.value) return const source = 'pricing_dialog' as const From a38ab480c5f139555a9c7ca5c5a4f9c2bde805ae Mon Sep 17 00:00:00 2001 From: Wei Hai Date: Wed, 26 Aug 2026 10:32:55 -0700 Subject: [PATCH 2/2] test(billing): assert the observable resubscribe outcome on the legacy rail The regression case only checked that the API mock was called, which the repo's test guidance excludes for reactivation cases. It now asserts the close emit as well. --- .../workspace/composables/useSubscriptionCheckout.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/platform/workspace/composables/useSubscriptionCheckout.test.ts b/src/platform/workspace/composables/useSubscriptionCheckout.test.ts index 8721b1376a5..7be8ba0e4fa 100644 --- a/src/platform/workspace/composables/useSubscriptionCheckout.test.ts +++ b/src/platform/workspace/composables/useSubscriptionCheckout.test.ts @@ -3890,9 +3890,16 @@ describe('useSubscriptionCheckout', () => { mockCapabilities.value.canReactivate = false mockCanReactivatePlan.value = true const checkout = await setup() + mockResubscribe.mockResolvedValueOnce({ + billing_op_id: 'op-legacy-rail', + status: 'active' + }) + mockFetchStatus.mockResolvedValueOnce(undefined) + mockFetchBalance.mockResolvedValueOnce(undefined) await checkout.handleResubscribe() + expect(emit).toHaveBeenCalledWith('close', true) expect(mockResubscribe).toHaveBeenCalled() })