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
17 changes: 17 additions & 0 deletions browser_tests/fixtures/liveOpenOnCloudFixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,20 @@ export const liveOpenOnCloudFixture = base.extend<{
await use(comfyPage)
}
})

export const liveOpenOnCloudLoginFixture = liveOpenOnCloudFixture.extend({
liveNetworkOrigins: async ({ liveNetworkOrigins }, use) => {
await use([
...liveNetworkOrigins,
'https://browser-intake-us5-datadoghq.com',
'https://utt.impactcdn.com',
'https://comfyui.sjv.io',
'https://d.impct.site',
'https://www.ojrq.net',
'https://cdn.sy-d.io',
'https://t.comfy.org',
'https://o4507954455314432.ingest.us.sentry.io',
'https://cdp.customer.io'
])
}
})
49 changes: 49 additions & 0 deletions browser_tests/tests/liveCloud/openOnCloudLogin.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { expect } from '@playwright/test'

import { liveOpenOnCloudLoginFixture as test } from '@e2e/fixtures/liveOpenOnCloudFixture'

test.describe(
'Open on Cloud live sign-in handoff',
{ tag: ['@cloud-live', '@smoke', '@ui'] },
() => {
test('opens the selected Cloud deployment login page for a signed-out user', async ({
comfyPage,
cloudOrigin
}) => {
await test.step('Load the runnable workflow and check compatibility', async () => {
await comfyPage.workflow.loadWorkflow(
'openOnCloud/01-runnable-on-cloud'
)
await comfyPage.page.getByTestId('cloud-button').click()
await expect(
comfyPage.page.getByRole('heading', {
name: 'Run on Comfy Cloud',
exact: true
})
).toBeVisible()
})

await test.step('Open the real Cloud sign-in page for the workflow', async () => {
const cloudTabPromise = comfyPage.page.waitForEvent('popup')
await comfyPage.page
.getByRole('button', { name: 'Open on Comfy Cloud', exact: true })
.click()
const cloudTab = await cloudTabPromise
await expect
.poll(() => new URL(cloudTab.url()).origin)
.toBe(cloudOrigin)
await expect(
cloudTab.getByRole('heading', {
name: 'Log in to your account',
exact: true
})
).toBeVisible()
await test.info().attach('cloud-sign-in.png', {
body: await cloudTab.screenshot(),
contentType: 'image/png'
})
await cloudTab.close()
})
})
}
)
119 changes: 119 additions & 0 deletions browser_tests/tests/openOnCloud/openOnCloudSignInHandoff.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import type { Page } from '@playwright/test'

import type { operations } from '@/types/comfyRegistryTypes'

import handedOverWorkflow from '@e2e/assets/nodes/note_nodes.json' with { type: 'json' }
import {
cloudAppExpect as expect,
cloudAppFixture as test
} from '@e2e/fixtures/cloudAppFixture'
import {
CLOUD_SELF_EMAIL,
CloudAuthHelper
} from '@e2e/fixtures/helpers/CloudAuthHelper'
import {
mockCloudBoot,
preselectCloudUser
} from '@e2e/fixtures/utils/cloudBootMocks'

const APP_URL = process.env.PLAYWRIGHT_TEST_URL || 'http://localhost:8188'
const OPENER_PATH = '/__e2e_local_opener'
const NONCE = '00000000-0000-4000-8000-000000000001'
const FILENAME = 'handed-over.json'

type CreateCustomerResponse =
operations['createCustomer']['responses']['201']['content']['application/json']

async function openLocalOpener(page: Page): Promise<void> {
await page.route(`**${OPENER_PATH}`, (route) =>
route.fulfill({ contentType: 'text/html', body: '<!doctype html>' })
)
await page.goto(`${APP_URL}${OPENER_PATH}`)
await page.evaluate(
({ nonce, filename, workflow }) => {
window.addEventListener('message', (event) => {
const data: unknown = event.data
if (
typeof data !== 'object' ||
data === null ||
!('nonce' in data) ||
data.nonce !== nonce ||
!event.source
)
return
;(event.source as Window).postMessage(
{ type: 'comfy-local-handoff:workflow', nonce, filename, workflow },
'*'
)
})
},
{ nonce: NONCE, filename: FILENAME, workflow: handedOverWorkflow }
)
}

