Skip to content
Closed
74 changes: 74 additions & 0 deletions browser_tests/fixtures/components/LiveCloudOnboarding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { expect } from '@playwright/test'
import type { Locator, Page } from '@playwright/test'

export class LiveCloudOnboarding {
public readonly survey: Locator
public readonly canvas: Locator
public readonly next: Locator
public readonly submit: Locator
public readonly option: Locator
public readonly text: Locator

constructor(private readonly page: Page) {
this.survey = page.getByRole('heading', {
name: "Let's get to know you",
exact: true
})
this.canvas = page.locator('#graph-canvas')
this.next = page.getByRole('button', { name: 'Next', exact: true })
this.submit = page.getByRole('button', { name: 'Submit', exact: true })
this.option = page
.getByRole('button', { pressed: false })
.and(page.locator('[aria-pressed="false"]:not([id$="-other"])'))
.first()
this.text = page.getByRole('textbox')
}

async completeSurveyIfNeeded(frontend: string) {
const { survey, canvas, next, submit } = this
await expect(survey.or(canvas)).toBeVisible()
if (await survey.isVisible()) {
for (let step = 0; step < 20; step++) {
Comment thread
huang47 marked this conversation as resolved.
Resolved
if (await this.answerSurveyQuestion(next, submit)) break
}
await expect(
submit,
'Complete Cloud onboarding within 20 questions'
).toBeEnabled()
const [response] = await Promise.all([
this.page.waitForResponse(
(response) =>
response.url() === `${frontend}/api/settings` &&
response.request().method() === 'POST'
),
submit.click()
])
expect(response.status(), 'Save Cloud onboarding survey').toBe(200)
await expect(survey).toBeHidden()
}
await expect(canvas).toBeVisible()
}

private async answerSurveyQuestion(next: Locator, submit: Locator) {
const { option, text } = this
await expect(option.or(text)).toBeVisible()
const control = (await option.isVisible()) ? option : text
const id = await control.getAttribute('id')
if (!id) throw new Error('Cloud survey control has no ID')
const answered = this.page.locator(`[id=${JSON.stringify(id)}]`)
if (await option.isVisible()) await control.click()
else await control.fill('Automated billing E2E')
await expect
.poll(
async () =>
!(await answered.isVisible()) ||
((await next.isVisible()) && (await next.isEnabled())) ||
((await submit.isVisible()) && (await submit.isEnabled()))
)
.toBe(true)
if ((await submit.isVisible()) && (await submit.isEnabled())) return true
if ((await next.isVisible()) && (await next.isEnabled())) await next.click()
await expect(answered).toBeHidden()
return false
}
}
14 changes: 14 additions & 0 deletions browser_tests/fixtures/components/Tour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class OnboardingCoachmarks {
/** The current spotlight step card (the dialog carrying a "Step N of M" label). */
public readonly spotlight: Locator
public readonly card: Locator
public readonly cardSkipButton: Locator
public readonly cardNextButton: Locator
public readonly cardDoneButton: Locator

Expand All @@ -31,10 +32,23 @@ export class OnboardingCoachmarks {
})
this.spotlight = page.getByTestId('coach-spotlight')
this.card = page.getByRole('dialog').filter({ hasText: /Step \d+ of \d+/ })
this.cardSkipButton = this.card.getByRole('button', {
name: 'Skip',
exact: true
})
this.cardNextButton = this.card.getByRole('button', { name: 'Next' })
this.cardDoneButton = this.card.getByRole('button', { name: 'Done' })
}

async dismissWhenVisible() {
await this.page.addLocatorHandler(this.landing, async () => {
await this.landingSkipButton.click()
})
await this.page.addLocatorHandler(this.card, async () => {
await this.cardSkipButton.click()
})
}

