From dbac9c50d33c422b6feba89622a45b3b296a1c97 Mon Sep 17 00:00:00 2001 From: ShihChi Huang Date: Sat, 7 Nov 2026 14:03:02 +0000 Subject: [PATCH 1/2] feat: check a local workflow against Comfy Cloud and offer to open it there (#23071) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit

J1 sequence

## Summary **J1, Cloud-compatible workflow.** On a local origin with the flag on, the Cloud button replaces Deploy in the top menu. Hovering or clicking it checks the workflow against the Cloud compatibility API; for a runnable workflow it opens a Comfy Cloud tab and offers the workflow by `postMessage`. The Cloud-side receiver lands in #23074, so with the flag on this PR alone, the Cloud tab opens but doesn't import yet. With the flag off nothing renders and nothing is requested. Also adds the live-Cloud fixture and network allowance the later live specs reuse, which is about half of this diff. Scope notes: - Browser path only. Desktop hides the button until its relay arrives in J5 (#23075). - The dialog renders only the ready state. A workflow Cloud can't run shows a toast until the missing-node and missing-model cards arrive in J2 and J3 (#23072). - `openCardDialog` is exported here because the J1 dialog needs it. - The check reads node types and widget values straight from the graph, so hovering never runs `serializeValue` hooks. A model on a loader the asset picker doesn't map (such as `DualCLIPLoader`) gets its folder from the local model library; if it can't be placed (not installed, in two folders, or on a loader that isn't installed locally), the check returns no verdict instead of claiming Cloud can run it. - The gate spec drives the flag through the server feature-flag handshake, because CI serves a production build where the `ff:` localStorage override is tree-shaken. ## Verification
J1 · Cloud-compatible workflow **1.** Load model-free EmptyImage → SaveImage.
J1 · Cloud-compatible workflow, step 1 **2.** Real HTTP 200: no missing nodes or models.
J1 · Cloud-compatible workflow, step 2 **3.** Cloud action and sign-in guidance shown.
J1 · Cloud-compatible workflow, step 3
🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: huang47 <157390+huang47@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- .../openOnCloud/01-runnable-on-cloud.json | 54 +++ .../fixtures/liveOpenOnCloudFixture.ts | 64 ++++ .../fixtures/networkIsolationFixture.ts | 28 +- browser_tests/playwrightSelection.test.ts | 12 +- .../tests/liveCloud/openOnCloud.spec.ts | 61 ++++ browser_tests/tests/openOnCloudGate.spec.ts | 45 +++ src/components/TopMenuSection.test.ts | 89 ++++- src/components/TopMenuSection.vue | 15 +- src/locales/en/main.json | 17 + .../openOnCloud/cloudCompatibilityApi.test.ts | 334 ++++++++++++++++++ .../openOnCloud/cloudCompatibilityApi.ts | 252 +++++++++++++ .../openOnCloud/cloudWorkflowCheck.test.ts | 58 +++ .../openOnCloud/cloudWorkflowCheck.ts | 42 +++ .../components/CloudButton.test.ts | 225 ++++++++++++ .../openOnCloud/components/CloudButton.vue | 96 +++++ .../openOnCloud/components/ProgressRing.vue | 25 ++ .../openOnCloud/components/RunOnCloudCard.vue | 51 +++ .../components/RunOnCloudDialog.vue | 32 ++ .../openOnCloud/localHandoffProtocol.test.ts | 46 +++ .../openOnCloud/localHandoffProtocol.ts | 63 ++++ .../openOnCloud/openRunOnCloudDialog.test.ts | 25 ++ .../openOnCloud/openRunOnCloudDialog.ts | 22 ++ .../openOnCloud/openWorkflowOnCloud.test.ts | 156 ++++++++ .../openOnCloud/openWorkflowOnCloud.ts | 107 ++++++ .../openOnCloud/runOnCloudModalState.test.ts | 92 +++++ .../openOnCloud/runOnCloudModalState.ts | 28 ++ .../openOnCloud/serializeRootGraph.test.ts | 24 ++ .../openOnCloud/serializeRootGraph.ts | 14 + .../stores/cloudWorkflowCheckStore.ts | 49 +++ .../workspace/openCustomDeploymentDialog.ts | 8 +- 30 files changed, 2122 insertions(+), 12 deletions(-) create mode 100644 browser_tests/assets/openOnCloud/01-runnable-on-cloud.json create mode 100644 browser_tests/fixtures/liveOpenOnCloudFixture.ts create mode 100644 browser_tests/tests/liveCloud/openOnCloud.spec.ts create mode 100644 browser_tests/tests/openOnCloudGate.spec.ts create mode 100644 src/platform/openOnCloud/cloudCompatibilityApi.test.ts create mode 100644 src/platform/openOnCloud/cloudCompatibilityApi.ts create mode 100644 src/platform/openOnCloud/cloudWorkflowCheck.test.ts create mode 100644 src/platform/openOnCloud/cloudWorkflowCheck.ts create mode 100644 src/platform/openOnCloud/components/CloudButton.test.ts create mode 100644 src/platform/openOnCloud/components/CloudButton.vue create mode 100644 src/platform/openOnCloud/components/ProgressRing.vue create mode 100644 src/platform/openOnCloud/components/RunOnCloudCard.vue create mode 100644 src/platform/openOnCloud/components/RunOnCloudDialog.vue create mode 100644 src/platform/openOnCloud/localHandoffProtocol.test.ts create mode 100644 src/platform/openOnCloud/localHandoffProtocol.ts create mode 100644 src/platform/openOnCloud/openRunOnCloudDialog.test.ts create mode 100644 src/platform/openOnCloud/openRunOnCloudDialog.ts create mode 100644 src/platform/openOnCloud/openWorkflowOnCloud.test.ts create mode 100644 src/platform/openOnCloud/openWorkflowOnCloud.ts create mode 100644 src/platform/openOnCloud/runOnCloudModalState.test.ts create mode 100644 src/platform/openOnCloud/runOnCloudModalState.ts create mode 100644 src/platform/openOnCloud/serializeRootGraph.test.ts create mode 100644 src/platform/openOnCloud/serializeRootGraph.ts create mode 100644 src/platform/openOnCloud/stores/cloudWorkflowCheckStore.ts 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" /> +