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
31 changes: 24 additions & 7 deletions browser_tests/fixtures/helpers/FeatureFlagHelper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { Page, Route } from '@playwright/test'

type FeaturesRouteHandler = (route: Route) => Promise<void>

export class FeatureFlagHelper {
private featuresRouteHandler: ((route: Route) => void) | null = null
private readonly featuresRouteHandlers: FeaturesRouteHandler[] = []

constructor(private readonly page: Page) {}

Expand Down Expand Up @@ -195,19 +197,34 @@ export class FeatureFlagHelper {
* Mock server feature flags via route interception on /api/features.
*/
async mockServerFeatures(features: Record<string, unknown>): Promise<void> {
this.featuresRouteHandler = (route: Route) =>
await this.routeFeatures((route) =>
route.fulfill({
status: 200,
contentType: 'application/json',
body: JSON.stringify(features)
})
await this.page.route('**/api/features', this.featuresRouteHandler)
)
}

/** Merge features into the real /api/features response. */
async mergeServerFeatures(features: Record<string, unknown>): Promise<void> {
await this.routeFeatures(async (route) => {
const response = await route.fetch()
await route.fulfill({
response,
json: { ...(await response.json()), ...features }
})
})
}

async clearMocks(): Promise<void> {
if (this.featuresRouteHandler) {
await this.page.unroute('**/api/features', this.featuresRouteHandler)
this.featuresRouteHandler = null
}
const handlers = this.featuresRouteHandlers.splice(0)
for (const handler of handlers)
await this.page.unroute('**/api/features', handler)
}

private async routeFeatures(handler: FeaturesRouteHandler): Promise<void> {
this.featuresRouteHandlers.push(handler)
await this.page.route('**/api/features', handler)
}
}
21 changes: 21 additions & 0 deletions browser_tests/fixtures/helpers/openOnCloudTraffic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { Page, Request } from '@playwright/test'

export const DESKTOP_RELAY_NONCE = '3f1c2b7e-9a4d-4c1e-8b2f-6d5e4a3b2c1d'

function isOpenOnCloudTraffic(request: Request): boolean {
const url = new URL(request.url())
return (
url.pathname.endsWith('/api/cloud/compatibility') ||
decodeURIComponent(url.pathname).includes('/userdata/open-on-cloud/')
)
}

/** Collect the decoded URLs of every Open on Cloud request the page sends. */
export function recordOpenOnCloudTraffic(page: Page): string[] {
const traffic: string[] = []
page.on('request', (request) => {
if (isOpenOnCloudTraffic(request))
traffic.push(decodeURIComponent(request.url()))
})
return traffic
}
55 changes: 42 additions & 13 deletions browser_tests/tests/openOnCloudGate.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import type { Request } from '@playwright/test'
import { expect } from '@playwright/test'

import { comfyPageFixture as test } from '@e2e/fixtures/ComfyPage'

function isOpenOnCloudTraffic(request: Request): boolean {
const url = new URL(request.url())
return (
url.pathname.endsWith('/api/cloud/compatibility') ||
decodeURIComponent(url.pathname).includes('/userdata/open-on-cloud/')
)
}
import {
DESKTOP_RELAY_NONCE,
recordOpenOnCloudTraffic
} from '@e2e/fixtures/helpers/openOnCloudTraffic'

test.describe('Open on Cloud gate', { tag: ['@ui'] }, () => {
test('boots, loads and hovers the top menu without any Open on Cloud surface or traffic while the gate is off', async ({
Expand All @@ -18,10 +13,7 @@ test.describe('Open on Cloud gate', { tag: ['@ui'] }, () => {
await comfyPage.featureFlags.seedServerFlags({
open_on_cloud_enabled: false
})
const traffic: string[] = []
comfyPage.page.on('request', (request) => {
if (isOpenOnCloudTraffic(request)) traffic.push(request.url())
})
const traffic = recordOpenOnCloudTraffic(comfyPage.page)

await comfyPage.workflow.reloadAndWaitForApp()
await comfyPage.workflow.loadWorkflow('openOnCloud/01-runnable-on-cloud')
Expand All @@ -31,6 +23,43 @@ test.describe('Open on Cloud gate', { tag: ['@ui'] }, () => {
expect(traffic).toEqual([])
})

for (const nonce of [DESKTOP_RELAY_NONCE, 'not-a-uuid']) {
test(`boots the editor from a Desktop relay link (${nonce}) without touching the transfer while the gate is off`, async ({
comfyPage
}) => {
await comfyPage.featureFlags.mergeServerFeatures({
open_on_cloud_enabled: false
})
const traffic = recordOpenOnCloudTraffic(comfyPage.page)

await comfyPage.goto({
url: `/?desktop_workflow=${nonce}&user=e2e-relay-user`
})
await comfyPage.waitForAppReady()

expect(traffic).toEqual([])
})
}

test('reads the staged transfer from a Desktop relay link while the gate is on, proving the gate-off check watches the right request', async ({
comfyPage
}) => {
await comfyPage.featureFlags.mergeServerFeatures({
open_on_cloud_enabled: true
})
const traffic = recordOpenOnCloudTraffic(comfyPage.page)

await comfyPage.goto({
url: `/?desktop_workflow=${DESKTOP_RELAY_NONCE}&user=e2e-relay-user`
})

await expect
.poll(() => traffic)
.toContainEqual(
expect.stringContaining(`open-on-cloud/${DESKTOP_RELAY_NONCE}`)
)
})

test('shows the Cloud button while the gate is on, proving the gate-off check looks at the right control', async ({
comfyPage
}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ describe('ErrorGroupList selection emphasis', () => {
).toBe(sendsToBuild)
expect(
within(hero).queryByRole('button', {
name: /Deploy with your agent/
name: /Build with your agent/
}) !== null
).toBe(sendsToBuild)
}
Expand Down Expand Up @@ -494,7 +494,7 @@ describe('ErrorGroupList selection emphasis', () => {
)
).toBeInTheDocument()
expect(
within(hero).queryByRole('button', { name: /Deploy with your agent/ })
within(hero).queryByRole('button', { name: /Build with your agent/ })
).not.toBeInTheDocument()
})

Expand Down
3 changes: 2 additions & 1 deletion src/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -4251,6 +4251,7 @@
},
"openOnCloud": {
"deploySetup": "Deploy your setup to Comfy Cloud",
"deployWithAgent": "Deploy with your agent",
"deploySetupDialog": {
"body": "This creates a deployment of your setup on Comfy Cloud. You manage it from Comfy Platform.",
"pointGpu": "Work in ComfyUI on the GPU you choose",
Expand Down Expand Up @@ -4898,7 +4899,7 @@
"body": "Deploy this workflow as a production API in minutes. Package your custom nodes, models and Python dependencies into a reproducible build, and Comfy API runs it as an autoscaling endpoint.",
"readDocs": "Read the docs",
"deployOnPlatform": "Deploy on Platform",
"deployWithAgent": "Deploy with your agent",
"deployWithAgent": "Build with your agent",
"copied": "Copied",
"summaryPacks": "{count} node pack | {count} node packs",
"summaryModels": "{count} model | {count} models",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</template>
<template v-else>
<DesktopAgentMarks />
{{ $t('deployToComfyApi.deployWithAgent') }}
{{ $t('openOnCloud.deployWithAgent') }}
</template>
<i class="icon-[lucide--chevron-down]" aria-hidden="true" />
</Button>
Expand Down
26 changes: 24 additions & 2 deletions src/platform/openOnCloud/desktopWorkflowRelay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ describe(handleDesktopWorkflowHandoff, () => {
beforeEach(() => {
openAt('http://127.0.0.1:8000/')
api.user = 'desktop-user'
vi.mocked(fetch).mockImplementation(async () => Response.json({}))
vi.mocked(fetch).mockImplementation(async () =>
Response.json({ open_on_cloud_enabled: true })
)
const previousConfig = remoteConfig.value
const previousWindowConfig = window.__CONFIG__
remoteConfig.value = {}
Expand Down Expand Up @@ -107,6 +109,25 @@ describe(handleDesktopWorkflowHandoff, () => {
}
)

it('boots the editor without touching the transfer while Open on Cloud is off', async () => {
const { relay } = await stagedRelay()
openAt(relay)
vi.mocked(fetch).mockResolvedValue(
Response.json({ open_on_cloud_enabled: false })
)
const replace = relayed()
const splash = showSplash()
splash.textContent = 'Loading'

await expect(handleDesktopWorkflowHandoff()).resolves.toBe(false)

expect(api.getUserData).not.toHaveBeenCalled()
expect(api.deleteUserData).not.toHaveBeenCalled()
expect(replace).not.toHaveBeenCalled()
expect(api.user).toBe('desktop-user')
expect(splash.textContent).toBe('Loading')
})

it('consumes the staged transfer once and forwards to Comfy Cloud', async () => {
const { relay, record } = await stagedRelay()
openAt(relay)
Expand All @@ -130,7 +151,8 @@ describe(handleDesktopWorkflowHandoff, () => {

it('accepts the staged Cloud origin after reading the relay server features', async () => {
const features = {
comfy_cloud_base_url: 'https://custom-cloud.example.com'
comfy_cloud_base_url: 'https://custom-cloud.example.com',
open_on_cloud_enabled: true
}
remoteConfig.value = features
const { relay, record } = await stagedRelay()
Expand Down
12 changes: 9 additions & 3 deletions src/platform/openOnCloud/desktopWorkflowRelay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,17 @@ async function takeRelayDestination(
return record.data.destination
}

async function relayWorkflow(url: URL): Promise<boolean> {
const nonce = relayNonce(url)
if (!nonce) return false
async function isOpenOnCloudEnabled(): Promise<boolean> {
const { refreshRemoteConfig } =
await import('@/platform/remoteConfig/refreshRemoteConfig')
await refreshRemoteConfig({ useAuth: false })
const { useFeatureFlags } = await import('@/composables/useFeatureFlags')
return useFeatureFlags().flags.openOnCloudEnabled
}

async function relayWorkflow(url: URL): Promise<boolean> {
const nonce = relayNonce(url)
if (!nonce) return false
api.user = url.searchParams.get('user') ?? ''
const destination = await takeRelayDestination(nonce)
if (!destination) return false
Expand All @@ -104,6 +109,7 @@ async function relayWorkflow(url: URL): Promise<boolean> {
async function redirectDesktopWorkflowRelay(): Promise<boolean> {
const url = new URL(window.location.href)
if (!url.searchParams.has(DESKTOP_RELAY_PARAM)) return false
if (!(await isOpenOnCloudEnabled().catch(() => false))) return false
const relayed = await relayWorkflow(url).catch(() => false)
if (!relayed) {
const splash = document.getElementById('splash-loader')
Expand Down
28 changes: 20 additions & 8 deletions src/platform/settings/globalSettingsApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { GlobalSetting } from '@comfyorg/ingest-types'
import { beforeEach, describe, expect, it, vi } from 'vitest'

import type { WebSessionSend } from '@comfyorg/api-client/webSessionFetch'
import { useFeatureFlags } from '@/composables/useFeatureFlags'
import { api } from '@/scripts/api'

import {
Expand All @@ -13,8 +14,10 @@ import {
} from './globalSettingsApi'

vi.mock(import('@/config/comfyApi'), () => ({
getComfyApiBaseUrl: () => 'https://api.comfy.test',
getComfyCloudBaseUrl: () => 'https://cloud.comfy.test'
}))
vi.mock(import('@/composables/useFeatureFlags'))
const distribution = vi.hoisted(() => ({ isCloud: true }))
vi.mock(import('@/platform/distribution/types'), () => distribution)
vi.mock(import('@/scripts/api'))
Expand Down Expand Up @@ -45,33 +48,42 @@ describe('Global Settings transport', () => {
vi.mocked(api.apiURL).mockImplementation((path) => `/api${path}`)
})

it.for([true, false])(
'reads with the credential it is handed (Cloud=%s)',
async (cloud) => {
const hosts = [
{ cloud: true, openOnCloudEnabled: false, host: '' },
{ cloud: true, openOnCloudEnabled: true, host: '' },
{ cloud: false, openOnCloudEnabled: false, host: 'https://api.comfy.test' },
{ cloud: false, openOnCloudEnabled: true, host: 'https://cloud.comfy.test' }
]

it.for(hosts)(
'reads with the credential it is handed (Cloud=$cloud, Open on Cloud=$openOnCloudEnabled)',
async ({ cloud, openOnCloudEnabled, host }) => {
distribution.isCloud = cloud
Object.assign(useFeatureFlags().flags, { openOnCloudEnabled })
respondWith(stored)

await expect(getGlobalSetting(key, authHeader)).resolves.toEqual(stored)
expect(fetchWithUnifiedRemint).toHaveBeenCalledWith(
`${cloud ? '' : 'https://cloud.comfy.test'}/api/global-settings/${key}`,
`${host}/api/global-settings/${key}`,
expect.objectContaining({ cache: 'no-store', headers: authHeader }),
false
)
expect(api.fetchApi).not.toHaveBeenCalled()
}
)

it.for([true, false])(
'posts a typed value to the collection (Cloud=%s)',
async (cloud) => {
it.for(hosts)(
'posts a typed value to the collection (Cloud=$cloud, Open on Cloud=$openOnCloudEnabled)',
async ({ cloud, openOnCloudEnabled, host }) => {
distribution.isCloud = cloud
Object.assign(useFeatureFlags().flags, { openOnCloudEnabled })
respondWith(stored)

await expect(
setGlobalSetting({ key, value: true }, authHeader)
).resolves.toEqual(stored)
expect(fetchWithUnifiedRemint).toHaveBeenCalledWith(
`${cloud ? '' : 'https://cloud.comfy.test'}/api/global-settings`,
`${host}/api/global-settings`,
expect.objectContaining({
method: 'POST',
headers: { ...authHeader, 'Content-Type': 'application/json' },
Expand Down
7 changes: 6 additions & 1 deletion src/platform/settings/globalSettingsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import type {
} from '@comfyorg/ingest-types'
import { zErrorResponse, zGlobalSetting } from '@comfyorg/ingest-types/zod'

import { getComfyApiBaseUrl } from '@/config/comfyApi'
import { useFeatureFlags } from '@/composables/useFeatureFlags'
import { isCloud } from '@/platform/distribution/types'
import { ingestApiUrl } from '@/platform/remote/ingest/ingestApiUrl'
import { api } from '@/scripts/api'
import {
fetchWithUnifiedRemint,
shouldRemintCloudRequest
Expand All @@ -26,7 +30,8 @@ export class GlobalSettingsApiError extends Error {

function globalSettingsUrl(key?: GlobalSettingKey): string {
const path = `/global-settings${key ? `/${encodeURIComponent(key)}` : ''}`
return ingestApiUrl(path)
if (useFeatureFlags().flags.openOnCloudEnabled) return ingestApiUrl(path)
return isCloud ? api.apiURL(path) : `${getComfyApiBaseUrl()}/api${path}`
}

async function responseBody(response: Response): Promise<unknown> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe('DeployToComfyApiCard', () => {
await user.click(screen.getByTestId('deploy-to-comfy-api-agent'))

expect(screen.getByTestId('deploy-to-comfy-api-agent')).toHaveTextContent(
'Deploy with your agent'
'Build with your agent'
)
})

Expand All @@ -146,7 +146,7 @@ describe('DeployToComfyApiCard', () => {

await user.click(button)

expect(button).toHaveTextContent('Deploy with your agent')
expect(button).toHaveTextContent('Build with your agent')
})

it('links to the developer platform in a new tab without a referrer, and reports done', async () => {
Expand Down
Loading
Loading