Repository navigation
FE-2218 feat(billing): mint billing-web entries from the shared contract when the hosted destination says billing_web #17860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dante01yoon
merged 8 commits into
jaewon/fe-2216-plan-change
from
jaewon/fe-2218-hosted-billing-routes
Sep 17, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4c0a3ca
feat(billing): mint hosted billing entries from the shared contract (…
dante01yoon 031acea
feat(billing): route hosted billing actions to the server's destinati…
dante01yoon a243c35
test(billing): cover the hosted billing destination end to end on clo…
dante01yoon a2c38c9
fix(billing): open the hosted pricing entry without a phantom popup f…
dante01yoon 923819d
test(billing): cover Plans and pricing on both hosted destinations (F…
dante01yoon fc1f36a
FE-2218 fix(billing): clear the stale error when the hosted destinati…
dante01yoon edbbb61
FE-2218 test(billing): pin the hosted return refresh and the deploy-e…
dante01yoon d89db10
FE-2218 test(billing): name the backend-family rows after what they a…
dante01yoon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
246 changes: 246 additions & 0 deletions
246
browser_tests/tests/dialogs/hostedBillingDestination.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,246 @@ | ||
| 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') | ||
| // 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) => { | ||
| document.documentElement.dataset.openedUrl = String(url) | ||
| return (features ?? '').includes('noopener') ? null : window | ||
| } | ||
| }) | ||
| 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() | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.