|
| 1 | +import { test, expect } from 'playwright/test' |
| 2 | +import { |
| 3 | + isComfyReachable, |
| 4 | + openSidebar, |
| 5 | + getModifiedWorkflow, |
| 6 | + queuePrompt, |
| 7 | + waitForQueueEmpty, |
| 8 | + getCards, |
| 9 | + getBadgeText, |
| 10 | +} from './helpers.mjs' |
| 11 | + |
| 12 | +test.describe('Queue Sidebar E2E', () => { |
| 13 | + test.beforeAll(async () => { |
| 14 | + const reachable = await isComfyReachable() |
| 15 | + if (!reachable) test.skip(true, 'ComfyUI is not running at 127.0.0.1:8188') |
| 16 | + }) |
| 17 | + |
| 18 | + test.beforeEach(async ({ page }) => { |
| 19 | + await page.goto('/', { waitUntil: 'networkidle', timeout: 30_000 }) |
| 20 | + await page.waitForTimeout(2000) // let extensions load |
| 21 | + await openSidebar(page) |
| 22 | + }) |
| 23 | + |
| 24 | + // ── #1 — Cached state renders immediately when sidebar reopens ───── |
| 25 | + test('cached state renders immediately on reopen', async ({ page }) => { |
| 26 | + // First, ensure state has data by running a prompt to completion. |
| 27 | + const wf = await getModifiedWorkflow(page) |
| 28 | + test.skip(!wf, 'No workflow available') |
| 29 | + |
| 30 | + await queuePrompt(page, wf) |
| 31 | + await waitForQueueEmpty(page) |
| 32 | + // Wait for history refresh to populate cards |
| 33 | + await page.waitForTimeout(2000) |
| 34 | + |
| 35 | + // Verify cards exist now |
| 36 | + const cardsBefore = await getCards(page) |
| 37 | + test.skip(cardsBefore.length === 0, 'No cards rendered after prompt completion') |
| 38 | + |
| 39 | + // Close the sidebar tab. |
| 40 | + const tab = page.locator('.sidebar-icon-wrapper .pi-history').first() |
| 41 | + await tab.click() |
| 42 | + await page.waitForTimeout(300) |
| 43 | + |
| 44 | + // Intercept /queue and /history with a 3-second delay so we can prove |
| 45 | + // that cards come from cached in-memory state, not from a fresh fetch. |
| 46 | + await page.route('**/queue', async (route) => { |
| 47 | + await new Promise(r => setTimeout(r, 3000)) |
| 48 | + await route.continue() |
| 49 | + }) |
| 50 | + await page.route('**/history*', async (route) => { |
| 51 | + await new Promise(r => setTimeout(r, 3000)) |
| 52 | + await route.continue() |
| 53 | + }) |
| 54 | + |
| 55 | + // Reopen the sidebar |
| 56 | + await tab.click() |
| 57 | + |
| 58 | + // Cards should appear within 500ms (from cached state, not delayed API) |
| 59 | + await expect(page.locator('[data-id][data-status]').first()) |
| 60 | + .toBeAttached({ timeout: 500 }) |
| 61 | + |
| 62 | + await page.unroute('**/queue') |
| 63 | + await page.unroute('**/history*') |
| 64 | + }) |
| 65 | + |
| 66 | + // ── #2 — Pending cards appear above running cards ────────────────── |
| 67 | + test('pending cards appear above running cards', async ({ page }) => { |
| 68 | + const wf = await getModifiedWorkflow(page) |
| 69 | + test.skip(!wf, 'No workflow available in history') |
| 70 | + |
| 71 | + // Queue two prompts with different seeds — the first starts running, |
| 72 | + // the second stays pending. |
| 73 | + await queuePrompt(page, wf) |
| 74 | + const wf2 = await getModifiedWorkflow(page) |
| 75 | + await queuePrompt(page, wf2) |
| 76 | + |
| 77 | + // Wait for at least one running AND one pending card to appear |
| 78 | + await expect(async () => { |
| 79 | + const cards = await getCards(page) |
| 80 | + const hasRunning = cards.some(c => c.status === 'running') |
| 81 | + const hasPending = cards.some(c => c.status === 'pending') |
| 82 | + expect(hasRunning && hasPending).toBe(true) |
| 83 | + }).toPass({ timeout: 15_000 }) |
| 84 | + |
| 85 | + // Verify order: all pending indices < all running indices |
| 86 | + const cards = await getCards(page) |
| 87 | + const pendingIndices = cards.filter(c => c.status === 'pending').map(c => c.index) |
| 88 | + const runningIndices = cards.filter(c => c.status === 'running').map(c => c.index) |
| 89 | + const maxPending = Math.max(...pendingIndices) |
| 90 | + const minRunning = Math.min(...runningIndices) |
| 91 | + expect(maxPending).toBeLessThan(minRunning) |
| 92 | + |
| 93 | + await waitForQueueEmpty(page) |
| 94 | + }) |
| 95 | + |
| 96 | + // ── #3 — No duplicate cards during pending→running transition ────── |
| 97 | + test('no duplicate cards during pending-to-running transition', async ({ page }) => { |
| 98 | + const wf = await getModifiedWorkflow(page) |
| 99 | + test.skip(!wf, 'No workflow available in history') |
| 100 | + |
| 101 | + await queuePrompt(page, wf) |
| 102 | + |
| 103 | + // Poll DOM rapidly, looking for duplicate data-id values |
| 104 | + let duplicateFound = false |
| 105 | + const start = Date.now() |
| 106 | + |
| 107 | + while (Date.now() - start < 15_000) { |
| 108 | + const ids = await page.evaluate(() => |
| 109 | + [...document.querySelectorAll('[data-id]')].map(el => el.dataset.id) |
| 110 | + ) |
| 111 | + const seen = new Set() |
| 112 | + for (const id of ids) { |
| 113 | + if (seen.has(id)) { duplicateFound = true; break } |
| 114 | + seen.add(id) |
| 115 | + } |
| 116 | + if (duplicateFound) break |
| 117 | + |
| 118 | + const q = await page.evaluate(async () => { |
| 119 | + const r = await fetch('/queue').then(res => res.json()) |
| 120 | + return { running: r.queue_running?.length ?? 0, pending: r.queue_pending?.length ?? 0 } |
| 121 | + }) |
| 122 | + if (q.running === 0 && q.pending === 0) break |
| 123 | + await page.waitForTimeout(100) |
| 124 | + } |
| 125 | + |
| 126 | + expect(duplicateFound).toBe(false) |
| 127 | + }) |
| 128 | + |
| 129 | + // ── #4 — Badge and card appear instantly on execution_start ──────── |
| 130 | + test('badge and running card appear on execution_start', async ({ page }) => { |
| 131 | + const wf = await getModifiedWorkflow(page) |
| 132 | + test.skip(!wf, 'No workflow available') |
| 133 | + |
| 134 | + // Block /api/queue so the API-poll path (refresh → fetchQueue → render) |
| 135 | + // can never deliver queue state. The ONLY way a running card can appear |
| 136 | + // is through the WS execution_start → onExecutionStart → render() path. |
| 137 | + const blocked = [] |
| 138 | + await page.route('**/queue', async (route) => { |
| 139 | + blocked.push(route.request().url()) |
| 140 | + await new Promise(r => setTimeout(r, 30_000)) |
| 141 | + await route.continue() |
| 142 | + }) |
| 143 | + |
| 144 | + await queuePrompt(page, wf) |
| 145 | + |
| 146 | + // If onExecutionStart works, the running card appears within seconds. |
| 147 | + // The 10s timeout is generous but still far shorter than the 30s block. |
| 148 | + await expect(page.locator('[data-status="running"]').first()) |
| 149 | + .toBeAttached({ timeout: 10_000 }) |
| 150 | + |
| 151 | + const badge = await getBadgeText(page) |
| 152 | + expect(badge).toBeTruthy() |
| 153 | + |
| 154 | + // Confirm the route actually blocked at least one /api/queue request, |
| 155 | + // proving the card did NOT come from the API-poll path. |
| 156 | + expect(blocked.length).toBeGreaterThanOrEqual(1) |
| 157 | + |
| 158 | + await page.unroute('**/queue') |
| 159 | + await waitForQueueEmpty(page) |
| 160 | + }) |
| 161 | + |
| 162 | + // ── #6 — No [QueueSidebar] console.warn during normal operation ──── |
| 163 | + test('no QueueSidebar console warnings during normal operation', async ({ page }) => { |
| 164 | + const warnings = [] |
| 165 | + page.on('console', msg => { |
| 166 | + if (msg.type() === 'warning' && msg.text().includes('[QueueSidebar]')) { |
| 167 | + warnings.push(msg.text()) |
| 168 | + } |
| 169 | + }) |
| 170 | + |
| 171 | + const wf = await getModifiedWorkflow(page) |
| 172 | + if (wf) { |
| 173 | + await queuePrompt(page, wf) |
| 174 | + await waitForQueueEmpty(page) |
| 175 | + } |
| 176 | + |
| 177 | + await page.waitForTimeout(1000) |
| 178 | + expect(warnings).toEqual([]) |
| 179 | + }) |
| 180 | +}) |
0 commit comments