Skip to content
Closed
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
217 changes: 217 additions & 0 deletions browser_tests/tests/dialogs/workspaceActivity.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
import { expect } from '@playwright/test'
import type { Page, Request } from '@playwright/test'

import type { RemoteConfig } from '@/platform/remoteConfig/types'
import type {
BillingBalanceResponse,
BillingEventsResponse,
BillingPlansResponse,
BillingStatusResponse,
Member
} from '@/platform/workspace/api/workspaceApi'

import { comfyPageFixture as test } from '@e2e/fixtures/ComfyPage'
import { bootCloud, mockCloudBoot } from '@e2e/fixtures/utils/cloudBootMocks'
import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute'
import { mockWorkspace, workspace } from '@e2e/fixtures/utils/workspaceMocks'

const APP_URL = process.env.PLAYWRIGHT_TEST_URL || 'http://localhost:8188'

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.

This new spec puts mock data, route setup, locator wiring, and boot helpers at file scope, then requests only the bare page fixture and performs more arrangement inside each test. The canonical browser_tests/README.md requires spec files to contain only imports, Playwright hooks/config, and test blocks; arrangement belongs in fixtures or beforeEach, and tests should use comfyPage rather than manually recreating its readiness wait. Please move stable response data to fixtures/data, put the cloud boot/routes and settings navigation behind the narrowest fixture or existing page object, and leave the test bodies with user actions and behavioral assertions.

const teamWorkspace = workspace('team', 'owner')
const teamMembers: Member[] = [
{
id: 'user-alice',
name: 'Alice Owner',
email: 'e2e@test.comfy.org',
role: 'owner',
joined_at: '2026-01-01T00:00:00Z',
is_original_owner: true
},
{
id: 'user-bob',
name: 'Bob Member',
email: 'bob@test.comfy.org',
role: 'member',
joined_at: '2026-01-02T00:00:00Z',
is_original_owner: false
}
]
const billingStatus: BillingStatusResponse = {
is_active: true,
subscription_tier: 'PRO',
subscription_duration: 'MONTHLY',
has_funds: true
}
const billingBalance: BillingBalanceResponse = {
amount_micros: 10_000,
effective_balance_micros: 10_000,
currency: 'usd'
}
const billingPlans: BillingPlansResponse = { plans: [] }

function eventsResponse(
events: BillingEventsResponse['events']
): BillingEventsResponse {
return {
total: events.length,
events,
page: 1,
limit: 100,
totalPages: events.length === 0 ? 0 : 1
}
}

async function mockBillingShell(page: Page) {
await page.route('**/api/billing/status', (route) =>
route.fulfill(jsonRoute(billingStatus))
)
await page.route('**/api/billing/balance', (route) =>
route.fulfill(jsonRoute(billingBalance))
)
await page.route('**/api/billing/plans', (route) =>
route.fulfill(jsonRoute(billingPlans))
)
}

