Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions browser_tests/fixtures/ComfyPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ import {
TOUR_SEEN_SETTING
} from '@/platform/onboarding/onboardingTours'
import { NodeBadgeMode } from '@/types/nodeSource'
import {
EMPTY_BILLING_BALANCE,
EMPTY_BILLING_PLANS,
LEGACY_PERSONAL_BILLING_STATUS
} from '@e2e/fixtures/data/cloudWorkspace'
import {
UNSUBSCRIBED,
ZERO_BALANCE
} from '@e2e/fixtures/data/subscriptionFixtures'
import { ComfyActionbar } from '@e2e/fixtures/components/Actionbar'
import { ComfyTemplates } from '@e2e/fixtures/components/Templates'
import { ComfyMouse } from '@e2e/fixtures/ComfyMouse'
Expand Down Expand Up @@ -569,6 +578,21 @@ export const comfyPageFixture = base.extend<{
await context.route('**/api/auth/session', (route) =>
route.fulfill({ status: 204 })
)
await context.route('**/api/billing/status', (route) =>
route.fulfill({ json: LEGACY_PERSONAL_BILLING_STATUS })
)
await context.route('**/api/billing/balance', (route) =>
route.fulfill({ json: EMPTY_BILLING_BALANCE })
)
await context.route('**/api/billing/plans', (route) =>
route.fulfill({ json: EMPTY_BILLING_PLANS })
)
await context.route('**/customers/cloud-subscription-status', (route) =>
route.fulfill({ json: UNSUBSCRIBED })
)
await context.route('**/customers/balance', (route) =>
route.fulfill({ json: ZERO_BALANCE })
)
await mockWorkspace(context, workspace('personal', 'owner'), [])
await comfyPage.cloudAuth.mockAuth()
}
Expand Down
33 changes: 28 additions & 5 deletions browser_tests/fixtures/data/cloudWorkspace.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { BillingStatusResponse as IngestBillingStatusResponse } from '@comfyorg/ingest-types'
import type {
BillingBalanceResponse,
BillingPlansResponse,
BillingStatusResponse as IngestBillingStatusResponse
} from '@comfyorg/ingest-types'

