diff --git a/TESTING.md b/TESTING.md index e012bc6e..a49cbd02 100644 --- a/TESTING.md +++ b/TESTING.md @@ -4147,6 +4147,9 @@ legacy page workflows), not by this check. | Clear server thumbnails | gallery | — | — | Thumbnail cache opens the S5 dialog (workspace-system-maintenance.spec.mjs) | | Refresh file listing | gallery | `#rescanFolderBtn` | `rescanFolder()` | Refresh files calls /gallery/rescan and toasts its counts (workspace-system-sources.spec.mjs) | | Duplicate image scan, review, delete | gallery | `#scanDuplicatesBtn`, `#dupScanPill`, `#dupScanPillText`, `#duplicatesModal`, `#closeDuplicatesBtn`, `#duplicatesScanStatus`, `#dupProgressText`, `#dupProgressBar`, `#duplicatesContent`, `#duplicatesList`, `#duplicatesFooter`, `#duplicatesCount`, `#selectAllBtn`, `#removeDuplicatesBtn` | `scanDuplicates()`, `attachDuplicateStream()`, `resumeDuplicateScan()`, `applyDuplicateEvent()`, `renderDuplicateProgress()`, `setDuplicateButton()`, `showDuplicatePill()`, `hideDuplicatePill()`, `openDuplicatesModal()`, `showDuplicatesModal()`, `hideDuplicatesModal()`, `displayDuplicates()`, `selectAllDuplicates()`, `removeDuplicates()` | Find duplicates starts a job; its view links Review groups; Keep radios build a duplicate_files plan (D101) (workspace-system-maintenance.spec.mjs) | +| Auto-tag model download | admin | `#autoTagDownloadModal`, `#downloadModelName`, `#downloadStatus`, `#downloadProgressPercent`, `#downloadProgressBar`, `#cancelDownloadBtn` | `downloadModel()`, `cancelDownload()` | Download starts the job and Activity shows it without Cancel (workspace-system-tagging.spec.mjs) | +| Auto-tag model download | gallery | `#autoTagDownloadModal`, `#downloadModelName`, `#downloadStatus`, `#downloadProgressPercent`, `#downloadProgressBar`, `#cancelDownloadBtn` | `downloadModel()`, `cancelDownload()` | Download starts the job and Activity shows it without Cancel (workspace-system-tagging.spec.mjs) | +| Unload model | gallery | — | `unloadModel()` | Unload is enabled only while a model is loaded, and a held gate's refusal names the operation (workspace-system-tagging.spec.mjs) | ### Browser cache ownership (#222) diff --git a/tests/browser/legacy-autotag.spec.mjs b/tests/browser/legacy-autotag.spec.mjs index ff96f681..089dafd2 100644 --- a/tests/browser/legacy-autotag.spec.mjs +++ b/tests/browser/legacy-autotag.spec.mjs @@ -1,11 +1,9 @@ -// #328: the legacy admin and gallery auto-tag tools keep working beside System › Auto-tagging. The model download is -// the `model_download` Activity job; the pages' stream attaches to it. No model is ever downloaded: the fixture's -// fake download waits until the test releases it (`/__test__/tagging/download`). +// #328: the legacy admin and gallery auto-tag batch and review keep working beside System › Auto-tagging. Since #330 +// the pages download and unload models only through System (legacy-system-links.spec.mjs); a batch never downloads +// one. The fixture's fake download (`/__test__/tagging/download`) is held so nothing is ever fetched. import { startCoverage, saveCoverage } from '../../tools/vendor/browser-coverage.mjs'; import { test, expect } from './fixtures.mjs'; -const TITLE = 'Tagging model download · WD14 ViT'; - async function post(request, url, data) { await expect(await request.post(url, data === undefined ? {} : { data })).toBeOK(); } @@ -33,61 +31,6 @@ test.afterEach(async ({ page, request, browserName }) => { await post(request, '/__test__/jobs/restart'); }); -async function startDownload(page, request) { - await page.locator('#autoTagBtn').click(); - const status = page.locator('#wd14VitModelStatus'); - await status.getByRole('button', { name: 'Download', exact: true }).click(); - const modal = page.locator('#autoTagDownloadModal'); - await expect(modal).toBeVisible(); - await expect(page.locator('#downloadStatus')).toHaveText('Downloading…'); - await expect(page.locator('#downloadProgressBar')).toHaveClass(/animate-pulse/); - await expect(modal).toContainText('The download continues in Activity.'); - await expect(page.locator('#cancelDownloadBtn')).toHaveText('Close'); - const running = (await downloads(request)).filter(job => job.state === 'running'); - expect(running.map(job => [job.title, job.cancellable])).toEqual([[TITLE, false]]); - return { modal, status }; -} - -test('admin download modal closes on complete and Activity lists the job without Cancel', async ({ page, request }) => { - await page.goto('/prompt_manager/admin'); - const { modal, status } = await startDownload(page, request); - - await page.goto('/prompt_manager/workspace#/activity'); - const item = page.locator('#workspace-main section.surface > .activity-item') - .filter({ has: page.getByRole('link', { name: new RegExp(`${TITLE}$`) }) }); - await expect(item.locator('.chip')).toHaveText('Running'); - await expect(item.locator('progress')).not.toHaveAttribute('value'); - await expect(item.getByRole('button', { name: 'Cancel job', exact: true })).toHaveCount(0); - - // Back on the admin page a second download of the same model attaches to the running job. - await page.goto('/prompt_manager/admin'); - await startDownload(page, request); - await post(request, '/__test__/tagging/download', { mode: 'succeed' }); - await expect(modal).toBeHidden(); - await expect(status).toContainText('Downloaded'); - expect((await downloads(request)).map(job => [job.title, job.state])).toEqual([[TITLE, 'finished']]); -}); - -test('gallery download modal closes on complete', async ({ page, request }) => { - await page.goto('/prompt_manager/gallery'); - const { modal, status } = await startDownload(page, request); - await post(request, '/__test__/tagging/download', { mode: 'succeed' }); - await expect(modal).toBeHidden(); - await expect(page.locator('#autoTagModal')).toBeVisible(); - await expect(status).toContainText('Downloaded'); - expect((await downloads(request)).map(job => job.state)).toEqual(['finished']); -}); - -test('a failed download closes the modal and says so', async ({ page, request }) => { - await page.goto('/prompt_manager/gallery'); - const { modal, status } = await startDownload(page, request); - await post(request, '/__test__/tagging/download', { mode: 'fail' }); - await expect(modal).toBeHidden(); - await expect(page.getByText('Download failed: Download failed')).toBeVisible(); - await expect(status.getByRole('button', { name: 'Download', exact: true })).toBeVisible(); - expect((await downloads(request)).map(job => job.state)).toEqual(['failed']); -}); - // (wd14-vit is not downloaded in these tests: beforeEach marks it so the download tests can offer it.) // The gallery's batch reader keyed on `data.status` values the server never sends, so its modal never moved or // closed (#328 Problem 5). It now reads `type` frames as the admin page does. @@ -171,25 +114,6 @@ test('admin review opens the first image', async ({ page }) => { await expect(page.getByText('Failed to start review mode')).toHaveCount(0); }); -test('gallery unload works and is refused while the gate is held', async ({ page, request }) => { - await page.goto('/prompt_manager/gallery'); - await runGalleryBatch(page); // keeps the model in memory - await page.locator('#autoTagBtn').click(); - const unload = page.locator('#unloadModelBtn'); - await expect(unload).toBeVisible(); - - // A held download owns the model gate: Unload is refused with the server's error. - const held = await request.post('/prompt_manager/jobs/model-download', { data: { model_type: 'gguf' } }); - expect(held.status()).toBe(202); - await unload.click(); - await expect(page.getByText(/^Failed to unload model: A tagging model is busy/)).toBeVisible(); - - await post(request, '/__test__/tagging/download', { mode: 'succeed' }); - await expect.poll(async () => (await downloads(request)).map(job => job.state)).toEqual(['finished']); - await unload.click(); - await expect(page.getByText('WD14-SWINV2 model unloaded successfully')).toBeVisible(); -}); - /** The admin review lists every row, videos too: Skip any image that is not one until the confirmation shows. */ async function untilAutoTagged(page, confirm) { // Each image's skip check answers before its confirmation or its error shows. diff --git a/tests/browser/legacy-system-links.spec.mjs b/tests/browser/legacy-system-links.spec.mjs index 56250bea..17d03509 100644 --- a/tests/browser/legacy-system-links.spec.mjs +++ b/tests/browser/legacy-system-links.spec.mjs @@ -20,6 +20,17 @@ async function openPageOptions(page) { await expect(page.locator('#settingsModal')).toBeVisible(); } +/** The auto-tag modal with its model rows read from /autotag/models. */ +async function openAutoTag(page) { + const read = page.waitForResponse(item => item.url().endsWith('/prompt_manager/autotag/models')); + await page.locator('#autoTagBtn').click(); + await read; + await expect(page.locator('#autoTagModal')).toBeVisible(); +} + +const notDownloaded = (page, request) => post(request, '/__test__/tagging/models', { unavailable: ['gguf'] }); +const modelLoaded = (page, request) => post(request, '/__test__/tagging/loaded', { model: 'wd14-vit' }); + // One row per System link of the design's §2 map: the page, the control's label, how to find it, the section it opens // and what a test must arrange before the control shows. const LINKS = Object.freeze([ @@ -28,6 +39,12 @@ const LINKS = Object.freeze([ { page: 'admin', label: 'Backup DB', locate: page => page.locator('#backupBtn'), section: 'backups' }, { page: 'admin', label: 'Restore DB', locate: page => page.locator('#restoreBtn'), section: 'backups' }, { page: 'gallery', label: 'Settings', locate: page => page.locator('#settingsBtn'), section: 'appearance' }, + { page: 'admin', label: 'Manage in System (model row)', arrange: notDownloaded, reveal: openAutoTag, + locate: page => page.locator('#ggufModelStatus a'), section: 'tagging' }, + { page: 'gallery', label: 'Manage in System (model row)', arrange: notDownloaded, reveal: openAutoTag, + locate: page => page.locator('#ggufModelStatus a'), section: 'tagging' }, + { page: 'gallery', label: 'Manage in System (Unload Model)', arrange: modelLoaded, reveal: openAutoTag, + locate: page => page.locator('#unloadModelBtn'), section: 'tagging' }, { page: 'gallery', label: 'Page options Maintenance', reveal: openPageOptions, locate: page => page.locator('#pageOptionsMaintenanceLink'), section: 'maintenance' }, { page: 'gallery', label: 'Page options Sources & scans', reveal: openPageOptions, @@ -249,3 +266,26 @@ test('Page options keeps the page-only settings gallery', async ({ page }) => { defaultLimit: 100, debugMode: false, checkThumbnailsAtStartup: true, lazyLoading: true, gridColumns: 8, infiniteScroll: false, apiTimeout: 30 }); }); + +test('the legacy auto-tag modal stays open after Manage in System', async ({ page, context, request }) => { + for (const legacy of ['admin', 'gallery']) { + await post(request, '/__test__/tagging/models', { unavailable: ['gguf'] }); + await page.goto(PAGES[legacy]); + await openAutoTag(page); + const link = page.locator('#ggufModelStatus').getByRole('link', { name: 'Manage in System', exact: true }); + await expect(link).toHaveAttribute('title', 'Opens System › Auto-tagging in a new tab'); + // A downloaded model keeps its status text. + await expect(page.locator('#wd14VitModelStatus')).toHaveText('\u2713 Downloaded'); + const opened = context.waitForEvent('page'); + await link.click(); + const system = await opened; + await expect(system).toHaveURL(/#\/system\/tagging$/); + await expect(page.locator('#autoTagModal')).toBeVisible(); + await system.close(); + // Downloaded in System meanwhile: reopening the modal reads the models again (CUJ 4). + await post(request, '/__test__/tagging/models', { unavailable: [] }); + await page.goto(PAGES[legacy]); + await openAutoTag(page); + await expect(page.locator('#ggufModelStatus')).toHaveText('\u2713 Downloaded'); + } +}); diff --git a/tests/browser/workspace_tagging_fixture.py b/tests/browser/workspace_tagging_fixture.py index 01667ee8..aaf412fe 100644 --- a/tests/browser/workspace_tagging_fixture.py +++ b/tests/browser/workspace_tagging_fixture.py @@ -247,6 +247,22 @@ def register_tagging_commands( model.unavailable = set(data["unavailable"]) return web.json_response({"success": True}) + @routes.post("/__test__/tagging/loaded") + async def loaded(request: web.Request) -> web.Response: + """Mark one fake model loaded (``{"model": ""}``), as a batch that + kept it in memory leaves it; ``/autotag/models`` then reports + ``model_loaded``. Reset unloads it.""" + data = await request.json() if request.can_read_body else None + if ( + request.query + or not isinstance(data, dict) + or set(data) != {"model"} + or data["model"] not in MODELS + ): + raise web.HTTPBadRequest() + model.loaded = data["model"] + return web.json_response({"success": True}) + @routes.post("/__test__/tagging/download") async def download_mode(request: web.Request) -> web.Response: """Switch the model's download to a fake (never a real download). diff --git a/web/admin.html b/web/admin.html index 4d0e4789..e55fbda6 100644 --- a/web/admin.html +++ b/web/admin.html @@ -988,36 +988,6 @@ No sentences, no commentary, no captions. Only tags. Keep length short but descr - - - diff --git a/web/gallery.html b/web/gallery.html index 3ce82d2a..74a9bef7 100644 --- a/web/gallery.html +++ b/web/gallery.html @@ -358,9 +358,11 @@ (Faster processing, uses ~4-16GB VRAM) - + -