Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6353dd6
feat(billing): route local billing reads to cloud ingest
MaanilVerma Aug 19, 2026
1257a7d
feat(billing): fetch live plans for the local plans section
MaanilVerma Aug 19, 2026
3c462c8
merge: bring S0 review fixes into S1
MaanilVerma Aug 19, 2026
f431856
test(billing): isolate ingest env override and assert plan loading vi…
MaanilVerma Aug 19, 2026
90a3eeb
refactor(billing): trim verbose comments to crisp one-liners
MaanilVerma Aug 20, 2026
8d541fb
Merge remote-tracking branch 'origin/maanil/fe-1600-s0-local-plan-car…
MaanilVerma Aug 20, 2026
bd5b210
Merge remote-tracking branch 'origin/main' into maanil/fe-1600-s1-ing…
MaanilVerma Aug 24, 2026
6084b11
refactor(billing): export the shared video-per-credit ratio
MaanilVerma Aug 24, 2026
63df8a5
feat(billing): make the API catalog the source of truth for the plans…
MaanilVerma Aug 24, 2026
9be5125
refactor(billing): drop the redundant team-stop re-snap and cover the…
MaanilVerma Aug 24, 2026
f7e82a8
fix(billing): announce the plans-unavailable error to assistive tech
MaanilVerma Aug 24, 2026
9c3fd5c
Merge branch 'maanil/fe-1600-s0-local-plan-cards' into maanil/fe-1600…
MaanilVerma Aug 25, 2026
47b312f
fix(billing): distinguish empty from failed catalog and stop card fla…
MaanilVerma Aug 25, 2026
7456e14
test(billing): drop comments that restate the hardening test titles
MaanilVerma Aug 25, 2026
07234ac
Merge branch 'maanil/fe-1600-s0-local-plan-cards' into maanil/fe-1600…
MaanilVerma Aug 25, 2026
84334c4
Merge branch 'maanil/fe-1600-s0-local-plan-cards' into maanil/fe-1600…
MaanilVerma Aug 25, 2026
559d53c
Merge remote-tracking branch 'origin/maanil/fe-1600-s0-local-plan-car…
MaanilVerma Aug 26, 2026
2fa2135
fix(billing): drive the local plans state from the workspace bootstrap
MaanilVerma Aug 26, 2026
fbeebc9
fix(billing): surface a failed plans refetch over cached cards
MaanilVerma Aug 26, 2026
ed69eb2
fix(billing): fetch the local catalog through its own state owner
MaanilVerma Aug 26, 2026
11c017f
fix(billing): treat the pre-boot workspace window as loading, not fai…
MaanilVerma Aug 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -2661,11 +2661,18 @@
"settingsPlans": {
"title": "Plans",
"subtitle": "Plans run on Comfy Cloud and their credits work on this install too.",
"personal": "Personal",
"teams": "Teams",
"billedYearlyToggle": "Billed yearly",
"creditsAYear": "{credits} credits a year",
"creditsAMonth": "{credits} credits a month",
"perDollar": "{credits} per dollar",
"choosePlan": "Choose {tier}"
"choosePlan": "Choose {tier}",
"noPlansAvailable": "No plans are available right now. Check back soon.",
"creditsPerMonth": "{credits} credits per month",
"comingSharedWorkflows": "Shared workflows & assets",
"comingProjects": "Projects",
"enterpriseCopy": "Need more members? Looking for more flexibility or custom features?"
},
"credits": {
"activity": "Activity",
Expand Down Expand Up @@ -2882,6 +2889,7 @@
"whatsIncluded": "What's included:",
"planLoadError": "We couldn't load your plan details.",
"planLoadErrorRetry": "Try again",
"planLoadErrorStale": "We couldn't refresh your plan details. These prices may be out of date.",
"teamPlanName": "Team",
"teamPlanIncludes": "Your plan includes everything in {plan}, plus:",
"inactiveTeamTitle": "Inactive team subscription",
Expand Down
8 changes: 8 additions & 0 deletions src/platform/cloud/subscription/constants/tierPricing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ export const TIER_PRICING: Record<
pro: { monthly: 100, yearly: 80, credits: 21100, videoEstimate: 1915 }
}

