diff --git a/src/platform/workspace/composables/useDeploymentCompatibility.test.ts b/src/platform/workspace/composables/useDeploymentCompatibility.test.ts index c4a1d26dc2a..646e9dfef8b 100644 --- a/src/platform/workspace/composables/useDeploymentCompatibility.test.ts +++ b/src/platform/workspace/composables/useDeploymentCompatibility.test.ts @@ -563,6 +563,83 @@ describe('useDeploymentCompatibility', () => { expect(markFor('dep-plain')).toEqual({ kind: 'runs' }) }) + it('keeps the newest answer when an older check of the same workflow answers last', async () => { + const answers: ((value: DeploymentCompatibility) => void)[] = [] + const checks: Promise[] = [] + vi.mocked(workspaceApi.checkDeploymentCompatibility).mockImplementation( + () => { + const check = new Promise((resolve) => { + answers.push(resolve) + }) + checks.push(check) + return check + } + ) + const { markFor } = setup() + + hoisted.rootGraph = graph({ type: 'KSampler' }) + useWorkflowStore().activeWorkflow = fromPartial({ + path: 'workflows/core-only.json' + }) + await nextTick() + hoisted.rootGraph = rgthreeWorkflow() + useWorkflowStore().activeWorkflow = fromPartial({ + path: 'workflows/rgthree.json' + }) + await nextTick() + expect(workspaceApi.checkDeploymentCompatibility).toHaveBeenCalledTimes(3) + + answers[2](answer) + await checks[2] + expect(markFor('dep-rgthree')).toEqual({ kind: 'runs' }) + + answers[0]({ + deployments: [ + { deployment_id: 'dep-rgthree', missing_node_types: [], unknown: true } + ], + cloud: { missing_node_types: [] } + }) + await checks[0] + + expect(markFor('dep-rgthree')).toEqual({ kind: 'runs' }) + }) + + it('shows no old marks when a workflow comes back and its new check fails', async () => { + const { markFor } = setup() + await vi.waitFor(() => + expect(markFor('dep-rgthree')).toEqual({ kind: 'runs' }) + ) + + hoisted.rootGraph = graph() + useWorkflowStore().activeWorkflow = fromPartial({ + path: 'workflows/empty.json' + }) + await nextTick() + expect(markFor('dep-rgthree')).toBeNull() + + let fail: (error: Error) => void = () => {} + const failure = new Promise((_, reject) => { + fail = reject + }) + vi.mocked(workspaceApi.checkDeploymentCompatibility).mockReturnValueOnce( + failure + ) + hoisted.rootGraph = rgthreeWorkflow() + useWorkflowStore().activeWorkflow = fromPartial({ + path: 'workflows/rgthree.json' + }) + await nextTick() + expect(workspaceApi.checkDeploymentCompatibility).toHaveBeenCalledTimes(2) + expect(markFor('dep-rgthree')).toBeNull() + expect(markFor(null)).toBeNull() + + fail(new Error('503')) + await failure.catch(() => {}) + + expect(markFor('dep-rgthree')).toBeNull() + expect(markFor(null)).toBeNull() + }) + it('starts the deployment listing when nothing has loaded it yet', async () => { useDeploymentPickStore().state = { phase: 'idle' } vi.mocked(workspaceApi.listDeployments).mockResolvedValue({ diff --git a/src/platform/workspace/composables/useDeploymentCompatibility.ts b/src/platform/workspace/composables/useDeploymentCompatibility.ts index 372cf968087..e2985d6762c 100644 --- a/src/platform/workspace/composables/useDeploymentCompatibility.ts +++ b/src/platform/workspace/composables/useDeploymentCompatibility.ts @@ -136,10 +136,13 @@ export const useDeploymentCompatibility = createSharedComposable(() => { compatibility: DeploymentCompatibility } | null>(null) let checkFailureReported = false + let latestCheck = 0 watch( requestKey, async (key) => { + const check = ++latestCheck + answer.value = null const current = request.value if (key === null || current === null) return try { @@ -147,7 +150,7 @@ export const useDeploymentCompatibility = createSharedComposable(() => { current.workspaceId, current.nodeTypes ) - if (requestKey.value === key) answer.value = { key, compatibility } + if (check === latestCheck) answer.value = { key, compatibility } } catch (error) { if (checkFailureReported) return checkFailureReported = true