import type {
Member,
Expand All @@ -7,13 +11,32 @@ import type {
} from '@/platform/workspace/api/workspaceApi'
import type { RemoteConfig } from '@/platform/remoteConfig/types'

// `/api/features` is the remote-config source: production builds resolve the
// workspaces flag from it (the `ff:` localStorage override is dev-only).
export const WORKSPACE_FEATURE_FLAG: RemoteConfig = {
team_workspaces_enabled: true,
export const CLOUD_REMOTE_CONFIG: RemoteConfig = {
consolidated_billing_enabled: true
}

export const LEGACY_PERSONAL_BILLING_STATUS = {
billing_rail: 'legacy_stripe',
billing_status: 'inactive',
has_funds: true,
is_active: false,
max_seats: 1,
occupied_seats: 1,
subscription_status: 'ended',
subscription_tier: 'FREE',
team_credit_stop: null
} satisfies IngestBillingStatusResponse

export const EMPTY_BILLING_BALANCE = {
amount_micros: 0,
currency: 'usd',
effective_balance_micros: 0
} satisfies BillingBalanceResponse

export const EMPTY_BILLING_PLANS = {
plans: []
} satisfies BillingPlansResponse

export const TEAM_WORKSPACE: WorkspaceWithRole = {
id: 'ws-team',
name: 'Team Comfy',
Expand Down
1 change: 0 additions & 1 deletion browser_tests/fixtures/data/workspaceSwitcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const TEAM_WORKSPACE_NAME = 'Team Workspace'
export const OFF_SCREEN_WORKSPACE_NAME = 'Off-screen Team Workspace'

export const WORKSPACE_SWITCHER_REMOTE_CONFIG: RemoteConfig = {
team_workspaces_enabled: true,
unified_cloud_auth: true
}

Expand Down
6 changes: 3 additions & 3 deletions browser_tests/fixtures/helpers/CloudWorkspaceMockHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import type {

import { mockSystemStats } from '@e2e/fixtures/data/systemStats'
import {
CLOUD_REMOTE_CONFIG,
DEFAULT_TEAM_MEMBERS,
TEAM_BILLING_STATUS,
TEAM_PRO_PLAN,
TEAM_WORKSPACE,
WORKSPACE_FEATURE_FLAG
TEAM_WORKSPACE
} from '@e2e/fixtures/data/cloudWorkspace'
import { CloudAuthHelper } from '@e2e/fixtures/helpers/CloudAuthHelper'
import { mockWorkspaceTokenMint } from '@e2e/fixtures/utils/workspaceMocks'
Expand Down Expand Up @@ -71,7 +71,7 @@ export class CloudWorkspaceMockHelper {
const { page } = this

await page.route('**/api/features', (r) =>
r.fulfill(jsonRoute(WORKSPACE_FEATURE_FLAG))
r.fulfill(jsonRoute(CLOUD_REMOTE_CONFIG))
)
await page.route('**/api/system_stats', (r) =>
r.fulfill(jsonRoute(mockSystemStats))
Expand Down
1 change: 0 additions & 1 deletion browser_tests/fixtures/utils/cloudAppSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export const APP_URL =
// billing surfaces the cloud specs assert; without it they fall back to the
// legacy variants.
const DEFAULT_FEATURES = {
team_workspaces_enabled: true,
consolidated_billing_enabled: true
} satisfies RemoteConfig

Expand Down
2 changes: 2 additions & 0 deletions browser_tests/fixtures/utils/cloudBootMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { RemoteConfig } from '@/platform/remoteConfig/types'
import { mockSystemStats } from '@e2e/fixtures/data/systemStats'
import { CloudAuthHelper } from '@e2e/fixtures/helpers/CloudAuthHelper'
import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute'
import { mockWorkspace, workspace } from '@e2e/fixtures/utils/workspaceMocks'

interface CloudBootOptions {
/** Remote-config payload for `/api/features` (enables the flags under test). */
Expand Down Expand Up @@ -47,6 +48,7 @@ export async function mockCloudBoot(
await page.route('**/api/auth/session', (r) =>
r.fulfill(jsonRoute({ token: 'mock-workspace-token' }))
)
await mockWorkspace(page, workspace('personal', 'owner'), [])
await page.route('**/releases**', (r) => r.fulfill(jsonRoute([])))
}

Expand Down
6 changes: 3 additions & 3 deletions browser_tests/tests/authAccountSwitch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import type { WorkspaceTokenResponse } from '@/platform/workspace/stores/workspa
import { comfyPageFixture as test } from '@e2e/fixtures/ComfyPage'
import { AssetsSidebarTab } from '@e2e/fixtures/components/SidebarTab'
import {
CLOUD_REMOTE_CONFIG,
DEFAULT_TEAM_MEMBERS,
TEAM_WORKSPACE,
WORKSPACE_FEATURE_FLAG
TEAM_WORKSPACE
} from '@e2e/fixtures/data/cloudWorkspace'
import { AssetsHelper, createMockJob } from '@e2e/fixtures/helpers/AssetsHelper'
import { CloudWorkspaceMockHelper } from '@e2e/fixtures/helpers/CloudWorkspaceMockHelper'
Expand Down Expand Up @@ -141,7 +141,7 @@ test.describe('Cloud account switch', { tag: '@cloud' }, () => {
await page.unroute('**/securetoken.googleapis.com/**')

const features = {
...WORKSPACE_FEATURE_FLAG,
...CLOUD_REMOTE_CONFIG,
onboarding_survey_enabled: false,
unified_cloud_auth: false
} satisfies RemoteConfig
Expand Down
100 changes: 66 additions & 34 deletions browser_tests/tests/billingFacadeConsumers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ import {
/**
* Billing facade consumers — FE-933 (B3) regression.
*
* The repointed surfaces (avatar popover tier badge / balance, free-tier
* dialog renewal date) must keep rendering from `useBillingContext`. The facade
* selects its backend by flag: `team_workspaces_enabled: false` routes through
* the legacy `/customers/*` endpoints, while `true` routes a personal workspace
* through the workspace `/api/billing/*` endpoints. Both shapes are mocked here.
* The repointed surfaces (avatar popover balance, free-tier dialog renewal
* date) must keep rendering from `useBillingContext`. Cloud
* personal workspaces route through the workspace `/api/billing/*` endpoints.
* Drives a raw `page` (not the `comfyPage` fixture) so the cloud app boots
* against fully mocked endpoints — same pattern as creditsTile.spec.ts.
*/
Expand Down Expand Up @@ -56,11 +54,24 @@ const mockBalance: BillingBalanceResponse = {
effective_balance_micros: 6000
}

const mockWorkspaceBalance: BillingBalanceResponse = {
amount_micros: 0,
currency: 'usd',
effective_balance_micros: 0
}

async function mockCloudBoot(
page: Page,
subscriptionStatus: CloudSubscriptionStatusResponse,
remoteConfig: RemoteConfig = { team_workspaces_enabled: false }
remoteConfig: RemoteConfig = {},
billingRail?: BillingStatusResponse['billing_rail']
) {
const billingRequests = {
legacyStatus: 0,
legacyBalance: 0,
workspaceStatus: 0
}

await page.route('**/api/features', (r) => r.fulfill(jsonRoute(remoteConfig)))
await page.route('**/api/system_stats', (r) =>
r.fulfill(jsonRoute(mockSystemStats))
Expand Down Expand Up @@ -106,25 +117,34 @@ async function mockCloudBoot(
)
)

// Legacy backend (team_workspaces_enabled: false).
await page.route('**/customers/cloud-subscription-status', (r) =>
r.fulfill(jsonRoute(subscriptionStatus))
)
await page.route('**/customers/balance', (r) =>
r.fulfill(jsonRoute(mockBalance))
)
// Legacy endpoints remain mocked for consumers that explicitly use them.
await page.route('**/customers/cloud-subscription-status', (r) => {
billingRequests.legacyStatus++
return r.fulfill(jsonRoute(subscriptionStatus))
})
await page.route('**/customers/balance', (r) => {
billingRequests.legacyBalance++
return r.fulfill(jsonRoute(mockBalance))
})

// Workspace backend (team_workspaces_enabled: true) — a personal workspace
// now routes through `/api/billing/*`.
await page.route('**/api/billing/status', (r) =>
r.fulfill(jsonRoute(toWorkspaceStatus(subscriptionStatus)))
)
await page.route('**/api/billing/balance', (r) =>
r.fulfill(jsonRoute(mockBalance))
)
// Cloud personal workspaces route through `/api/billing/*`.
await page.route('**/api/billing/status', (r) => {
billingRequests.workspaceStatus++
return r.fulfill(
jsonRoute({
...toWorkspaceStatus(subscriptionStatus),
billing_rail: billingRail
})
)
})
await page.route('**/api/billing/balance', (r) => {
return r.fulfill(jsonRoute(mockWorkspaceBalance))
})
await page.route('**/api/billing/plans', (r) =>
r.fulfill(jsonRoute({ plans: [] }))
)

return billingRequests
}

async function bootApp(page: Page) {
Expand All @@ -142,36 +162,43 @@ async function bootApp(page: Page) {
}

test.describe('Billing facade consumers (FE-933)', { tag: '@cloud' }, () => {
test('avatar popover renders tier badge and balance from the facade', async ({
test('avatar popover renders a legacy-rail balance from the facade', async ({
page
}) => {
test.setTimeout(60_000)

await mockCloudBoot(page, {
is_active: true,
subscription_tier: 'PRO',
subscription_duration: 'MONTHLY',
renewal_date: '2099-02-20T10:00:00Z',
end_date: null
})
const billingRequests = await mockCloudBoot(
page,
{
is_active: true,
subscription_tier: 'PRO',
subscription_duration: 'MONTHLY',
renewal_date: '2099-02-20T10:00:00Z',
end_date: null
},
{ consolidated_billing_enabled: true },
'legacy_stripe'
)
await bootApp(page)

await page.getByRole('button', { name: 'Current user' }).click()
const popover = page.locator('.current-user-popover')
await expect(popover).toBeVisible()

await expect(popover.getByText('Pro', { exact: true })).toBeVisible()
await expect(popover.getByText('12,660')).toBeVisible()
await expect(popover.getByTestId('add-credits-button')).toBeVisible()
expect(billingRequests.workspaceStatus).toBeGreaterThan(0)
expect(billingRequests.legacyStatus).toBeGreaterThan(0)
expect(billingRequests.legacyBalance).toBeGreaterThan(0)
})

test('subscribe-to-run routes an inactive FREE user to the pricing table', async ({
page
}) => {
test.setTimeout(60_000)

// Boots with team workspaces enabled (production shape); the facade routes a
// personal workspace through the workspace `/api/billing/*` endpoints. With
// The facade routes a personal workspace through the workspace
// `/api/billing/*` endpoints. With
// subscription gating on, an inactive FREE user gets the "Subscribe to run"
// button, which opens the pricing table on click. (refreshRemoteConfig
// overwrites window.__CONFIG__ from /api/features, so the flags must come
Expand All @@ -186,12 +213,17 @@ test.describe('Billing facade consumers (FE-933)', { tag: '@cloud' }, () => {
renewal_date: '2099-02-20T10:00:00Z',
end_date: null
},
{ team_workspaces_enabled: true, subscription_required: true }
{
subscription_required: true,
consolidated_billing_enabled: true
}
)
await bootApp(page)

await page.getByTestId('subscribe-to-run-button').click()

await expect(page.getByRole('heading', { name: /Plans for/ })).toBeVisible()
await expect(
page.getByRole('heading', { name: 'Choose a Plan' })
).toBeVisible()
})
})
Loading
Loading