From 50b38c89985110e9886789d3a68a738d3fa11be0 Mon Sep 17 00:00:00 2001 From: bymyself Date: Thu, 5 Nov 2026 07:30:30 +0000 Subject: [PATCH 1/5] fix(agent): say Add credits does not start a Cloud plan on the agent paywall A Cloud owner without a plan can top up, so the agent's Out of credits card offered Add credits and claimed the workspace had spent its monthly credits. Credits bought there fund the agent but not workflow runs, and nothing said so before the purchase (PM-2273 report #2: the user had to go back for a second budget approval for the subscription). When the Add credits plan line applies (no plan or an ended plan on Cloud), the card now uses the no-plan body and shows the same plan-required line as the Add credits dialog. No new strings. Refs PM-2273 --- .../tests/agent/agentPaywallPlanNote.spec.ts | 104 ++++++++++++++++++ .../composables/useTopUpPlanCreditCopy.ts | 12 +- src/platform/billing/topUpPlanCreditLine.ts | 11 +- .../agent/AgentPanelRoot.tabActivity.test.ts | 2 + .../extensions/agent/AgentPanelRoot.test.ts | 40 +++++++ .../extensions/agent/AgentPanelRoot.vue | 5 +- .../agent/message/AgentPaywallCard.stories.ts | 12 ++ .../agent/message/AgentPaywallCard.test.ts | 49 +++++++++ .../agent/message/AgentPaywallCard.vue | 18 ++- .../agent/agentPaywallPresentation.test.ts | 30 +++++ .../agent/agentPaywallPresentation.ts | 17 ++- 11 files changed, 287 insertions(+), 13 deletions(-) create mode 100644 browser_tests/tests/agent/agentPaywallPlanNote.spec.ts diff --git a/browser_tests/tests/agent/agentPaywallPlanNote.spec.ts b/browser_tests/tests/agent/agentPaywallPlanNote.spec.ts new file mode 100644 index 00000000000..a43dc55536c --- /dev/null +++ b/browser_tests/tests/agent/agentPaywallPlanNote.spec.ts @@ -0,0 +1,104 @@ +import { expect } from '@playwright/test' +import type { Page } from '@playwright/test' +import type { BillingStatusResponse } from '@comfyorg/ingest-types' + +import { zAgentAdmissionError } from '@/workbench/extensions/agent/schemas/agentApiSchema' + +import enMessages from '@/locales/en/main.json' with { type: 'json' } + +import { waitForCloudApp } from '@e2e/fixtures/cloudAppFixture' +import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute' +import { expectElementScreenshot } from '@e2e/fixtures/utils/screenshotRegion' +import { AGENT_COMPOSER_LABEL } from '@e2e/fixtures/utils/agentComposerLabel' +import { agentTest } from '@e2e/tests/agent/agentPanelMocks' + +// A Cloud owner with no plan can buy credits for the agent, but those credits +// do not run workflows. The agent's Out of credits card must say so before the +// purchase, not after (PM-2273 report #2). + +const NO_FUNDS_ERROR = zAgentAdmissionError.parse({ + error: { + message: + 'This workspace is out of funds. Add credits or subscribe to keep going.', + reason: 'no_funds', + type: 'PAYMENT_REQUIRED' + } +}) + +const NO_PLAN_STATUS = { + billing_rail: 'stripe', + billing_status: 'inactive', + has_funds: false, + is_active: false, + max_seats: 1, + occupied_seats: 1, + scoped_effective_has_funds: { agent: false }, + scoped_has_funds: { agent: false }, + scheduled_change: null, + next_charge: null, + subscription_state: 'never_subscribed', + subscription_tier: 'FREE', + ended_at: null, + team_credit_stop: null +} satisfies BillingStatusResponse + +async function showPaywall(page: Page) { + const panel = page.locator('#agent-panel-root') + await panel + .getByRole('button', { name: enMessages.agent.switchWorkflow }) + .click() + await page + .getByRole('menuitemradio', { name: 'Unsaved Workflow', exact: true }) + .click() + + await page.route('**/api/agent/threads/*/messages', async (route) => { + if (route.request().method() !== 'POST') return route.fallback() + await route.fulfill({ + status: 402, + contentType: 'application/json', + body: JSON.stringify(NO_FUNDS_ERROR) + }) + }) + + await panel + .getByRole('textbox', { name: AGENT_COMPOSER_LABEL }) + .fill('Make a red fox in the snow') + await panel.getByRole('button', { name: enMessages.agent.send }).click() + + const card = panel + .getByRole('alert') + .filter({ hasText: enMessages.agent.paywall.title }) + await expect(card).toBeVisible() + return card +} + +agentTest.describe( + 'Agent paywall for an account without a plan', + { tag: ['@cloud', '@ui'] }, + () => { + agentTest( + 'says buying credits does not start a Cloud plan', + { tag: '@screenshot' }, + async ({ page, agentPanel }) => { + await page.route('**/api/billing/status', (route) => + route.fulfill(jsonRoute(NO_PLAN_STATUS)) + ) + await page.reload() + await waitForCloudApp(page) + + await agentPanel.open() + const card = await showPaywall(page) + + await expect( + card.getByRole('button', { + name: enMessages.agent.paywall.addCredits + }) + ).toBeVisible() + await expect(card.getByTestId('agent-paywall-plan-note')).toContainText( + "Buying credits doesn't start a Cloud plan." + ) + await expectElementScreenshot(card, 'agent-paywall-plan-note.png') + } + ) + } +) diff --git a/src/platform/billing/composables/useTopUpPlanCreditCopy.ts b/src/platform/billing/composables/useTopUpPlanCreditCopy.ts index 0305dfa4183..c9c3cb33658 100644 --- a/src/platform/billing/composables/useTopUpPlanCreditCopy.ts +++ b/src/platform/billing/composables/useTopUpPlanCreditCopy.ts @@ -3,12 +3,13 @@ import { useI18n } from 'vue-i18n' import type { AddCreditsPlanLine } from '@comfyorg/account-core/billing' import { topUpPlanCreditLine } from '@/platform/billing/topUpPlanCreditLine' +import type { TopUpPlanCreditLine } from '@/platform/billing/topUpPlanCreditLine' import { useBillingCapabilities } from '@/platform/billing/composables/useBillingCapabilities' import { useBillingContext } from '@/platform/billing/composables/useBillingContext' import { useFreeTierQuota } from '@/platform/billing/subscription/composables/useFreeTierQuota' import { isCloud } from '@/platform/distribution/types' -const LINE_KEYS = { +export const TOP_UP_PLAN_CREDIT_LINE_KEYS = { planRequiredFreeRuns: 'credits.topUp.planRequiredFreeRuns', planRequiredSubscribe: 'credits.topUp.planRequiredSubscribe', planRequiredResubscribe: 'credits.topUp.planRequiredResubscribe' @@ -18,9 +19,10 @@ const ADD_CREDITS_LINES = { planRequiredFreeRuns: 'free_runs', planRequiredSubscribe: 'no_plan', planRequiredResubscribe: 'ended' -} as const satisfies Record +} as const satisfies Record -function usePlanCreditLine() { +/** Which plan-required line applies on Cloud, or null when none does. */ +export function usePlanCreditLine() { const { isInitialized, subscriptionState } = useBillingContext() const { canTopUp } = useBillingCapabilities() const { available: freeRunsRemaining } = useFreeTierQuota() @@ -40,7 +42,9 @@ function usePlanCreditLine() { export function useTopUpPlanCreditCopy() { const { t } = useI18n() const line = usePlanCreditLine() - return computed(() => (line.value === null ? null : t(LINE_KEYS[line.value]))) + return computed(() => + line.value === null ? null : t(TOP_UP_PLAN_CREDIT_LINE_KEYS[line.value]) + ) } /** The same line as the Add credits dialog's plan-line fact. */ diff --git a/src/platform/billing/topUpPlanCreditLine.ts b/src/platform/billing/topUpPlanCreditLine.ts index 839f86dcd85..c03906fd026 100644 --- a/src/platform/billing/topUpPlanCreditLine.ts +++ b/src/platform/billing/topUpPlanCreditLine.ts @@ -1,5 +1,10 @@ import type { SubscriptionState } from '@comfyorg/ingest-types' +export type TopUpPlanCreditLine = + | 'planRequiredFreeRuns' + | 'planRequiredSubscribe' + | 'planRequiredResubscribe' + /** Add credits line on Cloud for a served `subscription_state` that has no plan. */ export function topUpPlanCreditLine(facts: { isCloud: boolean @@ -7,11 +12,7 @@ export function topUpPlanCreditLine(facts: { canTopUp: boolean subscriptionState: SubscriptionState | null freeRunsRemaining: number -}): - | 'planRequiredFreeRuns' - | 'planRequiredSubscribe' - | 'planRequiredResubscribe' - | null { +}): TopUpPlanCreditLine | null { if (!facts.isCloud) return null if (!facts.isBillingInitialized) return null if (!facts.canTopUp) return null diff --git a/src/workbench/extensions/agent/AgentPanelRoot.tabActivity.test.ts b/src/workbench/extensions/agent/AgentPanelRoot.tabActivity.test.ts index bc70a6811d0..287243cb16e 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.tabActivity.test.ts +++ b/src/workbench/extensions/agent/AgentPanelRoot.tabActivity.test.ts @@ -312,6 +312,8 @@ beforeEach(() => { type: computed(() => 'workspace' as const), billingStatus: computed(() => 'paid' as const), canAccessSubscriptionFeatures: computed(() => true), + isInitialized: computed(() => true), + subscriptionState: computed(() => 'active' as const), fetchStatus: vi.fn(async () => {}) }) ) diff --git a/src/workbench/extensions/agent/AgentPanelRoot.test.ts b/src/workbench/extensions/agent/AgentPanelRoot.test.ts index ede01c149f6..a3f8596d76d 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.test.ts +++ b/src/workbench/extensions/agent/AgentPanelRoot.test.ts @@ -13,6 +13,7 @@ import type { BillingStatus, GlobalSetting, PaginationInfo, + SubscriptionState, SubscriptionTier } from '@comfyorg/ingest-types' import type { User } from 'firebase/auth' @@ -284,6 +285,7 @@ const paywallBilling = vi.hoisted(() => ({ type: 'workspace' as 'workspace' | 'unknown', status: 'paid' as BillingStatus | null, isActive: true, + subscriptionState: 'active' as SubscriptionState | null, fetchStatus: vi.fn<() => Promise>() })) const paywallHasFunds = ref(false) @@ -428,6 +430,8 @@ beforeEach(() => { type: computed(() => paywallBilling.type), billingStatus: computed(() => paywallBilling.status), canAccessSubscriptionFeatures: computed(() => paywallBilling.isActive), + isInitialized: computed(() => true), + subscriptionState: computed(() => paywallBilling.subscriptionState), fetchStatus: paywallBilling.fetchStatus }) ) @@ -545,6 +549,7 @@ beforeEach(() => { paywallBilling.tier = 'STANDARD' paywallBilling.type = 'workspace' paywallBilling.status = 'paid' + paywallBilling.subscriptionState = 'active' paywallBilling.isActive = true paywallBilling.fetchStatus.mockReset().mockResolvedValue(undefined) paywallHasFunds.value = false @@ -1319,6 +1324,39 @@ describe('AgentPanelRoot paywall actions', () => { ).not.toBeInTheDocument() }) + it('says Add credits does not start a Cloud plan for an owner without one', async () => { + paywallBilling.tier = 'FREE' + paywallBilling.isActive = false + paywallBilling.subscriptionState = 'never_subscribed' + render(AgentPanelRoot, { global: { plugins: [i18n] } }) + useAgentConversationStore().messages.push({ + id: toTurnId('msg-paywall'), + role: 'assistant', + parts: [{ type: 'paywall' }], + streaming: false, + thinking: false + }) + + expect(await findInlinePaywallButton('Add credits')).toBeInTheDocument() + expect( + await screen.findByTestId('agent-paywall-plan-note') + ).toHaveTextContent("Buying credits doesn't start a Cloud plan.") + }) + + it('keeps the plan note out for an owner with an active plan', async () => { + render(AgentPanelRoot, { global: { plugins: [i18n] } }) + useAgentConversationStore().messages.push({ + id: toTurnId('msg-paywall'), + role: 'assistant', + parts: [{ type: 'paywall' }], + streaming: false, + thinking: false + }) + + expect(await findInlinePaywallButton('Add credits')).toBeInTheDocument() + expect(screen.queryByTestId('agent-paywall-plan-note')).toBeNull() + }) + it('shows Subscribe only when the server allows self-serve subscription but not top-up', async () => { paywallCapabilities.canTopUp = false render(AgentPanelRoot, { global: { plugins: [i18n] } }) @@ -1443,6 +1481,8 @@ describe('AgentPanelRoot paywall telemetry', () => { tier, type: computed(() => 'workspace'), billingStatus: computed(() => 'paid'), + isInitialized: computed(() => true), + subscriptionState: computed(() => 'active' as const), fetchStatus: vi.fn().mockResolvedValue(undefined) }) ) diff --git a/src/workbench/extensions/agent/AgentPanelRoot.vue b/src/workbench/extensions/agent/AgentPanelRoot.vue index 1cadd28a788..4d927210994 100644 --- a/src/workbench/extensions/agent/AgentPanelRoot.vue +++ b/src/workbench/extensions/agent/AgentPanelRoot.vue @@ -85,6 +85,7 @@ import { parseNodeLocatorId } from '@comfyorg/graph-model/nodeIdentification' import { useBillingContext } from '@/platform/billing/composables/useBillingContext' import { useAccountPreconditionDialog } from '@/platform/billing/subscription/composables/useAccountPreconditionDialog' import { useBillingCapabilities } from '@/platform/billing/composables/useBillingCapabilities' +import { usePlanCreditLine } from '@/platform/billing/composables/useTopUpPlanCreditCopy' import { useOnboardingTourStore } from '@/platform/onboarding/onboardingTourStore' import { useWorkspaceUI } from '@/platform/workspace/composables/useWorkspaceUI' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' @@ -231,6 +232,7 @@ const { isReady: capabilityReadSettled, snapshotAuthoritative } = useBillingCapabilities() +const planCreditLine = usePlanCreditLine() const paywallPresentation = computed(() => { if (isCloud && !hasResolvedCapabilities.value && !canTopUp.value) { return DEFAULT_AGENT_PAYWALL_PRESENTATION @@ -240,7 +242,8 @@ const paywallPresentation = computed(() => { role: workspaceRole.value, tier: subscriptionTier.value, canTopUp: canTopUp.value, - canSubscribeSelfServe: canSubscribeSelfServe.value + canSubscribeSelfServe: canSubscribeSelfServe.value, + planCreditLine: planCreditLine.value }) }) const sidebarTabStore = useSidebarTabStore() diff --git a/src/workbench/extensions/agent/components/agent/message/AgentPaywallCard.stories.ts b/src/workbench/extensions/agent/components/agent/message/AgentPaywallCard.stories.ts index 68205e816fb..65e9ab0b934 100644 --- a/src/workbench/extensions/agent/components/agent/message/AgentPaywallCard.stories.ts +++ b/src/workbench/extensions/agent/components/agent/message/AgentPaywallCard.stories.ts @@ -28,6 +28,18 @@ export const HighestPlan: Story = { render: renderAtMinimumWidth } +// A Cloud owner with no plan: credits fund the agent but not workflow runs. +export const NoPlan: Story = { + args: { + presentation: { + kind: 'subscribed', + showUpgrade: false, + planCreditLine: 'planRequiredFreeRuns' + } + }, + render: renderAtMinimumWidth +} + export const SubscriptionRequired: Story = { args: { presentation: { kind: 'subscriptionRequired' } }, render: renderAtMinimumWidth diff --git a/src/workbench/extensions/agent/components/agent/message/AgentPaywallCard.test.ts b/src/workbench/extensions/agent/components/agent/message/AgentPaywallCard.test.ts index b9c1b1904d9..6d444688857 100644 --- a/src/workbench/extensions/agent/components/agent/message/AgentPaywallCard.test.ts +++ b/src/workbench/extensions/agent/components/agent/message/AgentPaywallCard.test.ts @@ -37,6 +37,55 @@ describe('AgentPaywallCard visual contract', () => { expect(onPaywallAction.mock.calls).toEqual([['upgrade'], ['addCredits']]) }) + it.for([ + { + planCreditLine: 'planRequiredFreeRuns' as const, + note: "Buying credits doesn't start a Cloud plan. Subscribe to keep running workflows once your free runs are used." + }, + { + planCreditLine: 'planRequiredSubscribe' as const, + note: "Buying credits doesn't start a Cloud plan. Subscribe to run workflows on Cloud." + } + ])( + 'says Add credits does not start a plan for an owner with no plan ($planCreditLine)', + ({ planCreditLine, note }) => { + render(AgentPaywallCard, { + props: { + presentation: { + kind: 'subscribed', + showUpgrade: false, + planCreditLine + } + }, + global: { plugins: [i18n] } + }) + + expect(screen.getByTestId('agent-paywall-plan-note')).toHaveTextContent( + note + ) + expect( + screen.getByText( + 'Your account has no credits available for the agent. Add credits to use it.' + ) + ).toBeInTheDocument() + expect( + screen.queryByText(/spent its monthly credits/) + ).not.toBeInTheDocument() + expect( + screen.getByRole('button', { name: 'Add credits' }) + ).toBeInTheDocument() + } + ) + + it('keeps the plan note out for a subscribed owner', () => { + render(AgentPaywallCard, { + props: { presentation: { kind: 'subscribed', showUpgrade: true } }, + global: { plugins: [i18n] } + }) + + expect(screen.queryByTestId('agent-paywall-plan-note')).toBeNull() + }) + it('announces the server denial without purchase actions when capabilities are unknown', () => { render(AgentPaywallCard, { props: { message: 'Your workspace spend limit was reached.' }, diff --git a/src/workbench/extensions/agent/components/agent/message/AgentPaywallCard.vue b/src/workbench/extensions/agent/components/agent/message/AgentPaywallCard.vue index 418f85637e0..898b679c394 100644 --- a/src/workbench/extensions/agent/components/agent/message/AgentPaywallCard.vue +++ b/src/workbench/extensions/agent/components/agent/message/AgentPaywallCard.vue @@ -3,6 +3,7 @@ import Card from '@comfyorg/design-system/card/Card' import { computed } from 'vue' import Button from '@comfyorg/design-system/button/Button' +import { TOP_UP_PLAN_CREDIT_LINE_KEYS } from '@/platform/billing/composables/useTopUpPlanCreditCopy' import { DEFAULT_AGENT_PAYWALL_PRESENTATION, @@ -30,7 +31,15 @@ const bodyKeys: Record = { local: 'agent.paywall.body.local', unavailable: 'agent.paywall.body.subscriptionRequired' } -const bodyKey = computed(() => bodyKeys[presentation.kind]) +const planNoteKey = computed(() => + presentation.kind === 'subscribed' && presentation.planCreditLine + ? TOP_UP_PLAN_CREDIT_LINE_KEYS[presentation.planCreditLine] + : null +) +// Without a plan there are no monthly credits to have spent. +const bodyKey = computed(() => + planNoteKey.value ? bodyKeys.local : bodyKeys[presentation.kind] +) const showUpgrade = computed( () => presentation.kind === 'subscribed' && presentation.showUpgrade ) @@ -57,6 +66,13 @@ const showAddCredits = computed(() => remediation.value === 'addCredits')

