From 1d9b5b1e3e5f4a33ff9a32dbf81eafef6fc43fea Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Thu, 1 Oct 2026 02:24:01 -0700 Subject: [PATCH 1/4] feat: cancel cloud asset downloads (#19281) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Justification: Alex reviewed exact head b3485a7ae8dae919604f93cd5188edbed1f36d28 and explicitly recorded “ready to approve”; all required exact-head checks are terminal green, every substantive thread is resolved, and the seven-commit main delta has zero file overlap with this PR. Applying the documented selective stale-approval exception; post-merge peer review remains routed to Alex. --- .../fixtures/helpers/AssetsHelper.ts | 7 + .../dialogs/modelImportProgressDialog.spec.ts | 260 +++++++++++++++++ ...ast-recovered-completed-chromium-linux.png | Bin ...lImportProgressDialogStuckDownload.spec.ts | 226 --------------- eslint-suppressions.json | 5 - .../toast/ProgressToastItem.test.ts | 45 ++- src/components/toast/ProgressToastItem.vue | 26 +- .../ModelImportProgressDialog.test.ts | 99 +++++++ .../components/ModelImportProgressDialog.vue | 45 ++- .../composables/useUploadModelWizard.test.ts | 82 +++++- .../composables/useUploadModelWizard.ts | 24 +- .../remote/comfyui/execution/types.ts | 6 +- .../tasks/services/taskService.test.ts | 137 +++++++++ src/platform/tasks/services/taskService.ts | 93 ++++-- src/stores/assetDownloadStore.test.ts | 272 +++++++++++++++++- src/stores/assetDownloadStore.ts | 176 ++++++++---- src/stores/assetExportStore.ts | 51 ++-- 17 files changed, 1177 insertions(+), 377 deletions(-) create mode 100644 browser_tests/tests/dialogs/modelImportProgressDialog.spec.ts rename browser_tests/tests/{modelImportProgressDialogStuckDownload.spec.ts-snapshots => dialogs/modelImportProgressDialog.spec.ts-snapshots}/model-import-progress-toast-recovered-completed-chromium-linux.png (100%) delete mode 100644 browser_tests/tests/modelImportProgressDialogStuckDownload.spec.ts create mode 100644 src/platform/assets/components/ModelImportProgressDialog.test.ts create mode 100644 src/platform/tasks/services/taskService.test.ts diff --git a/browser_tests/fixtures/helpers/AssetsHelper.ts b/browser_tests/fixtures/helpers/AssetsHelper.ts index 45d8a2f3db0..bbef403b0e1 100644 --- a/browser_tests/fixtures/helpers/AssetsHelper.ts +++ b/browser_tests/fixtures/helpers/AssetsHelper.ts @@ -10,6 +10,7 @@ import type { JobDetail, RawJobListItem } from '@/platform/remote/comfyui/jobs/jobTypes' +import type { AssetDownloadWsMessage } from '@/platform/remote/comfyui/execution/types' const jobsListRoutePattern = '**/api/jobs?*' const assetsListRoutePattern = /\/api\/assets(?:\?.*)?$/ @@ -138,6 +139,12 @@ export class AssetsHelper { constructor(private readonly page: Page) {} + async dispatchDownload(message: AssetDownloadWsMessage): Promise { + await this.page.evaluate((download) => { + window.app!.api.dispatchCustomEvent('asset_download', download) + }, message) + } + async mockOutputHistory(jobs: RawJobListItem[]): Promise { this.generatedJobs = [...jobs] diff --git a/browser_tests/tests/dialogs/modelImportProgressDialog.spec.ts b/browser_tests/tests/dialogs/modelImportProgressDialog.spec.ts new file mode 100644 index 00000000000..d81343948b7 --- /dev/null +++ b/browser_tests/tests/dialogs/modelImportProgressDialog.spec.ts @@ -0,0 +1,260 @@ +import type { TaskResponse } from '@/platform/tasks/services/taskService' + +import { + comfyPageFixture as test, + comfyExpect as expect +} from '@e2e/fixtures/ComfyPage' + +test.describe('Model import progress toast', { tag: ['@screenshot'] }, () => { + test('recovers from a premature failed status once the backend silently retries and completes it (PM-1302)', async ({ + comfyPage + }) => { + const { page } = comfyPage + const taskId = 'pm-1302-repro-task' + const assetName = 'stuck-model.safetensors' + + await test.step('show a running model import', async () => { + await comfyPage.assets.dispatchDownload({ + task_id: taskId, + asset_name: assetName, + bytes_total: 1000, + bytes_downloaded: 200, + progress: 20, + status: 'running' + }) + + await expect( + page.getByText('Importing Models', { exact: true }) + ).toBeVisible() + }) + + const failedFooterText = page.getByText('1 download failed', { + exact: true + }) + + await test.step('show the retryable failure reported by the backend', async () => { + await comfyPage.assets.dispatchDownload({ + task_id: taskId, + asset_name: assetName, + bytes_total: 1000, + bytes_downloaded: 200, + progress: 20, + status: 'failed', + error: 'Source server error' + }) + + await expect(failedFooterText).toBeVisible() + }) + + await test.step('recover after the backend retry succeeds', async () => { + await comfyPage.assets.dispatchDownload({ + task_id: taskId, + asset_name: assetName, + asset_id: 'asset-pm-1302', + bytes_total: 1000, + bytes_downloaded: 1000, + progress: 100, + status: 'completed' + }) + await comfyPage.nextFrame() + + await expect(failedFooterText).toBeHidden() + await expect( + page.getByText('All downloads completed', { exact: true }) + ).toBeVisible() + }) + + const toast = page + .getByRole('status') + .filter({ hasText: 'All downloads completed' }) + + await expect(toast).toHaveScreenshot( + 'model-import-progress-toast-recovered-completed.png', + { mask: [toast.locator('.timestamp')] } + ) + }) + + test('a failed download toast can still be manually dismissed when no later recovery message arrives (PM-1302)', async ({ + comfyPage + }) => { + const { page } = comfyPage + const taskId = 'pm-1302-dismiss-task' + const assetName = 'stuck-model.safetensors' + + await test.step('show a failed model import', async () => { + await comfyPage.assets.dispatchDownload({ + task_id: taskId, + asset_name: assetName, + bytes_total: 1000, + bytes_downloaded: 200, + progress: 20, + status: 'running' + }) + await comfyPage.assets.dispatchDownload({ + task_id: taskId, + asset_name: assetName, + bytes_total: 1000, + bytes_downloaded: 200, + progress: 20, + status: 'failed', + error: 'Source server error' + }) + }) + + const toast = page + .getByRole('status') + .filter({ hasText: '1 download failed' }) + await expect(toast).toBeVisible() + await expect( + page.getByText('1 download failed', { exact: true }) + ).toBeVisible() + + await test.step('dismiss the failed model import', async () => { + await toast.getByRole('button', { name: 'Close' }).click() + await expect(toast).toBeHidden() + }) + }) + + test('cancels a running download and renders the backend terminal state (PM-1309)', async ({ + comfyPage + }) => { + const { page } = comfyPage + const taskId = '1396cc07-bab2-4f12-9b54-741f83f9224c' + const assetName = 'cancelled-model.safetensors' + const cancellationResponse = page.waitForResponse( + (response) => + response.url().endsWith(`/tasks/${taskId}`) && + response.request().method() === 'DELETE' + ) + await page.route(`**/tasks/${taskId}`, async (route) => { + if (route.request().method() === 'DELETE') { + await route.fulfill({ status: 204 }) + return + } + + await route.fulfill({ + json: { + id: taskId, + idempotency_key: taskId, + task_name: 'task:download_file', + payload: {}, + status: 'running', + create_time: new Date().toISOString(), + update_time: new Date().toISOString() + } satisfies TaskResponse + }) + }) + + await test.step('show the running download', async () => { + await comfyPage.assets.dispatchDownload({ + task_id: taskId, + asset_name: assetName, + bytes_total: 1000, + bytes_downloaded: 200, + progress: 20, + status: 'running' + }) + }) + + const toast = page.getByRole('status').filter({ hasText: assetName }) + await expect(toast).toBeVisible() + + await test.step('cancel through user-visible controls', async () => { + await toast.getByRole('button', { name: 'Expand' }).click() + await expect( + toast.getByRole('button', { name: 'Collapse' }) + ).toBeVisible() + const cancelButton = toast.getByRole('button', { + name: 'Cancel Download' + }) + await expect(cancelButton).toBeVisible() + await cancelButton.click() + + const response = await cancellationResponse + expect(response.status()).toBe(204) + await expect( + toast.getByText('Cancelled', { exact: true }).first() + ).toBeVisible() + await expect(toast.getByRole('button', { name: 'Close' })).toBeHidden() + }) + + await test.step('keep the terminal backend state rendered', async () => { + await comfyPage.assets.dispatchDownload({ + task_id: taskId, + asset_name: assetName, + bytes_total: 1000, + bytes_downloaded: 200, + progress: 20, + status: 'cancelled' + }) + + await expect( + toast.getByText('Cancelled', { exact: true }).first() + ).toBeVisible() + await expect( + toast.getByRole('button', { name: 'Cancel Download' }) + ).toBeHidden() + await expect(toast.getByRole('button', { name: 'Close' })).toBeVisible() + }) + }) + + test('closing a failed download while polling does not reopen its toast', async ({ + comfyPage + }) => { + const { page } = comfyPage + const taskId = '1396cc07-bab2-4f12-9b54-741f83f9224b' + const assetName = 'failed-model.safetensors' + let releaseResponse!: () => void + const responseReady = new Promise((resolve) => { + releaseResponse = resolve + }) + const response: TaskResponse = { + id: taskId, + idempotency_key: taskId, + task_name: 'task:download_file', + payload: {}, + status: 'failed', + error_message: 'Download failed', + create_time: new Date().toISOString(), + update_time: new Date().toISOString() + } + await page.route(`**/tasks/${taskId}`, async (route) => { + await responseReady + await route.fulfill({ json: response }) + }) + + await test.step('start reconciling a failed model import', async () => { + await page.clock.install() + await comfyPage.assets.dispatchDownload({ + task_id: taskId, + asset_name: assetName, + bytes_total: 1000, + bytes_downloaded: 200, + progress: 20, + status: 'failed', + error: 'Source server error' + }) + const request = page.waitForRequest(`**/tasks/${taskId}`) + await page.clock.runFor(10_000) + await request + }) + + const toast = page + .getByRole('status') + .filter({ hasText: '1 download failed' }) + + await test.step('dismiss the model import during reconciliation', async () => { + await toast.getByRole('button', { name: 'Close' }).click() + await expect(toast).toBeHidden() + }) + + await test.step('keep the model import dismissed after polling settles', async () => { + const completedResponse = page.waitForResponse(`**/tasks/${taskId}`) + releaseResponse() + await (await completedResponse).finished() + await page.clock.runFor(100) + + await expect(toast).toBeHidden() + }) + }) +}) diff --git a/browser_tests/tests/modelImportProgressDialogStuckDownload.spec.ts-snapshots/model-import-progress-toast-recovered-completed-chromium-linux.png b/browser_tests/tests/dialogs/modelImportProgressDialog.spec.ts-snapshots/model-import-progress-toast-recovered-completed-chromium-linux.png similarity index 100% rename from browser_tests/tests/modelImportProgressDialogStuckDownload.spec.ts-snapshots/model-import-progress-toast-recovered-completed-chromium-linux.png rename to browser_tests/tests/dialogs/modelImportProgressDialog.spec.ts-snapshots/model-import-progress-toast-recovered-completed-chromium-linux.png diff --git a/browser_tests/tests/modelImportProgressDialogStuckDownload.spec.ts b/browser_tests/tests/modelImportProgressDialogStuckDownload.spec.ts deleted file mode 100644 index c3978be1720..00000000000 --- a/browser_tests/tests/modelImportProgressDialogStuckDownload.spec.ts +++ /dev/null @@ -1,226 +0,0 @@ -import type { Page } from '@playwright/test' - -import type { TaskResponse } from '@/platform/tasks/services/taskService' - -import { - comfyPageFixture as test, - comfyExpect as expect -} from '@e2e/fixtures/ComfyPage' - -/** - * REGRESSION COVERAGE PM-1302 / PM-1309 (frontend half): - * - * On the cloud side, `HandleDownloadFile` (download_file.go) can broadcast a - * terminal `failed` message for a retryable error before asynq decides - * whether a retry will happen, then quietly retries. `assetDownloadStore` - * (src/stores/assetDownloadStore.ts) now treats a `failed` status as - * recoverable rather than final, so a later `completed` message for the same - * `task_id` still updates it - keeping the ModelImportProgressDialog toast - * from getting stuck reporting a download as failed forever when it actually - * finished successfully. - * - * This test drives that exact WS sequence through the real `asset_download` - * client event (the same event `assetDownloadStore` listens on in - * production) and proves the toast recovers once the later success message - * arrives. - */ -const TASK_ID = 'pm-1302-repro-task' -const ASSET_NAME = 'stuck-model.safetensors' - -interface AssetDownloadMessage { - task_id: string - asset_name: string - bytes_total: number - bytes_downloaded: number - progress: number - status: 'created' | 'running' | 'completed' | 'failed' - asset_id?: string - error?: string -} - -async function dispatchAssetDownload( - page: Page, - message: AssetDownloadMessage -) { - await page.evaluate((msg) => { - window.app!.api.dispatchCustomEvent('asset_download', msg) - }, message) -} - -test.describe( - 'Model import progress toast - stuck download status', - { tag: ['@screenshot'] }, - () => { - test('recovers from a premature failed status once the backend silently retries and completes it (PM-1302)', async ({ - comfyPage - }) => { - const { page } = comfyPage - - // 1. Download starts. - await dispatchAssetDownload(page, { - task_id: TASK_ID, - asset_name: ASSET_NAME, - bytes_total: 1000, - bytes_downloaded: 200, - progress: 20, - status: 'running' - }) - - const toastHeader = page.getByText('Importing Models', { exact: true }) - await expect(toastHeader).toBeVisible() - - // 2. Backend hits a retryable error and (per the bug in - // download_file.go's HandleDownloadFile) broadcasts a premature - // terminal `failed` message before it decides to retry. - await dispatchAssetDownload(page, { - task_id: TASK_ID, - asset_name: ASSET_NAME, - bytes_total: 1000, - bytes_downloaded: 200, - progress: 20, - status: 'failed', - error: 'Source server error' - }) - - const failedFooterText = page.getByText('1 download failed', { - exact: true - }) - await expect(failedFooterText).toBeVisible() - - // 3. Backend silently retried (asynq's StatusMiddleware reset the task - // to pending) and the retry succeeded - cloud broadcasts the real, - // later `completed` message for the same task_id. - await dispatchAssetDownload(page, { - task_id: TASK_ID, - asset_name: ASSET_NAME, - asset_id: 'asset-pm-1302', - bytes_total: 1000, - bytes_downloaded: 1000, - progress: 100, - status: 'completed' - }) - await comfyPage.nextFrame() - - // The later `completed` message updates the download rather than - // being dropped, so the toast reflects the real, successful outcome. - await expect(failedFooterText).toBeHidden() - await expect( - page.getByText('All downloads completed', { exact: true }) - ).toBeVisible() - - // Scoped to the toast: a full-`body` screenshot also captures the - // canvas graph background, which isn't pixel-stable across CI runs. - const toast = page - .getByRole('status') - .filter({ hasText: 'All downloads completed' }) - - // Visual proof of the recovered, completed toast state. - await expect(toast).toHaveScreenshot( - 'model-import-progress-toast-recovered-completed.png', - { mask: [toast.locator('.timestamp')] } - ) - }) - - test('a failed download toast can still be manually dismissed when no later recovery message arrives (PM-1302)', async ({ - comfyPage - }) => { - const { page } = comfyPage - - // Same premature-failed sequence as above, minus the later `completed` - // message - the point here is only whether the user can get rid of a - // failed toast on their own when the backend never does send a - // recovery message. - await dispatchAssetDownload(page, { - task_id: TASK_ID, - asset_name: ASSET_NAME, - bytes_total: 1000, - bytes_downloaded: 200, - progress: 20, - status: 'running' - }) - await dispatchAssetDownload(page, { - task_id: TASK_ID, - asset_name: ASSET_NAME, - bytes_total: 1000, - bytes_downloaded: 200, - progress: 20, - status: 'failed', - error: 'Source server error' - }) - - // Scoped by footer text: `getByRole('status')` alone also matches the - // top-menu action bar's own status region and is a strict-mode - // violation with two toasts on screen. - const toast = page - .getByRole('status') - .filter({ hasText: '1 download failed' }) - await expect(toast).toBeVisible() - await expect( - page.getByText('1 download failed', { exact: true }) - ).toBeVisible() - - // `isInProgress` is false once a `failed` status lands, so - // ModelImportProgressDialog's close (X) button renders and is - // clickable regardless of whether a later recovery message ever - // arrives. - // - // Scoped to `toast`: `page.getByRole('button', { name: 'Close' })` - // alone also matches the canvas minimap's close button - // (`data-testid="close-minimap-button"`) and is a strict-mode - // violation with the minimap visible. - await toast.getByRole('button', { name: 'Close' }).click() - - await expect(toast).toBeHidden() - }) - - test('closing a failed download while polling does not reopen its toast', async ({ - comfyPage - }) => { - const { page } = comfyPage - const taskId = '1396cc07-bab2-4f12-9b54-741f83f9224b' - let releaseResponse!: () => void - const responseReady = new Promise((resolve) => { - releaseResponse = resolve - }) - const response: TaskResponse = { - id: taskId, - idempotency_key: taskId, - task_name: 'task:download_file', - payload: {}, - status: 'failed', - error_message: 'Download failed', - create_time: new Date().toISOString(), - update_time: new Date().toISOString() - } - await page.route(`**/tasks/${taskId}`, async (route) => { - await responseReady - await route.fulfill({ json: response }) - }) - await page.clock.install() - await dispatchAssetDownload(page, { - task_id: taskId, - asset_name: ASSET_NAME, - bytes_total: 1000, - bytes_downloaded: 200, - progress: 20, - status: 'failed', - error: 'Source server error' - }) - const request = page.waitForRequest(`**/tasks/${taskId}`) - await page.clock.runFor(10_000) - await request - - const toast = page - .getByRole('status') - .filter({ hasText: '1 download failed' }) - await toast.getByRole('button', { name: 'Close' }).click() - await expect(toast).toBeHidden() - const completedResponse = page.waitForResponse(`**/tasks/${taskId}`) - releaseResponse() - await (await completedResponse).finished() - await page.clock.runFor(100) - - await expect(toast).toBeHidden() - }) - } -) diff --git a/eslint-suppressions.json b/eslint-suppressions.json index ea3f6dd2cfa..2900c760e98 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -239,11 +239,6 @@ "count": 1 } }, - "src/platform/tasks/services/taskService.ts": { - "comfy/no-new-error-throw": { - "count": 3 - } - }, "src/platform/workflow/management/stores/comfyWorkflow.ts": { "comfy/no-new-error-throw": { "count": 2 diff --git a/src/components/toast/ProgressToastItem.test.ts b/src/components/toast/ProgressToastItem.test.ts index 14e5b5d867e..ceaf775821c 100644 --- a/src/components/toast/ProgressToastItem.test.ts +++ b/src/components/toast/ProgressToastItem.test.ts @@ -1,4 +1,5 @@ import { render, screen } from '@testing-library/vue' +import userEvent from '@testing-library/user-event' import { describe, expect, it } from 'vitest' import { createI18n } from 'vue-i18n' @@ -15,7 +16,12 @@ const i18n = createI18n({ finished: 'Finished', failed: 'Failed', pending: 'Pending' - } + }, + electronFileDownload: { + cancel: 'Cancel Download', + cancelled: 'Cancelled' + }, + g: { cancel: 'Cancel' } } } }) @@ -49,3 +55,40 @@ describe('ProgressToastItem — completed state', () => { expect(assetName.closest('.opacity-50')).not.toBeNull() }) }) + +describe('ProgressToastItem — cancellation', () => { + it('offers cancellation for running downloads', async () => { + const user = userEvent.setup() + const running = { ...completedJob(), status: 'running' as const } + const { emitted } = render(ProgressToastItem, { + props: { job: running }, + global: { plugins: [i18n] } + }) + + await user.click(screen.getByRole('button', { name: 'Cancel Download' })) + expect(emitted().cancel).toEqual([['task-1']]) + }) + + it('shows cancelled as terminal without another cancel button', () => { + const cancelled = { ...completedJob(), status: 'cancelled' as const } + render(ProgressToastItem, { + props: { job: cancelled }, + global: { plugins: [i18n] } + }) + + expect(screen.getByText('Cancelled')).toBeVisible() + expect(screen.queryByRole('button', { name: 'Cancel Download' })).toBeNull() + }) + + it('disables duplicate cancellation while the request is pending', () => { + const running = { ...completedJob(), status: 'running' as const } + render(ProgressToastItem, { + props: { job: running, isCancelling: true }, + global: { plugins: [i18n] } + }) + + expect( + screen.getByRole('button', { name: 'Cancel Download' }) + ).toBeDisabled() + }) +}) diff --git a/src/components/toast/ProgressToastItem.vue b/src/components/toast/ProgressToastItem.vue index 92a5cef08b1..2a0cde3f115 100644 --- a/src/components/toast/ProgressToastItem.vue +++ b/src/components/toast/ProgressToastItem.vue @@ -4,12 +4,17 @@ import { useI18n } from 'vue-i18n' import Loader from '@/components/loader/Loader.vue' import StatusBadge from '@/components/common/StatusBadge.vue' +import Button from '@/components/ui/button/Button.vue' +import type { TaskId } from '@/platform/tasks/services/taskService' import type { AssetDownload } from '@/stores/assetDownloadStore' +import { isDownloadCancelled } from '@/stores/assetDownloadStore' import { cn } from '@comfyorg/tailwind-utils' -const { job } = defineProps<{ +const { job, isCancelling = false } = defineProps<{ job: AssetDownload + isCancelling?: boolean }>() +const emit = defineEmits<{ cancel: [taskId: TaskId] }>() const { t } = useI18n() @@ -18,6 +23,7 @@ const isCompleted = computed(() => job.status === 'completed') const isFailed = computed(() => job.status === 'failed') const isRunning = computed(() => job.status === 'running') const isPending = computed(() => job.status === 'created') +const isCancelled = computed(() => isDownloadCancelled(job.status)) + + + + diff --git a/src/platform/assets/components/ModelImportProgressDialog.test.ts b/src/platform/assets/components/ModelImportProgressDialog.test.ts new file mode 100644 index 00000000000..e14ace9ceab --- /dev/null +++ b/src/platform/assets/components/ModelImportProgressDialog.test.ts @@ -0,0 +1,99 @@ +import { render, screen, waitFor } from '@testing-library/vue' +import userEvent from '@testing-library/user-event' +import { createI18n } from 'vue-i18n' +import { describe, expect, it, vi } from 'vitest' +import { nextTick } from 'vue' + +import enMessages from '@/locales/en/main.json' with { type: 'json' } +import { reportError } from '@/platform/telemetry/reportError' +import { useToastStore } from '@/platform/updates/common/toastStore' +import { useAssetDownloadStore } from '@/stores/assetDownloadStore' + +import ModelImportProgressDialog from './ModelImportProgressDialog.vue' + +vi.mock(import('@/platform/telemetry/reportError'), () => ({ + reportError: vi.fn() +})) + +const i18n = createI18n({ + legacy: false, + locale: 'en', + messages: { en: enMessages } +}) + +function renderDialog() { + const store = useAssetDownloadStore() + store.trackDownload('task-123', 'checkpoints', 'model.safetensors') + render(ModelImportProgressDialog, { + global: { plugins: [i18n] } + }) + return store +} + +describe('ModelImportProgressDialog cancellation', () => { + it('forwards the task ID and disables its cancel action while pending', async () => { + const user = userEvent.setup() + const store = renderDialog() + vi.spyOn(store, 'cancelDownload').mockImplementation((taskId) => { + store.cancellingTaskIds.add(taskId) + return new Promise(() => {}) + }) + + await user.click(screen.getByRole('button', { name: 'Expand' })) + const cancelButton = screen.getByRole('button', { + name: 'Cancel Download' + }) + await user.click(cancelButton) + + expect(store.cancelDownload).toHaveBeenCalledWith('task-123') + expect(cancelButton).toBeDisabled() + }) + + it('reports cancellation failures and shows the error toast', async () => { + const user = userEvent.setup() + const store = renderDialog() + const toastStore = useToastStore() + const addToast = vi.spyOn(toastStore, 'add') + vi.spyOn(console, 'error').mockImplementation(() => {}) + const error = new Error('Cancellation unavailable') + vi.spyOn(store, 'cancelDownload').mockResolvedValue({ ok: false, error }) + + await user.click(screen.getByRole('button', { name: 'Expand' })) + await user.click(screen.getByRole('button', { name: 'Cancel Download' })) + + await waitFor(() => { + expect(reportError).toHaveBeenCalledWith(error, { + surface: 'assets', + errorType: 'asset_download_cancellation_failure', + logToConsole: false + }) + expect(addToast).toHaveBeenCalledWith({ + severity: 'error', + summary: 'Error', + detail: 'Cancellation unavailable' + }) + }) + }) + + it('keeps provisional cancellations open for authoritative reconciliation', async () => { + const store = renderDialog() + + store.downloadList[0].status = 'cancellation_pending' + await nextTick() + + expect(screen.queryByRole('button', { name: 'Close' })).toBeNull() + expect(screen.getAllByText('Cancelled')).not.toHaveLength(0) + }) + + it('dismisses a failed download while reconciliation continues', async () => { + const user = userEvent.setup() + const store = renderDialog() + + store.downloadList[0].status = 'failed' + await nextTick() + + await user.click(screen.getByRole('button', { name: 'Close' })) + + expect(screen.queryByRole('status')).toBeNull() + }) +}) diff --git a/src/platform/assets/components/ModelImportProgressDialog.vue b/src/platform/assets/components/ModelImportProgressDialog.vue index 9e6457b164a..aef9d7c6bdb 100644 --- a/src/platform/assets/components/ModelImportProgressDialog.vue +++ b/src/platform/assets/components/ModelImportProgressDialog.vue @@ -8,11 +8,18 @@ import Loader from '@/components/loader/Loader.vue' import HoneyToast from '@/components/honeyToast/HoneyToast.vue' import ProgressToastItem from '@/components/toast/ProgressToastItem.vue' import Button from '@/components/ui/button/Button.vue' -import { useAssetDownloadStore } from '@/stores/assetDownloadStore' +import { useErrorHandling } from '@/composables/useErrorHandling' +import { reportError } from '@/platform/telemetry/reportError' +import type { TaskId } from '@/platform/tasks/services/taskService' +import { + isDownloadCancelled, + useAssetDownloadStore +} from '@/stores/assetDownloadStore' import { cn } from '@comfyorg/tailwind-utils' const { t } = useI18n() const assetDownloadStore = useAssetDownloadStore() +const { toastErrorHandler } = useErrorHandling() const visible = computed(() => assetDownloadStore.hasDownloads) @@ -47,6 +54,11 @@ const completedJobs = computed(() => const failedJobs = computed(() => assetDownloadStore.finishedDownloads.filter((d) => d.status === 'failed') ) +const cancelledJobs = computed(() => + assetDownloadStore.downloadList.filter((download) => + isDownloadCancelled(download.status) + ) +) const isInProgress = computed(() => assetDownloadStore.hasActiveDownloads) const currentJobName = computed(() => { @@ -55,7 +67,10 @@ const currentJobName = computed(() => { }) const completedCount = computed( - () => completedJobs.value.length + failedJobs.value.length + () => + completedJobs.value.length + + failedJobs.value.length + + cancelledJobs.value.length ) const totalCount = computed(() => downloadJobs.value.length) @@ -81,6 +96,18 @@ function closeDialog() { assetDownloadStore.clearFinishedDownloads() isExpanded.value = false } + +async function cancelDownload(taskId: TaskId) { + const result = await assetDownloadStore.cancelDownload(taskId) + if (result.ok) return + + reportError(result.error, { + surface: 'assets', + errorType: 'asset_download_cancellation_failure', + logToConsole: false + }) + toastErrorHandler(result.error) +} + +