Test, build, and deploy ComfyUI Jobs / test-build (push) Successful in 5m14s
Test, build, and deploy ComfyUI Jobs / deploy (push) Successful in 16s
Test, build, and deploy ComfyUI Jobs / browser-test (push) Successful in 1m58s
Test, build, and deploy ComfyUI Jobs / qa-gate (push) Successful in 5s
325 lines
18 KiB
JavaScript
325 lines
18 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);
|
||
});
|
||
});
|
||
|
||
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') 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('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);
|
||
});
|
||
});
|