Test, build, and deploy ComfyUI Jobs / test-build (push) Successful in 3m57s
Test, build, and deploy ComfyUI Jobs / deploy (push) Successful in 15s
Test, build, and deploy ComfyUI Jobs / browser-test (push) Successful in 2m16s
Test, build, and deploy ComfyUI Jobs / qa-gate (push) Successful in 5s
622 lines
37 KiB
JavaScript
622 lines
37 KiB
JavaScript
const { test, expect } = require('@playwright/test');
|
||
|
||
const username = process.env.E2E_USERNAME;
|
||
const password = process.env.E2E_PASSWORD;
|
||
const requiresCredentials = username && password;
|
||
|
||
test.describe('ComfyUI Portal browser flow', () => {
|
||
test.beforeEach(async ({ page }) => {
|
||
test.skip(!requiresCredentials, 'E2E_USERNAME and E2E_PASSWORD are required for deployed portal tests');
|
||
await page.goto('/login');
|
||
});
|
||
|
||
async function signIn(page, user = username, pass = password) {
|
||
await page.getByLabel('Username').fill(user);
|
||
await page.getByLabel('Password').fill(pass);
|
||
await page.getByRole('button', { name: 'Sign in' }).click();
|
||
}
|
||
|
||
test('valid credentials open the protected job monitor', async ({ page }) => {
|
||
await signIn(page);
|
||
await expect(page).toHaveURL(/\/jobs/);
|
||
await expect(page.getByRole('heading', { name: 'Job monitor' })).toBeVisible();
|
||
await expect(page.getByText('ComfyUI status')).toBeVisible();
|
||
});
|
||
|
||
test('invalid credentials remain on sign in with a clear error', async ({ page }) => {
|
||
await signIn(page, username, String(password) + '-invalid');
|
||
await expect(page).toHaveURL(/\/login/);
|
||
await expect(page.getByText('Invalid username or password.')).toBeVisible();
|
||
});
|
||
|
||
test('protected jobs route redirects an unauthenticated visitor', async ({ page }) => {
|
||
await page.context().clearCookies();
|
||
await page.goto('/jobs');
|
||
await expect(page).toHaveURL(/\/login/);
|
||
await expect(page.getByRole('heading', { name: 'Sign in' })).toBeVisible();
|
||
});
|
||
|
||
test('the job monitor exposes stable loading or empty/error states', async ({ page }) => {
|
||
await signIn(page);
|
||
await expect(page.getByRole('heading', { name: 'Job monitor' })).toBeVisible();
|
||
await expect(page.locator('.server-card')).toBeVisible();
|
||
await expect(page.locator('.loading, .empty, .notice, .grid .job, .server-error').first()).toBeVisible({ timeout: 15000 });
|
||
});
|
||
|
||
test('an authenticated user can sign out', async ({ page }) => {
|
||
await signIn(page);
|
||
await expect(page.getByRole('button', { name: 'Sign out' })).toBeVisible();
|
||
await page.getByRole('button', { name: 'Sign out' }).click();
|
||
await expect(page).toHaveURL(/\/login/);
|
||
await expect(page.getByRole('heading', { name: 'Sign in' })).toBeVisible();
|
||
});
|
||
|
||
test('the portal remains usable at mobile width without horizontal overflow', async ({ page }) => {
|
||
await page.setViewportSize({ width: 390, height: 844 });
|
||
await signIn(page);
|
||
await expect(page.getByRole('heading', { name: 'Job monitor' })).toBeVisible();
|
||
const overflow = await page.evaluate(() => document.documentElement.scrollWidth > window.innerWidth + 1);
|
||
expect(overflow, 'mobile layout should not create horizontal scrolling').toBe(false);
|
||
});
|
||
|
||
test('requires both credentials before submitting the sign-in form', async ({ page }) => {
|
||
await expect(page.getByLabel('Username')).toHaveAttribute('required', '');
|
||
await expect(page.getByLabel('Password')).toHaveAttribute('required', '');
|
||
await page.getByRole('button', { name: 'Sign in' }).click();
|
||
await expect(page).toHaveURL(/\/login/);
|
||
});
|
||
|
||
test('submits the remember-me preference without contacting a real login endpoint', async ({ page }) => {
|
||
let payload = null;
|
||
await page.route('**/api/login', async route => {
|
||
payload = JSON.parse(route.request().postData() || '{}');
|
||
await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ user: adminUser }) });
|
||
});
|
||
await page.getByLabel('Username').fill('test-user');
|
||
await page.getByLabel('Password').fill('test-password');
|
||
await page.getByLabel('Remember me').uncheck();
|
||
await page.getByRole('button', { name: 'Sign in' }).click();
|
||
await expect.poll(() => payload).toMatchObject({ username: 'test-user', password: 'test-password', remember: false });
|
||
});
|
||
});
|
||
|
||
const adminUser = { id: 'user_admin', username: 'admin', displayName: 'Admin', role: 'admin' };
|
||
const regularUser = { id: 'user_regular', username: 'user', displayName: 'User', role: 'user' };
|
||
const connectedServer = {
|
||
reachable: true,
|
||
version: '0.3.0',
|
||
os: 'linux',
|
||
pythonVersion: '3.12.8',
|
||
devices: [{ name: 'GPU 0', type: 'cuda', vramTotal: 8 * 1073741824, vramFree: 6 * 1073741824 }],
|
||
queue: { running: 0, pending: 0, total: 0 },
|
||
};
|
||
const managerInfo = { managerVersion: '3.0.0', currentVersion: '0.3.0', versions: ['0.3.0', '0.2.9'] };
|
||
const modelStats = { totalJobs: 3, totalModels: 2, models: [{ name: 'model-a.safetensors', jobCount: 2 }, { name: 'style.safetensors', jobCount: 1 }] };
|
||
|
||
async function mockReadOnlyApi(page, { user = adminUser, jobs = [], running = null, server = connectedServer, manager = managerInfo, stats = modelStats } = {}) {
|
||
test.skip(!requiresCredentials, 'deployed read-only UI tests require the configured E2E account');
|
||
if (user) {
|
||
await page.context().addCookies([{ name: 'cp_auth', value: username, url: process.env.E2E_BASE_URL || 'http://127.0.0.1:7002' }]);
|
||
}
|
||
await page.route('**/api/**', async (route) => {
|
||
const request = route.request();
|
||
const url = new URL(request.url());
|
||
if (url.pathname === '/api/me') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ user }) });
|
||
if (url.pathname === '/api/jobs') {
|
||
if (jobs === 'unavailable') return route.fulfill({ status: 503, contentType: 'application/json', body: JSON.stringify({ error: 'Jobs unavailable' }) });
|
||
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ jobs, running }) });
|
||
}
|
||
if (url.pathname === '/api/model-stats') {
|
||
if (stats === 'unavailable') return route.fulfill({ status: 502, contentType: 'application/json', body: JSON.stringify({ error: 'History unavailable' }) });
|
||
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(stats) });
|
||
}
|
||
if (url.pathname === '/api/server-status') {
|
||
if (server === 'unavailable') return route.fulfill({ status: 502, contentType: 'application/json', body: JSON.stringify({ error: 'ComfyUI is unavailable right now.' }) });
|
||
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ status: server }) });
|
||
}
|
||
if (url.pathname === '/api/comfy/manager') {
|
||
if (manager === 'unavailable') return route.fulfill({ status: 502, contentType: 'application/json', body: JSON.stringify({ error: 'Manager unavailable' }) });
|
||
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(manager) });
|
||
}
|
||
if (url.pathname === '/api/assets/meta') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ width: 1280, height: 720, sizeBytes: 2097152 }) });
|
||
if (url.pathname === '/api/assets') return route.fulfill({ status: 200, contentType: 'application/octet-stream', body: 'test asset' });
|
||
return route.continue();
|
||
});
|
||
}
|
||
|
||
test.describe('ComfyUI Portal read-only UI states', () => {
|
||
test('root and unknown routes redirect an unauthenticated visitor to sign in', async ({ page }) => {
|
||
await mockReadOnlyApi(page, { user: null });
|
||
await page.goto('/');
|
||
await expect(page).toHaveURL(/\/login/);
|
||
await expect(page.getByRole('heading', { name: 'Sign in' })).toBeVisible();
|
||
await page.goto('/does-not-exist');
|
||
await expect(page).toHaveURL(/\/login/);
|
||
});
|
||
|
||
test('refresh reloads the job list and returns to a non-loading state', async ({ page }) => {
|
||
let jobRequestCount = 0;
|
||
await mockReadOnlyApi(page, { jobs: [] });
|
||
await page.unroute('**/api/**');
|
||
await page.route('**/api/**', async (route) => {
|
||
const pathname = new URL(route.request().url()).pathname;
|
||
if (pathname === '/api/me') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ user: adminUser }) });
|
||
if (pathname === '/api/model-stats') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(modelStats) });
|
||
if (pathname === '/api/server-status') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ status: connectedServer }) });
|
||
if (pathname === '/api/comfy/manager') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(managerInfo) });
|
||
if (pathname === '/api/jobs') {
|
||
jobRequestCount += 1;
|
||
const jobs = jobRequestCount > 1 ? [{ promptId: 'job-refresh', title: 'Refreshed job', status: 'completed', queuedAt: 1000, durationMs: 2500, outputCount: 0, assets: [], models: [], progress: null }] : [];
|
||
return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ jobs, running: null }) });
|
||
}
|
||
return route.continue();
|
||
});
|
||
await page.goto('/jobs');
|
||
await expect(page.getByText('No remote jobs were returned.')).toBeVisible();
|
||
await page.getByRole('button', { name: 'Refresh' }).click();
|
||
await expect(page.getByText('Refreshed job')).toBeVisible();
|
||
await expect(page.getByText('No remote jobs were returned.')).toHaveCount(0);
|
||
});
|
||
|
||
test('renders running progress, queue metadata, models, and asset metadata', async ({ page }) => {
|
||
const running = { promptId: 'running-1', title: 'Generating scene', status: 'running', queuedAt: Date.now() - 65000, durationMs: null, outputCount: 0, assets: [], models: [{ nodeId: '1', type: 'CheckpointLoader', name: 'model.safetensors' }], progress: { value: 3, max: 10, percent: 30 } };
|
||
const jobs = [{ promptId: 'done-1', title: 'Finished scene', status: 'completed', queuedAt: 1000, durationMs: 65000, outputCount: 1, assets: [{ filename: 'scene.png', url: '/api/assets?filename=scene.png&subfolder=&type=output', type: 'image' }], models: [], progress: null }];
|
||
await mockReadOnlyApi(page, { jobs, running });
|
||
await page.goto('/jobs');
|
||
await expect(page.getByRole('heading', { name: 'Generating scene' })).toBeVisible();
|
||
await expect(page.getByText('30% complete')).toBeVisible();
|
||
await expect(page.getByText('model.safetensors')).toBeVisible();
|
||
await expect(page.getByRole('heading', { name: 'Finished scene' })).toBeVisible();
|
||
await expect(page.getByText('scene.png')).toBeVisible();
|
||
await expect(page.getByText('1280 × 720')).toBeVisible();
|
||
await expect(page.getByText('2.0 MB')).toBeVisible();
|
||
});
|
||
|
||
test('renders failed jobs and jobs without output assets', async ({ page }) => {
|
||
const jobs = [
|
||
{ promptId: 'failed-1', title: 'Failed scene', status: 'failed', queuedAt: 1000, durationMs: null, outputCount: 0, assets: [], models: [], progress: null },
|
||
{ promptId: 'queued-1', title: 'Queued scene', status: 'queued', queuedAt: null, durationMs: null, outputCount: 0, assets: [], models: [], progress: null },
|
||
];
|
||
await mockReadOnlyApi(page, { jobs });
|
||
await page.goto('/jobs');
|
||
await expect(page.getByRole('heading', { name: 'Failed scene' })).toBeVisible();
|
||
await expect(page.getByText('failed', { exact: true })).toBeVisible();
|
||
await expect(page.getByRole('heading', { name: 'Queued scene' })).toBeVisible();
|
||
await expect(page.getByText('queued', { exact: true })).toBeVisible();
|
||
await expect(page.getByText('No output assets')).toHaveCount(2);
|
||
});
|
||
|
||
test('shows a clear unavailable state when ComfyUI and Manager status cannot be read', async ({ page }) => {
|
||
await mockReadOnlyApi(page, { server: 'unavailable', manager: 'unavailable' });
|
||
await page.goto('/jobs');
|
||
await expect(page.getByText('Unavailable', { exact: true })).toBeVisible();
|
||
await expect(page.getByText('Unable to read server status')).toBeVisible();
|
||
await expect(page.getByText('No remote jobs were returned.')).toBeVisible();
|
||
});
|
||
|
||
test('shows Manager controls only to administrators', async ({ page }) => {
|
||
await mockReadOnlyApi(page, { user: regularUser });
|
||
await page.goto('/jobs');
|
||
await expect(page.getByText('Runtime controls')).toHaveCount(0);
|
||
|
||
await page.unroute('**/api/**');
|
||
await mockReadOnlyApi(page, { user: adminUser });
|
||
await page.reload();
|
||
await expect(page.getByText('Runtime controls')).toBeVisible();
|
||
await expect(page.getByRole('button', { name: 'Restart ComfyUI' })).toBeVisible();
|
||
await expect(page.getByRole('button', { name: 'Update all' })).toBeVisible();
|
||
});
|
||
|
||
test('renders connected server details, queue counts, and device capacity', async ({ page }) => {
|
||
await mockReadOnlyApi(page);
|
||
await page.goto('/jobs');
|
||
await expect(page.getByText('Connected', { exact: true })).toBeVisible();
|
||
await expect(page.getByText('0', { exact: true }).first()).toBeVisible();
|
||
await expect(page.getByText('linux', { exact: true })).toBeVisible();
|
||
await expect(page.getByText('3.12.8', { exact: true })).toBeVisible();
|
||
await expect(page.getByText('GPU 0', { exact: true })).toBeVisible();
|
||
await expect(page.getByText('6.0 GB free of 8.0 GB')).toBeVisible();
|
||
});
|
||
|
||
test('renders persistent most-used model statistics without counting duplicate jobs twice', async ({ page }) => {
|
||
await mockReadOnlyApi(page);
|
||
await page.goto('/jobs');
|
||
await expect(page.getByRole('heading', { name: 'Most used models' })).toBeVisible();
|
||
await expect(page.getByText('3 tracked jobs · 2 models')).toBeVisible();
|
||
await expect(page.locator('.stats-list li')).toHaveCount(2);
|
||
await expect(page.locator('.stats-list li').first()).toContainText('model-a.safetensors');
|
||
await expect(page.locator('.stats-list li').first()).toContainText('2 jobs');
|
||
await expect(page.locator('.stats-list li').nth(1)).toContainText('style.safetensors');
|
||
});
|
||
|
||
test('renders video assets with metadata and safe output links', async ({ page }) => {
|
||
const jobs = [{
|
||
promptId: 'video-1', title: 'Finished video', status: 'completed', queuedAt: 1000,
|
||
durationMs: 12000, outputCount: 1,
|
||
assets: [{ filename: 'clip.mp4', url: '/api/assets?filename=clip.mp4&subfolder=&type=output', type: 'video' }],
|
||
models: [], progress: null,
|
||
}];
|
||
await mockReadOnlyApi(page, { jobs });
|
||
await page.goto('/jobs');
|
||
await expect(page.locator('video')).toHaveAttribute('src', /filename=clip\.mp4/);
|
||
await expect(page.getByText('clip.mp4')).toBeVisible();
|
||
await expect(page.getByText('2.0 MB')).toBeVisible();
|
||
await expect(page.locator('figure a')).toHaveAttribute('target', '_blank');
|
||
await expect(page.locator('figure a')).toHaveAttribute('rel', 'noopener');
|
||
});
|
||
|
||
test('renders audio assets with a native player and safe output link', async ({ page }) => {
|
||
const jobs = [{
|
||
promptId: 'audio-1', title: 'Neo-soul piano', status: 'completed', queuedAt: 1000,
|
||
durationMs: 60000, outputCount: 1,
|
||
assets: [{ filename: 'neo_soul.flac', url: '/api/assets?filename=neo_soul.flac&subfolder=&type=output', type: 'audio' }],
|
||
models: [], progress: null,
|
||
}];
|
||
await mockReadOnlyApi(page, { jobs });
|
||
await page.goto('/jobs');
|
||
await expect(page.locator('audio')).toHaveAttribute('src', /filename=neo_soul\.flac/);
|
||
await expect(page.getByText('neo_soul.flac')).toBeVisible();
|
||
await expect(page.locator('figure a')).toHaveAttribute('target', '_blank');
|
||
});
|
||
|
||
test('shows a clear jobs error while retaining server status', async ({ page }) => {
|
||
await mockReadOnlyApi(page, { jobs: 'unavailable' });
|
||
await page.goto('/jobs');
|
||
await expect(page.getByText('Unable to load jobs.')).toBeVisible();
|
||
await expect(page.getByText('Connected', { exact: true })).toBeVisible();
|
||
await expect(page.getByText('No remote jobs were returned.')).toHaveCount(0);
|
||
});
|
||
|
||
test('does not invoke a runtime control when an administrator cancels confirmation', async ({ page }) => {
|
||
const requests = [];
|
||
await mockReadOnlyApi(page);
|
||
await page.route('**/api/comfy/restart', async (route) => {
|
||
requests.push(route.request().method());
|
||
await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ message: 'accepted' }) });
|
||
});
|
||
await page.goto('/jobs');
|
||
page.once('dialog', dialog => dialog.dismiss());
|
||
await page.getByRole('button', { name: 'Restart ComfyUI' }).click();
|
||
await expect.poll(() => requests).toEqual([]);
|
||
await expect(page.getByRole('button', { name: 'Restart ComfyUI' })).toBeEnabled();
|
||
});
|
||
|
||
test('shows an indeterminate working state when running progress is unavailable', async ({ page }) => {
|
||
const running = { promptId: 'running-unknown', title: 'Working without progress', status: 'running', queuedAt: Date.now() - 5000, durationMs: null, outputCount: 0, assets: [], models: [], progress: null };
|
||
await mockReadOnlyApi(page, { running });
|
||
await page.goto('/jobs');
|
||
await expect(page.getByText('Working…')).toBeVisible();
|
||
await expect(page.locator('.progress-track.indeterminate')).toBeVisible();
|
||
});
|
||
|
||
test('uses safe fallbacks when connected server metadata is missing', async ({ page }) => {
|
||
const server = { ...connectedServer, version: '', os: '', pythonVersion: '', devices: [] };
|
||
await mockReadOnlyApi(page, { server });
|
||
await page.goto('/jobs');
|
||
await expect(page.getByText('Connected', { exact: true })).toBeVisible();
|
||
await expect(page.getByText('Unknown', { exact: true })).toHaveCount(3);
|
||
await expect(page.locator('.devices')).toHaveCount(0);
|
||
});
|
||
|
||
test('keeps Manager controls safe when Manager status is unavailable', async ({ page }) => {
|
||
await mockReadOnlyApi(page, { manager: 'unavailable' });
|
||
await page.goto('/jobs');
|
||
await expect(page.getByText('Runtime controls')).toBeVisible();
|
||
await expect(page.getByText('ComfyUI Manager —')).toBeVisible();
|
||
await expect(page.locator('select')).toBeDisabled();
|
||
await expect(page.getByRole('button', { name: 'Switch version' })).toBeDisabled();
|
||
});
|
||
|
||
test('shows the accepted message after a confirmed control request using only mocked APIs', async ({ page }) => {
|
||
const requests = [];
|
||
await mockReadOnlyApi(page);
|
||
await page.route('**/api/comfy/restart', async (route) => {
|
||
requests.push(route.request().method());
|
||
await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ message: 'Request accepted.' }) });
|
||
});
|
||
await page.goto('/jobs');
|
||
page.once('dialog', dialog => dialog.accept());
|
||
await page.getByRole('button', { name: 'Restart ComfyUI' }).click();
|
||
await expect(page.getByText('Request accepted.')).toBeVisible();
|
||
await expect.poll(() => requests).toEqual(['POST']);
|
||
await expect(page.getByRole('button', { name: 'Restart ComfyUI' })).toBeEnabled();
|
||
});
|
||
|
||
test('redirects an authenticated unknown route back to the job monitor', async ({ page }) => {
|
||
await mockReadOnlyApi(page);
|
||
await page.goto('/does-not-exist');
|
||
await expect(page).toHaveURL(/\/jobs/);
|
||
await expect(page.getByRole('heading', { name: 'Job monitor' })).toBeVisible();
|
||
});
|
||
|
||
test('sends the selected Manager version through the mocked switch flow', async ({ page }) => {
|
||
let payload = null;
|
||
await mockReadOnlyApi(page);
|
||
await page.route('**/api/comfy/switch-version', async (route) => {
|
||
payload = JSON.parse(route.request().postData() || '{}');
|
||
await route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ message: 'Request accepted.' }) });
|
||
});
|
||
await page.goto('/jobs');
|
||
await page.locator('select').selectOption('0.2.9');
|
||
page.once('dialog', dialog => dialog.accept());
|
||
await page.getByRole('button', { name: 'Switch version' }).click();
|
||
await expect(page.getByText('Request accepted.')).toBeVisible();
|
||
await expect.poll(() => payload).toEqual({ version: '0.2.9' });
|
||
});
|
||
|
||
test('enters the update-all busy state after a mocked confirmation', async ({ page }) => {
|
||
let requestCount = 0;
|
||
await mockReadOnlyApi(page);
|
||
await page.route('**/api/comfy/update-all', async (route) => {
|
||
requestCount += 1;
|
||
await route.fulfill({ status: 202, contentType: 'application/json', body: JSON.stringify({ message: 'Update all started.' }) });
|
||
});
|
||
await page.goto('/jobs');
|
||
page.once('dialog', dialog => dialog.accept());
|
||
await page.getByRole('button', { name: 'Update all' }).click();
|
||
await expect(page.getByRole('button', { name: 'Updating everything…' })).toBeDisabled();
|
||
await expect(page.getByText('Update all started. Checking progress…')).toBeVisible();
|
||
await expect.poll(() => requestCount).toBe(1);
|
||
});
|
||
|
||
test('shows an empty model-history state when no jobs have been archived', async ({ page }) => {
|
||
await mockReadOnlyApi(page, { stats: { totalJobs: 0, totalModels: 0, models: [] } });
|
||
await page.goto('/jobs');
|
||
await expect(page.getByText('0 tracked jobs · 0 models')).toBeVisible();
|
||
await expect(page.getByText('No model usage has been recorded yet.')).toBeVisible();
|
||
await expect(page.locator('.stats-list')).toHaveCount(0);
|
||
});
|
||
|
||
test('keeps the model panel usable when its stats request fails', async ({ page }) => {
|
||
await mockReadOnlyApi(page, { stats: 'unavailable' });
|
||
await page.goto('/jobs');
|
||
await expect(page.getByRole('heading', { name: 'Most used models' })).toBeVisible();
|
||
await expect(page.getByText('No model usage has been recorded yet.')).toBeVisible();
|
||
});
|
||
|
||
test('preserves model names and job counts in rank order', async ({ page }) => {
|
||
const stats = { totalJobs: 7, totalModels: 3, models: [{ name: 'popular.safetensors', jobCount: 5 }, { name: 'second.safetensors', jobCount: 2 }, { name: 'rare.safetensors', jobCount: 1 }] };
|
||
await mockReadOnlyApi(page, { stats });
|
||
await page.goto('/jobs');
|
||
const rows = page.locator('.stats-list li');
|
||
await expect(rows).toHaveCount(3);
|
||
await expect(rows.nth(0)).toContainText('popular.safetensors');
|
||
await expect(rows.nth(0)).toContainText('5 jobs');
|
||
await expect(rows.nth(1)).toContainText('second.safetensors');
|
||
await expect(rows.nth(1)).toContainText('2 jobs');
|
||
await expect(rows.nth(2)).toContainText('rare.safetensors');
|
||
await expect(rows.nth(2)).toContainText('1 job');
|
||
});
|
||
|
||
test('renders multiple output assets in one completed job', async ({ page }) => {
|
||
const jobs = [{ promptId: 'multi-output', title: 'Multi output', status: 'completed', queuedAt: 1000, durationMs: 4000, outputCount: 2, assets: [
|
||
{ filename: 'frame.png', url: '/api/assets?filename=frame.png&subfolder=&type=output', type: 'image' },
|
||
{ filename: 'clip.mp4', url: '/api/assets?filename=clip.mp4&subfolder=&type=output', type: 'video' },
|
||
], models: [], progress: null }];
|
||
await mockReadOnlyApi(page, { jobs });
|
||
await page.goto('/jobs');
|
||
await expect(page.getByRole('heading', { name: 'Multi output' })).toBeVisible();
|
||
await expect(page.locator('figure')).toHaveCount(2);
|
||
await expect(page.locator('img[alt="frame.png"]')).toBeVisible();
|
||
await expect(page.locator('video')).toBeVisible();
|
||
await expect(page.getByText('2 outputs')).toBeVisible();
|
||
});
|
||
|
||
test('keeps an asset usable when metadata lookup fails', async ({ page }) => {
|
||
const jobs = [{ promptId: 'asset-meta-error', title: 'Metadata unavailable', status: 'completed', queuedAt: 1000, durationMs: 1000, outputCount: 1, assets: [{ filename: 'unknown.png', url: '/api/assets?filename=unknown.png&subfolder=&type=output', type: 'image' }], models: [], progress: null }];
|
||
await mockReadOnlyApi(page, { jobs });
|
||
await page.route('**/api/assets/meta**', async route => route.fulfill({ status: 502, contentType: 'application/json', body: JSON.stringify({ error: 'Metadata unavailable' }) }));
|
||
await page.goto('/jobs');
|
||
await expect(page.getByText('unknown.png')).toBeVisible();
|
||
await expect(page.getByText('1280 × 720')).toHaveCount(0);
|
||
await expect(page.getByText('2.0 MB')).toHaveCount(0);
|
||
});
|
||
|
||
test('shows queue counts for pending and running work', async ({ page }) => {
|
||
const server = { ...connectedServer, queue: { running: 1, pending: 3, total: 4 } };
|
||
await mockReadOnlyApi(page, { server });
|
||
await page.goto('/jobs');
|
||
const counts = page.locator('.queue-panel strong');
|
||
await expect(counts).toHaveCount(3);
|
||
await expect(counts.nth(0)).toHaveText('4');
|
||
await expect(counts.nth(1)).toHaveText('1');
|
||
await expect(counts.nth(2)).toHaveText('3');
|
||
});
|
||
|
||
test('reports a mocked Manager rejection without leaving controls stuck', async ({ page }) => {
|
||
await mockReadOnlyApi(page);
|
||
await page.route('**/api/comfy/update-all', async route => route.fulfill({ status: 502, contentType: 'application/json', body: JSON.stringify({ error: 'Manager rejected update' }) }));
|
||
await page.goto('/jobs');
|
||
page.once('dialog', dialog => dialog.accept());
|
||
await page.getByRole('button', { name: 'Update all' }).click();
|
||
await expect(page.getByText('Manager rejected update')).toBeVisible();
|
||
await expect(page.getByRole('button', { name: 'Update all' })).toBeEnabled();
|
||
});
|
||
|
||
test('renders model chips with their node-type tooltips on completed jobs', async ({ page }) => {
|
||
const jobs = [{ promptId: 'model-chips', title: 'Model details', status: 'completed', queuedAt: 1000, durationMs: 65000, outputCount: 0, assets: [], models: [
|
||
{ nodeId: '4', type: 'CheckpointLoaderSimple', name: 'checkpoint.safetensors' },
|
||
{ nodeId: '8', type: 'LoraLoader', name: 'style.safetensors' },
|
||
], progress: null }];
|
||
await mockReadOnlyApi(page, { jobs });
|
||
await page.goto('/jobs');
|
||
const models = page.locator('.job .models span');
|
||
await expect(models).toHaveCount(2);
|
||
await expect(models.nth(0)).toHaveAttribute('title', 'CheckpointLoaderSimple');
|
||
await expect(models.nth(1)).toHaveAttribute('title', 'LoraLoader');
|
||
await expect(page.getByText('1m 5s')).toBeVisible();
|
||
});
|
||
|
||
test('keeps the stats panel within a narrow mobile viewport', async ({ page }) => {
|
||
await page.setViewportSize({ width: 320, height: 700 });
|
||
await mockReadOnlyApi(page, { stats: { totalJobs: 123, totalModels: 2, models: [{ name: 'a-very-long-model-name-that-must-not-create-horizontal-overflow.safetensors', jobCount: 123 }, { name: 'second.safetensors', jobCount: 1 }] } });
|
||
await page.goto('/jobs');
|
||
await expect(page.getByRole('heading', { name: 'Most used models' })).toBeVisible();
|
||
const overflow = await page.evaluate(() => document.documentElement.scrollWidth > window.innerWidth + 1);
|
||
expect(overflow, 'persistent model stats should not create horizontal scrolling').toBe(false);
|
||
});
|
||
|
||
test('renders update-all completion results from mocked status polling', async ({ page }) => {
|
||
const result = { comfyui: 'Updated', updated: [{ id: 'node-a', title: 'Node A', url: '', error: '' }], skipped: [{ id: 'node-b', title: 'Node B', url: '', error: '' }], failed: [{ id: 'node-c', title: 'Node C', url: '', error: 'Permission denied' }], completedAt: Date.now() };
|
||
await mockReadOnlyApi(page);
|
||
await page.route('**/api/comfy/update-all', async route => route.fulfill({ status: 202, contentType: 'application/json', body: JSON.stringify({ message: 'started' }) }));
|
||
await page.route('**/api/comfy/update-status', async route => route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ status: { total_count: 3, done_count: 3, in_progress_count: 0, is_processing: false }, progress: null, result }) }));
|
||
await page.goto('/jobs');
|
||
page.once('dialog', dialog => dialog.accept());
|
||
await page.getByRole('button', { name: 'Update all' }).click();
|
||
await expect(page.getByText('Update all started. Checking progress…')).toBeVisible();
|
||
await page.waitForTimeout(5200);
|
||
await expect(page.getByText('Update all completed. See the results below.')).toBeVisible();
|
||
await expect(page.getByText('Node A')).toBeVisible();
|
||
await expect(page.getByText('Node B')).toBeVisible();
|
||
await expect(page.getByText('Node C')).toBeVisible();
|
||
await expect(page.getByText('Permission denied')).toBeVisible();
|
||
});
|
||
|
||
test('redirects to sign in when an authenticated session expires on reload', async ({ page }) => {
|
||
await page.route('**/api/**', async route => {
|
||
if (new URL(route.request().url()).pathname === '/api/me') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ user: null }) });
|
||
return route.continue();
|
||
});
|
||
await page.context().addCookies([{ name: 'cp_auth', value: username, url: process.env.E2E_BASE_URL || 'http://127.0.0.1:7002' }]);
|
||
await page.goto('/jobs');
|
||
await expect(page.getByRole('heading', { name: 'Job monitor' })).toHaveCount(0);
|
||
expect(new URL(page.url()).pathname).not.toBe('/jobs');
|
||
});
|
||
|
||
test('refreshes persistent model statistics after a newly discovered job', async ({ page }) => {
|
||
let refreshCount = 0;
|
||
await mockReadOnlyApi(page);
|
||
await page.unroute('**/api/**');
|
||
await page.route('**/api/**', async route => {
|
||
const pathname = new URL(route.request().url()).pathname;
|
||
if (pathname === '/api/me') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ user: adminUser }) });
|
||
if (pathname === '/api/model-stats') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(refreshCount > 1 ? { totalJobs: 4, totalModels: 3, models: [...modelStats.models, { name: 'new.safetensors', jobCount: 1 }] } : modelStats) });
|
||
if (pathname === '/api/jobs') { refreshCount += 1; return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ jobs: [], running: null }) }); }
|
||
if (pathname === '/api/server-status') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ status: connectedServer }) });
|
||
if (pathname === '/api/comfy/manager') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(managerInfo) });
|
||
return route.continue();
|
||
});
|
||
await page.goto('/jobs');
|
||
await expect(page.getByText('3 tracked jobs · 2 models')).toBeVisible();
|
||
await page.getByRole('button', { name: 'Refresh' }).click();
|
||
await expect(page.getByText('4 tracked jobs · 3 models')).toBeVisible();
|
||
await expect(page.getByText('new.safetensors')).toBeVisible();
|
||
});
|
||
|
||
test('does not duplicate a job when the same prompt is returned again', async ({ page }) => {
|
||
const jobs = [{ promptId: 'stable-id', title: 'Stable job', status: 'completed', queuedAt: 1000, durationMs: 1000, outputCount: 0, assets: [], models: [{ nodeId: '1', type: 'Checkpoint', name: 'same.safetensors' }], progress: null }];
|
||
await mockReadOnlyApi(page, { jobs, stats: { totalJobs: 1, totalModels: 1, models: [{ name: 'same.safetensors', jobCount: 1 }] } });
|
||
await page.goto('/jobs');
|
||
await page.getByRole('button', { name: 'Refresh' }).click();
|
||
await expect(page.locator('.job')).toHaveCount(1);
|
||
await expect(page.getByText('1 tracked jobs · 1 models')).toBeVisible();
|
||
});
|
||
|
||
test('renders unknown job statuses without losing the job card', async ({ page }) => {
|
||
const jobs = [{ promptId: 'unknown-status', title: 'Future status', status: 'paused', queuedAt: null, durationMs: null, outputCount: 0, assets: [], models: [], progress: null }];
|
||
await mockReadOnlyApi(page, { jobs });
|
||
await page.goto('/jobs');
|
||
await expect(page.getByRole('heading', { name: 'Future status' })).toBeVisible();
|
||
await expect(page.getByText('paused', { exact: true })).toBeVisible();
|
||
await expect(page.getByText('Duration Unavailable')).toBeVisible();
|
||
});
|
||
|
||
test('does not overflow with a long title and model name', async ({ page }) => {
|
||
const title = 'A very long job title that should remain readable without breaking the monitor layout';
|
||
const model = 'a-very-long-model-name-that-should-be-truncated-safely.safetensors';
|
||
const jobs = [{ promptId: 'long-content', title, status: 'completed', queuedAt: 1000, durationMs: 1000, outputCount: 0, assets: [], models: [{ nodeId: '1', type: 'CheckpointLoader', name: model }], progress: null }];
|
||
await page.setViewportSize({ width: 768, height: 800 });
|
||
await mockReadOnlyApi(page, { jobs });
|
||
await page.goto('/jobs');
|
||
await expect(page.getByRole('heading', { name: title })).toBeVisible();
|
||
const overflow = await page.evaluate(() => document.documentElement.scrollWidth > window.innerWidth + 1);
|
||
expect(overflow).toBe(false);
|
||
});
|
||
|
||
test('recovers the server connection after a refresh', async ({ page }) => {
|
||
let statusRequests = 0;
|
||
await mockReadOnlyApi(page);
|
||
await page.unroute('**/api/**');
|
||
await page.route('**/api/**', async route => {
|
||
const pathname = new URL(route.request().url()).pathname;
|
||
if (pathname === '/api/me') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ user: adminUser }) });
|
||
if (pathname === '/api/server-status') { statusRequests += 1; if (statusRequests === 1) return route.fulfill({ status: 502, contentType: 'application/json', body: JSON.stringify({ error: 'offline' }) }); return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ status: connectedServer }) }); }
|
||
if (pathname === '/api/model-stats') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(modelStats) });
|
||
if (pathname === '/api/jobs') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ jobs: [], running: null }) });
|
||
if (pathname === '/api/comfy/manager') return route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(managerInfo) });
|
||
return route.continue();
|
||
});
|
||
await page.goto('/jobs');
|
||
await expect(page.getByText('Unavailable', { exact: true })).toBeVisible();
|
||
await page.getByRole('button', { name: 'Refresh' }).click();
|
||
await expect(page.getByText('Connected', { exact: true })).toBeVisible();
|
||
});
|
||
|
||
test('keeps persistent stats visible when jobs are temporarily unavailable', async ({ page }) => {
|
||
await mockReadOnlyApi(page, { jobs: 'unavailable' });
|
||
await page.goto('/jobs');
|
||
await expect(page.getByText('Unable to load jobs.')).toBeVisible();
|
||
await expect(page.getByText('3 tracked jobs · 2 models')).toBeVisible();
|
||
});
|
||
|
||
test('repeated refreshes do not duplicate rendered job cards', async ({ page }) => {
|
||
const jobs = [{ promptId: 'one-card', title: 'One card', status: 'completed', queuedAt: 1000, durationMs: 1000, outputCount: 0, assets: [], models: [], progress: null }];
|
||
await mockReadOnlyApi(page, { jobs });
|
||
await page.goto('/jobs');
|
||
await page.getByRole('button', { name: 'Refresh' }).click();
|
||
await page.getByRole('button', { name: 'Refresh' }).click();
|
||
await expect(page.locator('.job')).toHaveCount(1);
|
||
});
|
||
|
||
test('rejects a mocked switch-version request and re-enables controls', async ({ page }) => {
|
||
await mockReadOnlyApi(page);
|
||
await page.route('**/api/comfy/switch-version', async route => route.fulfill({ status: 400, contentType: 'application/json', body: JSON.stringify({ error: 'Version is unavailable' }) }));
|
||
await page.goto('/jobs');
|
||
await page.locator('select').selectOption('0.2.9');
|
||
page.once('dialog', dialog => dialog.accept());
|
||
await page.getByRole('button', { name: 'Switch version' }).click();
|
||
await expect(page.getByText('Version is unavailable')).toBeVisible();
|
||
await expect(page.getByRole('button', { name: 'Switch version' })).toBeEnabled();
|
||
});
|
||
|
||
test('renders intermediate mocked update progress counts', async ({ page }) => {
|
||
await mockReadOnlyApi(page);
|
||
await page.route('**/api/comfy/update-all', async route => route.fulfill({ status: 202, contentType: 'application/json', body: JSON.stringify({ message: 'started' }) }));
|
||
await page.route('**/api/comfy/update-status', async route => route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ status: { total_count: 5, done_count: 2, in_progress_count: 1, is_processing: true }, progress: { target: 'Node C', uiTarget: 'Node C', totalCount: 5, doneCount: 2 }, result: null }) }));
|
||
await page.goto('/jobs');
|
||
page.once('dialog', dialog => dialog.accept());
|
||
await page.getByRole('button', { name: 'Update all' }).click();
|
||
await page.waitForTimeout(5200);
|
||
await expect(page.getByText('Update all in progress: 2 of 5 tasks complete. Current task: Node C.')).toBeVisible();
|
||
await expect(page.getByRole('button', { name: 'Updating everything…' })).toBeDisabled();
|
||
});
|
||
|
||
test('exposes the monitor controls with accessible names and keyboard focus', async ({ page }) => {
|
||
await mockReadOnlyApi(page);
|
||
await page.goto('/jobs');
|
||
await expect(page.getByRole('button', { name: 'Refresh' })).toBeVisible();
|
||
await expect(page.getByRole('button', { name: 'Sign out' })).toBeVisible();
|
||
await page.getByRole('button', { name: 'Refresh' }).focus();
|
||
await expect(page.getByRole('button', { name: 'Refresh' })).toBeFocused();
|
||
});
|
||
|
||
test('maintains tablet layout without horizontal overflow', async ({ page }) => {
|
||
await page.setViewportSize({ width: 768, height: 1024 });
|
||
await mockReadOnlyApi(page);
|
||
await page.goto('/jobs');
|
||
const overflow = await page.evaluate(() => document.documentElement.scrollWidth > window.innerWidth + 1);
|
||
expect(overflow).toBe(false);
|
||
});
|
||
|
||
test('keeps long output filenames inside their asset caption', async ({ page }) => {
|
||
const filename = 'very-long-output-filename-that-must-remain-contained-within-the-card.png';
|
||
const jobs = [{ promptId: 'long-file', title: 'Long filename', status: 'completed', queuedAt: 1000, durationMs: 1000, outputCount: 1, assets: [{ filename, url: `/api/assets?filename=${encodeURIComponent(filename)}&subfolder=&type=output`, type: 'image' }], models: [], progress: null }];
|
||
await mockReadOnlyApi(page, { jobs });
|
||
await page.goto('/jobs');
|
||
await expect(page.getByText(filename)).toBeVisible();
|
||
const overflow = await page.evaluate(() => document.documentElement.scrollWidth > window.innerWidth + 1);
|
||
expect(overflow).toBe(false);
|
||
});
|
||
});
|