/**
* Videos-per-credit ratio, constant across tiers. Presentation-only: the
* "~N 5s videos" estimate is derived from an API credit grant times this ratio,
* so it tracks what is sold rather than pinning a per-tier video count.
*/
export const VIDEO_PER_CREDIT =
TIER_PRICING.pro.videoEstimate / TIER_PRICING.pro.credits

interface TierFeatures {
customLoRAs: boolean
maxMembers: number
Expand Down
6 changes: 1 addition & 5 deletions src/platform/workspace/components/UnifiedPricingTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ import CreditSlider from '@/components/ui/credit-slider/CreditSlider.vue'
import { useBillingContext } from '@/composables/billing/useBillingContext'
import {
TIER_PRICING,
VIDEO_PER_CREDIT,
hasActivePaidPlan,
toTierKey
} from '@/platform/cloud/subscription/constants/tierPricing'
Expand Down Expand Up @@ -503,11 +504,6 @@ const QUESTIONS_URL = 'https://portal.usepylon.com/comfy-org/forms/question'
const ENTERPRISE_URL = 'https://www.comfy.org/enterprise'
const PRICING_URL = 'https://www.comfy.org/pricing'

/** Videos-per-credit ratio is constant across tiers; reuse it for the team
* plan's template-based estimate until the BE carries a team figure. */
const VIDEO_PER_CREDIT =
TIER_PRICING.pro.videoEstimate / TIER_PRICING.pro.credits

interface BillingCycleOption {
label: string
value: BillingCycle
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,302 @@
import userEvent from '@testing-library/user-event'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { createI18n } from 'vue-i18n'

import { ref } from 'vue'

import { render, screen, waitFor } from '@testing-library/vue'

import enMessages from '@/locales/en/main.json'
import { useBillingPlans } from '@/platform/cloud/subscription/composables/useBillingPlans'
import type {
BillingPlansResponse,
Plan
} from '@/platform/workspace/api/workspaceApi'

import PlanCreditsPanelContent from './PlanCreditsPanelContent.vue'

// The panel's real defect was a routing one: it fetched through
// useBillingContext (which lands on the legacy no-op before the workspace
// hydrates) while reading state from the useBillingPlans singleton that only
// the workspace adapter writes. These tests therefore run the REAL
// useBillingContext / useBillingRouting / useBillingPlans and mock only what
// this repo owns at its edges: the HTTP client and the workspace store's state.

type InitState = 'uninitialized' | 'loading' | 'ready' | 'error'

const workspace = vi.hoisted(() => ({
initialize: vi.fn(async () => {})
}))

// Reactive so a bootstrap that resolves mid-test re-drives the panel exactly as
// the real store would.
const state = {
initState: ref<InitState>('ready'),
error: ref<Error | null>(null),
active: ref<{ id: string; type: string } | null>({
id: 'ws-1',
type: 'personal'
})
}

const api = vi.hoisted(() => ({
getBillingPlans: vi.fn(),
getBillingStatus: vi.fn(async () => ({
is_active: false,
has_funds: true,
team_credit_stop: null
})),
getBillingBalance: vi.fn(async () => ({ amount_micros: 0 }))
}))

vi.mock('@/platform/distribution/types', () => ({ isCloud: false }))

// Siblings of the plans section; irrelevant here and each drags in the app graph.
vi.mock('@/components/dialog/content/setting/CreditsPanel.vue', () => ({
default: { template: '<section />' }
}))
vi.mock('@/components/dialog/content/setting/UsageLogsTable.vue', () => ({
default: { template: '<section />', methods: { refresh: () => {} } }
}))
vi.mock(
'@/platform/cloud/subscription/components/SubscriptionFooterLinks.vue',
() => ({ default: { template: '<footer />' } })
)
vi.mock(
'@/platform/workspace/components/SubscriptionPanelContentWorkspace.vue',
() => ({ default: { template: '<section />' } })
)

// The legacy adapter itself stays REAL — its no-op fetchPlans is the mechanism
// under test — but its Firebase-backed collaborators are stubbed out.
vi.mock('@/platform/cloud/subscription/composables/useSubscription', () => ({
useSubscription: () => ({
canAccessSubscriptionFeatures: ref(false),
subscriptionTier: ref(null),
subscriptionDuration: ref(null),
subscriptionStatus: ref(null),
isCancelled: ref(false),
fetchStatus: vi.fn(async () => {}),
manageSubscription: vi.fn(),
subscribe: vi.fn(),
subscribeDirect: vi.fn(),
showSubscriptionDialog: vi.fn()
})
}))
vi.mock('@/stores/authStore', () => ({
useAuthStore: () => ({ isLoggedIn: ref(true), balance: ref(null) })
}))
vi.mock('@/composables/auth/useAuthActions', () => ({
useAuthActions: () => ({ purchaseCredits: vi.fn(), fetchBalance: vi.fn() })
}))

vi.mock('@/platform/workspace/api/workspaceApi', () => ({
workspaceApi: api,
WorkspaceApiError: class extends Error {}
}))

vi.mock('@/platform/workspace/stores/teamWorkspaceStore', () => ({
useTeamWorkspaceStore: () => ({
get initState() {
return state.initState.value
},
get error() {
return state.error.value
},
get activeWorkspace() {
return state.active.value
},
get activeWorkspaceBillingRail() {
return undefined
},
get isPersonalWorkspace() {
return true
},
initialize: workspace.initialize,
updateActiveWorkspace: vi.fn(),
setWorkspaceBillingRail: vi.fn()
})
}))

function makePlan(
tier: Plan['tier'],
duration: Plan['duration'],
price_cents: number,
credits_cents: number
): Plan {
return {
slug: `${tier.toLowerCase()}-${duration.toLowerCase()}`,
tier,
duration,
price_cents,
credits_cents,
max_seats: 1,
availability: { available: true },
seat_summary: {
seat_count: 1,
total_cost_cents: price_cents,
total_credits_cents: credits_cents
}
}
}

const CATALOG: BillingPlansResponse = {
plans: [makePlan('STANDARD', 'ANNUAL', 24000, 50400)]
}

function renderPanel() {
const i18n = createI18n({
legacy: false,
locale: 'en',
messages: { en: enMessages }
})
return render(PlanCreditsPanelContent, { global: { plugins: [i18n] } })
}

const EMPTY_COPY = 'No plans are available right now. Check back soon.'
const ERROR_COPY = "We couldn't load your plan details."

// useBillingPlans is a module singleton; reset the state each test rather than
// resetting the module graph (a fresh graph deadlocks on the workspace).
beforeEach(() => {
const billingPlans = useBillingPlans()
billingPlans.plans.value = []
billingPlans.teamCreditStops.value = null
billingPlans.currentPlanSlug.value = null
billingPlans.isLoading.value = false
billingPlans.error.value = null

state.initState.value = 'ready'
state.error.value = null
state.active.value = { id: 'ws-1', type: 'personal' }
workspace.initialize.mockReset()
workspace.initialize.mockImplementation(async () => {})
api.getBillingPlans.mockReset()
api.getBillingPlans.mockResolvedValue(CATALOG)
})

describe('PlanCreditsPanelContent — workspace bootstrap drives the plans state', () => {
it('shows the loading state until the workspace hydrates, then the catalog', async () => {
state.initState.value = 'loading'
state.active.value = null

renderPanel()

expect(await screen.findByText('Loading')).toBeTruthy()
expect(screen.queryAllByText(EMPTY_COPY)).toHaveLength(0)
expect(api.getBillingPlans).not.toHaveBeenCalled()

state.initState.value = 'ready'
state.active.value = { id: 'ws-1', type: 'personal' }

expect(await screen.findByText('$20')).toBeTruthy()
expect(screen.getByText('50,400')).toBeTruthy()
expect(screen.queryByText('Loading')).toBeNull()
expect(api.getBillingPlans).toHaveBeenCalledOnce()
})

it('treats the pre-boot uninitialized window as loading, not failure', async () => {
// WorkspaceAuthGate awaits Firebase before it calls initialize(), so a panel
// mounted in that window sees 'uninitialized' with no workspace.
state.initState.value = 'uninitialized'
state.active.value = null

renderPanel()

expect(await screen.findByText('Loading')).toBeTruthy()
expect(screen.queryAllByText(ERROR_COPY)).toHaveLength(0)
expect(screen.queryAllByText(EMPTY_COPY)).toHaveLength(0)
expect(screen.queryByRole('button', { name: 'Try again' })).toBeNull()
expect(api.getBillingPlans).not.toHaveBeenCalled()

state.initState.value = 'loading'
expect(await screen.findByText('Loading')).toBeTruthy()
expect(api.getBillingPlans).not.toHaveBeenCalled()

state.initState.value = 'ready'
state.active.value = { id: 'ws-1', type: 'personal' }

expect(await screen.findByText('$20')).toBeTruthy()
expect(api.getBillingPlans).toHaveBeenCalledOnce()
})

it('shows a retryable error when the workspace bootstrap failed, and recovers', async () => {
state.initState.value = 'error'
state.error.value = new Error('workspaces unavailable')
state.active.value = null

renderPanel()

expect((await screen.findAllByText(ERROR_COPY)).length).toBeGreaterThan(0)
expect(screen.queryAllByText(EMPTY_COPY)).toHaveLength(0)

// Retry re-runs the workspace bootstrap; the billing context's workspace
// watch is what then fetches the catalog.
workspace.initialize.mockImplementation(async () => {
state.initState.value = 'ready'
state.active.value = { id: 'ws-1', type: 'personal' }
})

await userEvent.click(
screen.getAllByRole('button', { name: 'Try again' })[0]
)

expect(workspace.initialize).toHaveBeenCalledOnce()
await waitFor(() =>
expect(screen.getAllByText('$20').length).toBeGreaterThan(0)
)
})

it('retries the bootstrap when the wallet resolved to no workspace at all', async () => {
// 'ready' with no workspace should be impossible, but it must surface as a
// retryable error rather than spinning forever.
state.initState.value = 'ready'
state.active.value = null

renderPanel()

expect((await screen.findAllByText(ERROR_COPY)).length).toBeGreaterThan(0)

workspace.initialize.mockImplementation(async () => {
state.active.value = { id: 'ws-1', type: 'personal' }
})
await userEvent.click(
screen.getAllByRole('button', { name: 'Try again' })[0]
)

expect(workspace.initialize).toHaveBeenCalledOnce()
await waitFor(() =>
expect(screen.getAllByText('$20').length).toBeGreaterThan(0)
)
})

it('shows the empty state without a retry for a successful but empty catalog', async () => {
api.getBillingPlans.mockResolvedValue({ plans: [] })

renderPanel()

expect((await screen.findAllByText(EMPTY_COPY)).length).toBeGreaterThan(0)
expect(screen.queryByText(ERROR_COPY)).toBeNull()
expect(screen.queryByRole('button', { name: 'Try again' })).toBeNull()
})

it('shows a retryable error when the catalog fetch fails, and recovers', async () => {
vi.spyOn(console, 'error').mockImplementation(() => undefined)
api.getBillingPlans.mockRejectedValueOnce(new Error('plans exploded'))

renderPanel()

expect((await screen.findAllByText(ERROR_COPY)).length).toBeGreaterThan(0)
expect(screen.queryAllByText(EMPTY_COPY)).toHaveLength(0)

await userEvent.click(
screen.getAllByRole('button', { name: 'Try again' })[0]
)

await waitFor(() =>
expect(screen.getAllByText('$20').length).toBeGreaterThan(0)
)
// Retry re-fetches the catalog rather than re-running the bootstrap.
expect(workspace.initialize).not.toHaveBeenCalled()
})
})
Loading
Loading