Repository navigation
fix(billing): only one subscribe CTA at a time #16721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
57fb252
e6edd6f
1c88a84
12c7897
e243236
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,12 +3,17 @@ import { render, screen, waitFor } from '@testing-library/vue' | |
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import { nextTick, ref } from 'vue' | ||
|
|
||
| import { createI18n } from 'vue-i18n' | ||
|
|
||
| import TopbarSubscribeButton from '@/components/topbar/TopbarSubscribeButton.vue' | ||
| import enMessages from '@/locales/en/main.json' with { type: 'json' } | ||
| import type { BillingStatus } from '@/platform/workspace/api/workspaceApi' | ||
| import { useDialogStore } from '@/stores/dialogStore' | ||
|
|
||
| import CloudRunButtonWrapper from './CloudRunButtonWrapper.vue' | ||
|
|
||
| const mockCanRunWorkflows = ref(true) | ||
| const mockIsFreeTier = ref(true) | ||
| const mockIsInitialized = ref(true) | ||
| const mockBillingStatus = ref<BillingStatus | null>('paid') | ||
| const mockSubscriptionTier = ref<string | null>(null) | ||
|
|
@@ -33,6 +38,7 @@ vi.mock<unknown>( | |
| () => mockIsInitialized.value && !mockCanRunWorkflows.value | ||
| ), | ||
| billingStatus: mockBillingStatus, | ||
| isFreeTier: mockIsFreeTier, | ||
| subscription: computed(() => | ||
| mockSubscriptionTier.value | ||
| ? { tier: mockSubscriptionTier.value } | ||
|
|
@@ -46,6 +52,17 @@ vi.mock<unknown>( | |
| } | ||
| ) | ||
|
|
||
| vi.mock(import('@/platform/distribution/types'), () => ({ | ||
| isCloud: true | ||
| })) | ||
|
|
||
| vi.mock<unknown>( | ||
| import('@/platform/cloud/subscription/composables/useSubscriptionDialog'), | ||
| () => ({ | ||
| useSubscriptionDialog: () => ({ showPricingTable: vi.fn() }) | ||
| }) | ||
| ) | ||
|
|
||
| vi.mock<unknown>(import('@/composables/useFeatureFlags'), () => ({ | ||
| useFeatureFlags: () => ({ | ||
| flags: { | ||
|
|
@@ -93,12 +110,17 @@ vi.mock<unknown>( | |
|
|
||
| vi.mock<unknown>( | ||
| import('@/platform/cloud/subscription/components/SubscribeToRun.vue'), | ||
| () => ({ | ||
| default: { | ||
| name: 'SubscribeToRun', | ||
| template: '<div data-testid="subscribe-to-run-button" />' | ||
| async () => { | ||
| const { registerSubscribeToRunPrompt } = | ||
| await import('@/platform/cloud/subscription/composables/useSubscribeCtaPresence') | ||
| return { | ||
| default: { | ||
| name: 'SubscribeToRun', | ||
| setup: () => registerSubscribeToRunPrompt(), | ||
| template: '<div data-testid="subscribe-to-run-button" />' | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| ) | ||
|
|
||
| function renderWrapper() { | ||
|
|
@@ -113,6 +135,59 @@ describe('CloudRunButtonWrapper', () => { | |
| mockSubscriptionTier.value = null | ||
| state.v1PaymentRecovery = true | ||
| state.canManageSubscription = true | ||
| mockIsFreeTier.value = true | ||
| }) | ||
|
|
||
| describe('one subscribe CTA at a time', () => { | ||
| const CtaSurface = { | ||
| components: { CloudRunButtonWrapper, TopbarSubscribeButton }, | ||
| template: '<div><TopbarSubscribeButton /><CloudRunButtonWrapper /></div>' | ||
| } | ||
|
|
||
| function renderCtaSurface() { | ||
| const i18n = createI18n({ | ||
| legacy: false, | ||
| locale: 'en', | ||
| messages: { en: enMessages } | ||
| }) | ||
| return render(CtaSurface, { global: { plugins: [i18n] } }) | ||
| } | ||
|
|
||
| it('keeps the topbar CTA on a sales-managed plan, where the prompt never mounts', () => { | ||
| mockCanRunWorkflows.value = false | ||
| mockSubscriptionTier.value = 'ENTERPRISE' | ||
|
|
||
| renderCtaSurface() | ||
|
|
||
| expect( | ||
| screen.queryByTestId('subscribe-to-run-button') | ||
| ).not.toBeInTheDocument() | ||
| expect(screen.getByTestId('topbar-subscribe-button')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('keeps the topbar CTA under payment recovery, where the prompt never mounts', () => { | ||
| mockCanRunWorkflows.value = false | ||
| mockBillingStatus.value = 'paused' | ||
|
|
||
| renderCtaSurface() | ||
|
|
||
| expect( | ||
| screen.queryByTestId('subscribe-to-run-button') | ||
| ).not.toBeInTheDocument() | ||
| expect(screen.getByTestId('topbar-subscribe-button')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('yields the topbar CTA only while the prompt is actually mounted', async () => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (non-blocking): this proves the suppression direction but never the release direction with a real prompt. The unmount path is only covered in I ran it locally against the real components and it behaves correctly, so this is coverage rather than a defect. It closes cheaply here — flip |
||
| mockCanRunWorkflows.value = false | ||
|
|
||
| renderCtaSurface() | ||
| await nextTick() | ||
|
|
||
| expect(screen.getByTestId('subscribe-to-run-button')).toBeInTheDocument() | ||
| expect( | ||
| screen.queryByTestId('topbar-subscribe-button') | ||
| ).not.toBeInTheDocument() | ||
| }) | ||
| }) | ||
|
|
||
| it('renders the runnable queue button when the subscription is active', () => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import { getActivePinia } from 'pinia' | ||
| import { nextTick } from 'vue' | ||
| import { createI18n } from 'vue-i18n' | ||
|
|
||
| import { render, screen } from '@testing-library/vue' | ||
|
|
@@ -27,12 +28,35 @@ vi.mock<unknown>( | |
| }) | ||
| ) | ||
|
|
||
| vi.mock<unknown>(import('@/composables/billing/useBillingContext'), () => ({ | ||
| useBillingContext: vi.fn(() => ({ | ||
| isFreeTier: { value: true } | ||
| })) | ||
| const mockState = vi.hoisted(() => ({ | ||
| holder: null as null | { isFreeTier: boolean; promptMounted: boolean } | ||
| })) | ||
|
|
||
| vi.mock<unknown>( | ||
| import('@/composables/billing/useBillingContext'), | ||
| async () => { | ||
| const { computed, reactive } = await import('vue') | ||
| mockState.holder ??= reactive({ isFreeTier: true, promptMounted: false }) | ||
| return { | ||
| useBillingContext: vi.fn(() => ({ | ||
| isFreeTier: computed(() => mockState.holder!.isFreeTier) | ||
| })) | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| vi.mock<unknown>( | ||
| import('@/platform/cloud/subscription/composables/useSubscribeCtaPresence'), | ||
| async () => { | ||
| const { computed, reactive } = await import('vue') | ||
| mockState.holder ??= reactive({ isFreeTier: true, promptMounted: false }) | ||
| return { | ||
| useSubscribeToRunPromptPresence: () => | ||
| computed(() => mockState.holder!.promptMounted) | ||
| } | ||
| } | ||
| ) | ||
|
|
||
| vi.mock(import('firebase/app'), () => ({ | ||
| initializeApp: vi.fn(), | ||
| getApp: vi.fn() | ||
|
|
@@ -61,12 +85,30 @@ function renderComponent() { | |
| } | ||
|
|
||
| describe('TopbarSubscribeButton', () => { | ||
| beforeEach(() => { | ||
| mockState.holder!.isFreeTier = true | ||
| mockState.holder!.promptMounted = false | ||
| }) | ||
|
|
||
| it('renders on cloud when isFreeTier is true', () => { | ||
| mockIsCloud.value = true | ||
| renderComponent() | ||
| expect(screen.getByTestId('topbar-subscribe-button')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('yields while a Run-slot subscribe prompt is mounted, and returns when it unmounts', async () => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: The suite pins the behavior being added but not the invariant being protected. The three tests cover: renders on cloud when free tier, yields while a prompt is mounted, hides off-cloud. The description makes a stronger promise than that:
Nothing asserts it. And the sales-managed / payment-recovery case is the interesting one, because it's the case where The failure mode if it ever regresses is the worst one available here: a free-tier user who can't run and has no subscribe affordance anywhere in the UI. Strictly worse than the duplicate CTA this PR fixes. Could we add a case that mounts
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in 1c88a84, as a small integration surface rather than wrapper-only tests: |
||
| mockIsCloud.value = true | ||
| mockState.holder!.promptMounted = true | ||
| renderComponent() | ||
| expect( | ||
| screen.queryByTestId('topbar-subscribe-button') | ||
| ).not.toBeInTheDocument() | ||
|
|
||
| mockState.holder!.promptMounted = false | ||
| await nextTick() | ||
| expect(screen.getByTestId('topbar-subscribe-button')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('hides on non-cloud distribution', () => { | ||
| mockIsCloud.value = false | ||
| renderComponent() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| <template> | ||
| <Button | ||
| v-if="isCloud && isFreeTier" | ||
| v-if="isCloud && isFreeTier && !subscribeToRunPromptVisible" | ||
| class="mr-2 shrink-0 whitespace-nowrap" | ||
| variant="subscribe" | ||
| size="sm" | ||
|
|
@@ -14,10 +14,12 @@ | |
| <script setup lang="ts"> | ||
| import Button from '@/components/ui/button/Button.vue' | ||
| import { useBillingContext } from '@/composables/billing/useBillingContext' | ||
| import { useSubscribeToRunPromptPresence } from '@/platform/cloud/subscription/composables/useSubscribeCtaPresence' | ||
| import { useSubscriptionDialog } from '@/platform/cloud/subscription/composables/useSubscriptionDialog' | ||
| import { isCloud } from '@/platform/distribution/types' | ||
|
|
||
| const { isFreeTier } = useBillingContext() | ||
| const subscribeToRunPromptVisible = useSubscribeToRunPromptPresence() | ||
| const subscriptionDialog = useSubscriptionDialog() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟢 Low — The two flags settle at different times, so the button can flash. Raised by 2 of 8 reviewers (claude-opus-5-thinking-max adversarial, claude-opus-5-thinking-max edge-case).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dissolved by the presence fix: the topbar no longer infers from initialization timing at all. Upgrade shows as soon as the tier is known and yields at the moment the prompt mounts — the handoff is a single frame in the same render pass that mounts the prompt, not a window between two async flags settling.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟢 Low — This couples topbar visibility to graph contents: Raised by 1 of 8 reviewers (claude-opus-5-thinking-max adversarial).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That coupling is now the rule working as intended rather than a side effect: with credit-badged nodes in the graph, SubscribeToRun genuinely mounts in the Run slot, so the topbar yielding leaves exactly one subscribe CTA — the one adjacent to the blocked action. When the badged nodes leave and the prompt unmounts, Upgrade returns. |
||
|
|
||
| function handleClick() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { registerSubscribeToRunPrompt } from '@/platform/cloud/subscription/composables/useSubscribeCtaPresence' | ||
| import { breakpointsTailwind, useBreakpoints } from '@vueuse/core' | ||
| import { computed } from 'vue' | ||
| import { useI18n } from 'vue-i18n' | ||
|
|
@@ -27,6 +28,9 @@ import { isCloud } from '@/platform/distribution/types' | |
| import { useWorkspaceUI } from '@/platform/workspace/composables/useWorkspaceUI' | ||
|
|
||
| const { t } = useI18n() | ||
|
|
||
| // Mounting suppresses TopbarSubscribeButton; see useSubscribeCtaPresence | ||
| registerSubscribeToRunPrompt() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (non-blocking): this line has an effect outside the component and nothing here says so.
The concrete case I'd worry about is Storybook — A one-line comment at the call site — something like
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added the call-site comment in 1c88a84. The Storybook scenario is a fair worry — worth noting the floor from your other comment means a story unmounting cleanly now self-corrects, so the residual risk is a story that keeps the prompt mounted while someone views a topbar story in the same session. |
||
| const breakpoints = useBreakpoints(breakpointsTailwind) | ||
| const isMdOrLarger = breakpoints.greaterOrEqual('md') | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { computed, onMounted, onUnmounted, ref } from 'vue' | ||
|
|
||
| const mountedPrompts = ref(0) | ||
|
|
||
| /** | ||
| * Registers a mounted Run-slot subscribe prompt for the caller's lifetime. | ||
| * The billing flag alone is not evidence a prompt is on screen — builder | ||
| * mode unmounts the actionbar, Linear mode needs outputs, and the wrapper | ||
| * withholds the prompt for sales-managed and payment-recovery states — so | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit (non-blocking): this docblock's premise does not hold today. My earlier review checked the three call sites and concluded mounted means on screen. That was true of the call sites and wrong about their ancestors. So for a free-tier workspace that cannot run, entering agent node selection now yields zero subscribe CTAs: the Run-slot prompt is counted but invisible, and the topbar button stands down for it. Before this PR the Upgrade button stayed. I verified this by rendering the topbar button next to a prompt wrapped in I do not think this blocks: the mode is transient and user-initiated, the user is not being blocked from running at that moment, and everything returns correctly on exit. But the docblock currently argues the mechanism's correctness from an invariant that an ancestor already breaks, so it is worth either narrowing the claim or tracking the gap. |
||
| * anything yielding to the prompt must key on real presence. | ||
| */ | ||
| export function registerSubscribeToRunPrompt() { | ||
| onMounted(() => { | ||
| mountedPrompts.value += 1 | ||
| }) | ||
| onUnmounted(() => { | ||
| mountedPrompts.value = Math.max(0, mountedPrompts.value - 1) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit (non-blocking): the floor is unreachable. Either drop the |
||
| }) | ||
| } | ||
|
|
||
| /** Whether any Run-slot subscribe prompt is currently on screen. */ | ||
| export function useSubscribeToRunPromptPresence() { | ||
| return computed(() => mountedPrompts.value > 0) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -375,7 +375,8 @@ const showSubscribeAction = computed( | |
| ((isCancelled.value && canReactivatePlan.value) || | ||
| (!canAccessSubscriptionFeatures.value && | ||
| !hasDelinquentSubscription.value && | ||
| canSubscribeSelfServe.value)) | ||
| canSubscribeSelfServe.value && | ||
| canTopUp.value)) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This resolves the reported state correctly, and the gate is safe: both CTAs live inside the same Follow-up (not this PR): the cancelled branch is OR'd above this gate, so it still renders two subscription CTAs. With |
||
| ) | ||
|
|
||
| const handleOpenUserSettings = () => { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.