diff --git a/browser_tests/fixtures/workspaceRailAuthFixture.ts b/browser_tests/fixtures/workspaceRailAuthFixture.ts new file mode 100644 index 00000000000..6b2af32b8b5 --- /dev/null +++ b/browser_tests/fixtures/workspaceRailAuthFixture.ts @@ -0,0 +1,77 @@ +import { test as base } from '@playwright/test' + +import type { operations } from '@/types/comfyRegistryTypes' +import { ComfyPage } from '@e2e/fixtures/ComfyPage' +import { + createSubscriptionHelper, + withUnsubscribed +} from '@e2e/fixtures/helpers/SubscriptionHelper' +import type { SubscriptionOperator } from '@e2e/fixtures/helpers/SubscriptionHelper' +import { mockWorkspace, workspace } from '@e2e/fixtures/utils/workspaceMocks' + +type CreateCustomerResponse = + operations['createCustomer']['responses']['201']['content']['application/json'] + +// The subscription fixture pins billing_rail to legacy_stripe, which routes +// local billing through the legacy rail and its Local exemption from the +// subscription gate. The 1.51 QA finding #11 (no way to add credits without +// an active subscription) only reproduces on the workspace rail, so this +// fixture overrides the rail; localAuthFixture keeps the legacy-rail +// coverage. +const onWorkspaceRail: SubscriptionOperator = (config) => ({ + ...config, + status: { ...config.status, billing_rail: 'stripe' } +}) + +/** + * Boots the local (non-Cloud) build as a logged-in unsubscribed workspace + * owner on the workspace billing rail. See localAuthFixture for the boot + * ordering constraints this mirrors. + */ +export const workspaceRailAuthFixture = base.extend<{ comfyPage: ComfyPage }>({ + comfyPage: async ({ page, request }, use, testInfo) => { + testInfo.setTimeout(45_000) + + const comfyPage = new ComfyPage(page, request) + const userId = await comfyPage.setupUser( + `playwright-workspace-rail-${testInfo.parallelIndex}` + ) + await comfyPage.setupSettings({ + 'Comfy.TutorialCompleted': true, + 'Comfy.userId': userId + }) + + await comfyPage.cloudAuth.mockAuth() + await mockWorkspace(page, workspace('personal', 'owner'), []) + await page.route('**/customers', (route) => + route.fulfill({ + status: 201, + json: { id: 'test-user-e2e' } satisfies CreateCustomerResponse + }) + ) + await page.route('**/api/billing/balance', (route) => + route.fulfill({ + json: { amount_micros: 0, currency: 'usd', effective_balance_micros: 0 } + }) + ) + const subscriptionHelper = createSubscriptionHelper( + page, + withUnsubscribed(), + onWorkspaceRail + ) + await subscriptionHelper.mock() + + await page.evaluate((id) => { + localStorage.clear() + sessionStorage.clear() + localStorage.setItem('Comfy.userId', id) + }, userId) + + await comfyPage.goto() + await page.waitForFunction(() => document.fonts.ready) + await comfyPage.waitForAppReady() + + await use(comfyPage) + await subscriptionHelper.clearMocks() + } +}) diff --git a/browser_tests/tests/localCreditsWorkspaceRail.spec.ts b/browser_tests/tests/localCreditsWorkspaceRail.spec.ts new file mode 100644 index 00000000000..9985f5a2f51 --- /dev/null +++ b/browser_tests/tests/localCreditsWorkspaceRail.spec.ts @@ -0,0 +1,55 @@ +import { expect } from '@playwright/test' + +import { TopUpCreditsDialog } from '@e2e/fixtures/components/TopUpCreditsDialog' +import { TestIds } from '@e2e/fixtures/selectors' +import { workspaceRailAuthFixture as test } from '@e2e/fixtures/workspaceRailAuthFixture' + +/** + * Regression coverage for 1.51 QA finding #11: on a local (non-Cloud) + * distribution, a workspace without an active subscription had no way to add + * credits — the subscribe CTA is hidden on Local and both Add credits entry + * points were gated on an active subscription. Only reproduces on the + * workspace billing rail; localCreditsNoSubscribeUi.spec.ts covers the + * legacy rail. + */ +test.describe('Local credits surfaces on the workspace billing rail', () => { + test('lets an unsubscribed workspace owner reach the top-up dialog', async ({ + comfyPage + }) => { + const page = comfyPage.page + const topUpDialog = new TopUpCreditsDialog(page) + + await page.getByTestId(TestIds.user.currentUserButton).click() + const popover = page.getByTestId(TestIds.user.currentUserPopover) + await expect(popover).toBeVisible() + await expect(popover.getByTestId('add-credits-button')).toBeVisible() + await expect( + popover.getByTestId('upgrade-to-add-credits-button') + ).toHaveCount(0) + await expect( + popover.getByRole('button', { name: 'Subscribe', exact: true }) + ).toHaveCount(0) + + await popover.getByTestId('add-credits-button').click() + await expect(topUpDialog.heading).toBeVisible() + await topUpDialog.close() + + await page.getByTestId(TestIds.user.currentUserButton).click() + await page + .getByTestId(TestIds.user.currentUserPopover) + .getByTestId('plans-credits-menu-item') + .click() + + const settingsDialog = comfyPage.settingDialog + await settingsDialog.waitForVisible() + const settingsAddCredits = settingsDialog.contentArea.getByRole('button', { + name: 'Add credits' + }) + await expect(settingsAddCredits).toBeVisible() + await expect( + settingsDialog.contentArea.getByText('Upgrade to add credits') + ).toHaveCount(0) + await settingsAddCredits.click() + await expect(topUpDialog.heading).toBeVisible() + }) +}) diff --git a/src/platform/cloud/subscription/components/CreditsTile.test.ts b/src/platform/cloud/subscription/components/CreditsTile.test.ts index d5a7f8bbb62..df4532a42aa 100644 --- a/src/platform/cloud/subscription/components/CreditsTile.test.ts +++ b/src/platform/cloud/subscription/components/CreditsTile.test.ts @@ -367,6 +367,27 @@ describe('CreditsTile', () => { expect(screen.queryByText('Add credits')).toBeNull() }) + it('keeps add-credits available on local without an active subscription', async () => { + mockIsCloud.value = false + state.canAccessSubscriptionFeatures = false + state.balance = { amountMicros: 500 } + renderTile() + expect(screen.queryByText('Upgrade to add credits')).toBeNull() + await userEvent.click(screen.getByText('Add credits')) + expect(state.showTopUpCreditsDialog).toHaveBeenCalledOnce() + }) + + it('keeps add-credits available on local for an unsubscribed team workspace', async () => { + mockIsCloud.value = false + state.canAccessSubscriptionFeatures = false + state.isTeamPlan = true + state.balance = { amountMicros: 500 } + renderTile() + expect(screen.queryByText('Upgrade to add credits')).toBeNull() + await userEvent.click(screen.getByText('Add credits')) + expect(state.showTopUpCreditsDialog).toHaveBeenCalledOnce() + }) + it('shows no depletion notice or in-use badge while monthly credits remain', () => { activeProSubscription() const { container } = renderTile() diff --git a/src/platform/cloud/subscription/components/CreditsTile.vue b/src/platform/cloud/subscription/components/CreditsTile.vue index d6ca23d08ca..387b93b3eab 100644 --- a/src/platform/cloud/subscription/components/CreditsTile.vue +++ b/src/platform/cloud/subscription/components/CreditsTile.vue @@ -370,7 +370,9 @@ const showBar = computed( // including local/desktop) accounts have no workspace concept to gate on. const showActionButton = computed( () => - canAccessSubscriptionFeatures.value && + (billingPolicyCapabilities.value.topUpAccess === 'allowed' || + (billingPolicyCapabilities.value.showsSubscribeUpsellUI && + canAccessSubscriptionFeatures.value)) && !zeroState && !inactivePlan && (type.value !== 'workspace' || permissions.value.canTopUp) diff --git a/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts b/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts index 98328d9a6ea..d98332e75bc 100644 --- a/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts +++ b/src/platform/workspace/components/CurrentUserPopoverWorkspace.test.ts @@ -16,6 +16,8 @@ const state = vi.hoisted(() => ({ billingStatus: 'paid', canAccessSubscriptionFeatures: true, isFreeTier: false, + isTeamPlan: false, + tier: 'PRO' as 'PRO' | 'FREE' | null, isCancelled: false, planSlug: 'pro-monthly' as string | null, canTopUp: false, @@ -61,6 +63,8 @@ vi.mock('@/composables/billing/useBillingContext', () => ({ () => state.canAccessSubscriptionFeatures ), isFreeTier: computed(() => state.isFreeTier), + isTeamPlan: computed(() => state.isTeamPlan), + tier: computed(() => state.tier), subscription: computed(() => ({ isCancelled: state.isCancelled, planSlug: state.planSlug @@ -177,6 +181,8 @@ describe('CurrentUserPopoverWorkspace', () => { state.billingStatus = 'paid' state.canAccessSubscriptionFeatures = true state.isFreeTier = false + state.isTeamPlan = false + state.tier = 'PRO' state.isCancelled = false state.planSlug = 'pro-monthly' state.canTopUp = false @@ -343,6 +349,67 @@ describe('CurrentUserPopoverWorkspace', () => { ).not.toBeInTheDocument() }) + it('lets an owner add credits on Local without an active subscription', async () => { + const user = userEvent.setup() + state.isCloud = false + state.canAccessSubscriptionFeatures = false + state.tier = null + state.canTopUp = true + + renderComponent('personal') + + expect( + screen.queryByTestId('upgrade-to-add-credits-button') + ).not.toBeInTheDocument() + await user.click(screen.getByTestId('add-credits-button')) + + expect(state.showTopUpCreditsDialog).toHaveBeenCalledOnce() + }) + + it('keeps add-credits hidden for an unsubscribed Cloud owner', () => { + state.canAccessSubscriptionFeatures = false + state.tier = null + state.canTopUp = true + state.canManageSubscription = true + + renderComponent('personal') + + expect(screen.queryByTestId('add-credits-button')).not.toBeInTheDocument() + expect( + screen.queryByTestId('upgrade-to-add-credits-button') + ).not.toBeInTheDocument() + expect( + screen.getByRole('button', { name: 'Subscribe' }) + ).toBeInTheDocument() + }) + + it('offers add-credits instead of the upgrade upsell on the Local free tier', () => { + state.isCloud = false + state.isFreeTier = true + state.tier = 'FREE' + state.canTopUp = true + + renderComponent('personal') + + expect( + screen.queryByTestId('upgrade-to-add-credits-button') + ).not.toBeInTheDocument() + expect(screen.getByTestId('add-credits-button')).toBeInTheDocument() + }) + + it('keeps the upgrade upsell for the Cloud free tier', () => { + state.isFreeTier = true + state.tier = 'FREE' + state.canTopUp = true + + renderComponent('personal') + + expect( + screen.getByTestId('upgrade-to-add-credits-button') + ).toBeInTheDocument() + expect(screen.queryByTestId('add-credits-button')).not.toBeInTheDocument() + }) + it('keeps Resubscribe hidden on Local for a cancelled plan', () => { state.isCloud = false state.isCancelled = true diff --git a/src/platform/workspace/components/CurrentUserPopoverWorkspace.vue b/src/platform/workspace/components/CurrentUserPopoverWorkspace.vue index 3b6b53bc063..f759dadff28 100644 --- a/src/platform/workspace/components/CurrentUserPopoverWorkspace.vue +++ b/src/platform/workspace/components/CurrentUserPopoverWorkspace.vue @@ -91,7 +91,9 @@