diff --git a/browser_tests/fixtures/networkIsolationFixture.ts b/browser_tests/fixtures/networkIsolationFixture.ts index 00c5a839dad..e52d92a0365 100644 --- a/browser_tests/fixtures/networkIsolationFixture.ts +++ b/browser_tests/fixtures/networkIsolationFixture.ts @@ -13,6 +13,7 @@ import { } from '@e2e/fixtures/utils/liveCloudBillingPolicy' import type { NetworkPolicy } from '@e2e/fixtures/utils/networkPolicy' import { assetPath } from '@e2e/fixtures/utils/paths' +import { mockDeploymentRolloutRefusal } from '@e2e/fixtures/utils/workspaceMocks' dotenvConfig() @@ -189,6 +190,8 @@ export const networkIsolationFixture = base.extend<{ networkPolicy, liveCloudBillingConfig ) + } else { + await mockDeploymentRolloutRefusal(context) } await use(context) restore() diff --git a/browser_tests/fixtures/utils/cloudBootMocks.ts b/browser_tests/fixtures/utils/cloudBootMocks.ts index 8106040dfe9..c607eaa3cbc 100644 --- a/browser_tests/fixtures/utils/cloudBootMocks.ts +++ b/browser_tests/fixtures/utils/cloudBootMocks.ts @@ -6,7 +6,11 @@ import type { ComfyNodeDef } from '@/schemas/nodeDefSchema' import { mockSystemStats } from '@e2e/fixtures/data/systemStats' import { CloudAuthHelper } from '@e2e/fixtures/helpers/CloudAuthHelper' import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute' -import { mockWorkspace, workspace } from '@e2e/fixtures/utils/workspaceMocks' +import { + mockDeploymentRolloutRefusal, + mockWorkspace, + workspace +} from '@e2e/fixtures/utils/workspaceMocks' interface CloudBootOptions { /** Remote-config payload for `/api/features` (enables the flags under test). */ @@ -26,6 +30,7 @@ export async function mockCloudBootRoutes( page: Page, { features, settings = {}, objectInfo }: CloudBootOptions ) { + await mockDeploymentRolloutRefusal(page) await page.route('**/api/features', (r) => r.fulfill(jsonRoute(features))) await page.route('**/api/system_stats', (r) => r.fulfill(jsonRoute(mockSystemStats)) diff --git a/browser_tests/fixtures/utils/workspaceMocks.ts b/browser_tests/fixtures/utils/workspaceMocks.ts index ecec64927f8..3adcf464614 100644 --- a/browser_tests/fixtures/utils/workspaceMocks.ts +++ b/browser_tests/fixtures/utils/workspaceMocks.ts @@ -89,3 +89,15 @@ export async function mockWorkspace( ) ) } + +/** Refuse the deployment listing the way a workspace outside the rollout sees it. */ +export async function mockDeploymentRolloutRefusal( + routeTarget: Page | BrowserContext +): Promise { + await routeTarget.route('**/api/workspaces/*/deployments', (route) => + route.fulfill({ + ...jsonRoute({ error: 'Deployment selection is outside the rollout' }), + status: 403 + }) + ) +} diff --git a/scripts/checkAssetsFlagArtifact.test.ts b/scripts/checkAssetsFlagArtifact.test.ts index 7087ac431fd..e423d241e15 100644 --- a/scripts/checkAssetsFlagArtifact.test.ts +++ b/scripts/checkAssetsFlagArtifact.test.ts @@ -35,19 +35,23 @@ describe('assertWidgetAssetPickerGate', () => { } ) - it('accepts a Cloud gate folded to a static true', () => { + it('accepts a Cloud gate that excludes selected deployments', () => { expect(() => assertWidgetAssetPickerGate( - ['function isWidgetAssetPickerEnabled() {\n return true;\n}'], + [ + 'function isWidgetAssetPickerEnabled() {\n return !useDeploymentPickStore().bootDeployment;\n}' + ], 'cloud' ) ).not.toThrow() }) - it('accepts a minified Cloud gate spelling true as !0', () => { + it('accepts a compact Cloud deployment gate', () => { expect(() => assertWidgetAssetPickerGate( - ['function isWidgetAssetPickerEnabled(){return!0}'], + [ + 'function isWidgetAssetPickerEnabled(){return!useDeploymentPickStore().bootDeployment}' + ], 'cloud' ) ).not.toThrow() @@ -55,12 +59,17 @@ describe('assertWidgetAssetPickerGate', () => { it.for([ 'function isWidgetAssetPickerEnabled() {\n track();\n return true;\n}', - 'function isWidgetAssetPickerEnabled() {\n return isCloud;\n}' - ])('rejects a Cloud gate that is not a static constant: %s', (gate) => { - expect(() => assertWidgetAssetPickerGate([gate], 'cloud')).toThrow( - 'Built widget asset-picker gate is invalid for cloud' - ) - }) + 'function isWidgetAssetPickerEnabled() {\n return isCloud;\n}', + 'function isWidgetAssetPickerEnabled(){return!0}', + 'function isWidgetAssetPickerEnabled(){return useDeploymentPickStore().bootDeployment}' + ])( + 'rejects a Cloud gate that ignores the selected deployment: %s', + (gate) => { + expect(() => assertWidgetAssetPickerGate([gate], 'cloud')).toThrow( + 'Built widget asset-picker gate is invalid for cloud' + ) + } + ) it.for([ 'function isWidgetAssetPickerEnabled() {\n if (!api.getServerFeature("assets", false)) return false;\n return true;\n}', diff --git a/scripts/checkAssetsFlagArtifact.ts b/scripts/checkAssetsFlagArtifact.ts index fcafa6fefe6..47f51e30f9c 100644 --- a/scripts/checkAssetsFlagArtifact.ts +++ b/scripts/checkAssetsFlagArtifact.ts @@ -34,26 +34,9 @@ const TEXT_ASSET_EXTENSIONS = new Set([ /** Sourcemaps carry the gate's own source, which would count as a second gate. */ const EXECUTABLE_ASSET_EXTENSIONS = new Set(['.js', '.mjs', '.cjs', '.html']) -/** - * The widget asset-picker gate must compile to a static constant per - * distribution: `false`/`!1` off-cloud, meaning the feature is statically - * stripped, and `true`/`!0` on cloud. - * - * The two legs are deliberately asymmetric. `nonCloud` carries the real - * invariant: a body that folds to a constant `false` proves the picker is - * unreachable in a non-cloud artifact, which is what lets the bundler drop - * everything behind it. `cloud` is much weaker — it only proves some static - * truthy constant survived — but that is honest, because the gate is now - * nothing more than a build-time constant. Its job is to catch the gate - * regressing into a runtime read, not to constrain runtime behaviour. - * - * Both are anchored against the whole compiled body: a substring search would - * accept a `return true` sitting beside an extra statement. The alternations - * are the two spellings minification emits for each literal. - */ const GATE_BODIES = { nonCloud: /^return\s*(?:false|!1)\s*;?$/, - cloud: /^return\s*(?:true|!0)\s*;?$/ + cloud: /^return\s*!useDeploymentPickStore\(\)\.bootDeployment\s*;?$/ } as const function artifactFiles(directory: string): string[] { diff --git a/src/components/graph/GraphCanvas.test.ts b/src/components/graph/GraphCanvas.test.ts index acf0397487e..bc78a071631 100644 --- a/src/components/graph/GraphCanvas.test.ts +++ b/src/components/graph/GraphCanvas.test.ts @@ -14,10 +14,15 @@ import { import { nextTick } from 'vue' import { createI18n } from 'vue-i18n' +import type { Toast } from '@/components/ui/toast/toastStore' import { IS_CONTROL_WIDGET } from '@/core/graph/widgets/controlWidgetMarker' import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' import { LGraph, LGraphNode } from '@/lib/litegraph/src/litegraph' +import { bootstrapTracer } from '@/platform/telemetry/perf/bootstrapTracer' +import { useWorkspaceStore } from '@/stores/workspaceStore' import { useSettingStore } from '@/platform/settings/settingStore' +import { useDeploymentPickStore } from '@/platform/workspace/stores/deploymentPickStore' +import { DEPLOYMENT_LISTING_BACKSTOP_MS } from '@/platform/workspace/api/deploymentListingTimeouts' import { useReleaseStore } from '@/platform/updates/common/releaseStore' import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore' import { useCanvasStore } from '@/renderer/core/canvas/canvasStore' @@ -29,6 +34,15 @@ import { toNodeId } from '@/types/nodeId' import { createNodeLocatorId } from '@/types/nodeIdentification' import GraphCanvas from './GraphCanvas.vue' +const distribution = vi.hoisted(() => ({ isCloud: false })) +vi.mock(import('@/platform/distribution/types'), () => ({ + DISTRIBUTION: 'localhost' as const, + isDesktop: false, + isNightly: false, + get isCloud() { + return distribution.isCloud + } +})) const agentDocked = { value: true } vi.mock( import('@/workbench/extensions/agent/composables/useAgentDockMount'), @@ -636,3 +650,241 @@ describe('GraphCanvas agent dock', () => { expect(screen.queryByTestId('docked-agent-panel')).not.toBeInTheDocument() }) }) + +describe('deployment model options at startup', () => { + beforeEach(() => { + // These tests pin startup against the deployment lookup's backstop to the + // millisecond, so the fake clock must move only when a test moves it. With + // the suite's `shouldAdvanceTime`, a real 20ms interval also ticks it, and + // when that lands in the native yield after a timer fires mid-advance + // (the bootstrap watchdog at 30s), `advanceTimersByTimeAsync` extends its + // window by the same 20ms and runs the backstop early. + vi.useFakeTimers({ shouldAdvanceTime: false }) + distribution.isCloud = true + onTestFinished(() => { + distribution.isCloud = false + }) + }) + + it('waits for the deployment before constructing workflow widgets', async () => { + let finishListing = () => {} + const listing = new Promise((resolve) => { + finishListing = resolve + }) + vi.spyOn(useDeploymentPickStore(), 'loadOnce').mockReturnValue(listing) + await mountGraphCanvas() + expect(app.setup).not.toHaveBeenCalled() + useDeploymentPickStore().bootDeployment = null + finishListing() + await vi.waitFor(() => expect(app.setup).toHaveBeenCalledOnce()) + }) + + it.for([true, false])( + 'does not resume startup after unmount when deployment lookup succeeds: %s', + async (succeeds) => { + const store = useDeploymentPickStore() + let finishListing = () => {} + const listing = new Promise((resolve) => { + finishListing = resolve + }) + vi.spyOn(store, 'loadOnce').mockReturnValue(listing) + await mountGraphCanvas() + expect(store.loadOnce).toHaveBeenCalledOnce() + expect(app.setup).not.toHaveBeenCalled() + + cleanup() + store.bootDeployment = succeeds ? null : undefined + finishListing() + await vi.advanceTimersByTimeAsync(0) + + expect(app.setup).not.toHaveBeenCalled() + expect(mocks.initializeWorkflow).not.toHaveBeenCalled() + expect(getActivePinia()?.state.value.toast?.toasts ?? []).toEqual([]) + } + ) + + it.for([true, false])( + 'clears abandoned startup when lookup eventually succeeds: %s', + async (succeeds) => { + const store = useDeploymentPickStore() + let finishListing = () => {} + vi.spyOn(store, 'loadOnce').mockReturnValue( + new Promise((resolve) => { + finishListing = resolve + }) + ) + const complete = vi.spyOn(bootstrapTracer, 'complete') + await mountGraphCanvas() + expect(useWorkspaceStore().spinner).toBe(true) + + cleanup() + await nextTick() + + expect(useWorkspaceStore().spinner).toBe(false) + expect(complete).not.toHaveBeenCalled() + + store.bootDeployment = succeeds ? null : undefined + finishListing() + await vi.advanceTimersByTimeAsync(0) + + expect(useWorkspaceStore().spinner).toBe(false) + expect(complete).not.toHaveBeenCalled() + expect(app.setup).not.toHaveBeenCalled() + } + ) + + it.for([ + { name: 'immediate', remount: () => mountGraphCanvas() }, + { + name: 'after a Vue flush', + remount: () => nextTick().then(() => mountGraphCanvas()) + } + ])( + 'lets the replacement editor finish startup: $name', + async ({ remount }) => { + const store = useDeploymentPickStore() + let finishListing = () => {} + vi.spyOn(store, 'loadOnce').mockReturnValue( + new Promise((resolve) => { + finishListing = resolve + }) + ) + let finishSetup = () => {} + vi.mocked(app.setup).mockReturnValue( + new Promise((resolve) => { + finishSetup = resolve + }) + ) + const complete = vi.spyOn(bootstrapTracer, 'complete') + await mountGraphCanvas() + cleanup() + await remount() + + store.bootDeployment = null + finishListing() + await vi.advanceTimersByTimeAsync(0) + + expect(app.setup).toHaveBeenCalledOnce() + expect(useWorkspaceStore().spinner).toBe(true) + expect(complete).not.toHaveBeenCalled() + + finishSetup() + await vi.advanceTimersByTimeAsync(0) + + expect(useWorkspaceStore().spinner).toBe(false) + expect(complete).toHaveBeenCalledExactlyOnceWith('completed') + expect(mocks.initializeWorkflow).toHaveBeenCalledOnce() + } + ) + + it('boots on Comfy Cloud models with a Reload toast after a failed lookup', async () => { + const store = useDeploymentPickStore() + vi.spyOn(store, 'loadOnce').mockResolvedValue() + const reload = vi.spyOn(window.location, 'reload').mockReturnValue() + await mountGraphCanvas() + await vi.waitFor(() => expect(app.setup).toHaveBeenCalledOnce()) + expect(store.bootDeployment).toBeNull() + const toasts: Toast[] = getActivePinia()?.state.value.toast?.toasts ?? [] + const toast = toasts.find( + (t) => t.title === 'deploymentSwitcher.lookupUnavailable' + ) + expect(toast).toMatchObject({ + kind: 'error', + description: 'deploymentSwitcher.lookupUnavailableDetail', + duration: Number.POSITIVE_INFINITY, + action: { label: 'deploymentSwitcher.reload' } + }) + toast?.action?.onClick() + expect(reload).toHaveBeenCalledOnce() + store.bootDeployment = { + deployment_id: 'dep-1', + release_id: 'r-1', + build_id: 'b-1', + build_name: 'Build', + release_version: 1, + status: 'ready', + created_at: '' + } + await nextTick() + expect(app.setup).toHaveBeenCalledOnce() + }) + + it('shows no lookup toast when the lookup settles the boot source', async () => { + const store = useDeploymentPickStore() + vi.spyOn(store, 'loadOnce').mockImplementation(async () => { + store.bootDeployment = null + }) + await mountGraphCanvas() + await vi.waitFor(() => expect(app.setup).toHaveBeenCalledOnce()) + expect(getActivePinia()?.state.value.toast?.toasts ?? []).toEqual([]) + }) + + it('does not wait for a deployment lookup on a local build', async () => { + distribution.isCloud = false + vi.spyOn(useDeploymentPickStore(), 'loadOnce').mockReturnValue( + new Promise(() => {}) + ) + await mountGraphCanvas() + expect(app.setup).toHaveBeenCalledOnce() + expect(useDeploymentPickStore().loadOnce).not.toHaveBeenCalled() + }) + + it('boots on Comfy Cloud models if the deployment lookup never settles', async () => { + vi.spyOn(useDeploymentPickStore(), 'loadOnce').mockReturnValue( + new Promise(() => {}) + ) + await mountGraphCanvas() + await vi.advanceTimersByTimeAsync(DEPLOYMENT_LISTING_BACKSTOP_MS - 1) + expect(app.setup).not.toHaveBeenCalled() + await vi.advanceTimersByTimeAsync(1) + expect(getActivePinia()?.state.value.toast?.toasts).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + kind: 'error', + title: 'deploymentSwitcher.lookupUnavailable' + }) + ]) + ) + expect(useDeploymentPickStore().bootDeployment).toBeNull() + await vi.waitFor(() => expect(app.setup).toHaveBeenCalledOnce()) + expect(mocks.initializeWorkflow).toHaveBeenCalledOnce() + }) + + it('boots on the deployment when the lookup answers slowly', async () => { + const store = useDeploymentPickStore() + const deployment = { + deployment_id: 'dep-1', + release_id: 'r-1', + build_id: 'b-1', + build_name: 'Build', + release_version: 1, + status: 'ready', + created_at: '' + } as const + vi.spyOn(store, 'loadOnce').mockReturnValue( + new Promise((resolve) => { + setTimeout(() => { + store.bootDeployment = deployment + resolve() + }, 3_000) + }) + ) + let bootedOn: unknown = 'not booted' + vi.mocked(app.setup).mockImplementation(async () => { + bootedOn = store.bootDeployment + }) + await mountGraphCanvas() + await vi.advanceTimersByTimeAsync(2_999) + expect(app.setup).not.toHaveBeenCalled() + + await vi.advanceTimersByTimeAsync(1) + + expect(app.setup).toHaveBeenCalledOnce() + expect(bootedOn).toEqual(deployment) + await vi.advanceTimersByTimeAsync(DEPLOYMENT_LISTING_BACKSTOP_MS) + expect(store.bootDeployment).toEqual(deployment) + expect(app.setup).toHaveBeenCalledOnce() + expect(mocks.initializeWorkflow).toHaveBeenCalledOnce() + expect(getActivePinia()?.state.value.toast?.toasts ?? []).toEqual([]) + }) +}) diff --git a/src/components/graph/GraphCanvas.vue b/src/components/graph/GraphCanvas.vue index 406730364ac..2c02e6a8233 100644 --- a/src/components/graph/GraphCanvas.vue +++ b/src/components/graph/GraphCanvas.vue @@ -120,6 +120,10 @@ + +