async function openSignedOutCloudTab(opener: Page): Promise<Page> {
const [cloudTab] = await Promise.all([
opener.waitForEvent('popup'),
opener.evaluate(() => {
window.open('about:blank', 'comfy-cloud')
})
])
await mockCloudBoot(cloudTab, {
features: { open_on_cloud_enabled: true }
})
await preselectCloudUser(cloudTab)
await cloudTab.route('**/customers', (route) => {
if (route.request().method() !== 'POST') return route.fallback()
return route.fulfill({
status: 201,
json: { id: 'test-customer-e2e' } satisfies CreateCustomerResponse
})
})
await new CloudAuthHelper(cloudTab).mockLiveEmailSignIn()
await opener.evaluate((nonce) => {
window.open(`/?from_local=${nonce}`, 'comfy-cloud')
}, NONCE)
return cloudTab
}

test.describe(
'Open on Cloud handoff through sign-in',
{ tag: '@cloud' },
() => {
test('opens the handed-over workflow, uncovered, after a fresh account signs in', async ({
page
}) => {
await openLocalOpener(page)
const cloudTab = await openSignedOutCloudTab(page)

await expect(
cloudTab.getByRole('heading', { name: 'Log in to your account' })
).toBeVisible()
await cloudTab.getByRole('button', { name: 'Use email instead' }).click()
await cloudTab.locator('#cloud-sign-in-email').fill(CLOUD_SELF_EMAIL)
await cloudTab
.locator('#cloud-sign-in-password')
.fill('correct-horse-battery-staple')
await cloudTab.locator('#cloud-sign-in-password').blur()
await cloudTab.getByRole('button', { name: 'Sign in' }).click()

await expect(
cloudTab.getByTestId('toast').filter({
visible: true,
hasText: 'Opened from ComfyUI on your computer'
})
).toBeVisible()
await expect
.poll(() =>
cloudTab.evaluate(() =>
window.app?.graph.nodes.map((node) => node.type).toSorted()
)
)
.toEqual(['MarkdownNote', 'Note'])
await expect(cloudTab.getByRole('dialog')).toHaveCount(0)
await expect
.poll(() => new URL(cloudTab.url()).searchParams.has('from_local'))
.toBe(false)
})
}
)
17 changes: 16 additions & 1 deletion src/composables/useUrlActionLoaders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ const mocks = vi.hoisted(() => ({
loadTopUp: vi.fn(async () => undefined),
loadSettings: vi.fn(),
loadAssets: vi.fn(async () => undefined),
loadLocalHandoff: vi.fn(async () => undefined),
useDeployment: vi.fn(),
useWorkspace: vi.fn(),
useInvite: vi.fn(),
useCreateWorkspace: vi.fn(),
usePricingTable: vi.fn(),
useTopUp: vi.fn(),
useSettings: vi.fn(),
useAssets: vi.fn()
useAssets: vi.fn(),
useLocalHandoff: vi.fn()
}))
mocks.useDeployment.mockImplementation(() => ({
loadDeploymentFromUrl: mocks.loadDeployment
Expand All @@ -60,6 +62,9 @@ mocks.useSettings.mockImplementation(() => ({
mocks.useAssets.mockImplementation(() => ({
loadAssetsFromUrl: mocks.loadAssets
}))
mocks.useLocalHandoff.mockImplementation(() => ({
loadLocalHandoffFromUrl: mocks.loadLocalHandoff
}))

// A real router rather than a stub: several assertions are the URL a reader
// is left looking at, and only the real thing resolves and merges a query
Expand Down Expand Up @@ -108,6 +113,10 @@ vi.mock(import('@/platform/settings/composables/useSettingsUrlLoader'), () => ({
vi.mock(import('@/platform/assets/composables/useAssetsUrlLoader'), () => ({
useAssetsUrlLoader: mocks.useAssets
}))
vi.mock(
import('@/platform/openOnCloud/composables/useLocalHandoffUrlLoader'),
() => ({ useLocalHandoffUrlLoader: mocks.useLocalHandoff })
)
vi.mock(
import('@/platform/billing/subscription/composables/useSubscriptionDialog')
)
Expand Down Expand Up @@ -142,6 +151,9 @@ describe('useUrlActionLoaders', () => {
mocks.useAssets.mockImplementation(() => ({
loadAssetsFromUrl: mocks.loadAssets
}))
mocks.useLocalHandoff.mockImplementation(() => ({
loadLocalHandoffFromUrl: mocks.loadLocalHandoff
}))
vi.mocked(useRouter).mockReturnValue(router)
await router.replace({ path: '/', query: {} })
})
Expand Down Expand Up @@ -216,6 +228,7 @@ describe('useUrlActionLoaders', () => {
expect(mocks.useTopUp).not.toHaveBeenCalled()
expect(mocks.useSettings).not.toHaveBeenCalled()
expect(mocks.useAssets).not.toHaveBeenCalled()
expect(mocks.useLocalHandoff).not.toHaveBeenCalled()
expect(useSubscriptionDialog).not.toHaveBeenCalled()
expect(mocks.loadDeployment).not.toHaveBeenCalled()
expect(mocks.loadWorkspace).not.toHaveBeenCalled()
Expand All @@ -225,6 +238,7 @@ describe('useUrlActionLoaders', () => {
expect(mocks.loadTopUp).not.toHaveBeenCalled()
expect(mocks.loadSettings).not.toHaveBeenCalled()
expect(mocks.loadAssets).not.toHaveBeenCalled()
expect(mocks.loadLocalHandoff).not.toHaveBeenCalled()
expect(
useSubscriptionDialog().resumePendingPricingFlow
).not.toHaveBeenCalled()
Expand All @@ -242,6 +256,7 @@ describe('useUrlActionLoaders', () => {
expect(mocks.loadTopUp).toHaveBeenCalledOnce()
expect(mocks.loadSettings).toHaveBeenCalledOnce()
expect(mocks.loadAssets).toHaveBeenCalledOnce()
expect(mocks.loadLocalHandoff).toHaveBeenCalledOnce()
})

it('opens the requested workspace before any other loader reads the URL', async () => {
Expand Down
15 changes: 14 additions & 1 deletion src/composables/useUrlActionLoaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
import { isCloud } from '@/platform/distribution/types'
import { clearPreservedQuery } from '@/platform/navigation/preservedQueryManager'
import { PRESERVED_QUERY_NAMESPACES } from '@/platform/navigation/preservedQueryNamespaces'
import { useLocalHandoffUrlLoader } from '@/platform/openOnCloud/composables/useLocalHandoffUrlLoader'
import { LOCAL_HANDOFF_PARAM } from '@/platform/openOnCloud/localHandoffProtocol'
import { useSettingsUrlLoader } from '@/platform/settings/composables/useSettingsUrlLoader'
import { reportError } from '@/platform/telemetry/reportError'
import { useCreateWorkspaceUrlLoader } from '@/platform/workspace/composables/useCreateWorkspaceUrlLoader'
Expand Down Expand Up @@ -38,6 +40,7 @@ type UrlActionLoaders = {
topUpUrlLoader: ReturnType<typeof useTopUpUrlLoader> | null
settingsUrlLoader: ReturnType<typeof useSettingsUrlLoader> | null
assetsUrlLoader: ReturnType<typeof useAssetsUrlLoader> | null
localHandoffUrlLoader: ReturnType<typeof useLocalHandoffUrlLoader> | null
}

/**
Expand Down Expand Up @@ -70,6 +73,7 @@ const HANDLED_PARAMS = [
'topup',
'settings',
'assets',
LOCAL_HANDOFF_PARAM,
...STRIPE_RETURN_PARAMS,
...BILLING_WEB_RETURN_PARAMS
]
Expand Down Expand Up @@ -150,6 +154,13 @@ function buildUrlActionSteps(
run: () => loader.loadAssetsFromUrl()
})
}
if (loaders.localHandoffUrlLoader) {
const loader = loaders.localHandoffUrlLoader
steps.push({
failureMessage: 'Failed to open the workflow handed over from local:',
run: () => loader.loadLocalHandoffFromUrl()
})
}

steps.push({
failureMessage: 'Failed to clear handled deep-link params from the URL:',
Expand Down Expand Up @@ -230,6 +241,7 @@ export function useUrlActionLoaders() {
const topUpUrlLoader = useIfCloud(useTopUpUrlLoader)
const settingsUrlLoader = useIfCloud(useSettingsUrlLoader)
const assetsUrlLoader = useIfCloud(useAssetsUrlLoader)
const localHandoffUrlLoader = useIfCloud(useLocalHandoffUrlLoader)
const subscriptionDialog = useIfCloud(useSubscriptionDialog)

const steps = isCloud
Expand All @@ -242,7 +254,8 @@ export function useUrlActionLoaders() {
pricingTableUrlLoader,
topUpUrlLoader,
settingsUrlLoader,
assetsUrlLoader
assetsUrlLoader,
localHandoffUrlLoader
},
router
)
Expand Down
5 changes: 5 additions & 0 deletions src/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -4213,6 +4213,11 @@
"pointApi": "Call it from your product as an autoscaling API",
"pointNodes": "Bring your custom nodes and models"
},
"openedFromLocal": "Opened from ComfyUI on your computer",
"openedFromLocalDetail": "Comfy Cloud has every node and model this workflow uses. Press Run when you're ready.",
"handoffFailed": "Couldn't open the workflow from ComfyUI on your computer",
"handoffMissing": "Your workflow didn't arrive",
"handoffMissingDetail": "ComfyUI stops waiting after 10 minutes. Click Open on Comfy Cloud in ComfyUI again.",
"popupBlocked": "Your browser blocked the Comfy Cloud tab. Allow pop-ups for this page and try again.",
"prepareFailed": "Couldn't prepare this workflow for Comfy Cloud",
"prepareFailedDetail": "Check the workflow for errors, save it, and try again.",
Expand Down
3 changes: 2 additions & 1 deletion src/platform/navigation/preservedQueryDefinitions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ describe('PRESERVED_QUERY_DEFINITIONS', () => {
[PRESERVED_QUERY_NAMESPACES.PRICING, 'pricing'],
[PRESERVED_QUERY_NAMESPACES.WORKSPACE, 'workspace'],
[PRESERVED_QUERY_NAMESPACES.DEPLOYMENT, 'deployment'],
[PRESERVED_QUERY_NAMESPACES.WORKFLOWS, 'workflows']
[PRESERVED_QUERY_NAMESPACES.WORKFLOWS, 'workflows'],
[PRESERVED_QUERY_NAMESPACES.LOCAL_HANDOFF, 'from_local']
])('captures %s so a redirect cannot lose it', ([namespace, key]) => {
expect(registered.get(namespace)).toContain(key)
})
Expand Down
4 changes: 4 additions & 0 deletions src/platform/navigation/preservedQueryDefinitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,9 @@ export const PRESERVED_QUERY_DEFINITIONS: PreservedQueryDefinition[] = [
namespace: PRESERVED_QUERY_NAMESPACES.WORKFLOWS,
keys: ['workflows'],
rejectRepeated: true
},
{
namespace: PRESERVED_QUERY_NAMESPACES.LOCAL_HANDOFF,
keys: ['from_local']
}
]
3 changes: 2 additions & 1 deletion src/platform/navigation/preservedQueryNamespaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export const PRESERVED_QUERY_NAMESPACES = {
DESKTOP_LOGIN: 'desktop_login',
WORKSPACE: 'workspace',
DEPLOYMENT: 'deployment',
WORKFLOWS: 'workflows'
WORKFLOWS: 'workflows',
LOCAL_HANDOFF: 'local_handoff'
} as const
Loading
Loading