/** The tour's in-app help button, which replays it past the seen-flag. */
replayButton(tour: CoachTour): Locator {
return this.page.getByRole('button', { name: TOUR_REPLAY_BUTTONS[tour] })
Expand Down
99 changes: 99 additions & 0 deletions browser_tests/fixtures/helpers/LiveCloudBillingSession.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { getLiveCloudEnvironment } from '@e2e/fixtures/utils/liveCloudBillingConfig'
import {
zBillingStatusResponse,
zCurrentWorkspaceResponse,
zListSavedPaymentMethodsResponse,
zPaymentPortalResponse
} from '@comfyorg/ingest-types/zod'
import type { APIRequestContext, TestInfo } from '@playwright/test'
import { expect } from '@playwright/test'
import type { z } from 'zod'

export class LiveCloudBillingSession {
private readonly environment: ReturnType<typeof getLiveCloudEnvironment>
constructor(
private readonly request: APIRequestContext,
private readonly backend: string,
private readonly headers: Record<string, string>
) {
this.environment = getLiveCloudEnvironment(backend)
}

async read<T>(path: string, schema: z.ZodType<T>): Promise<T> {
const response = await this.request
.get(new URL(path, this.backend).href, {
headers: this.headers,
maxRedirects: 0
})
.catch(() => {
throw new Error(`Cloud billing request failed: ${path}`)
})
expect(response.status(), `GET ${path}`).toBe(200)
return schema.parse(await response.json())
}

async post<T>(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 — Bind this write to its generated request contract. This public helper accepts an arbitrary path, a hand-written Record<string, number | string> body, and an independently chosen response schema. Both current callers send /api/billing/payment-portal, whose generated zPaymentPortalRequest already owns the request shape, but nothing here makes that path/body/schema combination authoritative. A request-field change or accidental schema/path mismatch will still compile and can reach a real billing endpoint. Prefer one endpoint-specific paymentPortal method that accepts data inferred from zPaymentPortalRequest, parses it at this boundary, and owns the response schema; keep any generic transport primitive private.

path: string,
data: Record<string, number | string>,
schema: z.ZodType<T>,
acceptedStatuses = [200]
): Promise<T> {
const response = await this.request
.post(new URL(path, this.backend).href, {
data,
headers: this.headers,
maxRedirects: 0
})
.catch(() => {
throw new Error(`Cloud billing request failed: ${path}`)
})
expect(acceptedStatuses, `POST ${path}`).toContain(response.status())
return schema.parse(await response.json())
}

async assertNoCardAccount(testInfo: TestInfo) {
const workspace = await this.read(
'/api/workspaces/current',
zCurrentWorkspaceResponse
)
expect(workspace.type).toBe('personal')
expect(workspace.role).toBe('owner')
const status = await this.read(
'/api/billing/status',
zBillingStatusResponse
)
if (this.environment.stripeMode === 'live') {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: this stripeMode === 'live' gate makes the "no saved payment methods" precondition unreachable for the only caller, so the check never runs.

assertNoCardAccount is called from one place — liveCloudDisposableBillingFixture.disposableCheckout — and that fixture builds its config with allowPayments: true, which liveCloudBillingConfigSchema's refinement rejects on https://cloud.comfy.org. So by construction the config reaching this method always has stripeMode === 'test', the branch is skipped, and /api/billing/payment-methods is never read.

The failure path that matters is the one the message names: if a disposable account somehow arrives with a saved card (a retried run reusing an address, or a downstream PR passing a permanent account into this helper), the checkout-recovery scenarios in #17870 / #17545 would silently exercise the saved-card flow instead of the card-entry flow and still report green, because the guard meant to catch that never executed.

Should the condition be inverted — assert the account has no saved cards in test mode, where checkout can actually run? If instead the intent is "only bother on production", that reads as the production-checkout path I flagged on liveCloudBillingConfig.ts:50, and I think the two should be decided together. A short comment either way would help, since a reader today sees a precondition that looks enforced but is not.

const paymentMethods = await this.read(
'/api/billing/payment-methods',
zListSavedPaymentMethodsResponse
)
expect(
paymentMethods,
'Checkout recovery requires an account without saved payment methods'
).toHaveLength(0)
}
await testInfo.attach('billing-preflight.json', {
body: JSON.stringify({
workspaceId: workspace.id,
isActive: status.is_active,
billingStatus: status.billing_status,
subscriptionTier: status.subscription_tier,
backend: this.backend
}),
contentType: 'application/json'
})
if (status.is_active) expect(status.subscription_tier).toBe('FREE')
else
expect(['inactive', 'awaiting_payment_method']).toContain(
status.billing_status
)
}

async ensureProvisioned(returnUrl: string) {
await this.post(
'/api/billing/payment-portal',
{ return_url: returnUrl },
zPaymentPortalResponse
)
}
}
Loading
Loading