From daf1dd0b3b4ce0e907a63df330da7af1ba4e08a2 Mon Sep 17 00:00:00 2001 From: Vinh Date: Thu, 5 Nov 2026 03:52:34 +0000 Subject: [PATCH] feat: open Comfy Cloud itself from a deployment=standard link (#22932) **TL;DR:** A link with `deployment=standard` opens the editor on Comfy Cloud itself, the switcher's "Comfy Cloud" row. Today a link has no way to say that. **Why** `comfy workflow save` is getting a link that opens the saved folder in Cloud: `/?workspace=&workflows=&deployment=standard`. A workflow checked against stock Comfy Cloud should open there. A link with no `deployment` value changes nothing, so a browser that last picked a deployment, or follows a workspace default, would open that workflow on a build instead. It is opt-in: only a link that carries `deployment=standard` does anything, and only the CLI behind its server flag prints one. Every other link behaves as before. **Before / After** - Before: `/?workspace=ws-1&deployment=standard` asks ingest to pick a deployment named `standard`, which it refuses with "Couldn't open this deployment". - After, on a deployment: the page sends the same `DELETE /workspaces/{id}/deployment` the switcher sends for "Comfy Cloud" (`pick(null)`) and reloads onto Comfy Cloud. The `workflows` folder stays in the address for the boot after the reload, as it does for a deployment link. - After, already on Comfy Cloud (no pick, its own pick of Comfy Cloud, a gone default, or an account that cannot pick): nothing is sent, no reload, no toast. - After, in another workspace: it switches there first, keeping the link, like a deployment link. The wait is the deployment link's: it waits for the first listing up to the same backstop, then gives the same "took too long" toast. A listing that failed leaves the pick unknown, so it still asks. A request that does not answer in time is canceled, as `pickDeployment` is, so a late success never moves the browser after the toast. For that, `workspaceApi.clearDeployment` takes an optional `signal`, the way `pickDeployment` already does. **Seen in production by:** read from `deploymentPickStore.ts` on main: `pickFromLink` takes only a deployment id, and `useDeploymentUrlLoader` drops a link with no `deployment` value without picking anything. Not run: unit tests not run locally; CI runs them. `gate.py check` passed. Left to try on staging: open `/?workspace=&deployment=standard` from a browser on a deployment (it reloads onto Comfy Cloud) and from one already on Comfy Cloud (nothing happens). **Rule bent:** none. --- .../workspace/api/workspaceApi.test.ts | 26 ++++ src/platform/workspace/api/workspaceApi.ts | 6 +- .../useDeploymentUrlLoader.test.ts | 70 +++++++++ .../composables/useDeploymentUrlLoader.ts | 29 +--- .../stores/deploymentPickStore.test.ts | 141 ++++++++++++++++++ .../workspace/stores/deploymentPickStore.ts | 53 +++---- 6 files changed, 277 insertions(+), 48 deletions(-) diff --git a/src/platform/workspace/api/workspaceApi.test.ts b/src/platform/workspace/api/workspaceApi.test.ts index f5f83e72094..4cdc0b078fc 100644 --- a/src/platform/workspace/api/workspaceApi.test.ts +++ b/src/platform/workspace/api/workspaceApi.test.ts @@ -614,6 +614,32 @@ describe('workspaceApi', () => { ) }) + it('forwards a clear cancellation to the transport', async () => { + mockAxiosInstance.delete.mockResolvedValue({}) + const controller = new AbortController() + await workspaceApi.clearDeployment('ws-1', { signal: controller.signal }) + expect(mockAxiosInstance.delete).toHaveBeenCalledWith( + '/api/workspaces/ws-1/deployment', + { headers: AUTH_HEADER, params: undefined, signal: controller.signal } + ) + }) + + it('does not send a canceled clear when authorization finishes late', async () => { + let finishAuth!: (headers: typeof AUTH_HEADER) => void + const pendingAuth = new Promise((resolve) => { + finishAuth = resolve + }) + vi.mocked(auth.getWorkspaceAuthHeader).mockReturnValue(pendingAuth) + const controller = new AbortController() + const cleared = workspaceApi.clearDeployment('ws-1', { + signal: controller.signal + }) + controller.abort() + finishAuth(AUTH_HEADER) + await expect(cleared).rejects.toMatchObject({ name: 'AbortError' }) + expect(mockAxiosInstance.delete).not.toHaveBeenCalled() + }) + it('setDefaultDeployment() sends PUT /workspaces/:id/default-deployment with the deployment', async () => { mockAxiosInstance.put.mockResolvedValue({}) diff --git a/src/platform/workspace/api/workspaceApi.ts b/src/platform/workspace/api/workspaceApi.ts index 36245d8c060..2852e621208 100644 --- a/src/platform/workspace/api/workspaceApi.ts +++ b/src/platform/workspace/api/workspaceApi.ts @@ -197,15 +197,17 @@ export const workspaceApi = { }, async clearDeployment( workspaceId: WorkspaceId, - options: { follow?: 'workspace' } = {} + options: { follow?: 'workspace'; signal?: AbortSignal } = {} ): Promise { const auth = await requestAuth() + options.signal?.throwIfAborted() try { await workspaceApiClient.delete( ingestApiUrl(`/workspaces/${workspaceId}/deployment`), { ...auth, - params: options.follow ? { follow: options.follow } : undefined + params: options.follow ? { follow: options.follow } : undefined, + ...(options.signal ? { signal: options.signal } : {}) } ) } catch (err) { diff --git a/src/platform/workspace/composables/useDeploymentUrlLoader.test.ts b/src/platform/workspace/composables/useDeploymentUrlLoader.test.ts index 0f4e750495e..6f86e16b426 100644 --- a/src/platform/workspace/composables/useDeploymentUrlLoader.test.ts +++ b/src/platform/workspace/composables/useDeploymentUrlLoader.test.ts @@ -164,6 +164,76 @@ describe('useDeploymentUrlLoader', () => { expect(useDeploymentPickStore().pickFromLink).toHaveBeenCalledWith('dep-1') }) + it('picks Comfy Cloud itself for deployment=standard, keeping the folder', async () => { + mockRouteQuery.value = { + workspace: 'ws-1', + deployment: 'standard', + workflows: 'build' + } + + const { loadDeploymentFromUrl } = useDeploymentUrlLoader() + await expect(loadDeploymentFromUrl()).resolves.toBe(true) + + expect(mockRouterReplace).toHaveBeenCalledWith({ + query: { workflows: 'build' } + }) + expect(useDeploymentPickStore().pickFromLink).toHaveBeenCalledWith(null) + }) + + it('says nothing for deployment=standard when the browser is on Comfy Cloud', async () => { + mockRouteQuery.value = { workspace: 'ws-1', deployment: 'standard' } + vi.mocked(useDeploymentPickStore().pickFromLink).mockResolvedValue({ + kind: 'unchanged' + }) + + await expect( + useDeploymentUrlLoader().loadDeploymentFromUrl() + ).resolves.toBe(false) + + expect(useDeploymentPickStore().pickFromLink).toHaveBeenCalledWith(null) + expect(mockRouterReplace).toHaveBeenCalledWith({ query: {} }) + expect(useToast().error).not.toHaveBeenCalled() + }) + + it('shows the timed-out message when deployment=standard does not land', async () => { + mockRouteQuery.value = { workspace: 'ws-1', deployment: 'standard' } + vi.mocked(useDeploymentPickStore().pickFromLink).mockResolvedValue({ + kind: 'timedOut' + }) + + await expect( + useDeploymentUrlLoader().loadDeploymentFromUrl() + ).resolves.toBe(false) + + expect(useToast().error).toHaveBeenCalledWith( + 'This deployment took too long to open. Try the link again.', + { duration: 8000 } + ) + }) + + it('switches workspace for deployment=standard, then picks Comfy Cloud', async () => { + mockRouteQuery.value = { + workspace: 'ws-2', + deployment: 'standard', + workflows: 'build' + } + + await expect( + useDeploymentUrlLoader().loadDeploymentFromUrl() + ).resolves.toBe(true) + expect(useTeamWorkspaceStore().switchWorkspace).toHaveBeenCalledWith('ws-2') + expect(mockRouterReplace).not.toHaveBeenCalled() + + Object.assign(useTeamWorkspaceStore(), { activeWorkspace: studio }) + await expect( + useDeploymentUrlLoader().loadDeploymentFromUrl() + ).resolves.toBe(true) + expect(mockRouterReplace).toHaveBeenCalledWith({ + query: { workflows: 'build' } + }) + expect(useDeploymentPickStore().pickFromLink).toHaveBeenCalledWith(null) + }) + it('waits for URL cleanup to complete before starting the pick', async () => { mockRouteQuery.value = { workspace: 'ws-1', deployment: 'dep-1' } let finishCleanup!: () => void diff --git a/src/platform/workspace/composables/useDeploymentUrlLoader.ts b/src/platform/workspace/composables/useDeploymentUrlLoader.ts index 7ad84989e64..16a72613065 100644 --- a/src/platform/workspace/composables/useDeploymentUrlLoader.ts +++ b/src/platform/workspace/composables/useDeploymentUrlLoader.ts @@ -21,6 +21,8 @@ const WORKSPACE_NAMESPACE = PRESERVED_QUERY_NAMESPACES.WORKSPACE const DEPLOYMENT_NAMESPACE = PRESERVED_QUERY_NAMESPACES.DEPLOYMENT const SWITCH_KEY = WORKSPACE_STORAGE_KEYS.DEPLOYMENT_LINK_SWITCH +const COMFY_CLOUD_LINK_VALUE = 'standard' + /** * One usable value: a non-empty string. Null for absent, empty, a bare * `?deployment` (null), and a repeated value (an array, or the stash's `,` @@ -70,21 +72,8 @@ function setSwitchTarget(workspaceId: string | null): boolean { } /** - * Opens the editor on the deployment a link names (BE-20294): - * `/?workspace=&deployment=`. Runs before the - * `?workspace=` loader and owns both params when `deployment` is present. - * - * In another workspace it switches there first, keeping both params so the - * boot after the switch's reload picks; a switch that fails, or that did not - * land after its reload, stays in the active workspace and says so. In the - * named workspace it strips both params, then picks with the switcher's own - * request, which reloads onto the deployment's nodes; a refused pick (outside - * the rollout, a deployment gone or not the workspace's) shows the server's - * reason and changes nothing. A link without both values, or an API-key - * session (bound to one workspace, no pick), does nothing but drop - * `deployment`. Signed out, the router sends the person to sign in with the - * full path, query included, to come back to; both params are also stashed - * by the preserved-query tracker. + * Opens the deployment, or Comfy Cloud for `standard`, that a + * `?workspace=&deployment=` link names. */ export function useDeploymentUrlLoader() { const route = useRoute() @@ -149,16 +138,14 @@ export function useDeploymentUrlLoader() { return false } - /** - * In the named workspace: strip the link, then pick. Returns `true` when - * the pick took and the page is reloading onto the deployment. - */ async function pickDeployment( query: LocationQueryRaw, - deploymentId: string + linkValue: string ): Promise { await stripParams(query, ['workspace', 'deployment']) - const outcome = await pickStore.pickFromLink(deploymentId) + const outcome = await pickStore.pickFromLink( + linkValue === COMFY_CLOUD_LINK_VALUE ? null : linkValue + ) if (outcome.kind === 'timedOut') { toast.error(t('deploymentSwitcher.linkTimedOut'), { duration: 8000 }) } diff --git a/src/platform/workspace/stores/deploymentPickStore.test.ts b/src/platform/workspace/stores/deploymentPickStore.test.ts index 8a64cd532bb..2ad3e17dffa 100644 --- a/src/platform/workspace/stores/deploymentPickStore.test.ts +++ b/src/platform/workspace/stores/deploymentPickStore.test.ts @@ -932,6 +932,147 @@ describe('useDeploymentPickStore', () => { }) }) + describe('a link to Comfy Cloud itself', () => { + it("sends the switcher's Comfy Cloud request after the listing, then reloads", async () => { + mockWorkspaceApi.listDeployments.mockResolvedValue(listing) + mockWorkspaceApi.clearDeployment.mockResolvedValue(undefined) + const store = useDeploymentPickStore() + + await expect(store.pickFromLink(null)).resolves.toEqual({ + kind: 'picked' + }) + + expect(mockWorkspaceApi.listDeployments).toHaveBeenCalledOnce() + expect(mockWorkspaceApi.clearDeployment).toHaveBeenCalledExactlyOnceWith( + 'ws-1', + { signal: expect.any(AbortSignal) } + ) + expect(mockWorkspaceApi.pickDeployment).not.toHaveBeenCalled() + expect(readDeploymentHint('ws-1')).toBe('cloud') + expect(reload).toHaveBeenCalledOnce() + }) + + it.for([ + { + name: 'no pick and no default', + answer: { + ...listing, + picked_deployment_id: undefined, + pick_source: undefined + } + }, + { + name: 'its own pick of Comfy Cloud', + answer: { ...listing, picked_deployment_id: undefined } + }, + { + name: 'a default that is gone', + answer: { + ...listing, + picked_deployment_id: undefined, + pick_source: 'workspace_default' as const, + gone_default_deployment_id: 'dep-gone' + } + } + ])( + 'does nothing when the browser already runs on Comfy Cloud: $name', + async ({ answer }) => { + mockWorkspaceApi.listDeployments.mockResolvedValue(answer) + const store = useDeploymentPickStore() + + await expect(store.pickFromLink(null)).resolves.toEqual({ + kind: 'unchanged' + }) + expect(mockWorkspaceApi.clearDeployment).not.toHaveBeenCalled() + expect(reload).not.toHaveBeenCalled() + } + ) + + it('does nothing when the account cannot pick a deployment', async () => { + mockWorkspaceApi.listDeployments.mockRejectedValue( + new WorkspaceApiError('not enabled for this account yet', 403) + ) + const store = useDeploymentPickStore() + + await expect(store.pickFromLink(null)).resolves.toEqual({ + kind: 'unchanged' + }) + expect(mockWorkspaceApi.clearDeployment).not.toHaveBeenCalled() + expect(reload).not.toHaveBeenCalled() + }) + + it('still asks when the listing failed, since the pick is unknown', async () => { + mockWorkspaceApi.listDeployments.mockRejectedValue( + new WorkspaceApiError('Bad request', 400) + ) + mockWorkspaceApi.clearDeployment.mockResolvedValue(undefined) + const store = useDeploymentPickStore() + + await expect(store.pickFromLink(null)).resolves.toEqual({ + kind: 'picked' + }) + expect(mockWorkspaceApi.clearDeployment).toHaveBeenCalledOnce() + expect(reload).toHaveBeenCalledOnce() + }) + + it('stops waiting for a stalled listing and never asks when it answers', async () => { + vi.useFakeTimers() + const listed = deferred() + mockWorkspaceApi.listDeployments.mockReturnValue(listed.promise) + const store = useDeploymentPickStore() + const settled = vi.fn() + const linked = store.pickFromLink(null).then(settled) + await vi.advanceTimersByTimeAsync(DEPLOYMENT_LISTING_BACKSTOP_MS) + expect(settled).toHaveBeenCalledWith({ kind: 'timedOut' }) + listed.resolve(listing) + await linked + expect(mockWorkspaceApi.clearDeployment).not.toHaveBeenCalled() + expect(reload).not.toHaveBeenCalled() + }) + + it('times out and cancels a stalled request without reloading on late success', async () => { + vi.useFakeTimers() + const cleared = deferred() + let signal: AbortSignal | undefined + mockWorkspaceApi.listDeployments.mockResolvedValue(listing) + mockWorkspaceApi.clearDeployment.mockImplementation( + (_id: string, options?: { signal?: AbortSignal }) => { + signal = options?.signal + return cleared.promise + } + ) + const store = useDeploymentPickStore() + const settled = vi.fn() + const linked = store.pickFromLink(null).then(settled) + await vi.advanceTimersByTimeAsync(0) + expect(mockWorkspaceApi.clearDeployment).toHaveBeenCalledOnce() + await vi.advanceTimersByTimeAsync(DEPLOYMENT_LISTING_BACKSTOP_MS) + expect(settled).toHaveBeenCalledWith({ kind: 'timedOut' }) + expect(signal?.aborted).toBe(true) + expect(store.isSwitching).toBe(false) + cleared.resolve() + await linked + await vi.advanceTimersByTimeAsync(0) + expect(reload).not.toHaveBeenCalled() + }) + + it("hands back the server's refusal and keeps the listing's pick", async () => { + mockWorkspaceApi.listDeployments.mockResolvedValue(listing) + mockWorkspaceApi.clearDeployment.mockRejectedValue( + new WorkspaceApiError('workspace not found', 404) + ) + const store = useDeploymentPickStore() + + await expect(store.pickFromLink(null)).resolves.toEqual({ + kind: 'refused', + message: 'workspace not found' + }) + expect(store.state.phase).toBe('ready') + expect(store.pickedDeploymentId).toBe('dep-2') + expect(reload).not.toHaveBeenCalled() + }) + }) + it('does nothing without an active workspace', async () => { Object.assign(useTeamWorkspaceStore(), { workspaceId: null }) const store = useDeploymentPickStore() diff --git a/src/platform/workspace/stores/deploymentPickStore.ts b/src/platform/workspace/stores/deploymentPickStore.ts index 43452abf702..18ab2d3e9c7 100644 --- a/src/platform/workspace/stores/deploymentPickStore.ts +++ b/src/platform/workspace/stores/deploymentPickStore.ts @@ -30,11 +30,6 @@ import { import { reloadForDeploymentSwitch } from '@/platform/workspace/deploymentSwitchReload' import { useTeamWorkspaceStore } from '@/platform/workspace/stores/teamWorkspaceStore' -/** - * What picking a linked deployment did: `picked` (the page is reloading onto - * it), `unchanged` (this browser already runs on it), or `refused` with the - * server's reason. - */ type LinkPickOutcome = | { kind: 'picked' } | { kind: 'unchanged' } @@ -385,14 +380,14 @@ export const useDeploymentPickStore = defineStore('deploymentPick', () => { return pickAndReload(id, deploymentId) } - /** - * Pick the deployment a link names (BE-20294), then reload like `pick`. - * It waits for the page's first listing, so a link to what this browser - * already runs on does nothing, but it does not need that listing to have - * answered: an account outside the rollout, or a deployment that is gone - * or not the workspace's, gets the server's refusal rather than nothing. - */ - async function pickFromLink(deploymentId: string): Promise { + function runsOnComfyCloud(): boolean { + if (listingRefused.value) return true + return isVisible.value && pickedDeploymentId.value === null + } + + async function pickFromLink( + deploymentId: string | null + ): Promise { const id = workspaceStore.workspaceId if (!id || state.value.phase === 'switching') return { kind: 'unchanged' } let timeout: ReturnType | undefined @@ -409,27 +404,35 @@ export const useDeploymentPickStore = defineStore('deploymentPick', () => { if (workspaceStore.workspaceId !== id || isSwitching.value) { return { kind: 'unchanged' } } - if (deploymentId === pickedDeploymentId.value) return { kind: 'unchanged' } + const alreadyOn = + deploymentId === null + ? runsOnComfyCloud() + : deploymentId === pickedDeploymentId.value + if (alreadyOn) return { kind: 'unchanged' } return pickLinkAndReload(id, deploymentId) } async function pickLinkAndReload( workspaceId: string, - deploymentId: string + deploymentId: string | null ): Promise { dispatch({ type: 'switchStarted', target: deploymentId }) const controller = new AbortController() let timeout: ReturnType | undefined - const selection = workspaceApi - .pickDeployment( - workspaceId, - { deployment_id: deploymentId }, - controller.signal - ) - .then( - () => ({ kind: 'picked' }), - (error: unknown) => ({ kind: 'refused', message: errorMessage(error) }) - ) + const request = + deploymentId === null + ? workspaceApi.clearDeployment(workspaceId, { + signal: controller.signal + }) + : workspaceApi.pickDeployment( + workspaceId, + { deployment_id: deploymentId }, + controller.signal + ) + const selection = request.then( + () => ({ kind: 'picked' }), + (error: unknown) => ({ kind: 'refused', message: errorMessage(error) }) + ) const outcome = await Promise.race([ selection, new Promise((resolve) => {