{{ message || $t(bodyKey) }}

+

+ {{ $t(planNoteKey) }} +

diff --git a/src/workbench/extensions/agent/services/agent/agentPaywallPresentation.test.ts b/src/workbench/extensions/agent/services/agent/agentPaywallPresentation.test.ts index 5c1e6726752..022c4661f7c 100644 --- a/src/workbench/extensions/agent/services/agent/agentPaywallPresentation.test.ts +++ b/src/workbench/extensions/agent/services/agent/agentPaywallPresentation.test.ts @@ -7,6 +7,36 @@ import { } from './agentPaywallPresentation' describe('resolveAgentPaywallPresentation', () => { + it('carries the plan-required line for a Cloud owner who can top up but has no plan', () => { + expect( + resolveAgentPaywallPresentation({ + distribution: 'cloud', + role: 'owner', + tier: 'FREE', + canTopUp: true, + canSubscribeSelfServe: true, + planCreditLine: 'planRequiredFreeRuns' + }) + ).toEqual({ + kind: 'subscribed', + showUpgrade: false, + planCreditLine: 'planRequiredFreeRuns' + }) + }) + + it('omits the plan-required line on Local', () => { + expect( + resolveAgentPaywallPresentation({ + distribution: 'local', + role: 'owner', + tier: null, + canTopUp: true, + canSubscribeSelfServe: true, + planCreditLine: 'planRequiredSubscribe' + }) + ).toStrictEqual({ kind: 'local' }) + }) + it.for([ { name: 'both self-serve actions', diff --git a/src/workbench/extensions/agent/services/agent/agentPaywallPresentation.ts b/src/workbench/extensions/agent/services/agent/agentPaywallPresentation.ts index 0532ab78b3c..0bf04f93cd0 100644 --- a/src/workbench/extensions/agent/services/agent/agentPaywallPresentation.ts +++ b/src/workbench/extensions/agent/services/agent/agentPaywallPresentation.ts @@ -4,12 +4,21 @@ import type { AgentPaywallCta, AgentPaywallReason } from '@comfyorg/telemetry/types' +import type { TopUpPlanCreditLine } from '@/platform/billing/topUpPlanCreditLine' import type { WorkspaceRole } from '@/platform/workspace/api/workspaceApi' export type AgentPaywallAction = 'addCredits' | 'subscribe' | 'upgrade' export type AgentPaywallPresentation = - | { kind: 'subscribed'; showUpgrade: boolean } + | { + kind: 'subscribed' + showUpgrade: boolean + /** + * The account can top up but has no Cloud plan: credits fund the agent, + * not workflow runs, so the card says so before anyone pays. + */ + planCreditLine?: TopUpPlanCreditLine + } | { kind: 'subscriptionRequired' } | { kind: 'member' } | { kind: 'salesManaged' } @@ -22,6 +31,8 @@ interface AgentPaywallPresentationInput { tier: SubscriptionTier | null canTopUp: boolean canSubscribeSelfServe: boolean + /** Plan-required Add credits line for this account, when one applies. */ + planCreditLine?: TopUpPlanCreditLine | null } export const DEFAULT_AGENT_PAYWALL_PRESENTATION = { @@ -82,7 +93,8 @@ export function resolveAgentPaywallPresentation({ role, tier, canTopUp, - canSubscribeSelfServe + canSubscribeSelfServe, + planCreditLine }: AgentPaywallPresentationInput): AgentPaywallPresentation { if (distribution === 'local') return { kind: 'local' } if (role === undefined) return DEFAULT_AGENT_PAYWALL_PRESENTATION @@ -94,6 +106,7 @@ export function resolveAgentPaywallPresentation({ } return { kind: 'subscribed', + ...(planCreditLine && { planCreditLine }), showUpgrade: canSubscribeSelfServe && (tier === 'STANDARD' || tier === 'CREATOR') } From eb5db31481e724e26852e8385d8cf40e73a7ed7f Mon Sep 17 00:00:00 2001 From: bymyself Date: Thu, 5 Nov 2026 07:49:44 +0000 Subject: [PATCH 2/5] test(agent): assert the full plan-note text on the agent paywall e2e Refs PM-2273 --- browser_tests/tests/agent/agentPaywallPlanNote.spec.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/browser_tests/tests/agent/agentPaywallPlanNote.spec.ts b/browser_tests/tests/agent/agentPaywallPlanNote.spec.ts index a43dc55536c..4b51510d295 100644 --- a/browser_tests/tests/agent/agentPaywallPlanNote.spec.ts +++ b/browser_tests/tests/agent/agentPaywallPlanNote.spec.ts @@ -1,4 +1,5 @@ import { expect } from '@playwright/test' +import { escapeRegExp } from 'es-toolkit' import type { Page } from '@playwright/test' import type { BillingStatusResponse } from '@comfyorg/ingest-types' @@ -94,8 +95,12 @@ agentTest.describe( name: enMessages.agent.paywall.addCredits }) ).toBeVisible() - await expect(card.getByTestId('agent-paywall-plan-note')).toContainText( - "Buying credits doesn't start a Cloud plan." + const { planRequiredFreeRuns, planRequiredSubscribe } = + enMessages.credits.topUp + await expect(card.getByTestId('agent-paywall-plan-note')).toHaveText( + new RegExp( + `^(${escapeRegExp(planRequiredFreeRuns)}|${escapeRegExp(planRequiredSubscribe)})$` + ) ) await expectElementScreenshot(card, 'agent-paywall-plan-note.png') } From 7a72aec6c666cea0c025d713e191025a5b84e4a2 Mon Sep 17 00:00:00 2001 From: bymyself Date: Thu, 5 Nov 2026 08:00:24 +0000 Subject: [PATCH 3/5] fix(agent): offer Subscribe with the no-plan note, and show it on the no-funds pause Review: the note told a no-plan owner to subscribe but the card only offered Add credits, and an ended plan whose tier still reads CREATOR also got Upgrade plan. With the note, the card now offers Subscribe (secondary) next to Add credits and drops Upgrade; the note only applies when the owner can subscribe self-serve. The no-funds pause card, which also offers Add credits, shows the same note through a shared AgentPaywallPlanNote. Comments removed; e2e mocks moved to a fixture and beforeEach. Refs PM-2273 --- .../data/agent/agentPaywallPlanNote.ts | 29 +++++ .../tests/agent/agentPaywallPlanNote.spec.ts | 115 +++++++----------- .../agent/message/AgentPausedCard.test.ts | 34 ++++++ .../agent/message/AgentPausedCard.vue | 2 + .../agent/message/AgentPaywallCard.stories.ts | 1 - .../agent/message/AgentPaywallCard.test.ts | 4 + .../agent/message/AgentPaywallCard.vue | 25 ++-- .../agent/message/AgentPaywallPlanNote.vue | 26 ++++ .../agent/agentPaywallPresentation.test.ts | 30 +++++ .../agent/agentPaywallPresentation.ts | 9 +- 10 files changed, 178 insertions(+), 97 deletions(-) create mode 100644 browser_tests/fixtures/data/agent/agentPaywallPlanNote.ts create mode 100644 src/workbench/extensions/agent/components/agent/message/AgentPaywallPlanNote.vue diff --git a/browser_tests/fixtures/data/agent/agentPaywallPlanNote.ts b/browser_tests/fixtures/data/agent/agentPaywallPlanNote.ts new file mode 100644 index 00000000000..f859d90a628 --- /dev/null +++ b/browser_tests/fixtures/data/agent/agentPaywallPlanNote.ts @@ -0,0 +1,29 @@ +import type { BillingStatusResponse } from '@comfyorg/ingest-types' + +import { zAgentAdmissionError } from '@/workbench/extensions/agent/schemas/agentApiSchema' + +export const AGENT_NO_FUNDS_ERROR = zAgentAdmissionError.parse({ + error: { + message: + 'This workspace is out of funds. Add credits or subscribe to keep going.', + reason: 'no_funds', + type: 'PAYMENT_REQUIRED' + } +}) + +export const NEVER_SUBSCRIBED_BILLING_STATUS = { + billing_rail: 'stripe', + billing_status: 'inactive', + has_funds: false, + is_active: false, + max_seats: 1, + occupied_seats: 1, + scoped_effective_has_funds: { agent: false }, + scoped_has_funds: { agent: false }, + scheduled_change: null, + next_charge: null, + subscription_state: 'never_subscribed', + subscription_tier: 'FREE', + ended_at: null, + team_credit_stop: null +} satisfies BillingStatusResponse diff --git a/browser_tests/tests/agent/agentPaywallPlanNote.spec.ts b/browser_tests/tests/agent/agentPaywallPlanNote.spec.ts index 4b51510d295..80a8e0cd208 100644 --- a/browser_tests/tests/agent/agentPaywallPlanNote.spec.ts +++ b/browser_tests/tests/agent/agentPaywallPlanNote.spec.ts @@ -1,102 +1,69 @@ import { expect } from '@playwright/test' import { escapeRegExp } from 'es-toolkit' -import type { Page } from '@playwright/test' -import type { BillingStatusResponse } from '@comfyorg/ingest-types' - -import { zAgentAdmissionError } from '@/workbench/extensions/agent/schemas/agentApiSchema' import enMessages from '@/locales/en/main.json' with { type: 'json' } import { waitForCloudApp } from '@e2e/fixtures/cloudAppFixture' +import { + AGENT_NO_FUNDS_ERROR, + NEVER_SUBSCRIBED_BILLING_STATUS +} from '@e2e/fixtures/data/agent/agentPaywallPlanNote' import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute' import { expectElementScreenshot } from '@e2e/fixtures/utils/screenshotRegion' import { AGENT_COMPOSER_LABEL } from '@e2e/fixtures/utils/agentComposerLabel' import { agentTest } from '@e2e/tests/agent/agentPanelMocks' -// A Cloud owner with no plan can buy credits for the agent, but those credits -// do not run workflows. The agent's Out of credits card must say so before the -// purchase, not after (PM-2273 report #2). - -const NO_FUNDS_ERROR = zAgentAdmissionError.parse({ - error: { - message: - 'This workspace is out of funds. Add credits or subscribe to keep going.', - reason: 'no_funds', - type: 'PAYMENT_REQUIRED' - } -}) - -const NO_PLAN_STATUS = { - billing_rail: 'stripe', - billing_status: 'inactive', - has_funds: false, - is_active: false, - max_seats: 1, - occupied_seats: 1, - scoped_effective_has_funds: { agent: false }, - scoped_has_funds: { agent: false }, - scheduled_change: null, - next_charge: null, - subscription_state: 'never_subscribed', - subscription_tier: 'FREE', - ended_at: null, - team_credit_stop: null -} satisfies BillingStatusResponse - -async function showPaywall(page: Page) { - const panel = page.locator('#agent-panel-root') - await panel - .getByRole('button', { name: enMessages.agent.switchWorkflow }) - .click() - await page - .getByRole('menuitemradio', { name: 'Unsaved Workflow', exact: true }) - .click() - - await page.route('**/api/agent/threads/*/messages', async (route) => { - if (route.request().method() !== 'POST') return route.fallback() - await route.fulfill({ - status: 402, - contentType: 'application/json', - body: JSON.stringify(NO_FUNDS_ERROR) - }) - }) - - await panel - .getByRole('textbox', { name: AGENT_COMPOSER_LABEL }) - .fill('Make a red fox in the snow') - await panel.getByRole('button', { name: enMessages.agent.send }).click() - - const card = panel - .getByRole('alert') - .filter({ hasText: enMessages.agent.paywall.title }) - await expect(card).toBeVisible() - return card -} +const { planRequiredFreeRuns, planRequiredSubscribe } = enMessages.credits.topUp agentTest.describe( 'Agent paywall for an account without a plan', { tag: ['@cloud', '@ui'] }, () => { + agentTest.beforeEach(async ({ page, agentPanel }) => { + await page.route('**/api/billing/status', (route) => + route.fulfill(jsonRoute(NEVER_SUBSCRIBED_BILLING_STATUS)) + ) + await page.route('**/api/agent/threads/*/messages', (route) => + route.request().method() === 'POST' + ? route.fulfill({ ...jsonRoute(AGENT_NO_FUNDS_ERROR), status: 402 }) + : route.fallback() + ) + await page.reload() + await waitForCloudApp(page) + await agentPanel.open() + }) + agentTest( 'says buying credits does not start a Cloud plan', { tag: '@screenshot' }, - async ({ page, agentPanel }) => { - await page.route('**/api/billing/status', (route) => - route.fulfill(jsonRoute(NO_PLAN_STATUS)) - ) - await page.reload() - await waitForCloudApp(page) - - await agentPanel.open() - const card = await showPaywall(page) + async ({ page }) => { + const panel = page.locator('#agent-panel-root') + await panel + .getByRole('button', { name: enMessages.agent.switchWorkflow }) + .click() + await page + .getByRole('menuitemradio', { name: 'Unsaved Workflow', exact: true }) + .click() + await panel + .getByRole('textbox', { name: AGENT_COMPOSER_LABEL }) + .fill('Make a red fox in the snow') + await panel.getByRole('button', { name: enMessages.agent.send }).click() + const card = panel + .getByRole('alert') + .filter({ hasText: enMessages.agent.paywall.title }) + await expect(card).toBeVisible() await expect( card.getByRole('button', { name: enMessages.agent.paywall.addCredits }) ).toBeVisible() - const { planRequiredFreeRuns, planRequiredSubscribe } = - enMessages.credits.topUp + await expect( + card.getByRole('button', { + name: enMessages.agent.paywall.subscribe, + exact: true + }) + ).toBeVisible() await expect(card.getByTestId('agent-paywall-plan-note')).toHaveText( new RegExp( `^(${escapeRegExp(planRequiredFreeRuns)}|${escapeRegExp(planRequiredSubscribe)})$` diff --git a/src/workbench/extensions/agent/components/agent/message/AgentPausedCard.test.ts b/src/workbench/extensions/agent/components/agent/message/AgentPausedCard.test.ts index 1f3bd2d65a2..cdd821be5d3 100644 --- a/src/workbench/extensions/agent/components/agent/message/AgentPausedCard.test.ts +++ b/src/workbench/extensions/agent/components/agent/message/AgentPausedCard.test.ts @@ -106,6 +106,40 @@ describe('AgentPausedCard', () => { } ) + it('says credits do not start a Cloud plan on a no-funds pause without a plan', () => { + render(AgentPausedCard, { + props: { + part: pausedPart(), + presentation: { + kind: 'subscribed', + showUpgrade: false, + planCreditLine: 'planRequiredSubscribe' + } + }, + global: { plugins: [i18n] } + }) + + expect(screen.getByTestId('agent-paywall-plan-note')).toHaveTextContent( + "Buying credits doesn't start a Cloud plan. Subscribe to run workflows on Cloud." + ) + }) + + it('keeps the plan note off a pause that is not about credits', () => { + render(AgentPausedCard, { + props: { + part: pausedPart({ reason: 'other' }), + presentation: { + kind: 'subscribed', + showUpgrade: false, + planCreditLine: 'planRequiredSubscribe' + } + }, + global: { plugins: [i18n] } + }) + + expect(screen.queryByTestId('agent-paywall-plan-note')).toBeNull() + }) + it('drops the recheck line when the server names no window', () => { render(AgentPausedCard, { props: { part: pausedPart({ recheckAfterSeconds: 0 }) }, diff --git a/src/workbench/extensions/agent/components/agent/message/AgentPausedCard.vue b/src/workbench/extensions/agent/components/agent/message/AgentPausedCard.vue index 2588756b2b0..6f50b7bcb42 100644 --- a/src/workbench/extensions/agent/components/agent/message/AgentPausedCard.vue +++ b/src/workbench/extensions/agent/components/agent/message/AgentPausedCard.vue @@ -8,6 +8,7 @@ import { cn } from '@comfyorg/tailwind-utils' import type { PausedPart } from '@/workbench/extensions/agent/services/agent/agentMessageParts' import { NO_FUNDS_PAUSE_REASON } from '@/workbench/extensions/agent/services/agent/agentMessageParts' +import AgentPaywallPlanNote from '@/workbench/extensions/agent/components/agent/message/AgentPaywallPlanNote.vue' import type { AgentPaywallPresentation, AgentPaywallRemediation @@ -75,6 +76,7 @@ const body = computed(() => part.message || part.prompt)

{{ body }}

+

{ expect( screen.getByRole('button', { name: 'Add credits' }) ).toBeInTheDocument() + expect( + screen.getByRole('button', { name: 'Subscribe' }) + ).toBeInTheDocument() + expect(screen.queryByRole('button', { name: 'Upgrade plan' })).toBeNull() } ) diff --git a/src/workbench/extensions/agent/components/agent/message/AgentPaywallCard.vue b/src/workbench/extensions/agent/components/agent/message/AgentPaywallCard.vue index 898b679c394..99188db3914 100644 --- a/src/workbench/extensions/agent/components/agent/message/AgentPaywallCard.vue +++ b/src/workbench/extensions/agent/components/agent/message/AgentPaywallCard.vue @@ -3,8 +3,8 @@ import Card from '@comfyorg/design-system/card/Card' import { computed } from 'vue' import Button from '@comfyorg/design-system/button/Button' -import { TOP_UP_PLAN_CREDIT_LINE_KEYS } from '@/platform/billing/composables/useTopUpPlanCreditCopy' +import AgentPaywallPlanNote from '@/workbench/extensions/agent/components/agent/message/AgentPaywallPlanNote.vue' import { DEFAULT_AGENT_PAYWALL_PRESENTATION, toAgentPaywallRemediation @@ -31,20 +31,19 @@ const bodyKeys: Record = { local: 'agent.paywall.body.local', unavailable: 'agent.paywall.body.subscriptionRequired' } -const planNoteKey = computed(() => - presentation.kind === 'subscribed' && presentation.planCreditLine - ? TOP_UP_PLAN_CREDIT_LINE_KEYS[presentation.planCreditLine] - : null +const hasNoPlan = computed( + () => presentation.kind === 'subscribed' && !!presentation.planCreditLine ) -// Without a plan there are no monthly credits to have spent. const bodyKey = computed(() => - planNoteKey.value ? bodyKeys.local : bodyKeys[presentation.kind] + hasNoPlan.value ? bodyKeys.local : bodyKeys[presentation.kind] ) const showUpgrade = computed( () => presentation.kind === 'subscribed' && presentation.showUpgrade ) const remediation = computed(() => toAgentPaywallRemediation(presentation)) -const showSubscribe = computed(() => remediation.value === 'subscribe') +const showSubscribe = computed( + () => remediation.value === 'subscribe' || hasNoPlan.value +) const showAddCredits = computed(() => remediation.value === 'addCredits') @@ -66,13 +65,7 @@ const showAddCredits = computed(() => remediation.value === 'addCredits')

{{ message || $t(bodyKey) }}

-

- {{ $t(planNoteKey) }} -

+ @@ -90,7 +83,7 @@ const showAddCredits = computed(() => remediation.value === 'addCredits')