diff --git a/browser_tests/assets/openOnCloud/01-runnable-on-cloud.json b/browser_tests/assets/openOnCloud/01-runnable-on-cloud.json new file mode 100644 index 00000000000..1e85f8b64f5 --- /dev/null +++ b/browser_tests/assets/openOnCloud/01-runnable-on-cloud.json @@ -0,0 +1,54 @@ +{ + "last_node_id": 2, + "last_link_id": 1, + "nodes": [ + { + "id": 1, + "type": "EmptyImage", + "pos": [150, 140], + "size": [270, 130], + "flags": {}, + "order": 0, + "mode": 0, + "inputs": [], + "outputs": [ + { + "name": "IMAGE", + "type": "IMAGE", + "links": [1], + "slot_index": 0 + } + ], + "properties": { + "Node name for S&R": "EmptyImage" + }, + "widgets_values": [256, 256, 1, 42920] + }, + { + "id": 2, + "type": "SaveImage", + "pos": [480, 140], + "size": [300, 285], + "flags": {}, + "order": 1, + "mode": 0, + "inputs": [ + { + "name": "images", + "type": "IMAGE", + "link": 1 + } + ], + "outputs": [], + "properties": { + "Node name for S&R": "SaveImage" + }, + "widgets_values": ["open-on-cloud-validation"] + } + ], + "links": [[1, 1, 0, 2, 0, "IMAGE"]], + "groups": [], + "config": {}, + "extra": {}, + "version": 0.4 +} diff --git a/browser_tests/fixtures/liveOpenOnCloudFixture.ts b/browser_tests/fixtures/liveOpenOnCloudFixture.ts new file mode 100644 index 00000000000..ab20dff678e --- /dev/null +++ b/browser_tests/fixtures/liveOpenOnCloudFixture.ts @@ -0,0 +1,64 @@ +import { expect } from '@playwright/test' +import { z } from 'zod' + +import { ComfyPage } from '@e2e/fixtures/ComfyPage' +import { networkIsolationFixture as base } from '@e2e/fixtures/networkIsolationFixture' + +const cloudOriginSchema = z + .url() + .refine((value) => { + const url = new URL(value) + return ( + url.protocol === 'https:' && + url.href === `${url.origin}/` && + /^(testcloud\.comfy\.org|stagingcloud\.comfy\.org|(?:fe-)?pr-\d+\.testenvs\.comfy\.org)$/.test( + url.hostname + ) + ) + }, 'OPEN_ON_CLOUD_URL must be a test, staging, or PR preview origin') + .transform((value) => new URL(value).origin) + +export const liveOpenOnCloudFixture = base.extend<{ + cloudOrigin: string + comfyPage: ComfyPage +}>({ + baseURL: process.env.PLAYWRIGHT_TEST_URL, + cloudOrigin: [ + process.env.OPEN_ON_CLOUD_URL?.replace(/\/$/, '') ?? '', + { option: true } + ], + liveNetworkOrigins: async ({ cloudOrigin }, use) => { + await use([ + cloudOriginSchema.parse(cloudOrigin), + 'https://api.comfy.org', + 'https://stagingapi.comfy.org', + 'https://cloud.comfy.org', + 'https://testcloud.comfy.org', + 'https://media.comfy.org', + 'https://identitytoolkit.googleapis.com', + 'https://securetoken.googleapis.com', + 'https://dreamboothy-dev.firebaseapp.com', + 'https://apis.google.com', + 'https://www.gstatic.com', + 'https://fonts.googleapis.com', + 'https://fonts.gstatic.com', + 'https://huggingface.co' + ]) + }, + comfyPage: async ({ page, request }, use) => { + const comfyPage = new ComfyPage(page, request) + await comfyPage.goto() + await comfyPage.waitForAppReady() + const templates = page.getByRole('dialog', { + name: 'Get Started with a Template', + exact: true + }) + if (await templates.isVisible()) { + await templates + .getByRole('button', { name: 'Close dialog', exact: true }) + .press('Escape') + } + await expect(comfyPage.canvas).toBeVisible() + await use(comfyPage) + } +}) diff --git a/browser_tests/fixtures/networkIsolationFixture.ts b/browser_tests/fixtures/networkIsolationFixture.ts index 799d3a8b9ec..96bb01c1764 100644 --- a/browser_tests/fixtures/networkIsolationFixture.ts +++ b/browser_tests/fixtures/networkIsolationFixture.ts @@ -59,13 +59,19 @@ function guardApiRequests( export const networkIsolationFixture = base.extend<{ liveCloudBillingConfig: LiveCloudBillingConfig | undefined + liveNetworkOrigins: string[] networkPolicy: NetworkPolicy toast: ToastHelper }>({ serviceWorkers: 'block', liveCloudBillingConfig: [undefined, { option: true }], + liveNetworkOrigins: [[], { option: true }], networkPolicy: [ - async ({ baseURL, liveCloudBillingConfig }, use, testInfo) => { + async ( + { baseURL, liveCloudBillingConfig, liveNetworkOrigins }, + use, + testInfo + ) => { const frontend = process.env.PLAYWRIGHT_TEST_URL || 'http://localhost:8188' const origins = liveCloudBillingConfig @@ -82,7 +88,8 @@ export const networkIsolationFixture = base.extend<{ frontend, baseURL, process.env.PLAYWRIGHT_SETUP_API_URL, - process.env.DEV_SERVER_COMFYUI_URL + process.env.DEV_SERVER_COMFYUI_URL, + ...liveNetworkOrigins ].flatMap((url) => (url ? [new URL(url).origin] : [])) ) const unexpected = new Set() @@ -98,7 +105,9 @@ export const networkIsolationFixture = base.extend<{ liveCloudBillingConfig ? blocked.filter(isReportedViolation) : blocked, liveCloudBillingConfig ? 'Forbidden live Cloud requests' - : 'Unexpected external requests. Add a local mock.' + : liveNetworkOrigins.length > 0 + ? 'Unexpected external requests during a live test' + : 'Unexpected external requests. Add a local mock.' ).toEqual([]) }, { auto: true } @@ -123,7 +132,13 @@ export const networkIsolationFixture = base.extend<{ restore() }, context: async ( - { context, baseURL, networkPolicy, liveCloudBillingConfig }, + { + context, + baseURL, + networkPolicy, + liveCloudBillingConfig, + liveNetworkOrigins + }, use ) => { const { origins, unexpected } = networkPolicy @@ -151,6 +166,11 @@ export const networkIsolationFixture = base.extend<{ await socket.close() } ) + if (liveNetworkOrigins.length > 0) { + await use(context) + restore() + return + } await context.route('https://huggingface.co/**/resolve/**', (route) => route.request().method() === 'HEAD' ? route.fulfill({ status: 200, body: '' }) diff --git a/browser_tests/playwrightSelection.test.ts b/browser_tests/playwrightSelection.test.ts index 3aa22b6103f..d0303350cce 100644 --- a/browser_tests/playwrightSelection.test.ts +++ b/browser_tests/playwrightSelection.test.ts @@ -8,7 +8,7 @@ describe('Live billing opt-in', () => { { name: 'disabled', enabled: '0', - args: ['tests/liveCloud'], + args: [], status: 1, count: 0, hooks: true @@ -35,7 +35,15 @@ describe('Live billing opt-in', () => { ({ enabled, args, status, count, hooks }) => { const result = spawnSync( 'pnpm', - ['exec', 'playwright', 'test', ...args, '--list', '--reporter=json'], + [ + 'exec', + 'playwright', + 'test', + 'tests/liveCloud/billingSmoke.spec.ts', + ...args, + '--list', + '--reporter=json' + ], { cwd: process.cwd(), env: { diff --git a/browser_tests/tests/liveCloud/openOnCloud.spec.ts b/browser_tests/tests/liveCloud/openOnCloud.spec.ts new file mode 100644 index 00000000000..a6b4d763cd9 --- /dev/null +++ b/browser_tests/tests/liveCloud/openOnCloud.spec.ts @@ -0,0 +1,61 @@ +import { expect } from '@playwright/test' + +import { zCloudCompatibility } from '@comfyorg/ingest-types/zod' +import { liveOpenOnCloudFixture as test } from '@e2e/fixtures/liveOpenOnCloudFixture' + +test.describe( + 'Open on Cloud live compatibility', + { tag: ['@cloud-live', '@smoke', '@ui'] }, + () => { + test('offers to open a workflow that Cloud can run', async ({ + comfyPage, + cloudOrigin + }) => { + await test.step('Load the runnable workflow', async () => { + await comfyPage.workflow.loadWorkflow( + 'openOnCloud/01-runnable-on-cloud' + ) + }) + + await test.step('Check compatibility against the real Cloud server', async () => { + const responsePromise = comfyPage.page.waitForResponse( + (response) => + new URL(response.url()).pathname === '/api/cloud/compatibility' && + response.request().method() === 'POST' + ) + await comfyPage.page.getByTestId('cloud-button').click() + const response = await responsePromise + + expect(new URL(response.url()).origin).toBe(cloudOrigin) + expect(response.status()).toBe(200) + expect(await response.serverAddr()).not.toBeNull() + const compatibility = zCloudCompatibility.parse(await response.json()) + expect(compatibility.cloud.missing_node_types).toEqual([]) + expect(compatibility.cloud.missing_models).toEqual([]) + }) + + await test.step('Offer Cloud execution with the signed-out explanation', async () => { + await expect( + comfyPage.page.getByRole('heading', { + name: 'Run on Comfy Cloud', + exact: true + }) + ).toBeVisible() + await expect( + comfyPage.page.getByRole('button', { + name: 'Open on Comfy Cloud', + exact: true + }) + ).toBeVisible() + await expect( + comfyPage.page.getByText('Comfy Cloud will ask you to sign in.', { + exact: true + }) + ).toBeVisible() + await comfyPage.attachScreenshot('runnable-on-cloud.png', { + runInCI: true + }) + }) + }) + } +) diff --git a/browser_tests/tests/openOnCloudGate.spec.ts b/browser_tests/tests/openOnCloudGate.spec.ts new file mode 100644 index 00000000000..04d4198b3e0 --- /dev/null +++ b/browser_tests/tests/openOnCloudGate.spec.ts @@ -0,0 +1,45 @@ +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/') + ) +} + +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 ({ + comfyPage + }) => { + await comfyPage.featureFlags.seedServerFlags({ + open_on_cloud_enabled: false + }) + const traffic: string[] = [] + comfyPage.page.on('request', (request) => { + if (isOpenOnCloudTraffic(request)) traffic.push(request.url()) + }) + + await comfyPage.workflow.reloadAndWaitForApp() + await comfyPage.workflow.loadWorkflow('openOnCloud/01-runnable-on-cloud') + await comfyPage.page.getByTestId('top-menu-actionbars').hover() + + await expect(comfyPage.page.getByTestId('cloud-button')).toHaveCount(0) + expect(traffic).toEqual([]) + }) + + test('shows the Cloud button while the gate is on, proving the gate-off check looks at the right control', async ({ + comfyPage + }) => { + await comfyPage.featureFlags.seedServerFlags({ + open_on_cloud_enabled: true + }) + + await comfyPage.workflow.reloadAndWaitForApp() + + await expect(comfyPage.page.getByTestId('cloud-button')).toBeVisible() + }) +}) diff --git a/src/components/TopMenuSection.test.ts b/src/components/TopMenuSection.test.ts index 3ca1e98b42e..94670576d8d 100644 --- a/src/components/TopMenuSection.test.ts +++ b/src/components/TopMenuSection.test.ts @@ -14,6 +14,7 @@ import { onTestFinished, vi } from 'vitest' +import type { DetachedWindowAPI } from 'happy-dom' import { computed, defineComponent, h, nextTick, onMounted, ref } from 'vue' import type { Component } from 'vue' import { createI18n } from 'vue-i18n' @@ -59,11 +60,14 @@ vi.mock( vi.mock(import('@/composables/auth/useCurrentUser')) -const distribution = vi.hoisted(() => ({ isCloud: false })) +const distribution = vi.hoisted(() => ({ isCloud: false, isDesktop: false })) vi.mock(import('@/platform/distribution/types'), () => ({ get isCloud() { return distribution.isCloud }, + get isDesktop() { + return distribution.isDesktop + }, isNightly: false })) @@ -738,6 +742,89 @@ describe('TopMenuSection', () => { ) }) + describe('Cloud button', () => { + function servedFrom(origin: string) { + const { happyDOM } = window as unknown as { happyDOM: DetachedWindowAPI } + const previous = window.location.href + happyDOM.setURL(`${origin}/`) + onTestFinished(() => happyDOM.setURL(previous)) + } + + it.for([ + { origin: 'http://127.0.0.1:8188', count: 1 }, + { origin: 'http://192.168.1.20:8188', count: 1 }, + { origin: 'https://comfy.example.com', count: 0 } + ])( + 'renders $count Cloud button when ComfyUI is served from $origin', + ({ origin, count }) => { + servedFrom(origin) + Object.assign(useFeatureFlags().flags, { openOnCloudEnabled: true }) + + createWrapper({ stubs: { FreeTierQuota: true, CloudButton: true } }) + + expect(document.querySelectorAll('cloud-button-stub')).toHaveLength( + count + ) + } + ) + + it.for([ + { + host: 'the Desktop distribution', + enter: () => { + distribution.isDesktop = true + }, + leave: () => { + distribution.isDesktop = false + } + }, + { + host: 'a Desktop 2 host serving a localhost build', + enter: () => { + window.__comfyDesktop2 = {} + }, + leave: () => { + delete window.__comfyDesktop2 + } + } + ])( + 'renders no Cloud button on $host until its relay ships', + ({ enter, leave }) => { + enter() + onTestFinished(leave) + servedFrom('http://127.0.0.1:8188') + Object.assign(useFeatureFlags().flags, { openOnCloudEnabled: true }) + + createWrapper({ stubs: { FreeTierQuota: true, CloudButton: true } }) + + expect(document.querySelectorAll('cloud-button-stub')).toHaveLength(0) + } + ) + + it.for([ + { openOnCloudEnabled: false, cloud: 0, deploy: 1 }, + { openOnCloudEnabled: true, cloud: 1, deploy: 0 } + ])( + 'renders $cloud Cloud and $deploy deploy buttons when the Open on Cloud gate is $openOnCloudEnabled', + ({ openOnCloudEnabled, cloud, deploy }) => { + servedFrom('http://127.0.0.1:8188') + Object.assign(useFeatureFlags().flags, { + openOnCloudEnabled, + deployToCloud: true + }) + + createWrapper({ stubs: { FreeTierQuota: true, CloudButton: true } }) + + expect(document.querySelectorAll('cloud-button-stub')).toHaveLength( + cloud + ) + expect( + screen.queryAllByRole('button', { name: 'Deploy to Comfy API' }) + ).toHaveLength(deploy) + } + ) + }) + describe('Deploy to Comfy API button', () => { function enableDeployButton() { Object.assign(useFeatureFlags().flags, { deployToCloud: true }) diff --git a/src/components/TopMenuSection.vue b/src/components/TopMenuSection.vue index 074237c0f6a..b01acc5483a 100644 --- a/src/components/TopMenuSection.vue +++ b/src/components/TopMenuSection.vue @@ -86,8 +86,9 @@ class="absolute top-0.5 right-1 size-2 rounded-full bg-destructive" /> +