async function bootWorkspace(page: Page) {
await mockCloudBoot(page, {
features: {
team_workspaces_enabled: true,
billing_control_enabled: true
} satisfies RemoteConfig,
settings: { 'Comfy.TutorialCompleted': true }
})
await mockWorkspace(page, teamWorkspace, teamMembers)
await mockBillingShell(page)
await bootCloud(page)
await page.goto(APP_URL)
await page.waitForFunction(() => !!window.app?.extensionManager, null, {
timeout: 45_000
})
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 assertBillingEventsRequest(request: Request) {
const url = new URL(request.url())
expect(request.method()).toBe('GET')
expect(url.pathname).toBe('/api/billing/events')
expect(Object.fromEntries(url.searchParams)).toEqual({
page: '1',
limit: '100',
scope: 'workspace'
})
expect(request.headers().authorization).toBe('Bearer mock-workspace-token')
}

test.describe('Workspace Activity usage feed', { tag: '@cloud' }, () => {
test('requests, renders, filters, and refreshes usage events', async ({
page
}) => {
test.setTimeout(60_000)
const requests: Request[] = []
const initialEvents = eventsResponse([
{
event_type: 'cloud_workflow_executed',
event_id: 'gpu-event-unique-1',
params: { user_id: 'user-alice' },
createdAt: '2026-07-20T10:00:00Z'
},
{
event_type: 'api_usage_completed',
event_id: 'api-event-unique-2',
params: { user_id: 'user-bob', partner_node: 'Acme Upscaler' },
createdAt: '2026-07-20T11:00:00Z'
}
])
const refreshedEvents = eventsResponse([
...initialEvents.events,
{
event_type: 'cloud_workflow_executed',
event_id: 'gpu-event-unique-3',
params: { user_id: 'user-bob' },
createdAt: '2026-07-20T12:00:00Z'
}
])
await page.route('**/api/billing/events?*', async (route) => {
requests.push(route.request())
await route.fulfill(
jsonRoute(requests.length === 1 ? initialEvents : refreshedEvents)
)
})

const content = await bootWorkspace(page)
await content.getByRole('button', { name: 'Activity' }).click()
await expect.poll(() => requests.length).toBe(1)
assertBillingEventsRequest(requests[0])
await expect(content.getByText('Alice Owner')).toBeVisible()
await expect(content.getByText('Bob Member')).toBeVisible()
await expect(
content.getByText('Cloud workflow run', { exact: true })
).toBeVisible()
await expect(
content.getByText('Partner node usage', { exact: true })
).toBeVisible()

await content.getByPlaceholder('Search').fill('Alice')
await expect(content.getByText('Alice Owner')).toBeVisible()
await expect(content.getByText('Bob Member')).toBeHidden()
await content.getByPlaceholder('Search').fill('')

await content.getByRole('button', { name: 'Refresh' }).click()
await expect.poll(() => requests.length).toBe(2)
assertBillingEventsRequest(requests[1])
await expect(content.getByText('Bob Member')).toHaveCount(2)
})

test('renders the empty response', async ({ page }) => {
test.setTimeout(60_000)
await page.route('**/api/billing/events?*', (route) =>
route.fulfill(jsonRoute(eventsResponse([])))
)

const content = await bootWorkspace(page)
await content.getByRole('button', { name: 'Activity' }).click()
await expect(content.getByText('No activity yet.')).toBeVisible()
})

test('retries a failed request and renders the recovered event', async ({
page
}) => {
test.setTimeout(60_000)
let requestCount = 0
const recovered = eventsResponse([
{
event_type: 'cloud_workflow_executed',
event_id: 'retry-event-unique-1',
params: { user_id: 'user-alice' },
createdAt: '2026-07-20T13:00:00Z'
}
])
await page.route('**/api/billing/events?*', async (route) => {
requestCount += 1
if (requestCount === 1) {
await route.fulfill({ status: 503 })
return
}
await route.fulfill(jsonRoute(recovered))
})

const content = await bootWorkspace(page)
await content.getByRole('button', { name: 'Activity' }).click()
await expect(content.getByRole('alert')).toContainText(
'Failed to load activity. Please try again.'
)
await content.getByRole('button', { name: 'Try again' }).click()
await expect.poll(() => requestCount).toBe(2)
await expect(content.getByText('Alice Owner')).toBeVisible()
})
})
3 changes: 2 additions & 1 deletion src/platform/workspace/api/workspaceApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
BillingStatusResponse as GeneratedBillingStatusResponse,
ChurnkeyAuthResponse
} from '@comfyorg/ingest-types'
export type { BillingEventsResponse } from '@comfyorg/ingest-types'

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.

Please do not expand workspaceApi.ts's public API only to type raw endpoint mocks. browser_tests/README.md names @comfyorg/ingest-types as the source of truth for cloud billing response bodies, and both BillingEventsResponse and BillingPlansResponse are generated there. Import the generated billing response types directly in the fixture data and remove this re-export plus the new export on the local plans interface. This also avoids blessing a second hand-declared BillingPlansResponse that can drift from the generated contract.

import axios from 'axios'

import { attachUnifiedRemintInterceptor } from '@/platform/auth/unified/remintRetry'
Expand Down Expand Up @@ -149,7 +150,7 @@ export interface TeamCreditStops {
stops: TeamCreditStop[]
}

interface BillingPlansResponse {
export interface BillingPlansResponse {
current_plan_slug?: string
plans: Plan[]
team_credit_stops?: TeamCreditStops
Expand Down
Loading