diff --git a/src/composables/useCoreCommands.test.ts b/src/composables/useCoreCommands.test.ts index a98f4593e1b..46c63df9075 100644 --- a/src/composables/useCoreCommands.test.ts +++ b/src/composables/useCoreCommands.test.ts @@ -55,6 +55,7 @@ vi.mock('@/scripts/app', () => { } }), openClipspace: vi.fn(), + queuePrompt: vi.fn().mockResolvedValue(true), refreshComboInNodes: vi.fn().mockResolvedValue(undefined), canvas: mockCanvas, rootGraph: { @@ -130,7 +131,9 @@ vi.mock('@/services/litegraphService', () => ({ const mockTrackHelpResourceClicked = vi.hoisted(() => vi.fn()) vi.mock('@/platform/telemetry', () => ({ useTelemetry: vi.fn(() => ({ - trackHelpResourceClicked: mockTrackHelpResourceClicked + trackHelpResourceClicked: mockTrackHelpResourceClicked, + trackRunButton: vi.fn(), + trackWorkflowExecution: vi.fn() })) })) @@ -205,13 +208,25 @@ vi.mock('@/platform/cloud/subscription/composables/useSubscription', () => ({ })) })) +const mockBillingState = vi.hoisted(() => ({ + canAccessSubscriptionFeatures: true, + showSubscriptionDialog: vi.fn() +})) vi.mock('@/composables/billing/useBillingContext', () => ({ useBillingContext: vi.fn(() => ({ - canAccessSubscriptionFeatures: { value: true }, - showSubscriptionDialog: vi.fn() + canAccessSubscriptionFeatures: { + get value() { + return mockBillingState.canAccessSubscriptionFeatures + } + }, + showSubscriptionDialog: mockBillingState.showSubscriptionDialog })) })) +vi.mock('@/stores/queueSettingsStore', () => ({ + useQueueSettingsStore: vi.fn(() => ({ batchCount: 1 })) +})) + describe('useCoreCommands', () => { const createMockNode = (id: number, comfyClass: string): LGraphNode => { const baseNode = createMockLGraphNode({ id }) @@ -302,6 +317,7 @@ describe('useCoreCommands', () => { beforeEach(() => { mockDistributionState.isCloud = false + mockBillingState.canAccessSubscriptionFeatures = true vi.mocked(app.refreshComboInNodes).mockResolvedValue(undefined) mockModelStoreRefresh.mockResolvedValue(undefined) mockMissingModelStoreRefresh.mockResolvedValue(undefined) @@ -662,6 +678,64 @@ describe('useCoreCommands', () => { }) }) + describe('Queue commands subscription gate', () => { + const findCmd = (id: string) => + useCoreCommands().find((cmd) => cmd.id === id)! + + it.for([ + ['Comfy.QueuePrompt', 0], + ['Comfy.QueuePromptFront', -1] + ] as const)( + '%s queues on Local without subscription features', + async ([id, num]) => { + mockBillingState.canAccessSubscriptionFeatures = false + + await findCmd(id).function() + + expect(app.queuePrompt).toHaveBeenCalledWith(num, 1, expect.anything()) + expect(mockBillingState.showSubscriptionDialog).not.toHaveBeenCalled() + } + ) + + it('Comfy.QueueSelectedOutputNodes passes the gate on Local without subscription features', async () => { + mockBillingState.canAccessSubscriptionFeatures = false + + await findCmd('Comfy.QueueSelectedOutputNodes').function() + + expect(mockBillingState.showSubscriptionDialog).not.toHaveBeenCalled() + expect(mockToastAdd).toHaveBeenCalledWith( + expect.objectContaining({ severity: 'error' }) + ) + }) + + it.for([ + 'Comfy.QueuePrompt', + 'Comfy.QueuePromptFront', + 'Comfy.QueueSelectedOutputNodes' + ] as const)( + '%s shows the subscription dialog on Cloud without an active subscription', + async (id) => { + mockDistributionState.isCloud = true + mockBillingState.canAccessSubscriptionFeatures = false + + await findCmd(id).function() + + expect(app.queuePrompt).not.toHaveBeenCalled() + expect(mockBillingState.showSubscriptionDialog).toHaveBeenCalledWith({ + reason: 'subscribe_to_run' + }) + } + ) + + it('Comfy.QueuePrompt queues on Cloud with an active subscription', async () => { + mockDistributionState.isCloud = true + + await findCmd('Comfy.QueuePrompt').function() + + expect(app.queuePrompt).toHaveBeenCalledWith(0, 1, expect.anything()) + }) + }) + describe('Help commands', () => { const findCmd = (id: string) => useCoreCommands().find((cmd) => cmd.id === id)! diff --git a/src/composables/useCoreCommands.ts b/src/composables/useCoreCommands.ts index 5c0ff3bc469..bfda525b146 100644 --- a/src/composables/useCoreCommands.ts +++ b/src/composables/useCoreCommands.ts @@ -506,7 +506,7 @@ export function useCoreCommands(): ComfyCommand[] { trigger_source?: ExecutionTriggerSource }) => { trackRunButton(metadata) - if (!canAccessSubscriptionFeatures.value) { + if (isCloud && !canAccessSubscriptionFeatures.value) { showSubscriptionDialog({ reason: 'subscribe_to_run' }) return } @@ -529,7 +529,7 @@ export function useCoreCommands(): ComfyCommand[] { trigger_source?: ExecutionTriggerSource }) => { trackRunButton(metadata) - if (!canAccessSubscriptionFeatures.value) { + if (isCloud && !canAccessSubscriptionFeatures.value) { showSubscriptionDialog({ reason: 'subscribe_to_run' }) return } @@ -551,7 +551,7 @@ export function useCoreCommands(): ComfyCommand[] { trigger_source?: ExecutionTriggerSource }) => { trackRunButton(metadata) - if (!canAccessSubscriptionFeatures.value) { + if (isCloud && !canAccessSubscriptionFeatures.value) { showSubscriptionDialog({ reason: 'subscribe_to_run' }) return }