Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
ba38336
fix(account): let the server price a plan change (FE-2216)
dante01yoon Sep 16, 2026
c9e1946
feat(billing): subscribe and its quote on the SDK rail (FE-2216)
dante01yoon Sep 16, 2026
737c3d3
test(billing): cover the plan-change rail end to end on cloud (FE-2216)
dante01yoon Sep 16, 2026
05644b4
fix(account): subscribe never short-circuits on a scheduled cancel (F…
dante01yoon Sep 16, 2026
1b48bed
test(account-ui): expect the quote's cents as numbers (FE-2216)
dante01yoon Sep 16, 2026
0bd7cce
docs(account-core): put the command-eligibility record where its poin…
dante01yoon Sep 17, 2026
afe0fc9
fix(billing): show a declined plan change as a sentence, not a phase …
dante01yoon Sep 17, 2026
0fba2dd
FE-2218 feat(billing): mint billing-web entries from the shared contr…
dante01yoon Sep 17, 2026
d987ce9
FE-2216 fix(billing): keep the subscription conversion event on the S…
dante01yoon Sep 17, 2026
7e82c5b
FE-2216 fix(billing): give a blocked payment popup a way through
dante01yoon Sep 17, 2026
cb7d3e1
FE-2216 fix(billing): leave a way through when a hosted tab is blocked
dante01yoon Sep 17, 2026
89f3234
FE-2216 fix(billing): refuse billing input the customer would be char…
dante01yoon Sep 17, 2026
ae559b5
FE-2216 test(billing): quote the plan change on the rail the test names
dante01yoon Sep 17, 2026
e666919
fix(account): keep the hosted destination stub off this page (FE-2216)
dante01yoon Sep 17, 2026
ca7406c
FE-2216 fix(billing): keep falling through when the rail's portal tab…
dante01yoon Sep 17, 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
5 changes: 5 additions & 0 deletions .github/actions/build-cloud-frontend/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ runs:
run: pnpm build:cloud
env:
VITE_USE_LEGACY_DEFAULT_GRAPH: 'true'
# A reserved origin the e2e suite stubs, so the hosted billing
# destination has somewhere to mint to. Reachable only when the server
# flag says billing_web, which no deployment default does.
# browser_tests/tests/dialogs/hostedBillingDestination.spec.ts pins it.
VITE_BILLING_WEB_URL: 'https://billing-web.example'

- name: Verify cloud frontend
shell: bash
Expand Down
16 changes: 8 additions & 8 deletions apps/billing-web/src/test/fakeBillingClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,21 +166,21 @@ export function previewOf(
): SubscriptionPreview {
return {
allowed: true,
cost_today_cents: 2800n,
cost_next_period_cents: 2800n,
credits_today_cents: 6900n,
credits_next_period_cents: 6900n,
cost_today_cents: 2800,
cost_next_period_cents: 2800,
credits_today_cents: 6900,
credits_next_period_cents: 6900,
effective_at: '2026-10-01T00:00:00.000Z',
is_immediate: true,
transition_type: 'upgrade',
new_plan: {
credits_cents: 6900n,
credits_cents: 6900,
duration: 'MONTHLY',
price_cents: 2800n,
price_cents: 2800,
seat_summary: {
seat_count: 1,
total_cost_cents: 2800n,
total_credits_cents: 6900n
total_cost_cents: 2800,
total_credits_cents: 6900
},
slug: 'creator_monthly',
tier: 'CREATOR'
Expand Down
37 changes: 37 additions & 0 deletions browser_tests/fixtures/helpers/FeatureFlagHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,43 @@ export class FeatureFlagHelper {
}, flags)
}

/**
* Seed server feature flags before the app reads them, for a flag a
* boot-time action depends on — a `?pricing=` deep link opens its dialog
* from `onMounted`, so `setServerFlagsPersistent()` lands after the dialog
* has already chosen a rail.
*
* `window.app` is what gates this: it is assigned in `GraphCanvas`'s
* `onMounted` just before the URL action loaders run, so an accessor
* installed here applies the flags in that window and re-applies on every
* later `feature_flags` handshake, as `setServerFlagsPersistent()` does.
*
* Must be called before `page.goto()`; init scripts persist for the page
* lifetime and cannot be removed.
*/
async seedServerFlags(flags: Record<string, unknown>): Promise<void> {
await this.page.addInitScript((flagMap: Record<string, unknown>) => {
let comfyApp: Window['app']
Object.defineProperty(window, 'app', {
configurable: true,
get: () => comfyApp,
set: (value: Window['app']) => {
comfyApp = value
const api = value?.api
if (!api) return
const apply = () => {
api.serverFeatureFlags.value = {
...api.serverFeatureFlags.value,
...flagMap
}
}
apply()
api.addEventListener('feature_flags', apply)
}
})
}, flags)
}

/**
* Remove server feature flags and keep them removed across websocket
* reconnects, pinning the flag-ABSENT state. The real backend may or may
Expand Down
270 changes: 270 additions & 0 deletions browser_tests/tests/dialogs/hostedBillingDestination.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
import { expect } from '@playwright/test'
import type { Page, Request } from '@playwright/test'

import type { RemoteConfig } from '@/platform/remoteConfig/types'
import type { BillingStatusResponse } from '@/platform/workspace/api/workspaceApi'

import { comfyPageFixture as test } from '@e2e/fixtures/ComfyPage'
import { createWorkspaceBillingCapabilities } from '@e2e/fixtures/data/billingCapabilities'
import { mockSystemStats } from '@e2e/fixtures/data/systemStats'
import { CloudAuthHelper } from '@e2e/fixtures/helpers/CloudAuthHelper'
import { FeatureFlagHelper } from '@e2e/fixtures/helpers/FeatureFlagHelper'
import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute'
import {
mockWorkspaceTokenMint,
workspace
} from '@e2e/fixtures/utils/workspaceMocks'

/**
* Hosted billing destination — FE-2218, Layer C of the billing rollout.
*
* `hosted_billing_destination` decides where Billing & invoices and Plans and
* pricing land, and nothing else does: on `stripe` the app opens the URL
* `/billing/payment-portal` handed back and shows the in-app pricing table, on
* `billing_web` it mints the contract's `/v1/payment-methods` and `/v1/pricing`
* entries and never asks the server for a portal link.
*
* Drives a raw `page` so the cloud app boots against fully mocked endpoints,
* the same pattern as creditsTile.spec.ts.
*
* The hosted origin is baked in at build time. `.github/actions/build-cloud-frontend`
* supplies the value below; a locally served build needs the same
* `VITE_BILLING_WEB_URL`, or the hosted case falls back to the provider page.
*/
const APP_URL = process.env.PLAYWRIGHT_TEST_URL || 'http://localhost:8188'

const BILLING_WEB_ORIGIN = 'https://billing-web.example'
const PROVIDER_PORTAL_URL = 'https://billing.example/portal'

const ACTIVE_BILLING_STATUS: BillingStatusResponse = {
is_active: true,
max_seats: 1,
occupied_seats: 1,
team_credit_stop: null,
scheduled_change: null,
subscription_tier: 'PRO',
subscription_duration: 'MONTHLY',
plan_slug: 'pro-monthly',
billing_status: 'paid',
renewal_date: '2099-02-20T12:00:00Z',
has_funds: true
}

/** Every request the app made for a provider portal URL, in order. */
async function mockCloudBoot(page: Page): Promise<Request[]> {
const portalRequests: Request[] = []

await page.route('**/api/features', (r) =>
r.fulfill(
jsonRoute({ billing_control_enabled: true } satisfies RemoteConfig)
)
)
await page.route('**/api/system_stats', (r) =>
r.fulfill(jsonRoute(mockSystemStats))
)
await page.route('**/api/users', (r) =>
r.fulfill(
jsonRoute({
storage: 'server',
migrated: true,
users: { 'test-user-e2e': 'E2E Test User' }
})
)
)
// TutorialCompleted suppresses the new-user template browser, whose modal
// overlay would otherwise intercept the Settings click.
await page.route('**/api/settings', (r) =>
r.fulfill(jsonRoute({ 'Comfy.TutorialCompleted': true }))
)
await page.route('**/api/userdata**', (r) => r.fulfill(jsonRoute([])))
await page.route('**/api/extensions', (r) => r.fulfill(jsonRoute([])))
await page.route('**/api/object_info', (r) => r.fulfill(jsonRoute({})))
await page.route('**/api/global_subgraphs', (r) => r.fulfill(jsonRoute({})))
await page.route('**/api/i18n', (r) => r.fulfill(jsonRoute({})))
await page.route('**/api/auth/session', (r) =>
r.fulfill(jsonRoute({ token: 'mock-workspace-token' }))
)
await page.route('**/releases**', (r) => r.fulfill(jsonRoute([])))
await mockWorkspaceTokenMint(page, workspace('personal', 'owner'))
await page.route('**/api/workspaces', (r) =>
r.fulfill(jsonRoute({ workspaces: [workspace('personal', 'owner')] }))
)

await page.route('**/api/billing/status', (r) =>
r.fulfill(jsonRoute(ACTIVE_BILLING_STATUS))
)
await page.route('**/api/billing/balance', (r) =>
r.fulfill(jsonRoute({ amount_micros: 6000, currency: 'usd' }))
)
await page.route('**/customers/balance', (r) =>
r.fulfill(jsonRoute({ amount_micros: 6000, currency: 'usd' }))
)
await page.route('**/api/billing/plans', (r) =>
r.fulfill(jsonRoute({ plans: [] }))
)
await page.route('**/api/billing/capabilities', (r) => {
if (r.request().method() !== 'GET') return r.fallback()
return r.fulfill(
jsonRoute(
createWorkspaceBillingCapabilities(workspace('personal', 'owner'))
)
)
})
await page.route('**/api/billing/payment-portal', (r) => {
portalRequests.push(r.request())
return r.fulfill(jsonRoute({ url: PROVIDER_PORTAL_URL }))
})

return portalRequests
}

async function bootApp(page: Page) {
await new CloudAuthHelper(page).mockAuth()
await page.addInitScript(() => {
localStorage.setItem('Comfy.userId', 'test-user-e2e')
const recordDestination = (url: string) => {
document.documentElement.dataset.openedUrl = url
}
// A handle whose navigation is recorded rather than performed. Handing
// back the live `window` would let the disowned-tab open -- blank tab,
// null the opener, then assign `location.href` -- steer this page to the
// hosted origin instead.
const standInTab = new Proxy(window, {
get: (target, property) =>
property === 'location'
? {
get href() {
return document.documentElement.dataset.openedUrl ?? ''
},
set href(destination: string) {
recordDestination(destination)
}
}
: Reflect.get(target, property),
// The tab is disowned before it navigates, and a stand-in that never
// navigates has nothing to disown, so the write is swallowed rather
// than reaching this page's own `window.opener`.
set: () => true
})
// Records the destination instead of opening a tab the test would have to
// dismiss. The handle follows the spec: a `noopener` open always yields
// null, while a plain one returns a window and keeps the app's
// portal-return refresh armed.
window.open = (url, _target, features) => {
if (url) recordDestination(String(url))
return (features ?? '').includes('noopener') ? null : standInTab
}
})
await page.goto(APP_URL)
await page.waitForFunction(() => !!window.app?.extensionManager, null, {
timeout: 45_000
})
}

/** Settings ▸ Workspace ▸ Plan & Credits, where Billing & invoices lives. */
async function openPlanAndCredits(page: Page) {
await page
.getByRole('button', { name: /^Settings/ })
.first()
.click()
const dialog = page.getByTestId('settings-dialog')
await expect(dialog).toBeVisible()
await dialog
.locator('nav')
.getByRole('button', { name: 'Plan & Credits' })
.click()

return dialog.getByRole('main')
}

function openedUrl(page: Page) {
return page.locator('html').getAttribute('data-opened-url')
}

/** The avatar menu's Plans and pricing entry. */
async function clickPlansAndPricing(page: Page) {
await page.getByRole('button', { name: 'Current user' }).click()
await page.getByTestId('plans-pricing-menu-item').click()
}

const pricingHeading = (page: Page) =>
page.getByRole('heading', { name: 'Choose a Plan' })

/**
* The in-app pricing dialog's frame. Pushed synchronously by the click
* handler, unlike its lazily imported contents, so its absence right after
* the handler ran is a settled answer rather than a race.
*/
const pricingDialog = (page: Page) =>
page.locator('[data-dialog-key="subscription-required"]')

test.describe('Hosted billing destination (FE-2218)', { tag: '@cloud' }, () => {
test('opens the provider portal while the destination is stripe', async ({
page
}) => {
test.setTimeout(60_000)
const portalRequests = await mockCloudBoot(page)
await bootApp(page)

const content = await openPlanAndCredits(page)
await content.getByRole('button', { name: 'Billing & invoices' }).click()

await expect.poll(() => openedUrl(page)).toBe(PROVIDER_PORTAL_URL)
expect(portalRequests).toHaveLength(1)
})

test('mints the billing-web payment-methods entry while the destination is billing_web', async ({
page
}) => {
test.setTimeout(60_000)
const portalRequests = await mockCloudBoot(page)
await bootApp(page)
await new FeatureFlagHelper(page).setServerFlagsPersistent({
hosted_billing_destination: 'billing_web'
})

const content = await openPlanAndCredits(page)
await content.getByRole('button', { name: 'Billing & invoices' }).click()

await expect
.poll(() => openedUrl(page))
.toBe(
`${BILLING_WEB_ORIGIN}/v1/payment-methods?product=comfyui&return_to=comfyui_workspace`
)
expect(portalRequests).toHaveLength(0)
})

test('opens the in-app pricing table from the avatar menu while the destination is stripe', async ({
page
}) => {
test.setTimeout(60_000)
await mockCloudBoot(page)
await bootApp(page)

await clickPlansAndPricing(page)

await expect(pricingHeading(page)).toBeVisible()
expect(await openedUrl(page)).toBeNull()
})

test('opens the billing-web pricing entry alone from the avatar menu while the destination is billing_web', async ({
page
}) => {
test.setTimeout(60_000)
await mockCloudBoot(page)
await bootApp(page)
await new FeatureFlagHelper(page).setServerFlagsPersistent({
hosted_billing_destination: 'billing_web'
})

await clickPlansAndPricing(page)

await expect
.poll(() => openedUrl(page))
.toBe(
`${BILLING_WEB_ORIGIN}/v1/pricing?product=comfyui&return_to=comfyui_workspace`
)
await expect(pricingDialog(page)).toHaveCount(0)
await expect(pricingHeading(page)).toBeHidden()
})
})
Loading
Loading