Skip to content

Modern Docker Management, Designed for Everyone

chore: fix flakey e2e tests (#4145)

Kyle Mendell13accbe321fd
diff --git a/.depot/workflows/ci.yml b/.depot/workflows/ci.yml
index d70324b85..b27f510ab 100644
--- a/.depot/workflows/ci.yml
+++ b/.depot/workflows/ci.yml
@@ -184,16 +184,8 @@ jobs:
fi
done
- - name: Cache Playwright Browsers
- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
- with:
- path: ~/.cache/ms-playwright
- key: ${{ runner.os }}-playwright-${{ hashFiles('pnpm-lock.yaml', 'tests/package.json') }}
- restore-keys: |
- ${{ runner.os }}-playwright-
-
- - name: Setup and Install Playwright Dependencies
- run: just deps install tests
+ - name: Install E2E test dependencies
+ run: vp -C tests install
- name: Run Playwright E2E tests
run: mkdir -p tests/test-results && vp -C tests exec playwright test --project=chromium
@@ -207,7 +199,9 @@ jobs:
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: playwright-report-${{ matrix.database.name }}
- path: tests/.report
+ path: |
+ tests/.report
+ tests/test-results
include-hidden-files: true
retention-days: 15
@@ -257,6 +251,7 @@ jobs:
env:
COMPOSE_FILE: setup/compose-proxy.yaml
BASE_URL: http://localhost:3002
+ PLAYWRIGHT_DOCKER_BROWSER: '0'
PLAYWRIGHT_JUNIT_OUTPUT_FILE: test-results/playwright-cli.xml
- name: Upload Playwright HTML report
@@ -264,7 +259,9 @@ jobs:
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: playwright-report-proxy-cli
- path: tests/.report
+ path: |
+ tests/.report
+ tests/test-results
include-hidden-files: true
retention-days: 15
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 7605edf28..e39cf1172 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -267,23 +267,11 @@ jobs:
cache: true
run-install: false
- - name: Setup Just
- uses: extractions/setup-just@53165ef7e734c5c07cb06b3c8e7b647c5aa16db3 # v4.0.0
-
- name: Set up Depot CLI
uses: depot/setup-action@91bc8495a33ebfc504ffc89e5674379ccf23c29c # v1.7.2
with:
configure-docker: true
- - name: Cache Playwright Browsers
- uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
- id: playwright-cache
- with:
- path: ~/.cache/ms-playwright
- key: ${{ runner.os }}-playwright-${{ hashFiles('pnpm-lock.yaml', 'tests/package.json') }}
- restore-keys: |
- ${{ runner.os }}-playwright-
-
- name: Pull and save test images
run: |
docker pull public.ecr.aws/nginx/nginx:stable-alpine
@@ -292,8 +280,8 @@ jobs:
docker pull ghcr.io/rustic-rs/rustic:v0.11.2
docker save public.ecr.aws/nginx/nginx:stable-alpine public.ecr.aws/docker/library/busybox:1.37 > /tmp/test-images.tar
- - name: Setup and Install Playwright Dependencies
- run: just deps install tests
+ - name: Install E2E test dependencies
+ run: vp -C tests install
- name: Run Playwright E2E tests
run: vp -C tests exec playwright test ${{ matrix.database.playwright_projects }}
@@ -306,7 +294,9 @@ jobs:
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: playwright-report-${{ matrix.database.name }}
- path: tests/.report
+ path: |
+ tests/.report
+ tests/test-results
include-hidden-files: true
retention-days: 15
@@ -348,6 +338,7 @@ jobs:
env:
COMPOSE_FILE: setup/compose-proxy.yaml
BASE_URL: http://localhost:3002
+ PLAYWRIGHT_DOCKER_BROWSER: '0'
E2E_ADMIN_STATIC_API_KEY: ${{ secrets.E2E_ADMIN_STATIC_API_KEY }}
- name: Upload Playwright HTML report
@@ -355,6 +346,8 @@ jobs:
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: playwright-report-proxy-cli
- path: tests/.report
+ path: |
+ tests/.report
+ tests/test-results
include-hidden-files: true
retention-days: 15
diff --git a/tests/fixtures/test.fixture.ts b/tests/fixtures/test.fixture.ts
index b5860bc78..6aa4b1982 100644
--- a/tests/fixtures/test.fixture.ts
+++ b/tests/fixtures/test.fixture.ts
@@ -1,9 +1,5 @@
import { expect, test as base } from '@playwright/test';
-import type { Page, Request } from '@playwright/test';
-
-const NETWORK_CHANGE_ERROR = 'net::ERR_NETWORK_CHANGED';
-const DYNAMIC_IMPORT_ERROR = 'Failed to fetch dynamically imported module:';
-const NETWORK_CHANGE_MATCH_WINDOW_MS = 1000;
+import type { ConsoleMessage, Page, Request, Response } from '@playwright/test';
export type PageErrorRecord = {
url: string;
@@ -13,7 +9,8 @@ export type PageErrorRecord = {
timestamp: number;
};
-type PageErrorFixtures = {
+type TestFixtures = {
+ registerCleanup: (cleanup: () => Promise<void>) => void;
pageErrorGuard: {
allow: (matcher: string | RegExp) => void;
};
@@ -26,18 +23,6 @@ function pageErrorMatches(error: PageErrorRecord, matcher: string | RegExp): boo
: new RegExp(matcher.source, matcher.flags).test(value);
}
-function dynamicImportWasInterruptedByNetworkChange(
- error: PageErrorRecord,
- networkChangeTimestamps: number[]
-): boolean {
- return (
- error.message.includes(DYNAMIC_IMPORT_ERROR) &&
- networkChangeTimestamps.some(
- (timestamp) => Math.abs(error.timestamp - timestamp) <= NETWORK_CHANGE_MATCH_WINDOW_MS
- )
- );
-}
-
export function installPageErrorCollector(page: Page) {
const errors: PageErrorRecord[] = [];
const record = (error: Error) => {
@@ -67,28 +52,95 @@ export function formatPageErrors(pageErrors: PageErrorRecord[]): string {
.join('\n\n');
}
-export const test = base.extend<PageErrorFixtures>({
+export const test = base.extend<TestFixtures>({
+ connectOptions: [
+ async ({ connectOptions }, use) => {
+ const wsEndpoint = process.env.ARCANE_PLAYWRIGHT_WS_ENDPOINT;
+ await use(
+ connectOptions ?? (wsEndpoint ? { wsEndpoint, exposeNetwork: '<loopback>' } : undefined)
+ );
+ },
+ { scope: 'worker' }
+ ],
+ registerCleanup: [
+ async ({ page: _page }, use, testInfo) => {
+ const cleanups: Array<() => Promise<void>> = [];
+ await use((cleanup) => cleanups.push(cleanup));
+ for (const cleanup of cleanups.reverse()) {
+ try {
+ await cleanup();
+ } catch (error) {
+ const detail = String(error);
+ await testInfo.attach('cleanup-error', { body: detail, contentType: 'text/plain' });
+ expect.soft(false, detail).toBe(true);
+ }
+ }
+ },
+ { timeout: 120_000 }
+ ],
pageErrorGuard: [
async ({ page }, use, testInfo) => {
const collector = installPageErrorCollector(page);
const allowed: Array<string | RegExp> = [];
- const networkChangeTimestamps: number[] = [];
- const recordNetworkChange = (request: Request) => {
- if (request.failure()?.errorText === NETWORK_CHANGE_ERROR) {
- networkChangeTimestamps.push(Date.now());
+ const diagnostics: string[] = [];
+ const pendingConsoleDetails: Promise<void>[] = [];
+ const recordConsole = (message: ConsoleMessage) => {
+ if (message.type() === 'error') {
+ diagnostics.push(
+ `${new Date().toISOString()} console: ${message.text()} ${JSON.stringify(message.location())}`
+ );
+ pendingConsoleDetails.push(
+ (async () => {
+ for (const argument of message.args()) {
+ try {
+ const details = await argument.evaluate((value) =>
+ value instanceof Error
+ ? { name: value.name, message: value.message, stack: value.stack }
+ : null
+ );
+ if (details) diagnostics.push(JSON.stringify(details));
+ } catch {
+ // Navigation can dispose console handles; the text above is still retained.
+ }
+ }
+ })()
+ );
}
};
- page.on('requestfailed', recordNetworkChange);
+ const recordFailedRequest = (request: Request) => {
+ const url = new URL(request.url());
+ diagnostics.push(
+ `${new Date().toISOString()} ${request.method()} ${url.origin}${url.pathname}: ${request.failure()?.errorText}`
+ );
+ };
+ const recordHttpError = (response: Response) => {
+ if (response.status() < 400) return;
+ const url = new URL(response.url());
+ diagnostics.push(
+ `${new Date().toISOString()} ${response.request().method()} ${url.origin}${url.pathname}: HTTP ${response.status()}`
+ );
+ };
+ page.on('response', recordHttpError);
+ page.on('requestfailed', recordFailedRequest);
+ page.on('console', recordConsole);
try {
await use({ allow: (matcher) => allowed.push(matcher) });
} finally {
collector.stop();
- page.off('requestfailed', recordNetworkChange);
- const unexpected = collector.errors.filter((error) => {
- if (allowed.some((matcher) => pageErrorMatches(error, matcher))) return false;
- return !dynamicImportWasInterruptedByNetworkChange(error, networkChangeTimestamps);
- });
+ page.off('requestfailed', recordFailedRequest);
+ page.off('console', recordConsole);
+ page.off('response', recordHttpError);
+ await Promise.all(pendingConsoleDetails);
+ const unexpected = collector.errors.filter(
+ (error) => !allowed.some((matcher) => pageErrorMatches(error, matcher))
+ );
+ if (testInfo.status !== testInfo.expectedStatus || unexpected.length > 0) {
+ await testInfo.attach('browser-diagnostics', {
+ body: diagnostics.join('\n'),
+ contentType: 'text/plain'
+ });
+ }
if (unexpected.length > 0) {
const details = formatPageErrors(unexpected);
diff --git a/tests/playwright.config.ts b/tests/playwright.config.ts
index 6733f9225..2fbf521a9 100644
--- a/tests/playwright.config.ts
+++ b/tests/playwright.config.ts
@@ -6,7 +6,7 @@ const configuredWorkers = process.env.PLAYWRIGHT_WORKERS;
const workers =
configuredWorkers && Number.isInteger(Number(configuredWorkers))
? Number(configuredWorkers)
- : configuredWorkers || (process.env.CI ? 1 : 2);
+ : configuredWorkers || 1;
export default defineConfig({
testDir: '.',
@@ -16,7 +16,7 @@ export default defineConfig({
retries: process.env.CI ? 2 : 0,
retryStrategy: 'isolated',
workers,
- globalSetup: './setup/global-setup',
+ globalSetup: ['./setup/docker-browser', './setup/global-setup'],
globalTeardown: './setup/global-teardown',
reporter: process.env.CI
? [
@@ -35,7 +35,8 @@ export default defineConfig({
use: {
baseURL,
serviceWorkers: 'block',
- trace: 'on-first-retry',
+ trace: 'retain-on-failure',
+ screenshot: 'only-on-failure',
video: 'retain-on-failure'
},
projects: [
diff --git a/tests/setup/compose-proxy.yaml b/tests/setup/compose-proxy.yaml
index 1a3b9b15f..d58dacf9c 100644
--- a/tests/setup/compose-proxy.yaml
+++ b/tests/setup/compose-proxy.yaml
@@ -28,6 +28,7 @@ services:
- '-allowGET=(/v[\d.]+)?/containers(/.*)?'
- '-allowGET=(/v[\d.]+)?/exec(/.*)?'
- '-allowGET=(/v[\d.]+)?/images(/.*)?'
+ - '-allowGET=(/v[\d.]+)?/distribution/.+/json'
- '-allowGET=(/v[\d.]+)?/info(/.*)?'
- '-allowGET=(/v[\d.]+)?/networks(/.*)?'
- '-allowGET=(/v[\d.]+)?/volumes(/.*)?'
diff --git a/tests/setup/docker-browser.ts b/tests/setup/docker-browser.ts
new file mode 100644
index 000000000..625dba4d6
--- /dev/null
+++ b/tests/setup/docker-browser.ts
@@ -0,0 +1,97 @@
+import { expect, type FullConfig } from '@playwright/test';
+import { execFileSync, spawnSync } from 'node:child_process';
+import { mkdirSync, writeFileSync } from 'node:fs';
+import { createRequire } from 'node:module';
+import path from 'node:path';
+
+export default async function dockerBrowserSetup(config: FullConfig) {
+ if (
+ process.env.PLAYWRIGHT_DOCKER_BROWSER === '0' ||
+ process.env.PW_TEST_CONNECT_WS_ENDPOINT ||
+ config.projects.every((project) => project.use.connectOptions) ||
+ (process.platform !== 'linux' && process.env.PLAYWRIGHT_DOCKER_BROWSER !== '1')
+ )
+ return;
+ const version = createRequire(import.meta.url)('@playwright/test/package.json').version as string;
+ const name = `arcane-e2e-browser-${process.pid}-${Date.now()}`;
+ let created = false;
+ const cleanup = () => {
+ delete process.env.ARCANE_PLAYWRIGHT_WS_ENDPOINT;
+ if (created) {
+ const directory = path.join(config.rootDir, 'test-results', 'browser');
+ try {
+ mkdirSync(directory, { recursive: true });
+ const logs = spawnSync('docker', ['logs', name], {
+ encoding: 'utf8',
+ maxBuffer: 4 * 1024 * 1024
+ });
+ writeFileSync(path.join(directory, 'logs.txt'), `${logs.stdout ?? ''}${logs.stderr ?? ''}`);
+ if (logs.error || logs.status !== 0)
+ throw new Error(`Capture browser logs: ${logs.error ?? logs.stderr}`);
+ writeFileSync(
+ path.join(directory, 'state.json'),
+ execFileSync('docker', ['inspect', '--format', '{{json .State}}', name], {
+ encoding: 'utf8'
+ })
+ );
+ } finally {
+ execFileSync('docker', ['rm', '-f', name], { stdio: 'pipe' });
+ }
+ }
+ };
+ try {
+ // Docker changes host interfaces throughout these tests. Keep browsers on their own bridge.
+ execFileSync(
+ 'docker',
+ [
+ 'run',
+ '-d',
+ '--name',
+ name,
+ '--init',
+ '--ipc=host',
+ '--network',
+ 'bridge',
+ '--publish',
+ '127.0.0.1::3000',
+ `mcr.microsoft.com/playwright:v${version}-noble`,
+ 'npx',
+ '-y',
+ `playwright@${version}`,
+ 'run-server',
+ '--port',
+ '3000',
+ '--host',
+ '0.0.0.0'
+ ],
+ { encoding: 'utf8', timeout: 120_000 }
+ );
+ created = true;
+ const address = execFileSync('docker', ['port', name, '3000/tcp'], {
+ encoding: 'utf8'
+ }).trim();
+ expect(address).toMatch(/^127\.0\.0\.1:\d+$/);
+ await expect
+ .poll(
+ async () => {
+ try {
+ return (await fetch(`http://${address}/`, { signal: AbortSignal.timeout(2000) })).ok;
+ } catch {
+ return false;
+ }
+ },
+ { timeout: 90_000, message: 'Playwright browser server must be ready' }
+ )
+ .toBe(true);
+ process.env.ARCANE_PLAYWRIGHT_WS_ENDPOINT = `ws://${address}/`;
+ console.log(`Playwright browser server ready: ${name}`);
+ } catch (error) {
+ try {
+ cleanup();
+ } catch (cleanupError) {
+ throw new AggregateError([error, cleanupError], 'Browser setup and cleanup failed');
+ }
+ throw error;
+ }
+ return cleanup;
+}
diff --git a/tests/setup/global-setup.ts b/tests/setup/global-setup.ts
index 2f00dd1a5..20772a58e 100644
--- a/tests/setup/global-setup.ts
+++ b/tests/setup/global-setup.ts
@@ -1,4 +1,4 @@
-import { execFileSync, execSync } from 'child_process';
+import { execFileSync } from 'child_process';
import path from 'node:path';
import fs from 'node:fs';
import { fileURLToPath } from 'node:url';
@@ -6,6 +6,26 @@ import { fileURLToPath } from 'node:url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
+export function captureComposeDiagnostics(composeFile: string) {
+ const directory = path.resolve(__dirname, '../test-results/compose');
+ fs.mkdirSync(directory, { recursive: true });
+ for (const [name, args] of [
+ ['services', ['ps', '--all', '--format', 'json']],
+ ['logs', ['logs', '--no-color', '--timestamps']]
+ ] as const) {
+ try {
+ const output = execFileSync('docker', ['compose', '-f', composeFile, ...args], {
+ encoding: 'utf8',
+ maxBuffer: 32 * 1024 * 1024
+ });
+ fs.writeFileSync(path.join(directory, `${name}.txt`), output);
+ } catch (error) {
+ fs.writeFileSync(path.join(directory, `${name}.txt`), `Capture failed: ${String(error)}\n`);
+ console.error(`Failed to capture Compose ${name}:`, error);
+ }
+ }
+}
+
function ensureProjectsDirIsContainerWritable(projectsDir: string) {
fs.mkdirSync(projectsDir, { recursive: true });
@@ -47,13 +67,31 @@ async function globalSetup() {
// before `docker compose up` so Docker does not create it as root, and make it
// writable for the hardened non-root runtime user (65532).
const projectsDir = path.resolve(__dirname, 'projects');
- ensureProjectsDirIsContainerWritable(projectsDir);
try {
+ ensureProjectsDirIsContainerWritable(projectsDir);
+ const staticProjectDir = path.join(projectsDir, 'test-project-static');
+ fs.accessSync(path.join(staticProjectDir, 'compose.yaml'), fs.constants.R_OK);
+ const staticEnvFile = path.join(staticProjectDir, '.env');
+ if (!fs.existsSync(staticEnvFile)) fs.writeFileSync(staticEnvFile, '');
+ for (const image of [
+ 'public.ecr.aws/docker/library/busybox:1.37',
+ 'public.ecr.aws/docker/library/alpine:3.20',
+ 'public.ecr.aws/nginx/nginx:stable-alpine'
+ ]) {
+ try {
+ execFileSync('docker', ['image', 'inspect', image], { stdio: 'ignore' });
+ } catch {
+ execFileSync('docker', ['pull', image], { stdio: 'inherit' });
+ }
+ }
console.log('Building and starting Docker containers...');
- execSync(`docker compose -f ${composeFile} up -d --build`, { stdio: 'inherit' });
+ execFileSync('docker', ['compose', '-f', composeFile, 'up', '-d', '--build'], {
+ stdio: 'inherit'
+ });
console.log('Docker containers are up.');
} catch (error) {
+ captureComposeDiagnostics(composeFile);
console.error('Failed to start Docker containers:', error);
throw error;
}
@@ -66,7 +104,9 @@ async function globalSetup() {
let attempts = 0;
while (attempts < maxAttempts) {
try {
- const response = await fetch(baseURL);
+ const response = await fetch(new URL('/api/health', baseURL), {
+ signal: AbortSignal.timeout(2000)
+ });
if (response.ok) {
console.log('Server is ready!');
break;
@@ -79,6 +119,7 @@ async function globalSetup() {
}
if (attempts === maxAttempts) {
+ captureComposeDiagnostics(composeFile);
throw new Error(`Server at ${baseURL} did not become ready in time.`);
}
diff --git a/tests/setup/global-teardown.ts b/tests/setup/global-teardown.ts
index 01edca73a..b6136c5bb 100644
--- a/tests/setup/global-teardown.ts
+++ b/tests/setup/global-teardown.ts
@@ -1,4 +1,5 @@
-import { execFileSync, execSync } from 'child_process';
+import { execFileSync } from 'child_process';
+import { captureComposeDiagnostics } from './global-setup';
import path from 'node:path';
import fs from 'node:fs';
import { fileURLToPath } from 'node:url';
@@ -13,13 +14,16 @@ async function globalTeardown() {
? path.resolve(__dirname, '..', process.env.COMPOSE_FILE)
: path.resolve(__dirname, 'compose.yaml');
const projectsDir = path.resolve(__dirname, 'projects');
+ const failures: unknown[] = [];
+ captureComposeDiagnostics(composeFile);
// 1. Stop and remove Docker containers
try {
console.log('Stopping Docker containers...');
- execSync(`docker compose -f ${composeFile} down -v`, { stdio: 'inherit' });
+ execFileSync('docker', ['compose', '-f', composeFile, 'down', '-v'], { stdio: 'inherit' });
console.log('Docker containers stopped and volumes removed.');
} catch (error) {
+ failures.push(error);
console.error('Warning: Failed to stop Docker containers cleanly:', error);
}
@@ -69,9 +73,11 @@ async function globalTeardown() {
}
}
} catch (error) {
+ failures.push(error);
console.error('Warning: Failed to clean up projects directory:', error);
}
+ if (failures.length > 0) throw new AggregateError(failures, 'E2E environment cleanup failed');
console.log('Global teardown complete.\n');
}
diff --git a/tests/setup/projects/test-project-static/.env b/tests/setup/projects/test-project-static/.env
new file mode 100644
index 000000000..e69de29bb
diff --git a/tests/spec/account.spec.ts b/tests/spec/account.spec.ts
index c69f745d4..13667c420 100644
--- a/tests/spec/account.spec.ts
+++ b/tests/spec/account.spec.ts
@@ -1,3 +1,4 @@
+import { waitForDialogReady } from '../utils/playwright.util';
import { fileURLToPath } from 'node:url';
import {
expect,
@@ -7,7 +8,7 @@ import {
type BrowserContext,
type Page
} from '../fixtures/test.fixture';
-import { readApiData } from '../utils/fetch.util';
+import { removeApiResource, readApiData } from '../utils/fetch.util';
const AVATAR_PATH = fileURLToPath(
new URL('../../backend/resources/images/icon-128x128.png', import.meta.url)
@@ -161,6 +162,7 @@ test('manages an isolated account, preferences, credentials, and sessions', asyn
await accountPage.getByRole('button', { name: 'New key', exact: true }).click();
const keyDialog = accountPage.getByRole('dialog', { name: 'Create API Key' });
+ await waitForDialogReady(keyDialog);
await keyDialog.getByLabel('Name', { exact: true }).fill(keyName);
await keyDialog.getByLabel('Description', { exact: true }).fill('Account browser journey');
const keyCreateResponsePromise = accountPage.waitForResponse(
@@ -317,7 +319,7 @@ test('manages an isolated account, preferences, credentials, and sessions', asyn
} finally {
await accountContext?.close();
if (user) {
- await page.request.delete(`/api/users/${user.id}`).catch(() => undefined);
+ await removeApiResource(page, `/api/users/${user.id}`);
}
}
});
@@ -469,7 +471,14 @@ test('registers, renames, authenticates with, and removes a passkey with MFA', a
await dangerZone.getByRole('button', { name: 'Log out', exact: true }).click();
await expect(passkeyPage).toHaveURL('/login');
await passkeyPage.getByRole('button', { name: 'Passkey', exact: true }).click();
- if (await usePasskeyButton.isVisible().catch(() => false)) {
+ await expect
+ .poll(
+ async () =>
+ new URL(passkeyPage.url()).pathname === '/dashboard' ||
+ (await usePasskeyButton.isVisible())
+ )
+ .toBe(true);
+ if (await usePasskeyButton.isVisible()) {
await usePasskeyButton.click();
}
await expect(passkeyPage).toHaveURL('/dashboard');
@@ -518,7 +527,7 @@ test('registers, renames, authenticates with, and removes a passkey with MFA', a
} finally {
await passkeyContext?.close();
if (user) {
- await page.request.delete(`/api/users/${user.id}`).catch(() => undefined);
+ await removeApiResource(page, `/api/users/${user.id}`);
}
}
});
diff --git a/tests/spec/activity-center.spec.ts b/tests/spec/activity-center.spec.ts
index a438e0b0c..7c25ae812 100644
--- a/tests/spec/activity-center.spec.ts
+++ b/tests/spec/activity-center.spec.ts
@@ -1,3 +1,5 @@
+import { removeApiResource } from '../utils/fetch.util';
+import { waitForDialogReady } from '../utils/playwright.util';
import { test, expect, type Locator, type Page, type Route } from '../fixtures/test.fixture';
type MockEnvironment = {
@@ -255,7 +257,7 @@ async function createNetworkViaUI(page: Page, networkName: string) {
await page.getByRole('button', { name: 'Create Network' }).first().click();
const dialog = page.getByRole('dialog');
- await expect(dialog).toBeVisible();
+ await waitForDialogReady(dialog);
await dialog.locator('#network-name').fill(networkName);
const createRequest = page.waitForResponse(
@@ -282,13 +284,6 @@ async function createNetworkViaUI(page: Page, networkName: string) {
};
}
-async function removeNetworkViaApi(page: Page, networkId: string | undefined) {
- if (!networkId) return;
- await page.request
- .delete(`/api/environments/0/networks/${encodeURIComponent(networkId)}`)
- .catch(() => undefined);
-}
-
async function openActivityCenter(page: Page) {
await page.getByRole('button', { name: 'Open activity center' }).first().click();
const activityCenter = page.getByRole('dialog', { name: 'Activity Center' });
@@ -623,6 +618,7 @@ test.describe('Activity Center', () => {
try {
const created = await createNetworkViaUI(page, networkName);
networkId = created.networkId;
+ expect(networkId, 'Created network must have an ID').toBeTruthy();
expect(created.activityId).toBeTruthy();
const [environmentResponse, userResponse] = await Promise.all([
@@ -668,7 +664,10 @@ test.describe('Activity Center', () => {
// (e.g. "Creating network") are no longer rendered in the detail panel.
await expect(detailPanel.getByText('Network created successfully').first()).toBeVisible();
} finally {
- await removeNetworkViaApi(page, networkId);
+ await removeApiResource(
+ page,
+ `/api/environments/0/networks/${encodeURIComponent(networkId ?? networkName)}`
+ );
}
});
});
diff --git a/tests/spec/api-keys.spec.ts b/tests/spec/api-keys.spec.ts
index dcb225bd6..d7999e03e 100644
--- a/tests/spec/api-keys.spec.ts
+++ b/tests/spec/api-keys.spec.ts
@@ -1,5 +1,6 @@
import { test, expect, type Page } from '../fixtures/test.fixture';
-import { createTestApiKeys, deleteTestApiKeys } from '../utils/playwright.util';
+import { createTestApiKeys, deleteTestApiKeys, waitForDialogReady } from '../utils/playwright.util';
+import { fetchApiKeysWithRetry } from '../utils/fetch.util';
import { openRowActionsMenu } from '../utils/table-actions.util';
const API_KEYS_ROUTE = '/settings/api-keys';
@@ -10,14 +11,22 @@ async function navigateToApiKeys(page: Page) {
}
test.describe('API Keys Page', () => {
- // Create test API keys before tests that need existing data
- test.beforeAll(async () => {
+ // Each test starts with its own required keys.
+ test.beforeEach(async () => {
await createTestApiKeys(3);
});
- // Clean up test API keys after all tests
- test.afterAll(async () => {
+ // Remove fixture keys before the next test.
+ test.afterEach(async ({ page }) => {
await deleteTestApiKeys();
+ await expect
+ .poll(
+ async () =>
+ (await fetchApiKeysWithRetry(page)).data.filter((key) =>
+ key.name.startsWith('test-api-key-')
+ ).length
+ )
+ .toBe(0);
});
test('should display the API keys page title and description', async ({ page }) => {
@@ -55,18 +64,16 @@ test.describe('API Keys Page', () => {
await page.getByRole('button', { name: 'Create API Key' }).click();
const createDialog = page.getByRole('dialog');
- await expect(createDialog).toBeVisible();
+ await waitForDialogReady(createDialog);
- const apiKeyName = `test-key-${Date.now()}`;
+ const apiKeyName = `test-api-key-created-${Date.now()}`;
// Fill in the name field
await createDialog.getByLabel('Name', { exact: true }).fill(apiKeyName);
// Optionally fill description
const descInput = createDialog.getByLabel('Description', { exact: true });
- if (await descInput.count()) {
- await descInput.fill('E2E test API key');
- }
+ await descInput.fill('E2E test API key');
// Select at least one permission (form requires min 1)
await createDialog
@@ -158,7 +165,7 @@ test.describe('API Keys Page', () => {
await page.getByRole('button', { name: 'Create API Key' }).click();
const createDialog = page.getByRole('dialog');
- const apiKeyName = `delete-test-${Date.now()}`;
+ const apiKeyName = `test-api-key-delete-${Date.now()}`;
await createDialog.getByLabel('Name', { exact: true }).fill(apiKeyName);
// Select at least one permission (form requires min 1)
@@ -170,11 +177,11 @@ test.describe('API Keys Page', () => {
await createDialog.getByRole('button', { name: 'Create API Key', exact: true }).click();
// Wait for creation success and close reveal dialog
- await expect(page.getByText('API Key Created')).toBeVisible({ timeout: 10000 });
- await page.getByRole('button', { name: 'Done' }).click();
+ const createdDialog = page.getByRole('dialog', { name: 'API Key Created' });
+ await expect(createdDialog).toBeVisible({ timeout: 10000 });
+ await createdDialog.getByRole('button', { name: 'Done' }).click();
- // Wait for toasts to clear
- await page.waitForTimeout(1000);
+ await expect(createdDialog).toBeHidden();
// Now delete the key
const keyRow = page
@@ -208,12 +215,7 @@ test.describe('API Keys Page', () => {
.getByRole('row')
.filter({ has: page.getByRole('button', { name: 'Open menu', exact: true }) })
.getByRole('checkbox');
- const checkboxCount = await checkboxes.count();
-
- if (checkboxCount < 2) {
- test.skip(true, 'Need at least 2 API keys for bulk selection test');
- return;
- }
+ await expect(checkboxes.nth(1)).toBeVisible();
await checkboxes.nth(0).check();
await checkboxes.nth(1).check();
diff --git a/tests/spec/builds.spec.ts b/tests/spec/builds.spec.ts
index 3ae709a99..266350908 100644
--- a/tests/spec/builds.spec.ts
+++ b/tests/spec/builds.spec.ts
@@ -46,12 +46,11 @@ async function switchContextMode(page: Page, mode: 'Workspace' | 'Remote Git'):
async function openAdvancedBuildOptions(page: Page) {
const dockerfileInput = page.locator('#dockerfile');
- const alreadyVisible = await dockerfileInput.isVisible().catch(() => false);
- if (alreadyVisible) {
- return;
+ const trigger = page.getByRole('button', { name: 'Advanced', exact: true }).first();
+ await expect(trigger).toBeVisible();
+ if ((await trigger.getAttribute('aria-expanded')) !== 'true') {
+ await trigger.click();
}
-
- await page.getByRole('button', { name: 'Advanced', exact: true }).first().click();
await expect(dockerfileInput).toBeVisible();
}
@@ -133,7 +132,8 @@ async function mockDepotConfiguredSettings(page: Page) {
}
const upstream = await route.fetch();
- const original = await upstream.json().catch(() => ({}));
+ expect(upstream.ok(), `Fetch settings: ${upstream.status()}`).toBe(true);
+ const original = await upstream.json();
const patched = injectDepotSettings(original);
await route.fulfill({
diff --git a/tests/spec/cli.spec.ts b/tests/spec/cli.spec.ts
index 378cc26b2..2118c36f1 100644
--- a/tests/spec/cli.spec.ts
+++ b/tests/spec/cli.spec.ts
@@ -605,7 +605,9 @@ test.describe('arcane-cli e2e', () => {
'api-keys',
'delete',
created.id
- ]).catch(() => undefined);
+ ]).catch((error: unknown) => {
+ expect.soft(false, `Remove CLI test key: ${String(error)}`).toBe(true);
+ });
}
}
});
@@ -735,14 +737,30 @@ test.describe('arcane-cli remote environment RBAC', () => {
test.afterAll(async () => {
if (readonlyKeyId) {
- await adminFetch(`/api/api-keys/${readonlyKeyId}`, { method: 'DELETE' }).catch(
- () => undefined
- );
+ try {
+ const response = await adminFetch(`/api/api-keys/${readonlyKeyId}`, { method: 'DELETE' });
+ expect
+ .soft(
+ response.ok || response.status === 404,
+ `Remove read-only key: ${response.status} ${await response.text()}`
+ )
+ .toBe(true);
+ } catch (error) {
+ expect.soft(false, `Remove read-only key: ${String(error)}`).toBe(true);
+ }
}
if (remoteEnvId) {
- await adminFetch(`/api/environments/${remoteEnvId}`, { method: 'DELETE' }).catch(
- () => undefined
- );
+ try {
+ const response = await adminFetch(`/api/environments/${remoteEnvId}`, { method: 'DELETE' });
+ expect
+ .soft(
+ response.ok || response.status === 404,
+ `Remove remote environment: ${response.status} ${await response.text()}`
+ )
+ .toBe(true);
+ } catch (error) {
+ expect.soft(false, `Remove remote environment: ${String(error)}`).toBe(true);
+ }
}
if (createdAdminKey) {
await deleteTestApiKeys();
diff --git a/tests/spec/container-lifecycle.spec.ts b/tests/spec/container-lifecycle.spec.ts
index 71d9ffba1..19065d841 100644
--- a/tests/spec/container-lifecycle.spec.ts
+++ b/tests/spec/container-lifecycle.spec.ts
@@ -1,5 +1,6 @@
import { expect, test, type Locator, type Page, type Response } from '../fixtures/test.fixture';
-import { readApiData } from '../utils/fetch.util';
+import { readApiData, removeApiResource } from '../utils/fetch.util';
+import { waitForDialogReady } from '../utils/playwright.util';
const TEST_IMAGE = 'public.ecr.aws/docker/library/busybox:1.37';
@@ -105,6 +106,12 @@ async function updateExperimentalFeatures(page: Page, enabled: string) {
`Update experimentalFeaturesEnabled failed with ${response.status()}: ${await response.text()}`
);
}
+ const settingsResponse = await page.request.get('/api/environments/0/settings');
+ expect(settingsResponse.ok(), 'Read back experimental feature setting').toBe(true);
+ const settings = (await settingsResponse.json()) as Array<{ key: string; value: string }>;
+ expect(settings).toContainEqual(
+ expect.objectContaining({ key: 'experimentalFeaturesEnabled', value: enabled })
+ );
}
async function getContainer(page: Page, containerId: string): Promise<ContainerDetails> {
@@ -161,31 +168,34 @@ async function runSimpleContainerAction(
buttonName: string,
expectedActivityType: string
) {
- const responseTimeout = pathAction === 'stop' ? 120_000 : 60_000;
- const matchesActionRequest = (url: string, method: string) => {
- const pathname = new URL(url).pathname.replace(/\/$/, '');
- return method === 'POST' && pathname.endsWith(`/containers/${containerId}/${pathAction}`);
- };
- const requestPromise = page.waitForRequest(
- (request) => matchesActionRequest(request.url(), request.method()),
- { timeout: 30_000 }
- );
- const responsePromise = page.waitForResponse(
- (response) => matchesActionRequest(response.url(), response.request().method()),
- { timeout: responseTimeout }
- );
- await page
- .getByRole('button', { name: buttonName, exact: true })
- .filter({ visible: true })
- .first()
- .click();
- await requestPromise;
- const result = await readApiData<ActionResult>(
- await responsePromise,
- `${buttonName} container ${containerId}`
- );
- expect(result.activityId, `${buttonName} must return an activity ID`).toBeTruthy();
- await expectActivitySucceeded(page, result.activityId!, expectedActivityType);
+ return test.step(`${buttonName} container`, async () => {
+ const responseTimeout = pathAction === 'stop' ? 120_000 : 60_000;
+ const matchesActionRequest = (url: string, method: string) => {
+ const pathname = new URL(url).pathname.replace(/\/$/, '');
+ return method === 'POST' && pathname.endsWith(`/containers/${containerId}/${pathAction}`);
+ };
+ const requestPromise = page.waitForRequest(
+ (request) => matchesActionRequest(request.url(), request.method()),
+ { timeout: 30_000 }
+ );
+ const responsePromise = page.waitForResponse(
+ (response) => matchesActionRequest(response.url(), response.request().method()),
+ { timeout: responseTimeout }
+ );
+ await page
+ .locator('[data-tabs-root] > :not([inert])')
+ .getByRole('button', { name: buttonName, exact: true })
+ .filter({ visible: true })
+ .first()
+ .click();
+ await requestPromise;
+ const result = await readApiData<ActionResult>(
+ await responsePromise,
+ `${buttonName} container ${containerId}`
+ );
+ expect(result.activityId, `${buttonName} must return an activity ID`).toBeTruthy();
+ await expectActivitySucceeded(page, result.activityId!, expectedActivityType);
+ });
}
async function selectSearchableOption(page: Page, scope: Locator, option: string) {
@@ -204,360 +214,422 @@ async function createContainerThroughUI(
page: Page,
containerName: string,
volumeName: string,
- networkName: string
+ networkName: string,
+ containerIds: Set<string>
) {
- await page.goto('/containers/new');
- await page.getByRole('button', { name: 'Create Container', exact: true }).click();
- await expect(page.getByText('Container name is required', { exact: true })).toBeVisible();
- await expect(page.getByText('Image is required', { exact: true })).toBeVisible();
-
- await page.getByLabel('Container Name *', { exact: true }).fill(containerName);
- await page.getByLabel('Image *', { exact: true }).fill(TEST_IMAGE);
- await page.getByLabel('Command', { exact: true }).fill('sleep 3600');
- await page.getByLabel('Working Directory', { exact: true }).fill('/tmp');
-
- await page.getByRole('tab', { name: 'Environment', exact: true }).click();
- const environmentGroup = formGroup(page, 'Environment Variables');
- await environmentGroup.getByRole('button', { name: 'Add', exact: true }).click();
- await environmentGroup.getByPlaceholder('KEY').fill('E2E_VALUE');
- await environmentGroup.getByPlaceholder('value').fill('initial');
-
- const labelsGroup = formGroup(page, 'Labels');
- await labelsGroup.getByRole('button', { name: 'Add', exact: true }).click();
- await labelsGroup.getByPlaceholder('com.example.key').fill('arcane.e2e');
- await labelsGroup.getByPlaceholder('value').fill('container-lifecycle');
-
- await page.getByRole('tab', { name: 'Ports', exact: true }).click();
- await page.getByRole('button', { name: 'Add', exact: true }).click();
- await page.getByPlaceholder('0.0.0.0').fill('127.0.0.1');
- await page.getByPlaceholder('80', { exact: true }).fill('8080');
-
- await page.getByRole('tab', { name: 'Volumes', exact: true }).click();
- await page.getByRole('button', { name: 'Add Volume Mount', exact: true }).click();
- await selectSearchableOption(page, page.getByRole('tabpanel'), volumeName);
- await page.getByPlaceholder('Container path').fill('/data');
-
- await page.getByRole('tab', { name: 'Networks', exact: true }).click();
- await page.getByRole('button', { name: 'Add', exact: true }).click();
- await selectSearchableOption(page, page.getByRole('tabpanel'), networkName);
- await page.getByPlaceholder('Aliases').fill('lifecycle-alias');
-
- await page.getByRole('tab', { name: 'Advanced', exact: true }).click();
- await page.locator('#restart-policy').click();
- await page.getByRole('option', { name: 'On Failure', exact: true }).click();
- await page.getByLabel('Maximum Retries', { exact: true }).fill('3');
- await page.locator('#health-mode').click();
- await page.getByRole('option', { name: 'Custom', exact: true }).click();
- await page.getByLabel('Test Command', { exact: true }).fill('test "$E2E_VALUE" = "initial"');
- await page.getByLabel('Interval (s)', { exact: true }).fill('2');
- await page.getByLabel('Timeout (s)', { exact: true }).fill('1');
- await page.getByLabel('Retries', { exact: true }).fill('2');
-
- const requestPromise = page.waitForRequest(
- (request) =>
- request.method() === 'POST' &&
- new URL(request.url()).pathname === '/api/environments/0/containers'
- );
- const responsePromise = page.waitForResponse(
- (response) =>
- response.request().method() === 'POST' &&
- new URL(response.url()).pathname === '/api/environments/0/containers'
- );
- await page.getByRole('button', { name: 'Create Container', exact: true }).click();
+ return test.step('Create container', async () => {
+ await page.goto('/containers/new');
+ await page.getByRole('button', { name: 'Create Container', exact: true }).click();
+ await expect(page.getByText('Container name is required', { exact: true })).toBeVisible();
+ await expect(page.getByText('Image is required', { exact: true })).toBeVisible();
+
+ await page.getByLabel('Container Name *', { exact: true }).fill(containerName);
+ await page.getByLabel('Image *', { exact: true }).fill(TEST_IMAGE);
+ await page.getByLabel('Command', { exact: true }).fill('sleep 3600');
+ await page.getByLabel('Working Directory', { exact: true }).fill('/tmp');
+
+ await page.getByRole('tab', { name: 'Environment', exact: true }).click();
+ const environmentGroup = formGroup(page, 'Environment Variables');
+ await environmentGroup.getByRole('button', { name: 'Add', exact: true }).click();
+ await environmentGroup.getByPlaceholder('KEY').fill('E2E_VALUE');
+ await environmentGroup.getByPlaceholder('value').fill('initial');
+
+ const labelsGroup = formGroup(page, 'Labels');
+ await labelsGroup.getByRole('button', { name: 'Add', exact: true }).click();
+ await labelsGroup.getByPlaceholder('com.example.key').fill('arcane.e2e');
+ await labelsGroup.getByPlaceholder('value').fill('container-lifecycle');
+
+ await page.getByRole('tab', { name: 'Ports', exact: true }).click();
+ await page.getByRole('button', { name: 'Add', exact: true }).click();
+ await page.getByPlaceholder('0.0.0.0').fill('127.0.0.1');
+ await page.getByPlaceholder('80', { exact: true }).fill('8080');
+
+ await page.getByRole('tab', { name: 'Volumes', exact: true }).click();
+ await page.getByRole('button', { name: 'Add Volume Mount', exact: true }).click();
+ await selectSearchableOption(page, page.getByRole('tabpanel'), volumeName);
+ await page.getByPlaceholder('Container path').fill('/data');
+
+ await page.getByRole('tab', { name: 'Networks', exact: true }).click();
+ await page.getByRole('button', { name: 'Add', exact: true }).click();
+ await selectSearchableOption(page, page.getByRole('tabpanel'), networkName);
+ await page.getByPlaceholder('Aliases').fill('lifecycle-alias');
+
+ await page.getByRole('tab', { name: 'Advanced', exact: true }).click();
+ await page.locator('#restart-policy').click();
+ await page.getByRole('option', { name: 'On Failure', exact: true }).click();
+ await page.getByLabel('Maximum Retries', { exact: true }).fill('3');
+ await page.locator('#health-mode').click();
+ await page.getByRole('option', { name: 'Custom', exact: true }).click();
+ await page.getByLabel('Test Command', { exact: true }).fill('test "$E2E_VALUE" = "initial"');
+ await page.getByLabel('Interval (s)', { exact: true }).fill('2');
+ await page.getByLabel('Timeout (s)', { exact: true }).fill('1');
+ await page.getByLabel('Retries', { exact: true }).fill('2');
+
+ const requestPromise = page.waitForRequest(
+ (request) =>
+ request.method() === 'POST' &&
+ new URL(request.url()).pathname === '/api/environments/0/containers'
+ );
+ const responsePromise = page.waitForResponse(
+ (response) =>
+ response.request().method() === 'POST' &&
+ new URL(response.url()).pathname === '/api/environments/0/containers'
+ );
+ await page.getByRole('button', { name: 'Create Container', exact: true }).click();
- const request = await requestPromise;
- const payload = request.postDataJSON() as ContainerCreatePayload;
- const created = await readApiData<CreatedContainer>(
- await responsePromise,
- `Create container ${containerName}`
- );
- await expect(page).toHaveURL((url) => url.pathname === `/containers/${created.id}`);
-
- expect(payload).toMatchObject({
- name: containerName,
- image: TEST_IMAGE,
- cmd: ['sleep', '3600'],
- workingDir: '/tmp',
- env: ['E2E_VALUE=initial'],
- labels: { 'arcane.e2e': 'container-lifecycle' },
- healthcheck: {
- test: ['CMD-SHELL', 'test "$E2E_VALUE" = "initial"'],
- interval: 2,
- timeout: 1,
- retries: 2
- },
- hostConfig: {
- binds: [`${volumeName}:/data`],
- portBindings: {
- '8080/tcp': [{ hostIp: '127.0.0.1', hostPort: '' }]
+ const request = await requestPromise;
+ const payload = request.postDataJSON() as ContainerCreatePayload;
+ const created = await readApiData<CreatedContainer>(
+ await responsePromise,
+ `Create container ${containerName}`
+ );
+ containerIds.add(created.id);
+ await expect(page).toHaveURL((url) => url.pathname === `/containers/${created.id}`);
+
+ expect(payload).toMatchObject({
+ name: containerName,
+ image: TEST_IMAGE,
+ cmd: ['sleep', '3600'],
+ workingDir: '/tmp',
+ env: ['E2E_VALUE=initial'],
+ labels: { 'arcane.e2e': 'container-lifecycle' },
+ healthcheck: {
+ test: ['CMD-SHELL', 'test "$E2E_VALUE" = "initial"'],
+ interval: 2,
+ timeout: 1,
+ retries: 2
+ },
+ hostConfig: {
+ binds: [`${volumeName}:/data`],
+ portBindings: {
+ '8080/tcp': [{ hostIp: '127.0.0.1', hostPort: '' }]
+ },
+ restartPolicy: { name: 'on-failure', maximumRetryCount: 3 }
},
- restartPolicy: { name: 'on-failure', maximumRetryCount: 3 }
- },
- networkingConfig: {
- endpointsConfig: {
- [networkName]: { aliases: ['lifecycle-alias'] }
+ networkingConfig: {
+ endpointsConfig: {
+ [networkName]: { aliases: ['lifecycle-alias'] }
+ }
}
- }
- });
+ });
- return created;
+ return created;
+ });
}
async function verifyShell(page: Page, marker: string) {
- await page.getByRole('tab', { name: 'Shell', exact: true }).click();
- await expect(page.getByText('Live', { exact: true })).toBeVisible({ timeout: 15_000 });
-
- const terminal = page.locator('.terminal-container');
- const input = terminal.locator('textarea.xterm-helper-textarea');
- await expect(input).toBeAttached();
- await input.pressSequentially(
- `echo ${marker}-$E2E_VALUE && echo volume-ok > /data/e2e-marker && cat /data/e2e-marker`,
- { delay: 5 }
- );
- await input.press('Enter');
- await expect(terminal.locator('.xterm-rows')).toContainText(`${marker}-initial`, {
- timeout: 15_000
+ return test.step('Verify shell and volume', async () => {
+ await page.getByRole('tab', { name: 'Shell', exact: true }).click();
+ await expect(page.getByText('Live', { exact: true })).toBeVisible({ timeout: 15_000 });
+
+ const terminal = page.locator('.terminal-container');
+ const input = terminal.locator('textarea.xterm-helper-textarea');
+ await expect(input).toBeAttached();
+ await input.pressSequentially(
+ `echo ${marker}-$E2E_VALUE && echo volume-ok > /data/e2e-marker && cat /data/e2e-marker`,
+ { delay: 5 }
+ );
+ await input.press('Enter');
+ await expect(terminal.locator('.xterm-rows')).toContainText(`${marker}-initial`, {
+ timeout: 15_000
+ });
+ await expect(terminal.locator('.xterm-rows')).toContainText('volume-ok');
});
- await expect(terminal.locator('.xterm-rows')).toContainText('volume-ok');
}
async function connectAndDisconnectNetwork(page: Page, containerId: string, networkName: string) {
- await page.getByRole('tab', { name: 'Networks', exact: true }).click();
- const connectSection = page.locator('div').filter({
- has: page.getByRole('heading', { name: 'Connect to network', exact: true })
+ return test.step('Connect and disconnect network', async () => {
+ await page.getByRole('tab', { name: 'Networks', exact: true }).click();
+ const connectSection = page.locator('div').filter({
+ has: page.getByRole('heading', { name: 'Connect to network', exact: true })
+ });
+ await selectSearchableOption(page, connectSection, networkName);
+ await connectSection.getByPlaceholder('Aliases').fill('attached-live');
+
+ const connectResponsePromise = page.waitForResponse(
+ (response) =>
+ response.request().method() === 'POST' &&
+ /\/api\/environments\/0\/networks\/[^/]+\/connect$/.test(new URL(response.url()).pathname)
+ );
+ await connectSection.getByRole('button', { name: 'Connect', exact: true }).click();
+ expect((await connectResponsePromise).ok()).toBe(true);
+ await expect
+ .poll(async () =>
+ Object.keys((await getContainer(page, containerId)).networkSettings.networks)
+ )
+ .toContain(networkName);
+
+ const networkCard = page
+ .locator('[data-slot="card"]')
+ .filter({ has: page.getByText(networkName, { exact: true }) })
+ .filter({ has: page.getByRole('button', { name: 'Disconnect', exact: true }) })
+ .last();
+ await networkCard.getByRole('button', { name: 'Disconnect', exact: true }).click();
+ const disconnectResponsePromise = page.waitForResponse(
+ (response) =>
+ response.request().method() === 'POST' &&
+ /\/api\/environments\/0\/networks\/[^/]+\/disconnect$/.test(
+ new URL(response.url()).pathname
+ )
+ );
+ await page.getByRole('dialog').getByRole('button', { name: 'Disconnect', exact: true }).click();
+ expect((await disconnectResponsePromise).ok()).toBe(true);
+ await expect(page.getByRole('dialog')).toBeHidden();
+ await expect(page.locator('[data-dialog-overlay]')).toHaveCount(0);
+ await expect
+ .poll(async () =>
+ Object.keys((await getContainer(page, containerId)).networkSettings.networks)
+ )
+ .not.toContain(networkName);
});
- await selectSearchableOption(page, connectSection, networkName);
- await connectSection.getByPlaceholder('Aliases').fill('attached-live');
-
- const connectResponsePromise = page.waitForResponse(
- (response) =>
- response.request().method() === 'POST' &&
- /\/api\/environments\/0\/networks\/[^/]+\/connect$/.test(new URL(response.url()).pathname)
- );
- await connectSection.getByRole('button', { name: 'Connect', exact: true }).click();
- expect((await connectResponsePromise).ok()).toBe(true);
- await expect
- .poll(async () => Object.keys((await getContainer(page, containerId)).networkSettings.networks))
- .toContain(networkName);
-
- const networkCard = page
- .locator('[data-slot="card"]')
- .filter({ has: page.getByText(networkName, { exact: true }) })
- .filter({ has: page.getByRole('button', { name: 'Disconnect', exact: true }) })
- .last();
- await networkCard.getByRole('button', { name: 'Disconnect', exact: true }).click();
- const disconnectResponsePromise = page.waitForResponse(
- (response) =>
- response.request().method() === 'POST' &&
- /\/api\/environments\/0\/networks\/[^/]+\/disconnect$/.test(new URL(response.url()).pathname)
- );
- await page.getByRole('dialog').getByRole('button', { name: 'Disconnect', exact: true }).click();
- expect((await disconnectResponsePromise).ok()).toBe(true);
- await expect
- .poll(async () => Object.keys((await getContainer(page, containerId)).networkSettings.networks))
- .not.toContain(networkName);
}
async function commitContainer(
page: Page,
containerId: string,
containerName: string,
- repository: string
+ repository: string,
+ imageIds: Set<string>
) {
- const floatingHeader = page
- .locator('div.fixed')
- .filter({ has: page.getByText(containerName, { exact: true }) });
- const commitButton = (await floatingHeader.isVisible())
- ? floatingHeader.getByRole('button', { name: 'Commit', exact: true })
- : page.getByRole('button', { name: 'Commit', exact: true }).filter({ visible: true }).first();
- await commitButton.click();
- const dialog = page.getByRole('dialog', { name: `Commit "${containerName}"` });
- await dialog.locator('#repository').fill(repository);
- await dialog.locator('#tag').fill('e2e');
- await dialog.getByLabel('Description', { exact: true }).fill('Playwright lifecycle snapshot');
- await dialog.getByLabel('Author', { exact: true }).fill('Arcane Playwright');
-
- const requestPromise = page.waitForRequest(
- (request) =>
- request.method() === 'POST' &&
- new URL(request.url()).pathname === `/api/environments/0/containers/${containerId}/commit`
- );
- const responsePromise = page.waitForResponse(
- (response) =>
- response.request().method() === 'POST' &&
- new URL(response.url()).pathname === `/api/environments/0/containers/${containerId}/commit`
- );
- await dialog.getByRole('button', { name: 'Commit', exact: true }).click();
- const request = await requestPromise;
- expect(request.postDataJSON()).toMatchObject({
- repository,
- tag: 'e2e',
- comment: 'Playwright lifecycle snapshot',
- author: 'Arcane Playwright'
+ return test.step('Commit image', async () => {
+ await page
+ .locator('[data-tabs-root] > :not([inert])')
+ .getByRole('button', { name: 'Commit', exact: true })
+ .filter({ visible: true })
+ .first()
+ .click();
+ const dialog = page.getByRole('dialog', { name: `Commit "${containerName}"` });
+ await waitForDialogReady(dialog);
+ await expect(dialog.locator('#repository')).toBeFocused();
+ await dialog.locator('#repository').fill(repository);
+ await dialog.locator('#tag').fill('e2e');
+ await dialog.getByLabel('Description', { exact: true }).fill('Playwright lifecycle snapshot');
+ await dialog.getByLabel('Author', { exact: true }).fill('Arcane Playwright');
+ await expect(dialog.locator('#repository')).toHaveValue(repository);
+ await expect(dialog.locator('#tag')).toHaveValue('e2e');
+ await expect(dialog.getByLabel('Description', { exact: true })).toHaveValue(
+ 'Playwright lifecycle snapshot'
+ );
+ await expect(dialog.getByLabel('Author', { exact: true })).toHaveValue('Arcane Playwright');
+
+ const requestPromise = page.waitForRequest(
+ (request) =>
+ request.method() === 'POST' &&
+ new URL(request.url()).pathname === `/api/environments/0/containers/${containerId}/commit`
+ );
+ const responsePromise = page.waitForResponse(
+ (response) =>
+ response.request().method() === 'POST' &&
+ new URL(response.url()).pathname === `/api/environments/0/containers/${containerId}/commit`
+ );
+ await dialog.getByRole('button', { name: 'Commit', exact: true }).click();
+ const request = await requestPromise;
+ const result = await readApiData<CommitResult>(
+ await responsePromise,
+ `Commit container ${containerId}`
+ );
+ imageIds.add(result.id);
+ expect(request.postDataJSON()).toMatchObject({
+ repository,
+ tag: 'e2e',
+ comment: 'Playwright lifecycle snapshot',
+ author: 'Arcane Playwright'
+ });
+ expect(result.id).toMatch(/^sha256:/);
+ await expect(dialog).toBeHidden();
+ return result;
});
- const result = await readApiData<CommitResult>(
- await responsePromise,
- `Commit container ${containerId}`
- );
- expect(result.id).toMatch(/^sha256:/);
- await expect(dialog).toBeHidden();
- return result;
}
-async function editContainerThroughUI(page: Page, containerId: string, newContainerName: string) {
- const floatingEditLink = page
- .locator('div.fixed')
- .getByRole('link', { name: 'Edit', exact: true });
- const editLink = (await floatingEditLink.isVisible())
- ? floatingEditLink
- : page.getByRole('link', { name: 'Edit', exact: true }).filter({ visible: true }).first();
- await editLink.click();
- await expect(page).toHaveURL(`/containers/${containerId}/edit`);
- await expect(page.getByText('Applying changes recreates this container.')).toBeVisible();
-
- await page.getByLabel('Container Name *', { exact: true }).fill(newContainerName);
- await page.getByLabel('Command', { exact: true }).fill('sleep 7200');
- await page.getByRole('tab', { name: 'Environment', exact: true }).click();
- const environmentGroup = formGroup(page, 'Environment Variables');
- const environmentKeys = environmentGroup.getByPlaceholder('KEY');
- const customEnvironmentIndex = await environmentKeys.evaluateAll((inputs) =>
- inputs.findIndex((input) => (input as HTMLInputElement).value === 'E2E_VALUE')
- );
- expect(customEnvironmentIndex).toBeGreaterThanOrEqual(0);
- const customEnvironmentRow = environmentKeys.nth(customEnvironmentIndex).locator('..');
- await customEnvironmentRow.getByPlaceholder('value').fill('edited');
-
- const responsePromise = page.waitForResponse(
- (response) =>
- response.request().method() === 'POST' &&
- new URL(response.url()).pathname === `/api/environments/0/containers/${containerId}/edit`,
- { timeout: 60_000 }
- );
- await page.getByRole('button', { name: 'Save', exact: true }).click();
- const dialog = page.getByRole('dialog', { name: 'Recreate container?' });
- await dialog.getByRole('button', { name: 'Save', exact: true }).click();
- const edited = await readApiData<ContainerDetails>(
- await responsePromise,
- `Edit container ${containerId}`
- );
- await expect(page).toHaveURL((url) => url.pathname === `/containers/${edited.id}`);
- expect(edited.id).not.toBe(containerId);
- expect(edited.activityId).toBeTruthy();
- await expectActivitySucceeded(page, edited.activityId!, 'container_edit');
- return edited;
+async function editContainerThroughUI(
+ page: Page,
+ containerId: string,
+ newContainerName: string,
+ containerIds: Set<string>
+) {
+ return test.step('Edit and recreate container', async () => {
+ await page
+ .locator('[data-tabs-root] > :not([inert])')
+ .getByRole('link', { name: 'Edit', exact: true })
+ .filter({ visible: true })
+ .first()
+ .click();
+ await expect(page).toHaveURL(`/containers/${containerId}/edit`);
+ await expect(page.getByText('Applying changes recreates this container.')).toBeVisible();
+ await expect(page.getByLabel('Container Name *', { exact: true })).toHaveValue(
+ newContainerName.replace(/-edited$/, '')
+ );
+ await expect(page.getByLabel('Command', { exact: true })).toHaveValue('sleep 3600');
+
+ await page.getByLabel('Container Name *', { exact: true }).fill(newContainerName);
+ await page.getByLabel('Command', { exact: true }).fill('sleep 7200');
+ await page.getByRole('tab', { name: 'Environment', exact: true }).click();
+ const environmentGroup = formGroup(page, 'Environment Variables');
+ const environmentKeys = environmentGroup.getByPlaceholder('KEY');
+ const customEnvironmentIndex = await environmentKeys.evaluateAll((inputs) =>
+ inputs.findIndex((input) => (input as HTMLInputElement).value === 'E2E_VALUE')
+ );
+ expect(customEnvironmentIndex).toBeGreaterThanOrEqual(0);
+ const customEnvironmentRow = environmentKeys.nth(customEnvironmentIndex).locator('..');
+ await customEnvironmentRow.getByPlaceholder('value').fill('edited');
+
+ const responsePromise = page.waitForResponse(
+ (response) =>
+ response.request().method() === 'POST' &&
+ new URL(response.url()).pathname === `/api/environments/0/containers/${containerId}/edit`,
+ { timeout: 60_000 }
+ );
+ await page.getByRole('button', { name: 'Save', exact: true }).click();
+ const dialog = page.getByRole('dialog', { name: 'Recreate container?' });
+ await dialog.getByRole('button', { name: 'Save', exact: true }).click();
+ const edited = await readApiData<ContainerDetails>(
+ await responsePromise,
+ `Edit container ${containerId}`
+ );
+ containerIds.add(edited.id);
+ await expect(page).toHaveURL((url) => url.pathname === `/containers/${edited.id}`);
+ expect(edited.id).not.toBe(containerId);
+ expect(edited.activityId).toBeTruthy();
+ await expectActivitySucceeded(page, edited.activityId!, 'container_edit');
+ return edited;
+ });
}
-async function redeployContainerThroughUI(page: Page, containerId: string) {
- await page
- .getByRole('button', { name: 'Redeploy', exact: true })
- .filter({ visible: true })
- .first()
- .click();
- const dialog = page.getByRole('dialog');
- const responsePromise = page.waitForResponse(
- (response) =>
- response.request().method() === 'POST' &&
- new URL(response.url()).pathname === `/api/environments/0/containers/${containerId}/redeploy`,
- { timeout: 60_000 }
- );
- await dialog.getByRole('button', { name: 'Redeploy', exact: true }).click();
- const redeployed = await readApiData<ContainerDetails>(
- await responsePromise,
- `Redeploy container ${containerId}`
- );
- await expect(page).toHaveURL((url) => url.pathname === `/containers/${redeployed.id}`);
- expect(redeployed.id).not.toBe(containerId);
- expect(redeployed.activityId).toBeTruthy();
- await expectActivitySucceeded(page, redeployed.activityId!, 'container_redeploy');
- return redeployed;
+async function redeployContainerThroughUI(
+ page: Page,
+ containerId: string,
+ containerIds: Set<string>
+) {
+ return test.step('Redeploy container', async () => {
+ await page
+ .locator('[data-tabs-root] > :not([inert])')
+ .getByRole('button', { name: 'Redeploy', exact: true })
+ .filter({ visible: true })
+ .first()
+ .click();
+ const dialog = page.getByRole('dialog');
+ const responsePromise = page.waitForResponse(
+ (response) =>
+ response.request().method() === 'POST' &&
+ new URL(response.url()).pathname ===
+ `/api/environments/0/containers/${containerId}/redeploy`,
+ { timeout: 60_000 }
+ );
+ await dialog.getByRole('button', { name: 'Redeploy', exact: true }).click();
+ const redeployed = await readApiData<ContainerDetails>(
+ await responsePromise,
+ `Redeploy container ${containerId}`
+ );
+ containerIds.add(redeployed.id);
+ await expect(page).toHaveURL((url) => url.pathname === `/containers/${redeployed.id}`);
+ expect(redeployed.id).not.toBe(containerId);
+ expect(redeployed.activityId).toBeTruthy();
+ await expectActivitySucceeded(page, redeployed.activityId!, 'container_redeploy');
+ return redeployed;
+ });
}
-async function convertContainerToProject(page: Page, containerId: string, containerName: string) {
- const generateResponsePromise = page.waitForResponse(
- (response) =>
- response.request().method() === 'POST' &&
- new URL(response.url()).pathname === '/api/environments/0/containers/generate-compose'
- );
- const floatingConvertLink = page
- .locator('div.fixed')
- .getByRole('link', { name: 'Convert to Compose', exact: true });
- const convertLink = (await floatingConvertLink.isVisible())
- ? floatingConvertLink
- : page
- .getByRole('link', { name: 'Convert to Compose', exact: true })
- .filter({ visible: true })
- .first();
- await convertLink.click();
- const generated = await readApiData<{ composeContent: string }>(
- await generateResponsePromise,
- `Generate Compose for ${containerId}`
- );
- expect(generated.composeContent).toContain(containerName);
- await expect(page).toHaveURL(`/projects/new?fromContainers=${containerId}&fromEnv=0`);
- await expect(page.locator('.cm-editor').first()).toContainText(containerName);
-
- const createButton = page.locator('button[data-action="create"]');
- await expect(createButton).toBeEnabled({ timeout: 15_000 });
- const responsePromise = page.waitForResponse(
- (response) =>
- response.request().method() === 'POST' &&
- new URL(response.url()).pathname === '/api/environments/0/projects'
- );
- await createButton.click();
- const dialog = page.getByRole('dialog');
- await expect(dialog.getByLabel('Remove original container(s) after creation')).not.toBeChecked();
- await dialog.getByRole('button', { name: 'Create Project', exact: true }).click();
- const project = await readApiData<CreatedProject>(
- await responsePromise,
- `Create converted project for ${containerId}`
- );
- await expect(page).toHaveURL((url) => url.pathname === `/projects/${project.id}`);
- return project;
+async function convertContainerToProject(
+ page: Page,
+ containerId: string,
+ containerName: string,
+ projectIds: Set<string>
+) {
+ return test.step('Convert to Compose', async () => {
+ const generateResponsePromise = page.waitForResponse(
+ (response) =>
+ response.request().method() === 'POST' &&
+ new URL(response.url()).pathname === '/api/environments/0/containers/generate-compose'
+ );
+ await page
+ .locator('[data-tabs-root] > :not([inert])')
+ .getByRole('link', { name: 'Convert to Compose', exact: true })
+ .filter({ visible: true })
+ .first()
+ .click();
+ const generated = await readApiData<{ composeContent: string }>(
+ await generateResponsePromise,
+ `Generate Compose for ${containerId}`
+ );
+ expect(generated.composeContent).toContain(containerName);
+ await expect(page).toHaveURL(`/projects/new?fromContainers=${containerId}&fromEnv=0`);
+ await expect(page.locator('.cm-editor').first()).toContainText(containerName);
+
+ const createButton = page.locator('button[data-action="create"]');
+ await expect(createButton).toBeEnabled({ timeout: 15_000 });
+ const responsePromise = page.waitForResponse(
+ (response) =>
+ response.request().method() === 'POST' &&
+ new URL(response.url()).pathname === '/api/environments/0/projects'
+ );
+ await createButton.click();
+ const dialog = page.getByRole('dialog');
+ await expect(
+ dialog.getByLabel('Remove original container(s) after creation')
+ ).not.toBeChecked();
+ await dialog.getByRole('button', { name: 'Create Project', exact: true }).click();
+ const project = await readApiData<CreatedProject>(
+ await responsePromise,
+ `Create converted project for ${containerId}`
+ );
+ projectIds.add(project.id);
+ await expect(page).toHaveURL((url) => url.pathname === `/projects/${project.id}`);
+ return project;
+ });
}
async function killContainerThroughUI(page: Page, containerId: string, containerName: string) {
- await page
- .getByRole('button', { name: 'Kill', exact: true })
- .filter({ visible: true })
- .first()
- .click();
- const dialog = page.getByRole('dialog', { name: `Kill "${containerName}"` });
- const responsePromise = page.waitForResponse(
- (response) =>
- response.request().method() === 'POST' &&
- new URL(response.url()).pathname === `/api/environments/0/containers/${containerId}/kill`
- );
- await dialog.getByRole('button', { name: 'Kill container', exact: true }).click();
- const result = await readApiData<ActionResult>(
- await responsePromise,
- `Kill container ${containerId}`
- );
- expect(result.activityId).toBeTruthy();
- await expectActivitySucceeded(page, result.activityId!, 'container_kill');
+ return test.step('Kill container', async () => {
+ await page
+ .locator('[data-tabs-root] > :not([inert])')
+ .getByRole('button', { name: 'Kill', exact: true })
+ .filter({ visible: true })
+ .first()
+ .click();
+ const dialog = page.getByRole('dialog', { name: `Kill "${containerName}"` });
+ const responsePromise = page.waitForResponse(
+ (response) =>
+ response.request().method() === 'POST' &&
+ new URL(response.url()).pathname === `/api/environments/0/containers/${containerId}/kill`
+ );
+ await dialog.getByRole('button', { name: 'Kill container', exact: true }).click();
+ const result = await readApiData<ActionResult>(
+ await responsePromise,
+ `Kill container ${containerId}`
+ );
+ expect(result.activityId).toBeTruthy();
+ await expectActivitySucceeded(page, result.activityId!, 'container_kill');
+ });
}
async function removeContainerThroughUI(page: Page, containerId: string) {
- await page
- .getByRole('button', { name: 'Remove', exact: true })
- .filter({ visible: true })
- .first()
- .click();
- const responsePromise = page.waitForResponse(
- (response) =>
- response.request().method() === 'DELETE' &&
- new URL(response.url()).pathname === `/api/environments/0/containers/${containerId}`
- );
- await page.getByRole('dialog').getByRole('button', { name: 'Remove', exact: true }).click();
- const result = await readApiData<ActionResult>(
- await responsePromise,
- `Remove container ${containerId}`
- );
- expect(result.activityId).toBeTruthy();
- await expectActivitySucceeded(page, result.activityId!, 'container_delete');
- await expect(page).toHaveURL('/containers');
+ return test.step('Remove container', async () => {
+ await page
+ .locator('[data-tabs-root] > :not([inert])')
+ .getByRole('button', { name: 'Remove', exact: true })
+ .filter({ visible: true })
+ .first()
+ .click();
+ const responsePromise = page.waitForResponse(
+ (response) =>
+ response.request().method() === 'DELETE' &&
+ new URL(response.url()).pathname === `/api/environments/0/containers/${containerId}`
+ );
+ await page.getByRole('dialog').getByRole('button', { name: 'Remove', exact: true }).click();
+ const result = await readApiData<ActionResult>(
+ await responsePromise,
+ `Remove container ${containerId}`
+ );
+ expect(result.activityId).toBeTruthy();
+ await expectActivitySucceeded(page, result.activityId!, 'container_delete');
+ await expect(page).toHaveURL('/containers');
+ });
}
-test('creates, mutates, converts, and removes a standalone container', async ({ page }) => {
+test('creates, mutates, converts, and removes a standalone container', async ({
+ page,
+ registerCleanup
+}) => {
test.setTimeout(300_000);
page.setDefaultTimeout(15_000);
page.setDefaultNavigationTimeout(20_000);
@@ -571,173 +643,178 @@ test('creates, mutates, converts, and removes a standalone container', async ({
const committedRepository = `arcane-e2e/${containerName}`;
let currentContainerId: string | null = null;
let committedImageId: string | null = null;
- let convertedProjectId: string | null = null;
+ const containerIds = new Set<string>();
+ const imageIds = new Set<string>();
+ const projectIds = new Set<string>();
+ let settingsChanged = false;
let originalExperimentalSetting = 'false';
- try {
- const settingsResponse = await page.request.get('/api/environments/0/settings');
- if (!settingsResponse.ok()) {
- throw new Error(`Get settings failed with ${settingsResponse.status()}`);
- }
- const settings = (await settingsResponse.json()) as Array<{ key: string; value: string }>;
- originalExperimentalSetting =
- settings.find((setting) => setting.key === 'experimentalFeaturesEnabled')?.value ?? 'false';
- await updateExperimentalFeatures(page, 'true');
-
- await readApiData(
- await page.request.post('/api/environments/0/volumes', {
- data: { name: volumeName, driver: 'local' }
- }),
- `Create volume ${volumeName}`
- );
- for (const networkName of [primaryNetworkName, secondaryNetworkName]) {
- await readApiData(
- await page.request.post('/api/environments/0/networks', {
- data: { name: networkName, options: { driver: 'bridge' } }
- }),
- `Create network ${networkName}`
+ registerCleanup(async () => {
+ for (const id of projectIds)
+ await removeApiResource(page, `/api/environments/0/projects/${id}/destroy`, {
+ data: { removeVolumes: false }
+ });
+ for (const id of containerIds)
+ await removeApiResource(
+ page,
+ `/api/environments/0/containers/${id}?force=true&volumes=false`
);
- }
-
- const created = await createContainerThroughUI(
+ for (const id of imageIds)
+ await removeApiResource(
+ page,
+ `/api/environments/0/images/${encodeURIComponent(id)}?force=true`
+ );
+ for (const name of [secondaryNetworkName, primaryNetworkName])
+ await removeApiResource(page, `/api/environments/0/networks/${encodeURIComponent(name)}`);
+ await removeApiResource(
page,
- containerName,
- volumeName,
- primaryNetworkName
- );
- currentContainerId = created.id;
-
- let details = await getContainer(page, currentContainerId);
- expect(details.name).toBe(containerName);
- expect(details.image).toBe(TEST_IMAGE);
- expect(details.state.status).toBe('running');
- expect(details.config.cmd).toEqual(['sleep', '3600']);
- expect(details.config.workingDir).toBe('/tmp');
- expect(details.config.env).toContain('E2E_VALUE=initial');
- expect(details.config.healthcheck?.test).toEqual([
- 'CMD-SHELL',
- 'test "$E2E_VALUE" = "initial"'
- ]);
- expect(details.config.healthcheck?.interval).toBe(2_000_000_000);
- expect(details.hostConfig.restartPolicy).toBe('on-failure');
- expect(details.labels?.['arcane.e2e']).toBe('container-lifecycle');
- expect(details.ports.some((port) => port.privatePort === 8080 && port.type === 'tcp')).toBe(
- true
+ `/api/environments/0/volumes/${encodeURIComponent(volumeName)}?force=true`
);
- expect(details.mounts).toEqual(
- expect.arrayContaining([
- expect.objectContaining({ type: 'volume', name: volumeName, destination: '/data' })
- ])
- );
- expect(details.networkSettings.networks[primaryNetworkName]?.aliases).toContain(
- 'lifecycle-alias'
- );
-
- await verifyShell(page, `shell-${suffix}`);
- await page.getByRole('tab', { name: 'Overview', exact: true }).click();
+ if (settingsChanged) await updateExperimentalFeatures(page, originalExperimentalSetting);
+ });
- await runSimpleContainerAction(page, currentContainerId, 'pause', 'Pause', 'container_pause');
- await expectContainerStatus(page, currentContainerId, 'paused');
- await runSimpleContainerAction(
- page,
- currentContainerId,
- 'unpause',
- 'Unpause',
- 'container_unpause'
- );
- await expectContainerStatus(page, currentContainerId, 'running');
- await runSimpleContainerAction(
- page,
- currentContainerId,
- 'restart',
- 'Restart',
- 'container_restart'
+ const settingsResponse = await page.request.get('/api/environments/0/settings');
+ if (!settingsResponse.ok()) {
+ throw new Error(`Get settings failed with ${settingsResponse.status()}`);
+ }
+ const settings = (await settingsResponse.json()) as Array<{ key: string; value: string }>;
+ const experimentalSetting = settings.find(
+ (setting) => setting.key === 'experimentalFeaturesEnabled'
+ );
+ expect(experimentalSetting, 'Experimental feature setting must be present').toBeDefined();
+ originalExperimentalSetting = experimentalSetting!.value;
+ settingsChanged = true;
+ await updateExperimentalFeatures(page, 'true');
+
+ await readApiData(
+ await page.request.post('/api/environments/0/volumes', {
+ data: { name: volumeName, driver: 'local' }
+ }),
+ `Create volume ${volumeName}`
+ );
+ for (const networkName of [primaryNetworkName, secondaryNetworkName]) {
+ await readApiData(
+ await page.request.post('/api/environments/0/networks', {
+ data: { name: networkName, options: { driver: 'bridge' } }
+ }),
+ `Create network ${networkName}`
);
- await expectContainerStatus(page, currentContainerId, 'running');
- await runSimpleContainerAction(page, currentContainerId, 'stop', 'Stop', 'container_stop');
- await expectContainerStatus(page, currentContainerId, 'exited');
- await runSimpleContainerAction(page, currentContainerId, 'start', 'Start', 'container_start');
- await expectContainerStatus(page, currentContainerId, 'running');
+ }
- await connectAndDisconnectNetwork(page, currentContainerId, secondaryNetworkName);
+ const created = await createContainerThroughUI(
+ page,
+ containerName,
+ volumeName,
+ primaryNetworkName,
+ containerIds
+ );
+ currentContainerId = created.id;
+
+ let details = await getContainer(page, currentContainerId);
+ expect(details.name).toBe(containerName);
+ expect(details.image).toBe(TEST_IMAGE);
+ expect(details.state.status).toBe('running');
+ expect(details.config.cmd).toEqual(['sleep', '3600']);
+ expect(details.config.workingDir).toBe('/tmp');
+ expect(details.config.env).toContain('E2E_VALUE=initial');
+ expect(details.config.healthcheck?.test).toEqual(['CMD-SHELL', 'test "$E2E_VALUE" = "initial"']);
+ expect(details.config.healthcheck?.interval).toBe(2_000_000_000);
+ expect(details.hostConfig.restartPolicy).toBe('on-failure');
+ expect(details.labels?.['arcane.e2e']).toBe('container-lifecycle');
+ expect(details.ports.some((port) => port.privatePort === 8080 && port.type === 'tcp')).toBe(true);
+ expect(details.mounts).toEqual(
+ expect.arrayContaining([
+ expect.objectContaining({ type: 'volume', name: volumeName, destination: '/data' })
+ ])
+ );
+ expect(details.networkSettings.networks[primaryNetworkName]?.aliases).toContain(
+ 'lifecycle-alias'
+ );
- const commit = await commitContainer(
- page,
- currentContainerId,
- containerName,
- committedRepository
- );
- committedImageId = commit.id;
- const committedImageResponse = await page.request.get(
- `/api/environments/0/images/${encodeURIComponent(committedImageId)}`
- );
- expect(committedImageResponse.ok()).toBe(true);
-
- const oldContainerId = currentContainerId;
- const edited = await editContainerThroughUI(page, currentContainerId, editedContainerName);
- currentContainerId = edited.id;
- await expectContainerMissing(page, oldContainerId);
- details = await getContainer(page, currentContainerId);
- expect(details.name).toBe(editedContainerName);
- expect(details.config.cmd).toEqual(['sleep', '7200']);
- expect(details.config.env).toContain('E2E_VALUE=edited');
- expect(details.mounts.some((mount) => mount.name === volumeName)).toBe(true);
- expect(details.ports.some((port) => port.privatePort === 8080)).toBe(true);
- expect(details.networkSettings.networks).toHaveProperty(primaryNetworkName);
-
- const preRedeployId = currentContainerId;
- const redeployed = await redeployContainerThroughUI(page, currentContainerId);
- currentContainerId = redeployed.id;
- await expectContainerMissing(page, preRedeployId);
- await expectContainerStatus(page, currentContainerId, 'running');
-
- const convertedProject = await convertContainerToProject(
- page,
- currentContainerId,
- editedContainerName
- );
- convertedProjectId = convertedProject.id;
- expect(
- (await page.request.get(`/api/environments/0/containers/${currentContainerId}`)).ok()
- ).toBe(true);
-
- await page.goto(`/containers/${currentContainerId}`);
- await killContainerThroughUI(page, currentContainerId, editedContainerName);
- await expectContainerStatus(page, currentContainerId, 'exited');
- await runSimpleContainerAction(page, currentContainerId, 'start', 'Start', 'container_start');
- await expectContainerStatus(page, currentContainerId, 'running');
- await runSimpleContainerAction(page, currentContainerId, 'stop', 'Stop', 'container_stop');
- await expectContainerStatus(page, currentContainerId, 'exited');
-
- await removeContainerThroughUI(page, currentContainerId);
- await expectContainerMissing(page, currentContainerId);
- currentContainerId = null;
- } finally {
- if (convertedProjectId) {
- await page.request
- .delete(`/api/environments/0/projects/${convertedProjectId}/destroy`, {
- data: { removeVolumes: false }
- })
- .catch(() => undefined);
- }
- if (currentContainerId) {
- await page.request
- .delete(`/api/environments/0/containers/${currentContainerId}?force=true&volumes=false`)
- .catch(() => undefined);
- }
- if (committedImageId) {
- await page.request
- .delete(`/api/environments/0/images/${encodeURIComponent(committedImageId)}?force=true`)
- .catch(() => undefined);
- }
- for (const networkName of [secondaryNetworkName, primaryNetworkName]) {
- await page.request
- .delete(`/api/environments/0/networks/${encodeURIComponent(networkName)}`)
- .catch(() => undefined);
- }
- await page.request
- .delete(`/api/environments/0/volumes/${encodeURIComponent(volumeName)}?force=true`)
- .catch(() => undefined);
- await updateExperimentalFeatures(page, originalExperimentalSetting).catch(() => undefined);
- }
+ await verifyShell(page, `shell-${suffix}`);
+ await page.getByRole('tab', { name: 'Overview', exact: true }).click();
+
+ await runSimpleContainerAction(page, currentContainerId, 'pause', 'Pause', 'container_pause');
+ await expectContainerStatus(page, currentContainerId, 'paused');
+ await runSimpleContainerAction(
+ page,
+ currentContainerId,
+ 'unpause',
+ 'Unpause',
+ 'container_unpause'
+ );
+ await expectContainerStatus(page, currentContainerId, 'running');
+ await runSimpleContainerAction(
+ page,
+ currentContainerId,
+ 'restart',
+ 'Restart',
+ 'container_restart'
+ );
+ await expectContainerStatus(page, currentContainerId, 'running');
+ await runSimpleContainerAction(page, currentContainerId, 'stop', 'Stop', 'container_stop');
+ await expectContainerStatus(page, currentContainerId, 'exited');
+ await runSimpleContainerAction(page, currentContainerId, 'start', 'Start', 'container_start');
+ await expectContainerStatus(page, currentContainerId, 'running');
+
+ await connectAndDisconnectNetwork(page, currentContainerId, secondaryNetworkName);
+
+ const commit = await commitContainer(
+ page,
+ currentContainerId,
+ containerName,
+ committedRepository,
+ imageIds
+ );
+ committedImageId = commit.id;
+ const committedImageResponse = await page.request.get(
+ `/api/environments/0/images/${encodeURIComponent(committedImageId)}`
+ );
+ expect(committedImageResponse.ok()).toBe(true);
+
+ const oldContainerId = currentContainerId;
+ const edited = await editContainerThroughUI(
+ page,
+ currentContainerId,
+ editedContainerName,
+ containerIds
+ );
+ currentContainerId = edited.id;
+ await expectContainerMissing(page, oldContainerId);
+ details = await getContainer(page, currentContainerId);
+ expect(details.name).toBe(editedContainerName);
+ expect(details.config.cmd).toEqual(['sleep', '7200']);
+ expect(details.config.env).toContain('E2E_VALUE=edited');
+ expect(details.mounts.some((mount) => mount.name === volumeName)).toBe(true);
+ expect(details.ports.some((port) => port.privatePort === 8080)).toBe(true);
+ expect(details.networkSettings.networks).toHaveProperty(primaryNetworkName);
+
+ const preRedeployId = currentContainerId;
+ const redeployed = await redeployContainerThroughUI(page, currentContainerId, containerIds);
+ currentContainerId = redeployed.id;
+ await expectContainerMissing(page, preRedeployId);
+ await expectContainerStatus(page, currentContainerId, 'running');
+
+ const convertedProject = await convertContainerToProject(
+ page,
+ currentContainerId,
+ editedContainerName,
+ projectIds
+ );
+ expect(projectIds.has(convertedProject.id)).toBe(true);
+ expect(
+ (await page.request.get(`/api/environments/0/containers/${currentContainerId}`)).ok()
+ ).toBe(true);
+
+ await page.goto(`/containers/${currentContainerId}`);
+ await killContainerThroughUI(page, currentContainerId, editedContainerName);
+ await expectContainerStatus(page, currentContainerId, 'exited');
+ await runSimpleContainerAction(page, currentContainerId, 'start', 'Start', 'container_start');
+ await expectContainerStatus(page, currentContainerId, 'running');
+ await runSimpleContainerAction(page, currentContainerId, 'stop', 'Stop', 'container_stop');
+ await expectContainerStatus(page, currentContainerId, 'exited');
+
+ await removeContainerThroughUI(page, currentContainerId);
+ await expectContainerMissing(page, currentContainerId);
+ currentContainerId = null;
});
diff --git a/tests/spec/container-resource-sort.spec.ts b/tests/spec/container-resource-sort.spec.ts
index 487f9ccab..b13c633d1 100644
--- a/tests/spec/container-resource-sort.spec.ts
+++ b/tests/spec/container-resource-sort.spec.ts
@@ -262,6 +262,7 @@ test('resource sort polls, suspends in background tabs, and surfaces failures',
page
}) => {
test.setTimeout(60000);
+ await page.clock.install();
const scenario: Scenario = { supported: true, fixtures: basicFixtures, requests: [] };
await installContainersMock(page, scenario);
await openContainers(page);
@@ -283,7 +284,7 @@ test('resource sort polls, suspends in background tabs, and surfaces failures',
document.dispatchEvent(new Event('visibilitychange'));
});
const frozen = scenario.requests.length;
- await page.waitForTimeout(6500);
+ await page.clock.runFor(6500);
expect(scenario.requests.length).toBe(frozen);
await page.evaluate(() => {
diff --git a/tests/spec/containers.spec.ts b/tests/spec/containers.spec.ts
index 9c01b9f8c..e254f13e0 100644
--- a/tests/spec/containers.spec.ts
+++ b/tests/spec/containers.spec.ts
@@ -1,5 +1,6 @@
+import { stat } from 'node:fs/promises';
import { test, expect, type Page } from '../fixtures/test.fixture';
-import { fetchContainersWithRetry, type Paginated } from '../utils/fetch.util';
+import { readApiData, removeApiResource, type Paginated } from '../utils/fetch.util';
import { ContainerSummary } from 'types/containers.type';
import { openRowActionsMenu } from '../utils/table-actions.util';
@@ -124,10 +125,48 @@ async function navigateToContainers(page: Page) {
let containersData: Paginated<ContainerSummary> = { data: [], pagination: { totalItems: 0 } };
+const fixtureContainerIds = new Set<string>();
+
test.describe('Containers Page', () => {
test.beforeEach(async ({ page }) => {
+ containersData = { data: [] };
+ for (const state of ['running', 'exited']) {
+ const name = `e2e-list-${state}-${Date.now()}`;
+ const container = await readApiData<{ id: string }>(
+ await page.request.post('/api/environments/0/containers', {
+ data: {
+ name,
+ image: 'public.ecr.aws/docker/library/busybox:1.37',
+ cmd: state === 'running' ? ['sleep', '3600'] : ['true']
+ }
+ }),
+ `Create ${state} container fixture`
+ );
+ fixtureContainerIds.add(container.id);
+ await expect
+ .poll(
+ async () =>
+ (
+ await readApiData<{ state: { status: string } }>(
+ await page.request.get(`/api/environments/0/containers/${container.id}`),
+ 'Read fixture state'
+ )
+ ).state.status
+ )
+ .toBe(state);
+ containersData.data.push({ id: container.id, names: [name], state });
+ }
await navigateToContainers(page);
- containersData = await fetchContainersWithRetry(page);
+ });
+
+ test.afterEach(async ({ page }) => {
+ for (const id of fixtureContainerIds) {
+ await removeApiResource(
+ page,
+ `/api/environments/0/containers/${id}?force=true&volumes=false`
+ );
+ }
+ fixtureContainerIds.clear();
});
test('should display the containers page title and description', async ({ page }) => {
@@ -168,7 +207,7 @@ test.describe('Containers Page', () => {
});
test('should navigate to container details on Inspect', async ({ page }) => {
- test.skip(containersData.data.length === 0, 'No containers available');
+ expect(containersData.data.length, 'No containers available').toBeGreaterThan(0);
await navigateToContainers(page);
const firstRow = page
@@ -187,7 +226,7 @@ test.describe('Containers Page', () => {
page
}) => {
const running = containersData.data.find((c) => c.state === 'running');
- test.skip(!running, 'No running container available');
+ expect(running, 'No running container available').toBeDefined();
await page.goto(`/containers/${running!.id}`);
await page.waitForLoadState('load');
@@ -204,7 +243,7 @@ test.describe('Containers Page', () => {
page
}) => {
const running = containersData.data.find((container) => container.state === 'running');
- test.skip(!running, 'No running container available');
+ expect(running, 'No running container available').toBeDefined();
await mockContainerLogsWebSocket(page);
await page.goto(`/containers/${running!.id}`);
@@ -229,7 +268,7 @@ test.describe('Containers Page', () => {
page
}) => {
const stopped = containersData.data.find((c) => c.state !== 'running');
- test.skip(!stopped, 'No stopped container available');
+ expect(stopped, 'No stopped container available').toBeDefined();
await page.goto(`/containers/${stopped!.id}`);
await page.waitForLoadState('load');
@@ -242,9 +281,9 @@ test.describe('Containers Page', () => {
await expect(page.getByTestId('container-log-memory-monitor')).toContainText('N/A');
});
- test('downloads the full log history from the logs tab', async ({ page }) => {
+ test('downloads the full log history from the logs tab', async ({ page }, testInfo) => {
const running = containersData.data.find((c) => c.state === 'running');
- test.skip(!running, 'No running container available');
+ expect(running, 'No running container available').toBeDefined();
await page.goto(`/containers/${running!.id}`);
await page.waitForLoadState('load');
@@ -258,7 +297,9 @@ test.describe('Containers Page', () => {
.click();
const download = await downloadPromise;
expect(download.suggestedFilename()).toBe(`container-${running!.id.slice(0, 12)}-logs.log`);
- expect(await download.path()).toBeTruthy();
+ const downloadPath = testInfo.outputPath(download.suggestedFilename());
+ await download.saveAs(downloadPath);
+ expect((await stat(downloadPath)).isFile()).toBe(true);
});
test('should show correct actions based on container state (without changing state)', async ({
@@ -269,40 +310,28 @@ test.describe('Containers Page', () => {
await navigateToContainers(page);
- if (running) {
- const runningName = running.names?.[0]?.replace(/^\/+/, '') ?? running.id;
- const row = page
- .getByRole('row')
- .filter({ has: page.getByRole('link', { name: runningName, exact: true }) });
- const menu = await openRowActionsMenu(page, row);
- await expect(menu.getByRole('menuitem', { name: 'Restart', exact: true })).toBeVisible();
- await expect(menu.getByRole('menuitem', { name: 'Stop', exact: true })).toBeVisible();
- await page.keyboard.press('Escape');
- } else {
- test.info().annotations.push({
- type: 'note',
- description: 'No running container to validate actions'
- });
- }
-
- if (stopped) {
- const stoppedName = stopped.names?.[0]?.replace(/^\/+/, '') ?? stopped.id;
- const row = page
- .getByRole('row')
- .filter({ has: page.getByRole('link', { name: stoppedName, exact: true }) });
- const menu = await openRowActionsMenu(page, row);
- await expect(menu.getByRole('menuitem', { name: 'Start', exact: true })).toBeVisible();
- await page.keyboard.press('Escape');
- } else {
- test.info().annotations.push({
- type: 'note',
- description: 'No stopped container to validate actions'
- });
- }
+ expect(running, 'Running container fixture must exist').toBeDefined();
+ expect(stopped, 'Stopped container fixture must exist').toBeDefined();
+ const runningName = running!.names?.[0]?.replace(/^\/+/, '') ?? running!.id;
+ const runningRow = page
+ .getByRole('row')
+ .filter({ has: page.getByRole('link', { name: runningName, exact: true }) });
+ const runningMenu = await openRowActionsMenu(page, runningRow);
+ await expect(runningMenu.getByRole('menuitem', { name: 'Restart', exact: true })).toBeVisible();
+ await expect(runningMenu.getByRole('menuitem', { name: 'Stop', exact: true })).toBeVisible();
+ await page.keyboard.press('Escape');
+
+ const stoppedName = stopped!.names?.[0]?.replace(/^\/+/, '') ?? stopped!.id;
+ const stoppedRow = page
+ .getByRole('row')
+ .filter({ has: page.getByRole('link', { name: stoppedName, exact: true }) });
+ const stoppedMenu = await openRowActionsMenu(page, stoppedRow);
+ await expect(stoppedMenu.getByRole('menuitem', { name: 'Start', exact: true })).toBeVisible();
+ await page.keyboard.press('Escape');
});
test('should open the Remove dialog from row actions and allow cancel', async ({ page }) => {
- test.skip(containersData.data.length === 0, 'No containers available');
+ expect(containersData.data.length, 'No containers available').toBeGreaterThan(0);
const any = containersData.data[0];
await navigateToContainers(page);
diff --git a/tests/spec/converter.spec.ts b/tests/spec/converter.spec.ts
index ade4814fc..233ff7227 100644
--- a/tests/spec/converter.spec.ts
+++ b/tests/spec/converter.spec.ts
@@ -38,6 +38,7 @@ async function openConvertFromDockerRun(page: Page) {
await menu.getByRole('menuitem', { name: 'Convert from Docker Run', exact: true }).click();
await expect(page.getByRole('button', SELECTORS.convertButton())).toBeVisible();
+ await expect(page.getByPlaceholder(SELECTORS.textareaPlaceholder)).toBeEditable();
}
async function setupMockConvert(page: Page, payload: ConvertResponse) {
@@ -85,7 +86,6 @@ test.describe('Docker Run to Compose Converter', () => {
test('should convert docker run command with environment variables', async ({ page }) => {
await openConvertFromDockerRun(page);
- await page.waitForTimeout(300);
const dockerCommand =
'docker run -d --name postgres -e POSTGRES_DB=mydb -e POSTGRES_USER=user -e POSTGRES_PASSWORD=pass postgres:15';
@@ -114,7 +114,6 @@ test.describe('Docker Run to Compose Converter', () => {
test('should use example commands', async ({ page }) => {
await openConvertFromDockerRun(page);
- await page.waitForTimeout(300);
await page.getByRole('button', { name: SELECTORS.exampleButtonName }).first().click();
@@ -125,7 +124,6 @@ test.describe('Docker Run to Compose Converter', () => {
test('should disable convert button when no command is entered', async ({ page }) => {
await openConvertFromDockerRun(page);
- await page.waitForTimeout(300);
const convertBtn = page.getByRole('button', SELECTORS.convertButton());
@@ -140,7 +138,6 @@ test.describe('Docker Run to Compose Converter', () => {
test('should populate stack name only when empty', async ({ page }) => {
await openConvertFromDockerRun(page);
- await page.waitForTimeout(300);
await page
.getByPlaceholder(SELECTORS.textareaPlaceholder)
diff --git a/tests/spec/customization.spec.ts b/tests/spec/customization.spec.ts
index c1de0c428..0a003ccf9 100644
--- a/tests/spec/customization.spec.ts
+++ b/tests/spec/customization.spec.ts
@@ -1,5 +1,6 @@
+import { waitForDialogReady } from '../utils/playwright.util';
import { expect, test, type Locator, type Page } from '../fixtures/test.fixture';
-import { readApiData } from '../utils/fetch.util';
+import { removeApiResource, readApiData } from '../utils/fetch.util';
import { openRowActionsMenu } from '../utils/table-actions.util';
type GlobalVariable = {
@@ -55,7 +56,7 @@ function variableRow(page: Page, key: string) {
async function openVariableSheet(page: Page) {
await page.getByRole('button', { name: 'Add Variable', exact: true }).click();
const dialog = page.getByRole('dialog', { name: 'Create Variable' });
- await expect(dialog).toBeVisible();
+ await waitForDialogReady(dialog);
return dialog;
}
@@ -176,6 +177,7 @@ test('manages variables and deploys an edited template with real substitution',
const editMenu = await openRowActionsMenu(page, editableRow);
await editMenu.getByRole('menuitem', { name: 'Edit', exact: true }).click();
const editDialog = page.getByRole('dialog', { name: 'Edit Variable' });
+ await waitForDialogReady(editDialog);
await editDialog.locator('#variable-value').fill('first-edited');
const editResponsePromise = page.waitForResponse(
(response) =>
@@ -334,7 +336,7 @@ test('manages variables and deploys an edited template with real substitution',
);
expect(container.config.env).toContain(`${publicKey}=${publicValue}`);
- await page.request.delete(`/api/environments/0/projects/${project.id}/destroy`, {
+ await removeApiResource(page, `/api/environments/0/projects/${project.id}/destroy`, {
data: { removeVolumes: false }
});
projectId = null;
@@ -356,18 +358,20 @@ test('manages variables and deploys an edited template with real substitution',
templateId = null;
} finally {
if (projectId) {
- await page.request
- .delete(`/api/environments/0/projects/${projectId}/destroy`, {
- data: { removeVolumes: false }
- })
- .catch(() => undefined);
+ await removeApiResource(page, `/api/environments/0/projects/${projectId}/destroy`, {
+ data: { removeVolumes: false }
+ });
}
if (templateId) {
- await page.request.delete(`/api/templates/${templateId}`).catch(() => undefined);
+ await removeApiResource(page, `/api/templates/${templateId}`);
}
- const variables = await listVariables(page).catch(() => []);
- for (const variable of variables.filter((candidate) => candidate.key.endsWith(suffix))) {
- await page.request.delete(`/api/variables/${variable.id}`).catch(() => undefined);
+ try {
+ const variables = await listVariables(page);
+ for (const variable of variables.filter((candidate) => candidate.key.endsWith(suffix))) {
+ await removeApiResource(page, `/api/variables/${variable.id}`);
+ }
+ } catch (error) {
+ expect.soft(false, `Clean up variables: ${String(error)}`).toBe(true);
}
}
});
diff --git a/tests/spec/dashboard-system-stats.spec.ts b/tests/spec/dashboard-system-stats.spec.ts
index 0c59a74ee..e22b28934 100644
--- a/tests/spec/dashboard-system-stats.spec.ts
+++ b/tests/spec/dashboard-system-stats.spec.ts
@@ -230,22 +230,23 @@ test.describe('Dashboard system stats websocket', () => {
test('keeps skeletons until the deadline when the stream opens without a sample', async ({
page
}) => {
+ await page.clock.install();
await mockDashboardStatsWebSocket(page, { deliverAfterMs: 12_000 });
await page.goto(defaultDashboardPath);
await page.waitForLoadState('load');
await expect(page.getByRole('button', { name: 'Card view', exact: true })).toBeVisible();
- await page.waitForTimeout(5_000);
+ await page.clock.runFor(5_000);
await expect(page.getByText('Live stats unavailable', { exact: true })).toHaveCount(0);
await expect(page.getByText('12.3%', { exact: true })).toHaveCount(0);
- await expect(page.getByText('Live stats unavailable', { exact: true })).toBeVisible({
- timeout: 10_000
- });
+ await page.clock.runFor(5_000);
+ await expect(page.getByText('Live stats unavailable', { exact: true })).toBeVisible();
await expect(page.getByText('12.3%', { exact: true })).toHaveCount(0);
- await expect(page.getByText('12.3%', { exact: true })).toBeVisible({ timeout: 10_000 });
+ await page.clock.runFor(2_000);
+ await expect(page.getByText('12.3%', { exact: true })).toBeVisible();
await expect(page.getByText('Live stats unavailable', { exact: true })).toHaveCount(0);
});
diff --git a/tests/spec/docker-runtime-identity.spec.ts b/tests/spec/docker-runtime-identity.spec.ts
index 9fb7c580c..2c9b5677f 100644
--- a/tests/spec/docker-runtime-identity.spec.ts
+++ b/tests/spec/docker-runtime-identity.spec.ts
@@ -176,39 +176,56 @@ function dockerFileStat(volumePath: string, filePath: string) {
function cleanupContainer(name: string) {
try {
- docker(['rm', '-f', name], { stdio: 'inherit' });
- } catch {
- // ignore cleanup failures
+ docker(['rm', '-f', name]);
+ } catch (error) {
+ if (!String(error).includes('No such container'))
+ expect.soft(false, `Remove container ${name}: ${String(error)}`).toBe(true);
}
}
function cleanupDir(dir: string) {
- try {
- // Files may be owned by root inside the container, so use Docker to remove them.
- docker(['run', '--rm', '-v', `${dir}:/mnt`, HELPER_IMAGE, 'rm', '-rf', '/mnt']);
- } catch {
- // ignore
- }
try {
fs.rmSync(dir, { recursive: true, force: true });
} catch {
- // ignore cleanup failures
+ try {
+ // The runtime may leave files owned by its container user.
+ const runnerUid = process.getuid?.();
+ const runnerGid = process.getgid?.();
+ if (runnerUid === undefined || runnerGid === undefined) {
+ throw new Error('Cannot restore test directory ownership without runner UID/GID');
+ }
+ docker([
+ 'run',
+ '--rm',
+ '-v',
+ `${dir}:/mnt`,
+ HELPER_IMAGE,
+ 'sh',
+ '-c',
+ `chown ${runnerUid}:${runnerGid} /mnt && chmod 0700 /mnt && find /mnt -mindepth 1 -delete`
+ ]);
+ fs.rmSync(dir, { recursive: true, force: true });
+ } catch (error) {
+ expect.soft(false, `Remove directory ${dir}: ${String(error)}`).toBe(true);
+ }
}
}
function cleanupNetwork(name: string) {
try {
- docker(['network', 'rm', name], { stdio: 'inherit' });
- } catch {
- // ignore cleanup failures
+ docker(['network', 'rm', name]);
+ } catch (error) {
+ if (!String(error).includes('not found'))
+ expect.soft(false, `Remove network ${name}: ${String(error)}`).toBe(true);
}
}
function cleanupVolume(name: string) {
try {
- docker(['volume', 'rm', '-f', name], { stdio: 'inherit' });
- } catch {
- // ignore cleanup failures
+ docker(['volume', 'rm', '-f', name]);
+ } catch (error) {
+ if (!String(error).includes('no such volume'))
+ expect.soft(false, `Remove volume ${name}: ${String(error)}`).toBe(true);
}
}
diff --git a/tests/spec/edge-agent.spec.ts b/tests/spec/edge-agent.spec.ts
index 06c82d04a..f039808a6 100644
--- a/tests/spec/edge-agent.spec.ts
+++ b/tests/spec/edge-agent.spec.ts
@@ -1,3 +1,4 @@
+import { removeApiResource } from '../utils/fetch.util';
import { test, expect, type Page } from '../fixtures/test.fixture';
const ROUTES = {
@@ -155,7 +156,7 @@ test.describe('Edge Agent Environment', () => {
expect(agentSettingsRequests).toEqual([]);
} finally {
if (createdEnvironmentId) {
- await page.request.delete(`/api/environments/${createdEnvironmentId}`);
+ await removeApiResource(page, `/api/environments/${createdEnvironmentId}`);
}
}
});
diff --git a/tests/spec/environment-settings.spec.ts b/tests/spec/environment-settings.spec.ts
index 8f62a3713..feb23adef 100644
--- a/tests/spec/environment-settings.spec.ts
+++ b/tests/spec/environment-settings.spec.ts
@@ -1,3 +1,5 @@
+import { waitForDialogReady } from '../utils/playwright.util';
+import { removeApiResource } from '../utils/fetch.util';
import { test, expect, type Locator, type Page, type Request } from '../fixtures/test.fixture';
const LOCAL_ENV_ID = '0';
@@ -23,7 +25,11 @@ async function renameEnvironmentInHeader(page: Page, newName: string) {
await expect(environmentTitleButton(page)).toHaveText(newName);
}
-async function createDirectEnvironmentViaUI(page: Page, environmentName: string) {
+async function createDirectEnvironmentViaUI(
+ page: Page,
+ environmentName: string,
+ environmentIds: Set<string>
+) {
await page.goto('/environments');
await page.waitForLoadState('load');
@@ -31,6 +37,7 @@ async function createDirectEnvironmentViaUI(page: Page, environmentName: string)
await expect(page.getByText('Create New Agent Environment')).toBeVisible();
const dialog = page.getByRole('dialog');
+ await waitForDialogReady(dialog);
await dialog.getByLabel('Name', { exact: true }).fill(environmentName);
await dialog.getByLabel('Agent Address', { exact: true }).fill('localhost:3552');
const createResponsePromise = page.waitForResponse(
@@ -42,6 +49,7 @@ async function createDirectEnvironmentViaUI(page: Page, environmentName: string)
const createResponse = await createResponsePromise;
expect(createResponse.ok(), await createResponse.text()).toBeTruthy();
const created: { data: { id: string } } = await createResponse.json();
+ environmentIds.add(created.data.id);
expect(created.data.id).toBeTruthy();
await expect(
@@ -52,25 +60,6 @@ async function createDirectEnvironmentViaUI(page: Page, environmentName: string)
return created.data.id;
}
-async function deleteEnvironmentViaUI(page: Page, environmentName: string) {
- await page.goto('/environments');
- await page.waitForLoadState('load');
-
- const envRow = page.getByRole('row').filter({
- has: page.getByRole('button', { name: environmentName, exact: true })
- });
-
- if ((await envRow.count()) === 0) {
- return;
- }
-
- await envRow.hover();
- await envRow.getByRole('button', { name: 'Open menu', exact: true }).click();
- await page.getByRole('menuitem', { name: 'Delete', exact: true }).click();
- await page.getByRole('button', { name: 'Remove', exact: true }).click();
- await expect(page.getByRole('button', { name: environmentName, exact: true })).toHaveCount(0);
-}
-
async function openLocalEnvironment(page: Page) {
await openEnvironment(page, LOCAL_ENV_ID);
}
@@ -102,6 +91,61 @@ async function selectSettingOption(page: Page, trigger: Locator, optionText: str
test.describe('Environment Settings UI', () => {
test.describe.configure({ mode: 'serial' });
+ const settingKeys = new Set([
+ 'baseServerUrl',
+ 'followProjectSymlinks',
+ 'defaultDeployPullPolicy',
+ 'trivyNetwork',
+ 'trivyResourceLimitsEnabled',
+ 'trivyMemoryLimitMb',
+ 'trivyCpuLimit'
+ ]);
+ let originalSettings: Record<string, string> = {};
+ test.beforeEach(async ({ page }) => {
+ originalSettings = {};
+ const response = await page.request.get(`/api/environments/${LOCAL_ENV_ID}/settings`);
+ expect(response.ok(), 'Read original environment settings').toBe(true);
+ const settings: Array<{ key: string; value: string }> = await response.json();
+ expect(Array.isArray(settings)).toBe(true);
+ originalSettings = Object.fromEntries(
+ settings
+ .filter((setting) => settingKeys.has(setting.key))
+ .map((setting) => [setting.key, setting.value])
+ );
+ });
+ test.afterEach(async ({ page }) => {
+ if (Object.keys(originalSettings).length === 0) return;
+ try {
+ const currentResponse = await page.request.get(`/api/environments/${LOCAL_ENV_ID}/settings`);
+ expect(currentResponse.ok()).toBe(true);
+ const current: Array<{ key: string; value: string }> = await currentResponse.json();
+ const changed = Object.fromEntries(
+ Object.entries(originalSettings).filter(
+ ([key, value]) => current.find((setting) => setting.key === key)?.value !== value
+ )
+ );
+ if (Object.keys(changed).length === 0) return;
+ const response = await page.request.put(`/api/environments/${LOCAL_ENV_ID}/settings`, {
+ data: changed
+ });
+ expect(
+ response.ok(),
+ `Restore environment settings: ${response.status()} ${await response.text()}`
+ ).toBe(true);
+ const restoredResponse = await page.request.get(`/api/environments/${LOCAL_ENV_ID}/settings`);
+ expect(restoredResponse.ok()).toBe(true);
+ const restored: Array<{ key: string; value: string }> = await restoredResponse.json();
+ expect(
+ Object.fromEntries(
+ restored
+ .filter((setting) => settingKeys.has(setting.key))
+ .map((setting) => [setting.key, setting.value])
+ )
+ ).toEqual(originalSettings);
+ } catch (error) {
+ expect.soft(false, `Restore environment settings: ${String(error)}`).toBe(true);
+ }
+ });
test('should keep primary tabs selectable and restore them from the URL', async ({ page }) => {
await page.goto('/settings');
@@ -148,9 +192,10 @@ test.describe('Environment Settings UI', () => {
const envName = `settings-ui-${Date.now().toString().slice(-5)}`;
const updatedName = `${envName}-updated`;
let environmentId = '';
+ const environmentIds = new Set<string>();
try {
- environmentId = await createDirectEnvironmentViaUI(page, envName);
+ environmentId = await createDirectEnvironmentViaUI(page, envName, environmentIds);
await page.getByRole('button', { name: envName, exact: true }).click();
await expect(page).toHaveURL(/\/environments\/[^/?]+\?tab=[a-z]+$/);
@@ -160,11 +205,7 @@ test.describe('Environment Settings UI', () => {
await page.reload();
await expect(environmentTitleButton(page)).toHaveText(updatedName);
} finally {
- if (environmentId) {
- await page.request.delete(`/api/environments/${environmentId}`).catch(() => undefined);
- }
- await deleteEnvironmentViaUI(page, updatedName);
- await deleteEnvironmentViaUI(page, envName);
+ for (const id of environmentIds) await removeApiResource(page, `/api/environments/${id}`);
}
});
diff --git a/tests/spec/image-updates.spec.ts b/tests/spec/image-updates.spec.ts
index d0cedf806..74a20e451 100644
--- a/tests/spec/image-updates.spec.ts
+++ b/tests/spec/image-updates.spec.ts
@@ -1,5 +1,5 @@
import { test, expect, type Locator, type Page } from '../fixtures/test.fixture';
-import { fetchImagesWithRetry } from '../utils/fetch.util';
+import { fetchImagesWithRetry, readList } from '../utils/fetch.util';
const ROUTES = {
page: '/images',
@@ -57,12 +57,12 @@ async function fetchImagesTotal(page: Page, updatesFilter?: string): Promise<num
params.set('updates', updatesFilter);
}
- const res = await page.request.get(`/api/environments/0/images?${params.toString()}`);
- expect(res.status()).toBe(200);
-
- const body = await res.json().catch(() => null as any);
- const totalItems = Number(body?.pagination?.totalItems ?? 0);
- return Number.isFinite(totalItems) ? totalItems : 0;
+ const result = await readList(
+ await page.request.get(`/api/environments/0/images?${params.toString()}`),
+ 'List filtered images'
+ );
+ expect(result.pagination?.totalItems, 'Image list must include a total').toBeDefined();
+ return result.pagination!.totalItems!;
}
async function getCheckUpdatesAction(page: Page): Promise<Locator> {
@@ -73,22 +73,13 @@ async function getCheckUpdatesAction(page: Page): Promise<Locator> {
.filter({ visible: true })
.first();
- if (
- await expect(directButton)
- .toBeVisible({ timeout: 5000 })
- .then(
- () => true,
- () => false
- )
- ) {
- return directButton;
- }
-
const menuTrigger = page
.getByRole('button', { name: 'More actions' })
.filter({ visible: true })
.first();
- await expect(menuTrigger).toBeVisible();
+ await expect(directButton.or(menuTrigger).first()).toBeVisible();
+ if (await directButton.isVisible()) return directButton;
+
await menuTrigger.click();
const menu = page.getByRole('menu').filter({ visible: true }).last();
@@ -98,17 +89,25 @@ async function getCheckUpdatesAction(page: Page): Promise<Locator> {
return menuItem;
}
+async function openImageUpdateCard(page: Page, trigger: Locator): Promise<Locator> {
+ const usesTouchPopover = await page.evaluate(() => window.matchMedia('(hover: none)').matches);
+ if (usesTouchPopover) {
+ await trigger.click();
+ } else {
+ await trigger.hover();
+ }
+
+ const content = page.locator('[data-open="true"]').filter({ visible: true }).last();
+ await expect(content).toBeVisible();
+ return content;
+}
+
let realImages: any[] = [];
test.beforeEach(async ({ page }) => {
await navigateToImages(page);
- try {
- const images = await fetchImagesWithRetry(page);
- realImages = Array.isArray(images) ? images : [];
- } catch {
- realImages = [];
- }
+ realImages = await fetchImagesWithRetry(page);
});
test.describe('Image Update UI - Check All Updates Button', () => {
@@ -152,7 +151,7 @@ test.describe('Image Update UI - Check All Updates Button', () => {
test.describe('Image Update UI - Individual Image Update Check via Hover Card', () => {
test('should display update status icons in the images table', async ({ page }) => {
- test.skip(!realImages.length, 'No images available');
+ expect(realImages.length, 'No images available').toBeGreaterThan(0);
await navigateToImages(page);
@@ -165,7 +164,7 @@ test.describe('Image Update UI - Individual Image Update Check via Hover Card',
});
test('should show hover card tooltip when hovering over update status icon', async ({ page }) => {
- test.skip(!realImages.length, 'No images available');
+ expect(realImages.length, 'No images available').toBeGreaterThan(0);
await navigateToImages(page);
@@ -181,90 +180,57 @@ test.describe('Image Update UI - Individual Image Update Check via Hover Card',
// Look for the update status icon trigger element (Tooltip.Trigger wraps a span)
const updateStatusTrigger = firstRow.getByTestId('image-update-trigger').first();
- const hasTrigger = await updateStatusTrigger.isVisible().catch(() => false);
-
- if (hasTrigger) {
- // Hover to trigger tooltip
- await updateStatusTrigger.hover();
-
- // Wait for tooltip content to appear
- await page.waitForTimeout(500);
-
- // Check if tooltip/hover card content appeared
- const tooltipContent = page.getByRole('tooltip');
- const tooltipVisible = await tooltipContent.isVisible().catch(() => false);
-
- // The hover card should be visible after hovering
- if (tooltipVisible) {
- await expect(tooltipContent).toBeVisible();
- }
- }
+ await openImageUpdateCard(page, updateStatusTrigger);
});
test('should allow triggering individual image update check from hover card', async ({
page
}) => {
- test.skip(!realImages.length, 'No images available');
+ expect(realImages.length, 'No images available').toBeGreaterThan(0);
- // Find an image with valid repo/tag for update checking
- const testImage = realImages.find(
- (img) => img.repo && img.tag && img.repo !== '<none>' && img.tag !== '<none>'
+ const fixtures = await readList<{ id: string; repoTags: string[] }>(
+ await page.request.get('/api/environments/0/images', {
+ params: { search: TEST_IMAGE_REFS.busybox }
+ }),
+ 'Find BusyBox fixture'
);
- test.skip(!testImage, 'No suitable image found for update check');
-
+ const testImage = fixtures.data.find((image) =>
+ image.repoTags?.includes(TEST_IMAGE_REFS.busybox)
+ );
+ expect(testImage, 'BusyBox fixture must be present').toBeDefined();
await navigateToImages(page);
- await expect(page.getByRole('table')).toBeVisible();
-
- // Find the row for our test image or the first row with a valid image
- const firstRow = page
+ const filteredImagesResponse = page.waitForResponse((response) => {
+ const url = new URL(response.url());
+ return (
+ response.request().method() === 'GET' &&
+ url.pathname === '/api/environments/0/images' &&
+ url.searchParams.get('search') === testImage!.id
+ );
+ });
+ await page.getByPlaceholder('Search…').first().fill(testImage!.id);
+ const filteredResponse = await filteredImagesResponse;
+ expect(filteredResponse.ok()).toBe(true);
+ await filteredResponse.finished();
+ await expect(page.getByRole('table').locator('tbody tr')).toHaveCount(1);
+ const row = page
.getByRole('row')
- .filter({ has: page.getByTestId('image-update-trigger') })
- .first();
- await expect(firstRow).toBeVisible();
-
- // Look for the update status trigger (could be a button or icon)
- const updateTrigger = firstRow.getByTestId('image-update-trigger').first();
- const hasUpdateTrigger = await updateTrigger.isVisible().catch(() => false);
-
- if (hasUpdateTrigger) {
- // If it's a clickable button (for unchecked images), click it
- const updateButton = updateTrigger.getByRole('button').first();
- const hasButton = await updateButton.isVisible().catch(() => false);
-
- if (hasButton) {
- await updateButton.click();
-
- // Wait for checking to complete (either a toast or state change)
- await expect(async () => {
- const toast = page
- .getByRole('region', { name: 'Notifications alt+T', exact: true })
- .getByRole('listitem');
- const toastVisible = await toast.isVisible().catch(() => false);
- expect(toastVisible).toBeTruthy();
- }).toPass({ timeout: 30000 });
- } else {
- // If it's an icon, hover to show the tooltip with recheck button
- await updateTrigger.hover();
- await page.waitForTimeout(500);
-
- // Look for the recheck button in the tooltip
- const recheckButton = page.getByRole('tooltip').getByRole('button').first();
- const hasRecheckButton = await recheckButton.isVisible().catch(() => false);
-
- if (hasRecheckButton) {
- await recheckButton.click();
-
- // Wait for the check to complete
- await expect(async () => {
- const toast = page
- .getByRole('region', { name: 'Notifications alt+T', exact: true })
- .getByRole('listitem');
- const toastVisible = await toast.isVisible().catch(() => false);
- expect(toastVisible).toBeTruthy();
- }).toPass({ timeout: 30000 });
- }
- }
+ .filter({ has: page.locator(`a[href="/images/${testImage!.id}"]`) });
+ const trigger = row.getByTestId('image-update-trigger');
+ await expect(trigger).toBeVisible();
+ const responsePromise = page.waitForResponse(
+ (response) =>
+ response.request().method() === 'POST' &&
+ decodeURIComponent(new URL(response.url()).pathname) ===
+ `/api/environments/0/image-updates/check/${testImage!.id}`
+ );
+ if (await trigger.evaluate((element) => element.tagName === 'BUTTON')) {
+ await trigger.click();
+ } else {
+ const updateCard = await openImageUpdateCard(page, trigger);
+ await updateCard.getByRole('button', { name: 'Re-check Updates', exact: true }).click();
}
+ expect((await responsePromise).ok()).toBe(true);
+ await expect(page.locator('li[data-sonner-toast]').first()).toBeVisible();
});
});
@@ -323,7 +289,7 @@ test.describe('Image Update API Endpoints', () => {
test.describe('Image Update UI Integration', () => {
test('should display update status icon in images table', async ({ page }) => {
- test.skip(!realImages.length, 'No images available');
+ expect(realImages.length, 'No images available').toBeGreaterThan(0);
await navigateToImages(page);
@@ -336,12 +302,12 @@ test.describe('Image Update UI Integration', () => {
});
test('should display update information in image detail page', async ({ page }) => {
- test.skip(!realImages.length, 'No images available');
+ expect(realImages.length, 'No images available').toBeGreaterThan(0);
const testImage = realImages.find(
(img) => img.repoTags?.[0] && !img.repoTags[0].includes('<none>')
);
- test.skip(!testImage, 'No suitable image found');
+ expect(testImage, 'No suitable image found').toBeTruthy();
// Navigate to image detail
await page.goto(`/images/${encodeURIComponent(testImage.id)}`);
diff --git a/tests/spec/images.spec.ts b/tests/spec/images.spec.ts
index 33f713dbf..e4c590c95 100644
--- a/tests/spec/images.spec.ts
+++ b/tests/spec/images.spec.ts
@@ -1,7 +1,13 @@
import { test, expect, type Page } from '../fixtures/test.fixture';
-import { fetchImageCountsWithRetry, fetchImagesWithRetry } from '../utils/fetch.util';
+import {
+ fetchImageCountsWithRetry,
+ fetchImagesWithRetry,
+ readApiData,
+ readList
+} from '../utils/fetch.util';
import { ImageUsageCounts } from 'types/image.type';
import { openRowActionsMenu } from '../utils/table-actions.util';
+import { waitForDialogReady } from '../utils/playwright.util';
const ROUTES = {
page: '/images',
@@ -83,22 +89,19 @@ async function mockImageDeleteFlow(page: Page, failFirst = false) {
return state;
}
-async function fetchAllImagesForUsage(page: Page): Promise<any[]> {
+async function fetchAllImagesForUsage(page: Page): Promise<Record<string, unknown>[]> {
const limit = 200;
let start = 0;
- const all: any[] = [];
+ const all: Record<string, unknown>[] = [];
while (true) {
- const res = await page.request.get(`${ROUTES.apiImages}?start=${start}&limit=${limit}`);
- if (!res.ok()) {
- throw new Error(`HTTP ${res.status()}`);
- }
-
- const body = await res.json().catch(() => null as any);
- const data = Array.isArray(body?.data) ? body.data : [];
+ const { data, pagination } = await readList<Record<string, unknown>>(
+ await page.request.get(`${ROUTES.apiImages}?start=${start}&limit=${limit}`),
+ 'List images for usage'
+ );
all.push(...data);
-
- const totalItems = Number(body?.pagination?.totalItems ?? all.length);
+ expect(pagination?.totalItems, 'Image list must include a total').toBeDefined();
+ const totalItems = pagination!.totalItems!;
if (data.length === 0 || all.length >= totalItems) {
break;
}
@@ -211,13 +214,8 @@ let imageCounts: ImageUsageCounts = {
test.beforeEach(async ({ page }) => {
await navigateToImages(page);
- try {
- const images = await fetchImagesWithRetry(page);
- realImages = Array.isArray(images) ? images : [];
- imageCounts = await fetchImageCountsWithRetry(page);
- } catch {
- realImages = [];
- }
+ realImages = await fetchImagesWithRetry(page);
+ imageCounts = await fetchImageCountsWithRetry(page);
});
test.describe('Images Page', () => {
@@ -309,7 +307,13 @@ test.describe('Images Page', () => {
await navigateToImages(page);
let pruneButton = page.getByRole('button', { name: 'Prune Unused' });
- const isDirectlyVisible = await pruneButton.isVisible().catch(() => false);
+ await expect(
+ pruneButton
+ .or(page.getByRole('button', { name: 'More actions' }))
+ .filter({ visible: true })
+ .first()
+ ).toBeVisible();
+ const isDirectlyVisible = await pruneButton.isVisible();
if (!isDirectlyVisible) {
await page.getByRole('button', { name: 'More actions' }).click();
@@ -334,29 +338,69 @@ test.describe('Images Page', () => {
});
test('should pull image from dropdown menu', async ({ page }) => {
- test.skip(!realImages.length, 'No images available for pull API test');
+ test.setTimeout(90_000);
+ const reference = 'public.ecr.aws/docker/library/busybox:1.37';
+ const fixtures = await readList<{ id: string }>(
+ await page.request.get(ROUTES.apiImages, { params: { search: reference } }),
+ 'Find image pull fixture'
+ );
+ expect(fixtures.data).toHaveLength(1);
await navigateToImages(page);
+ await page.getByPlaceholder('Search…').first().fill(fixtures.data[0].id);
- const firstRow = page
+ const row = page
.getByRole('row')
- .filter({ has: page.getByRole('button', { name: 'Open menu', exact: true }) })
- .first();
- const menu = await openRowActionsMenu(page, firstRow);
+ .filter({ has: page.locator(`a[href="/images/${fixtures.data[0].id}"]`) });
+ const menu = await openRowActionsMenu(page, row);
+ const responsePromise = page.waitForResponse(
+ (response) =>
+ response.request().method() === 'POST' &&
+ new URL(response.url()).pathname === `${ROUTES.apiImages}/pull`
+ );
await menu.getByRole('menuitem', { name: 'Pull' }).click();
-
- await page.waitForLoadState('load');
-
+ const response = await responsePromise;
+ expect(response.ok(), 'Pull fixture image').toBe(true);
+ const frames = (await response.text())
+ .trim()
+ .split('\n')
+ .map(
+ (line) =>
+ JSON.parse(line) as {
+ activityId?: string;
+ done?: boolean;
+ error?: unknown;
+ }
+ );
+ expect(frames.some((frame) => frame.error)).toBe(false);
+ expect(frames).toContainEqual(expect.objectContaining({ done: true }));
+ const activityId = frames.find((frame) => frame.activityId)?.activityId;
+ expect(activityId).toBeTruthy();
await expect(
- page.getByRole('region', { name: 'Notifications alt+T', exact: true }).getByRole('listitem')
+ page
+ .getByRole('region', { name: 'Notifications alt+T', exact: true })
+ .getByRole('listitem')
+ .filter({ hasText: `Image ${reference} pulled successfully` })
).toBeVisible();
+ await expect
+ .poll(
+ async () => {
+ const detail = await readApiData<{ activity: { status: string } }>(
+ await page.request.get(`/api/environments/0/activities/${activityId}`),
+ 'Get image pull activity'
+ );
+ return detail.activity.status;
+ },
+ { timeout: 60_000 }
+ )
+ .toBe('success');
});
test('should call remove API on row action remove click and confirmation', async ({ page }) => {
- test.skip(!realImages.length, 'No images available for remove API test');
+ expect(realImages.length, 'No images available for remove API test').toBeGreaterThan(0);
await navigateToImages(page);
const removableImage = realImages.find((image) => image.repo && image.repo !== '<none>');
- test.skip(!removableImage, 'No removable images available');
+ expect(removableImage, 'No removable images available').toBeTruthy();
const removePath = `/api/environments/0/images/${removableImage.id}`;
let removeRequestCount = 0;
@@ -408,7 +452,10 @@ test.describe('Images Page', () => {
test('should remove selected images sequentially and refresh the list and usage counts', async ({
page
}) => {
- test.skip(realImages.length < 2, 'At least two images are required for bulk remove test');
+ expect(
+ realImages.length,
+ 'At least two images are required for bulk remove test'
+ ).toBeGreaterThanOrEqual(2);
await navigateToImages(page);
const rows = getImageRows(page);
@@ -441,7 +488,10 @@ test.describe('Images Page', () => {
test('should continue bulk removal after a failed image and refresh successful results', async ({
page
}) => {
- test.skip(realImages.length < 2, 'At least two images are required for bulk remove test');
+ expect(
+ realImages.length,
+ 'At least two images are required for bulk remove test'
+ ).toBeGreaterThanOrEqual(2);
await navigateToImages(page);
const rows = getImageRows(page);
@@ -472,7 +522,13 @@ test.describe('Images Page', () => {
await navigateToImages(page);
let pruneButton = page.getByRole('button', { name: 'Prune Unused' });
- const isDirectlyVisible = await pruneButton.isVisible().catch(() => false);
+ await expect(
+ pruneButton
+ .or(page.getByRole('button', { name: 'More actions' }))
+ .filter({ visible: true })
+ .first()
+ ).toBeVisible();
+ const isDirectlyVisible = await pruneButton.isVisible();
if (!isDirectlyVisible) {
await page.getByRole('button', { name: 'More actions' }).click();
@@ -485,7 +541,13 @@ test.describe('Images Page', () => {
await expect(
dialog.getByRole('heading', { name: 'Prune Unused Images', exact: true })
).toBeVisible();
+ const pruneResponsePromise = page.waitForResponse(
+ (response) =>
+ response.request().method() === 'POST' &&
+ new URL(response.url()).pathname === '/api/environments/0/images/prune'
+ );
await dialog.getByRole('button', { name: 'Prune Images', exact: true }).click();
+ await readApiData<Record<string, unknown>>(await pruneResponsePromise, 'Prune dangling images');
await expect(
page
@@ -505,11 +567,16 @@ test.describe('Images Page', () => {
await page.getByRole('button', { name: 'Pull Image' }).click();
const dialogHeading = page.getByRole('heading', { name: 'Pull Image' });
await expect(dialogHeading).toBeVisible();
+ await waitForDialogReady(page.getByRole('dialog'));
await page
.getByRole('textbox', { name: 'Image Name *' })
.fill('public.ecr.aws/docker/library/alpine');
await page.getByRole('textbox', { name: 'Tag' }).fill('3.20');
+ await expect(page.getByRole('textbox', { name: 'Image Name *' })).toHaveValue(
+ 'public.ecr.aws/docker/library/alpine'
+ );
+ await expect(page.getByRole('textbox', { name: 'Tag' })).toHaveValue('3.20');
await page.getByRole('button', { name: 'Pull', exact: true }).click();
diff --git a/tests/spec/network.spec.ts b/tests/spec/network.spec.ts
index a9601a5e0..dbba11445 100644
--- a/tests/spec/network.spec.ts
+++ b/tests/spec/network.spec.ts
@@ -1,5 +1,6 @@
import { test, expect, type Locator, type Page } from '../fixtures/test.fixture';
-import { fetchNetworksCountsWithRetry } from '../utils/fetch.util';
+import { removeApiResource, fetchNetworksCountsWithRetry, readApiData } from '../utils/fetch.util';
+import { waitForDialogReady } from '../utils/playwright.util';
import authUtil from '../utils/auth.util';
async function navigateToNetworks(page: Page) {
@@ -10,9 +11,11 @@ async function navigateToNetworks(page: Page) {
async function ensureAuthenticated(page: Page) {
const currentUserResponse = await page.request.get('/api/auth/me');
- if (!currentUserResponse.ok()) {
+ if (currentUserResponse.status() === 401) {
await authUtil.login(page);
await expect(page.getByRole('button', { name: 'Card view', exact: true })).toBeVisible();
+ } else {
+ expect(currentUserResponse.ok(), 'Check current user').toBe(true);
}
}
@@ -24,7 +27,7 @@ test.beforeEach(async ({ page }) => {
async function openCreateNetworkDialog(page: Page, networkName: string) {
await page.getByRole('button', { name: 'Create Network' }).first().click();
const dialog = page.getByRole('dialog');
- await expect(dialog).toBeVisible();
+ await waitForDialogReady(dialog);
await expect(dialog.getByRole('heading', { name: 'Create New Network' })).toBeVisible();
await dialog.getByLabel('Network Name *').fill(networkName);
return dialog;
@@ -58,21 +61,18 @@ async function createNetworkViaUI(page: Page, networkName: string) {
await dialog.getByRole('button', { name: 'Create Network' }).click();
const createResponse = await createRequest;
- const responseBody = await createResponse.json().catch(() => undefined);
- if (!createResponse.ok()) {
- const responseText = await createResponse.text().catch(() => '');
- throw new Error(
- `Failed to create network ${networkName}: ${createResponse.status()} ${responseText}`
- );
- }
+ const network = await readApiData<{ id: string }>(
+ createResponse,
+ `Create network ${networkName}`
+ );
+ expect(network.id).toBeTruthy();
await expect(dialog).toBeHidden();
await expect(page.getByText(networkName, { exact: true }).first()).toBeVisible();
- return responseBody?.data?.id ?? networkName;
+ return network.id;
}
async function createNetworkViaApi(page: Page, networkName: string) {
- await page.goto('about:blank');
const response = await page.request.post('/api/environments/0/networks', {
data: {
name: networkName,
@@ -88,32 +88,13 @@ async function createNetworkViaApi(page: Page, networkName: string) {
}
}
-async function findNetworkRow(page: Page, networkName: string, maxRetries = 10) {
- for (let i = 0; i < maxRetries; i++) {
- const searchInput = page.getByPlaceholder('Search…').first();
- if (await searchInput.isVisible().catch(() => false)) {
- await searchInput.fill(networkName);
- }
-
- const row = page
- .getByRole('row')
- .filter({ has: page.getByRole('link', { name: networkName, exact: true }) })
- .first();
- if (await row.isVisible().catch(() => false)) return row;
- await page.waitForTimeout(500);
- await navigateToNetworks(page);
- }
- return page
- .getByRole('row')
- .filter({ has: page.getByRole('link', { name: networkName, exact: true }) })
- .first();
-}
-
-async function removeNetworkViaApi(page: Page, networkName: string) {
- await page.goto('about:blank');
- await page.request
- .delete(`/api/environments/0/networks/${encodeURIComponent(networkName)}`)
- .catch(() => undefined);
+async function findNetworkRow(page: Page, networkName: string) {
+ await page.getByPlaceholder('Search…').first().fill(networkName);
+ const row = page.getByRole('row').filter({
+ has: page.getByRole('link', { name: networkName, exact: true })
+ });
+ await expect(row).toBeVisible();
+ return row;
}
test.describe('Networks Page', () => {
@@ -145,7 +126,10 @@ test.describe('Networks Page', () => {
await expect(page.getByRole('button', { name: 'Name' })).toBeVisible();
await expect(await findNetworkRow(page, networkName)).toBeVisible();
} finally {
- await removeNetworkViaApi(page, networkName);
+ await removeApiResource(
+ page,
+ `/api/environments/0/networks/${encodeURIComponent(networkName)}`
+ );
}
});
@@ -173,7 +157,10 @@ test.describe('Networks Page', () => {
})
.toBe(404);
} finally {
- await removeNetworkViaApi(page, networkName);
+ await removeApiResource(
+ page,
+ `/api/environments/0/networks/${encodeURIComponent(networkName)}`
+ );
}
});
@@ -185,7 +172,10 @@ test.describe('Networks Page', () => {
await expect(page).toHaveURL(/\/networks\/.+/);
await expect(page.getByRole('heading', { level: 1, name: networkName })).toBeVisible();
} finally {
- await removeNetworkViaApi(page, networkName);
+ await removeApiResource(
+ page,
+ `/api/environments/0/networks/${encodeURIComponent(networkName)}`
+ );
}
});
@@ -253,7 +243,10 @@ test.describe('Networks Page', () => {
await expect(page.getByRole('heading', { level: 1, name: networkName })).toBeVisible();
await expect(page.getByText(ipRange, { exact: true })).toBeVisible();
} finally {
- await removeNetworkViaApi(page, networkName);
+ await removeApiResource(
+ page,
+ `/api/environments/0/networks/${encodeURIComponent(networkName)}`
+ );
}
});
@@ -298,8 +291,14 @@ test.describe('Networks Page', () => {
await dialog.getByLabel('Enable IPAM Configuration').check();
await expect(dialog.getByLabel('IP Range')).toHaveValue('');
} finally {
- await removeNetworkViaApi(page, blankRangeName);
- await removeNetworkViaApi(page, disabledIpamName);
+ await removeApiResource(
+ page,
+ `/api/environments/0/networks/${encodeURIComponent(blankRangeName)}`
+ );
+ await removeApiResource(
+ page,
+ `/api/environments/0/networks/${encodeURIComponent(disabledIpamName)}`
+ );
}
});
@@ -330,7 +329,10 @@ test.describe('Networks Page', () => {
await expect(dialog).toBeVisible();
await expect(dialog.getByLabel('Network Name *')).toHaveValue(networkName);
} finally {
- await removeNetworkViaApi(page, networkName);
+ await removeApiResource(
+ page,
+ `/api/environments/0/networks/${encodeURIComponent(networkName)}`
+ );
}
});
@@ -343,7 +345,10 @@ test.describe('Networks Page', () => {
await expect(page.getByText('Unused').first()).toBeVisible();
} finally {
- await removeNetworkViaApi(page, networkName);
+ await removeApiResource(
+ page,
+ `/api/environments/0/networks/${encodeURIComponent(networkName)}`
+ );
}
});
});
diff --git a/tests/spec/project.spec.ts b/tests/spec/project.spec.ts
index 4a729ecca..2bb386d8b 100644
--- a/tests/spec/project.spec.ts
+++ b/tests/spec/project.spec.ts
@@ -1,5 +1,10 @@
import { test, expect, type Locator, type Page, type Response } from '../fixtures/test.fixture';
-import { fetchProjectCountsWithRetry, fetchProjectsWithRetry } from '../utils/fetch.util';
+import {
+ readApiData,
+ removeApiResource,
+ fetchProjectCountsWithRetry,
+ fetchProjectsWithRetry
+} from '../utils/fetch.util';
import type { Activity } from '../types/activity.type';
import { Project, ProjectStatusCounts } from 'types/project.type';
import { TEST_COMPOSE_YAML, TEST_ENV_FILE } from '../setup/project.data';
@@ -9,7 +14,6 @@ const ROUTES = {
page: '/projects',
apiProjects: '/api/environments/0/projects',
apiImageUpdatesCheckAll: '/api/environments/0/image-updates/check-all',
- apiImageUpdatesCheckBatch: '/api/environments/0/image-updates/check-batch',
apiUpdaterRun: '/api/environments/0/updater/run',
newProject: '/projects/new'
};
@@ -56,37 +60,31 @@ async function clickProjectsPageUpdateAction(page: Page) {
async function clickProjectDetailUpdateAction(page: Page) {
const recheckButton = page.getByRole('button', { name: 'Re-check Updates', exact: true }).first();
- if (await recheckButton.isVisible().catch(() => false)) {
+ const updateTrigger = page.getByTestId('project-update-trigger').first();
+ await expect(recheckButton.or(updateTrigger).filter({ visible: true }).first()).toBeVisible();
+ if (await recheckButton.isVisible()) {
await recheckButton.click();
return true;
}
-
- const updateTrigger = page.getByTestId('project-update-trigger').first();
- if (!(await updateTrigger.isVisible().catch(() => false))) {
- return false;
- }
- await updateTrigger.click();
-
- if (!(await recheckButton.isVisible().catch(() => false))) {
- return false;
+ if (await updateTrigger.evaluate((element) => element.tagName === 'BUTTON')) {
+ await updateTrigger.click();
+ return true;
}
+ const usesTouchPopover = await page.evaluate(() => window.matchMedia('(hover: none)').matches);
+ if (usesTouchPopover) await updateTrigger.click();
+ else await updateTrigger.hover();
await recheckButton.click();
return true;
}
-async function fetchProjectDetail(page: Page, projectId: string): Promise<Project | null> {
- const res = await page.request.get(`/api/environments/0/projects/${projectId}`);
- if (!res.ok()) {
- return null;
- }
-
- const body = await res.json().catch(() => null as any);
- if (!body) return null;
- if (body.project) return body.project as Project;
- if (body.data?.project) return body.data.project as Project;
- if (body.data) return body.data as Project;
- return body as Project;
+async function fetchProjectDetail(page: Page, projectId: string): Promise<Project> {
+ const project = await readApiData<Project>(
+ await page.request.get(`/api/environments/0/projects/${projectId}`),
+ `Get project ${projectId}`
+ );
+ expect(project.id).toBeTruthy();
+ return project;
}
async function fetchLatestProjectDeployActivity(
@@ -99,13 +97,11 @@ async function fetchLatestProjectDeployActivity(
search: projectId,
limit: '10'
});
- const res = await page.request.get(`/api/environments/0/activities?${params.toString()}`);
- if (!res.ok()) {
- return null;
- }
-
- const body = await res.json().catch(() => null as any);
- const activities = (body?.data ?? []) as Activity[];
+ const activities = await readApiData<Activity[]>(
+ await page.request.get(`/api/environments/0/activities?${params.toString()}`),
+ 'List project deploy activities'
+ );
+ expect(Array.isArray(activities)).toBe(true);
return (
activities.find(
(activity) =>
@@ -128,26 +124,6 @@ async function expectProjectDeployActivitySucceeded(page: Page, projectId: strin
.toBe('success');
}
-async function findProjectWithDetailUpdateAction(page: Page): Promise<Project | null> {
- for (const project of realProjects) {
- if (Number(project.serviceCount ?? 0) <= 0) {
- continue;
- }
-
- const projectID = project.id || project.name;
- if (!projectID) {
- continue;
- }
-
- const detail = await fetchProjectDetail(page, projectID);
- if ((detail?.updateInfo?.imageRefs?.length ?? 0) > 0) {
- return detail;
- }
- }
-
- return null;
-}
-
function getPathname(url: string): string {
return url.replace(/^[a-z]+:\/\/[^/]+/i, '').split(/[?#]/)[0] || '/';
}
@@ -173,6 +149,7 @@ async function createProjectViaUI(
projectName: string,
composeContent = TEST_COMPOSE_YAML
) {
+ createdProjectNames.add(projectName);
const containerName = `test-nginx-container-${Date.now()}`;
const envFile = TEST_ENV_FILE.replace(/CONTAINER_NAME=.*/m, `CONTAINER_NAME=${containerName}`);
@@ -227,40 +204,30 @@ async function destroyCurrentProjectViaUI(page: Page) {
const dialog = page.getByRole('dialog');
await expect(dialog).toBeVisible();
+ await dialog
+ .getByRole('checkbox', { name: 'Remove volumes (Warning: Data will be lost)', exact: true })
+ .check();
await dialog.getByRole('button', { name: 'Destroy', exact: true }).click();
await page.waitForURL(ROUTES.page, { timeout: 10000 });
}
-async function destroyProjectByNameViaUI(page: Page, projectName: string) {
- if (page.isClosed()) {
- return;
- }
-
- await page.goto(ROUTES.page);
- await page.waitForLoadState('load');
-
- const searchInput = page.getByPlaceholder('Search…');
- if (await searchInput.isVisible().catch(() => false)) {
- await searchInput.fill(projectName);
- }
-
- const projectLink = page.getByRole('link', { name: projectName, exact: true });
- const row = page.getByRole('row').filter({ has: projectLink }).first();
- if (!(await row.isVisible().catch(() => false))) {
- return;
+async function destroyProjectByNameViaAPI(page: Page, projectName: string) {
+ try {
+ const projects = await readApiData<Project[]>(
+ await page.request.get(ROUTES.apiProjects, {
+ params: { search: projectName, archived: 'all' }
+ }),
+ `Find project ${projectName} for cleanup`
+ );
+ expect(Array.isArray(projects)).toBe(true);
+ for (const project of projects.filter((candidate) => candidate.name === projectName)) {
+ expect(project.id).toBeTruthy();
+ await destroyProjectByIdViaAPI(page, project.id!);
+ }
+ } catch (error) {
+ expect.soft(false, `Clean up project ${projectName}: ${String(error)}`).toBe(true);
}
-
- const menu = await openRowActionsMenu(page, row);
- await menu.getByRole('menuitem', { name: 'Destroy', exact: true }).click();
-
- const dialog = page.getByRole('dialog');
- await expect(dialog).toBeVisible();
- await dialog.getByRole('button', { name: 'Destroy', exact: true }).click();
-
- await expect(page.getByRole('row').filter({ has: projectLink })).toHaveCount(0, {
- timeout: 15000
- });
}
async function destroyProjectByIdViaAPI(page: Page, projectId: string) {
@@ -268,13 +235,15 @@ async function destroyProjectByIdViaAPI(page: Page, projectId: string) {
return;
}
- await page.request
- .delete(`/api/environments/0/projects/${encodeURIComponent(projectId)}/destroy`, {
+ await removeApiResource(
+ page,
+ `/api/environments/0/projects/${encodeURIComponent(projectId)}/destroy`,
+ {
data: {
- removeVolumes: false
+ removeVolumes: true
}
- })
- .catch(() => undefined);
+ }
+ );
}
async function expectProjectStopped(page: Page, projectId: string) {
@@ -325,6 +294,7 @@ async function createExitedMarkerProject(page: Page, projectName: string) {
return { projectId, marker };
}
+const createdProjectNames = new Set<string>();
let realProjects: Project[] = [];
let projectCounts: ProjectStatusCounts = {
runningProjects: 0,
@@ -340,7 +310,11 @@ function getRequiredGitOpsProject(): Project & { id: string } {
return project as Project & { id: string };
}
-test.beforeEach(async ({ page }) => {
+test.beforeEach(async ({ page, registerCleanup }) => {
+ createdProjectNames.clear();
+ registerCleanup(async () => {
+ for (const name of createdProjectNames) await destroyProjectByNameViaAPI(page, name);
+ });
await navigateToProjects(page);
realProjects = await fetchProjectsWithRetry(page);
@@ -386,7 +360,7 @@ test.describe('Projects Page', () => {
});
test('should show project actions menu', async ({ page }) => {
- test.skip(!realProjects.length, 'No projects available for actions menu test');
+ expect(realProjects.length, 'No projects available for actions menu test').toBeGreaterThan(0);
await page.waitForLoadState('load');
const firstRow = page
@@ -403,9 +377,7 @@ test.describe('Projects Page', () => {
name: 'Restart',
exact: true
});
- const hasStateAction =
- (await upItem.count()) > 0 || (await downItem.count()) > 0 || (await restartItem.count()) > 0;
- expect(hasStateAction).toBe(true);
+ await expect(upItem.or(downItem).or(restartItem).first()).toBeVisible();
await expect(menu.getByRole('menuitem', { name: 'Pull & Redeploy' })).toBeVisible();
await expect(menu.getByRole('menuitem', { name: 'Archive' })).toBeVisible();
await expect(menu.getByRole('menuitem', { name: 'Destroy' })).toBeVisible();
@@ -444,18 +416,15 @@ test.describe('Projects Page', () => {
await expect(row).toHaveCount(0, { timeout: 10000 });
} finally {
if (projectId) {
- await page.request
- .post(`/api/environments/0/projects/${projectId}/unarchive`)
- .catch(() => undefined);
await destroyProjectByIdViaAPI(page, projectId);
} else {
- await destroyProjectByNameViaUI(page, projectName);
+ await destroyProjectByNameViaAPI(page, projectName);
}
}
});
test('should navigate to project details when project name is clicked', async ({ page }) => {
- test.skip(!realProjects.length, 'No projects available for navigation test');
+ expect(realProjects.length, 'No projects available for navigation test').toBeGreaterThan(0);
await page.waitForLoadState('load');
const projectName = realProjects[0].name;
@@ -467,7 +436,7 @@ test.describe('Projects Page', () => {
});
test('should allow searching/filtering projects', async ({ page }) => {
- test.skip(!realProjects.length, 'No projects available for search test');
+ expect(realProjects.length, 'No projects available for search test').toBeGreaterThan(0);
const searchInput = page.getByPlaceholder('Search…');
await expect(searchInput).toBeVisible();
@@ -509,7 +478,7 @@ test.describe('Projects Page', () => {
});
test('should display project status badges', async ({ page }) => {
- test.skip(!realProjects.length, 'No projects available for status badge test');
+ expect(realProjects.length, 'No projects available for status badge test').toBeGreaterThan(0);
await page.waitForLoadState('load');
@@ -758,32 +727,11 @@ test.describe('New Compose Project Page', () => {
await expectProjectDeployActivitySucceeded(page, projectId);
expect(projectPullRequestCount).toBe(0);
- // The activity record is committed before the streamed response reaches EOF in
- // the browser, so polling the API can beat the detail page's local state update.
- // Reload from the completed server state before asserting the rendered action.
- // A transient 500 from any request in the reload's load chain lands on the app
- // error page (rendered as the generic "Unable to connect to Docker daemon"
- // message), which never recovers on its own — retry the reload instead of
- // failing the test on a one-off backend blip under CI load.
- await expect(async () => {
- await page.reload();
- await expect(page).toHaveURL(new RegExp(`/projects/${projectId}`));
- await expect(page.getByRole('button', { name: projectName, exact: true })).toBeVisible({
- timeout: 10000
- });
- }).toPass({ timeout: 60000 });
- await expect
- .poll(async () => (await fetchProjectDetail(page, projectId))?.status, {
- message: 'Expected project to still be running after reload',
- timeout: 30000
- })
- .toBe('running');
await expect(page.getByRole('button', { name: 'Down', exact: true })).toBeVisible({
timeout: 30000
});
} finally {
- const projectId = createdProjectId ?? getProjectIdFromPageUrl(page.url());
- await destroyProjectByIdViaAPI(page, projectId);
+ await destroyProjectByNameViaAPI(page, projectName);
}
});
@@ -866,11 +814,7 @@ test.describe('New Compose Project Page', () => {
recreateVolumes: false
});
} finally {
- if (!page.isClosed() && /\/projects\/.+/.test(getPathname(page.url()))) {
- await destroyCurrentProjectViaUI(page);
- } else {
- await destroyProjectByNameViaUI(page, projectName);
- }
+ await destroyProjectByNameViaAPI(page, projectName);
}
});
@@ -962,21 +906,21 @@ test.describe('New Compose Project Page', () => {
recreateVolumes: false
});
} finally {
- if (!page.isClosed() && /\/projects\/.+/.test(getPathname(page.url()))) {
- await destroyCurrentProjectViaUI(page);
- } else {
- await destroyProjectByNameViaUI(page, projectName);
- }
+ await destroyProjectByNameViaAPI(page, projectName);
}
});
test('should allow redeploy requests to complete after 10 seconds without client timeout', async ({
page
}) => {
- test.slow();
+ await page.clock.install();
const projectName = `test-redeploy-timeout-${Date.now()}`;
- let redeployRequestStartedAt: number | undefined;
+ let redeployRequestStarted = false;
+ let releaseRedeploy!: () => void;
+ const redeployReleased = new Promise<void>((resolve) => {
+ releaseRedeploy = resolve;
+ });
const redeployPathPattern = /\/api\/environments\/[^/]+\/projects\/[^/]+\/redeploy$/;
try {
@@ -992,8 +936,8 @@ test.describe('New Compose Project Page', () => {
return;
}
- redeployRequestStartedAt = Date.now();
- await new Promise((resolve) => setTimeout(resolve, 11_000));
+ redeployRequestStarted = true;
+ await redeployReleased;
await route.fulfill({
status: 200,
contentType: 'application/json',
@@ -1031,17 +975,22 @@ test.describe('New Compose Project Page', () => {
await redeployRequestPromise;
await expect
- .poll(() => redeployRequestStartedAt, {
+ .poll(() => redeployRequestStarted, {
message: 'Expected the redeploy request to be issued'
})
- .toBeDefined();
+ .toBe(true);
+
+ const startedAt = await page.evaluate(() => Date.now());
+ await page.clock.runFor(11_000);
+ expect((await page.evaluate(() => Date.now())) - startedAt).toBeGreaterThanOrEqual(11_000);
+ releaseRedeploy();
await expect(page.getByText('Project pulled successfully.', { exact: true })).toBeVisible({
timeout: 20_000
});
- expect(Date.now() - redeployRequestStartedAt!).toBeGreaterThanOrEqual(11_000);
} finally {
- await destroyProjectByNameViaUI(page, projectName);
+ releaseRedeploy();
+ await destroyProjectByNameViaAPI(page, projectName);
}
});
@@ -1153,7 +1102,6 @@ test.describe('GitOps Managed Project', () => {
await configTab.click();
await page.waitForLoadState('load');
- await page.waitForTimeout(800);
const composeContent = page
.locator('.cm-editor')
.filter({ visible: true })
@@ -1180,15 +1128,16 @@ test.describe('GitOps Managed Project', () => {
});
const workspaceFilesLabel = page.getByText('Workspace Files', { exact: true });
// Projects with extra files default to tree view; start from classic.
- if (await workspaceFilesLabel.isVisible().catch(() => false)) {
+ await expect(page.locator('.cm-editor').filter({ visible: true }).first()).toBeVisible();
+ if (await workspaceFilesLabel.isVisible()) {
await layoutSwitch.click();
await expect(workspaceFilesLabel).not.toBeVisible();
}
- await page.waitForTimeout(800);
const envEditor = page.locator('.cm-editor').filter({ visible: true }).nth(1);
const marker = `ARCANE_E2E_${Date.now()}`;
const envContent = envEditor.locator('.cm-content');
+ await expect(envContent).toBeVisible();
const originalEnv = await getCodeMirrorValue(envEditor);
const updatedEnv = `${originalEnv.trimEnd()}\n${marker}=1\n`;
@@ -1197,25 +1146,25 @@ test.describe('GitOps Managed Project', () => {
await expect(envEditor).toContainText(marker);
await expect(page.getByRole('button', { name: 'Save', exact: true }).first()).toBeVisible();
- if (await layoutSwitch.count()) {
- await layoutSwitch.click();
- await page.waitForLoadState('load');
- await expect(workspaceFilesLabel).toBeVisible();
+ await expect(layoutSwitch).toBeVisible();
- const envFileButton = page.getByRole('button', { name: '.env' }).first();
- await expect(envFileButton).toBeVisible();
- await envFileButton.click();
+ await layoutSwitch.click();
+ await page.waitForLoadState('load');
+ await expect(workspaceFilesLabel).toBeVisible();
- const treeEnvEditor = page.locator('.cm-editor').filter({ visible: true }).first();
- const treeEnvContent = treeEnvEditor.locator('.cm-content');
- await expect(treeEnvContent).not.toHaveAttribute('aria-readonly', 'true');
- await expect(treeEnvEditor).toContainText(marker);
- }
+ const envFileButton = page.getByRole('button', { name: '.env' }).first();
+ await expect(envFileButton).toBeVisible();
+ await envFileButton.click();
+
+ const treeEnvEditor = page.locator('.cm-editor').filter({ visible: true }).first();
+ const treeEnvContent = treeEnvEditor.locator('.cm-content');
+ await expect(treeEnvContent).not.toHaveAttribute('aria-readonly', 'true');
+ await expect(treeEnvEditor).toContainText(marker);
});
test('should allow editing for non-GitOps managed projects', async ({ page }) => {
const regularProject = realProjects.find((p) => !p.gitOpsManagedBy && p.status === 'stopped');
- test.skip(!regularProject, 'No regular (non-GitOps) stopped projects found');
+ expect(regularProject, 'No regular (non-GitOps) stopped projects found').toBeTruthy();
await page.goto(`/projects/${regularProject!.id}`);
await page.waitForLoadState('load');
@@ -1240,7 +1189,7 @@ test.describe('GitOps Managed Project', () => {
page
}) => {
const regularProject = realProjects.find((p) => !p.gitOpsManagedBy);
- test.skip(!regularProject, 'No regular (non-GitOps) projects found');
+ expect(regularProject, 'No regular (non-GitOps) projects found').toBeTruthy();
await page.goto(`/projects/${regularProject!.id}`);
await page.waitForLoadState('load');
@@ -1262,7 +1211,9 @@ test.describe('GitOps Managed Project', () => {
test.describe('Project Detail Page', () => {
test('should navigate back to projects by default', async ({ page }) => {
- test.skip(!realProjects.length, 'No projects available for back navigation test');
+ expect(realProjects.length, 'No projects available for back navigation test').toBeGreaterThan(
+ 0
+ );
const firstProject = realProjects[0];
await page.goto(`/projects/${firstProject.id || firstProject.name}`);
@@ -1277,7 +1228,7 @@ test.describe('Project Detail Page', () => {
});
test('should display project details for existing project', async ({ page }) => {
- test.skip(!realProjects.length, 'No projects available for detail page test');
+ expect(realProjects.length, 'No projects available for detail page test').toBeGreaterThan(0);
const firstProject = realProjects[0];
await page.goto(`/projects/${firstProject.id || firstProject.name}`);
@@ -1296,7 +1247,7 @@ test.describe('Project Detail Page', () => {
});
test('should display tabs navigation', async ({ page }) => {
- test.skip(!realProjects.length, 'No projects available for navigation test');
+ expect(realProjects.length, 'No projects available for navigation test').toBeGreaterThan(0);
const firstProject = realProjects[0];
await page.goto(`/projects/${firstProject.id || firstProject.name}`);
await page.waitForLoadState('load');
@@ -1311,28 +1262,29 @@ test.describe('Project Detail Page', () => {
await expect(page.getByRole('tab', { name: 'Logs', exact: true })).toHaveCount(0);
});
- test('should check updates for the current project via the image batch endpoint', async ({
- page
- }) => {
- const projectWithServices = await findProjectWithDetailUpdateAction(page);
- test.skip(
- !projectWithServices,
- 'No project with detail-page update action available for project update check test'
+ test('should check updates for the current project without deploying it', async ({ page }) => {
+ const projectName = `test-project-update-check-${Date.now()}`;
+ const projectID = await createProjectViaUI(page, projectName);
+ const project = await readApiData<Project>(
+ await page.request.get(`/api/environments/0/projects/${projectID}/updates`),
+ `Get project ${projectID} update metadata`
);
+ expect(
+ project.updateInfo?.imageRefs?.length,
+ 'Created project must expose its configured image'
+ ).toBeGreaterThan(0);
- let batchRequests = 0;
+ let checkRequests = 0;
let updaterRunRequests = 0;
- await page.route('**/api/environments/*/image-updates/check-batch', async (route) => {
- batchRequests += 1;
- const body = route.request().postDataJSON() as { imageRefs?: string[] } | null;
- expect(Array.isArray(body?.imageRefs)).toBe(true);
- expect((body?.imageRefs?.length ?? 0) > 0).toBe(true);
-
+ await page.route(`**/api/environments/*/updater/projects/${projectID}/check`, async (route) => {
+ checkRequests += 1;
+ expect(route.request().method()).toBe('POST');
+ expect(route.request().postDataJSON()).toEqual({});
await route.fulfill({
status: 200,
contentType: 'application/json',
- body: JSON.stringify({ success: true, data: {} })
+ body: JSON.stringify({ success: true, data: project.updateInfo })
});
});
@@ -1345,18 +1297,18 @@ test.describe('Project Detail Page', () => {
});
});
- await page.goto(`/projects/${projectWithServices!.id || projectWithServices!.name}`);
+ await page.goto(`/projects/${projectID}`);
await page.waitForLoadState('load');
const clicked = await clickProjectDetailUpdateAction(page);
- test.skip(!clicked, 'Current project detail view has no clickable update action');
+ expect(clicked, 'Current project detail view has no clickable update action').toBeTruthy();
- await expect.poll(() => batchRequests).toBe(1);
+ await expect.poll(() => checkRequests).toBe(1);
expect(updaterRunRequests).toBe(0);
});
test('should display services tab content', async ({ page }) => {
- test.skip(!realProjects.length, 'No projects available for services test');
+ expect(realProjects.length, 'No projects available for services test').toBeGreaterThan(0);
const projectWithServices =
realProjects.find((p) => (p.serviceCount ?? 0) > 0) ?? realProjects[0]!;
@@ -1373,20 +1325,11 @@ test.describe('Project Detail Page', () => {
const nginxService = page.getByRole('heading', { name: 'nginx', exact: true });
const emptyState = page.getByText('No services found for this project', { exact: true });
- if ((await nginxService.count()) > 0) {
- await expect(nginxService.first()).toBeVisible();
- } else {
- const anyServiceBadge = page
- .getByText('Running', { exact: true })
- .or(page.getByText('Stopped', { exact: true }))
- .or(page.getByText('Unknown', { exact: true }))
- .first();
- if ((await anyServiceBadge.count()) > 0) {
- await expect(anyServiceBadge).toBeVisible();
- } else {
- await expect(emptyState).toBeVisible();
- }
- }
+ const serviceStatus = page
+ .getByText('Running', { exact: true })
+ .or(page.getByText('Stopped', { exact: true }))
+ .or(page.getByText('Unknown', { exact: true }));
+ await expect(nginxService.or(serviceStatus).or(emptyState).first()).toBeVisible();
});
test('should display the configured service port host IP', async ({ page }) => {
@@ -1423,13 +1366,13 @@ test.describe('Project Detail Page', () => {
if (projectId) {
await destroyProjectByIdViaAPI(page, projectId);
} else {
- await destroyProjectByNameViaUI(page, projectName);
+ await destroyProjectByNameViaAPI(page, projectName);
}
}
});
test('should display configuration editors', async ({ page }) => {
- test.skip(!realProjects.length, 'No projects available for configuration test');
+ expect(realProjects.length, 'No projects available for configuration test').toBeGreaterThan(0);
const firstProject = realProjects[0];
await page.goto(`/projects/${firstProject.id || firstProject.name}`);
@@ -1443,7 +1386,8 @@ test.describe('Project Detail Page', () => {
// - tree view (default when the project has extra files): file list on the
// left and a tabbed code panel on the right
const workspaceFilesLabel = page.getByText('Workspace Files', { exact: true });
- const isTreeView = await workspaceFilesLabel.isVisible().catch(() => false);
+ await expect(page.locator('.cm-editor').filter({ visible: true }).first()).toBeVisible();
+ const isTreeView = await workspaceFilesLabel.isVisible();
if (isTreeView) {
const composeFileButton = page.getByRole('button', { name: 'compose.yaml' }).first();
@@ -1469,7 +1413,8 @@ test.describe('Project Detail Page', () => {
name: 'Toggle workspace mode',
exact: true
});
- if (await layoutSwitch.count()) {
+ await expect(layoutSwitch).toBeVisible();
+ {
await layoutSwitch.click();
await expect(workspaceFilesLabel).toBeVisible();
@@ -1487,8 +1432,11 @@ test.describe('Project Detail Page', () => {
test('should apply the account default project editor layout', async ({ page }) => {
const regularProject = realProjects.find((p) => !p.gitOpsManagedBy);
- test.skip(!regularProject, 'No regular (non-GitOps) projects found');
+ expect(regularProject, 'No regular (non-GitOps) projects found').toBeTruthy();
+ const originalUser = await readApiData<{
+ preferences?: { defaultProjectEditorLayout?: 'auto' | 'classic' | 'tree' };
+ }>(await page.request.get('/api/auth/me'), 'Get original editor preference');
const setDefaultLayout = async (layout: 'auto' | 'classic' | 'tree') => {
const response = await page.request.put('/api/auth/me/profile', {
data: { preferences: { defaultProjectEditorLayout: layout } }
@@ -1522,7 +1470,7 @@ test.describe('Project Detail Page', () => {
await expect(page.getByRole('heading', { name: 'Docker Compose File' })).toBeVisible();
await expect(workspaceFilesLabel).not.toBeVisible();
} finally {
- await setDefaultLayout('auto');
+ await setDefaultLayout(originalUser.preferences?.defaultProjectEditorLayout ?? 'auto');
}
});
@@ -1530,7 +1478,7 @@ test.describe('Project Detail Page', () => {
page
}) => {
const regularProject = realProjects.find((p) => !p.gitOpsManagedBy);
- test.skip(!regularProject, 'No regular (non-GitOps) projects found');
+ expect(regularProject, 'No regular (non-GitOps) projects found').toBeTruthy();
await page.goto(`/projects/${regularProject!.id || regularProject!.name}`);
await page.waitForLoadState('load');
@@ -1543,14 +1491,12 @@ test.describe('Project Detail Page', () => {
name: 'Toggle workspace mode',
exact: true
});
- test.skip(
- (await layoutSwitch.count()) === 0,
- 'No layout switch available for project configuration'
- );
+ await expect(layoutSwitch).toBeVisible();
const workspaceFilesLabel = page.getByText('Workspace Files', { exact: true });
- if (!(await workspaceFilesLabel.isVisible().catch(() => false))) {
+ await expect(page.locator('.cm-editor').filter({ visible: true }).first()).toBeVisible();
+ if (!(await workspaceFilesLabel.isVisible())) {
await layoutSwitch.click();
await expect(workspaceFilesLabel).toBeVisible();
}
@@ -1631,7 +1577,8 @@ test.describe('Project Detail Page', () => {
name: 'Toggle workspace mode',
exact: true
});
- if (await layoutSwitch.count()) {
+ await expect(layoutSwitch).toBeVisible();
+ {
await layoutSwitch.click();
await expect(page.locator('.cm-editor').filter({ visible: true }).first()).toBeVisible();
@@ -1663,7 +1610,7 @@ test.describe('Project Detail Page', () => {
})
.toContain(marker);
} finally {
- await destroyCurrentProjectViaUI(page);
+ await destroyProjectByNameViaAPI(page, projectName);
}
});
@@ -1722,7 +1669,7 @@ test.describe('Project Detail Page', () => {
socketsAfterStop
);
} finally {
- await destroyProjectByIdViaAPI(page, projectId || getProjectIdFromPageUrl(page.url()));
+ await destroyProjectByNameViaAPI(page, projectName);
}
});
@@ -1764,7 +1711,10 @@ test.describe('Project Detail Page', () => {
});
test('should surface a project log stream connection failure inline', async ({ page }) => {
- test.skip(!realProjects.length, 'No projects available for log stream failure test');
+ expect(
+ realProjects.length,
+ 'No projects available for log stream failure test'
+ ).toBeGreaterThan(0);
const targetProject = realProjects[0];
await page.routeWebSocket('**/api/environments/*/ws/projects/*/logs**', (ws) => {
diff --git a/tests/spec/rbac.spec.ts b/tests/spec/rbac.spec.ts
index dd6e719d1..3113138ac 100644
--- a/tests/spec/rbac.spec.ts
+++ b/tests/spec/rbac.spec.ts
@@ -7,7 +7,7 @@ import {
type Page,
type Request
} from '../fixtures/test.fixture';
-import { readApiData } from '../utils/fetch.util';
+import { removeApiResource, readApiData } from '../utils/fetch.util';
import { openRowActionsMenu } from '../utils/table-actions.util';
type TestRole = {
@@ -615,18 +615,18 @@ test('administers scoped identities and enforces their browser access immediatel
await noAccessContext?.close();
if (restrictedUser) {
- await page.request.delete(`/api/users/${restrictedUser.id}`).catch(() => undefined);
+ await removeApiResource(page, `/api/users/${restrictedUser.id}`);
}
if (noAccessUser) {
- await page.request.delete(`/api/users/${noAccessUser.id}`).catch(() => undefined);
+ await removeApiResource(page, `/api/users/${noAccessUser.id}`);
}
for (const role of [clonedRole, localRole, remoteRole]) {
if (role) {
- await page.request.delete(`/api/roles/${role.id}`).catch(() => undefined);
+ await removeApiResource(page, `/api/roles/${role.id}`);
}
}
if (remoteEnvironment) {
- await page.request.delete(`/api/environments/${remoteEnvironment.id}`).catch(() => undefined);
+ await removeApiResource(page, `/api/environments/${remoteEnvironment.id}`);
}
}
});
diff --git a/tests/spec/registries.spec.ts b/tests/spec/registries.spec.ts
index 8a6ca74c3..9fa726bf5 100644
--- a/tests/spec/registries.spec.ts
+++ b/tests/spec/registries.spec.ts
@@ -1,3 +1,5 @@
+import { readApiData, removeApiResource } from '../utils/fetch.util';
+import { waitForDialogReady } from '../utils/playwright.util';
import { test, expect, type Page } from '../fixtures/test.fixture';
import { openRowActionsMenu } from '../utils/table-actions.util';
@@ -77,6 +79,11 @@ async function mockRegistryPullUsage(
}
test.describe('Container Registries', () => {
+ const registryIds = new Set<string>();
+ test.afterEach(async ({ page }) => {
+ for (const id of registryIds) await removeApiResource(page, `/api/container-registries/${id}`);
+ registryIds.clear();
+ });
test.beforeEach(async ({ page }) => {
await page.goto(route);
await page.waitForLoadState('load');
@@ -146,7 +153,7 @@ test.describe('Container Registries', () => {
// Create
await page.getByRole('button', { name: 'Add Registry' }).click();
const dialog = page.getByRole('dialog');
- await expect(dialog).toBeVisible();
+ await waitForDialogReady(dialog);
const url = `e2e.example.com-${Date.now()}`;
@@ -160,10 +167,18 @@ test.describe('Container Registries', () => {
// Optional description
const desc = dialog.getByLabel('Description', { exact: true });
- if (await desc.count()) await desc.fill('E2E test registry');
+ await desc.fill('E2E test registry');
+ const createdPromise = page.waitForResponse(
+ (response) =>
+ response.request().method() === 'POST' &&
+ new URL(response.url()).pathname === '/api/container-registries'
+ );
await dialog.getByRole('button', { name: 'Add Registry', exact: true }).click();
+ const created = await readApiData<{ id: string }>(await createdPromise, 'Create registry');
+ registryIds.add(created.id);
+
// Creation complete when dialog closes
await expect(dialog).toBeHidden({ timeout: 10000 });
@@ -180,29 +195,38 @@ test.describe('Container Registries', () => {
});
test('should open Remove Selected dialog and cancel (no mutation)', async ({ page }) => {
+ const registry = await readApiData<{ id: string }>(
+ await page.request.post('/api/container-registries', {
+ data: {
+ url: `e2e-select-${Date.now()}.example.com`,
+ username: 'e2e',
+ token: TOKEN,
+ description: '',
+ insecure: false,
+ enabled: true,
+ registryType: 'generic',
+ repositoryNames: [],
+ awsAccessKeyId: '',
+ awsSecretAccessKey: '',
+ awsRegion: ''
+ }
+ }),
+ 'Create registry selection fixture'
+ );
+ registryIds.add(registry.id);
+ await page.goto(route);
const firstRowCheckbox = page
.getByRole('row')
.filter({ has: page.getByRole('button', { name: 'Open menu', exact: true }) })
.getByRole('checkbox')
.first();
- if (await firstRowCheckbox.count()) {
- await firstRowCheckbox.check();
-
- const removeSelected = page.getByRole('button', {
- name: 'Remove Selected (1)',
- exact: true
- });
- if (await removeSelected.count()) {
- await removeSelected.click();
-
- const confirm = page.getByRole('dialog');
- await expect(
- confirm.getByRole('heading', { name: 'Remove 1 Registry(ies)', exact: true })
- ).toBeVisible();
-
- await page.getByRole('button', { name: 'Cancel' }).click();
- await expect(confirm).toBeHidden();
- }
- }
+ await firstRowCheckbox.check();
+ await page.getByRole('button', { name: 'Remove Selected (1)', exact: true }).click();
+ const confirm = page.getByRole('dialog');
+ await expect(
+ confirm.getByRole('heading', { name: 'Remove 1 Registry(ies)', exact: true })
+ ).toBeVisible();
+ await confirm.getByRole('button', { name: 'Cancel', exact: true }).click();
+ await expect(confirm).toBeHidden();
});
});
diff --git a/tests/spec/responsive-browser.spec.ts b/tests/spec/responsive-browser.spec.ts
index 4b1452574..b8d05d436 100644
--- a/tests/spec/responsive-browser.spec.ts
+++ b/tests/spec/responsive-browser.spec.ts
@@ -33,6 +33,12 @@ test('navigation matches the configured mobile or tablet viewport', async ({ pag
test('resource dialog stays usable in the configured viewport', async ({ page }) => {
await page.goto('/networks');
const createButton = page.getByRole('button', { name: 'Create Network', exact: true }).first();
+ await expect(
+ createButton
+ .or(page.getByRole('button', { name: 'More actions', exact: true }))
+ .filter({ visible: true })
+ .first()
+ ).toBeVisible();
if (await createButton.isVisible().catch(() => false)) {
await createButton.click();
} else {
diff --git a/tests/spec/s3-backups.spec.ts b/tests/spec/s3-backups.spec.ts
index 06e6830a0..ba540825d 100644
--- a/tests/spec/s3-backups.spec.ts
+++ b/tests/spec/s3-backups.spec.ts
@@ -1,3 +1,4 @@
+import { removeApiResource, readApiData } from '../utils/fetch.util';
import { test, expect, type Page } from '../fixtures/test.fixture';
import { openRowActionsMenu } from '../utils/table-actions.util';
@@ -50,7 +51,7 @@ async function createDestinationViaApi(
}
async function deleteDestinationViaApi(page: Page, destinationId: string) {
- await page.request.delete(`/api/backups/s3/${destinationId}`).catch(() => undefined);
+ await removeApiResource(page, `/api/backups/s3/${destinationId}`);
}
async function createVolumeViaApi(page: Page, volumeName: string) {
@@ -63,9 +64,10 @@ async function createVolumeViaApi(page: Page, volumeName: string) {
}
async function removeVolumeViaApi(page: Page, volumeName: string) {
- await page.request
- .delete(`/api/environments/0/volumes/${encodeURIComponent(volumeName)}?force=true`)
- .catch(() => undefined);
+ await removeApiResource(
+ page,
+ `/api/environments/0/volumes/${encodeURIComponent(volumeName)}?force=true`
+ );
}
async function getVolumeWorkspaceRevision(page: Page, volumeName: string) {
@@ -111,23 +113,18 @@ async function readVolumeFile(page: Page, volumeName: string, filePath: string)
const response = await page.request.get(
`/api/environments/0/volumes/${encodeURIComponent(volumeName)}/workspace/file?relativePath=${encodeURIComponent(relativePath)}`
);
- if (!response.ok()) {
- return null;
- }
- const body = await response.json();
- const content = body?.data?.content;
- return typeof content === 'string' ? content : null;
+ const data = await readApiData<{ content: string }>(response, `Read volume file ${filePath}`);
+ expect(typeof data.content).toBe('string');
+ return data.content;
}
async function listBackups(page: Page, volumeName: string): Promise<BackupEntry[]> {
- const response = await page.request.get(
- `/api/environments/0/volumes/${encodeURIComponent(volumeName)}/backups`
+ const backups = await readApiData<BackupEntry[]>(
+ await page.request.get(`/api/environments/0/volumes/${encodeURIComponent(volumeName)}/backups`),
+ `List backups for ${volumeName}`
);
- if (!response.ok()) {
- return [];
- }
- const body = await response.json();
- return (body?.data ?? []) as BackupEntry[];
+ expect(Array.isArray(backups)).toBe(true);
+ return backups;
}
// Backups run Rustic in a helper container, so the request returns before the
@@ -353,9 +350,7 @@ test.describe('S3 Backups', () => {
expect(await readVolumeFile(page, volumeName, '/payload.txt')).toBe(fileContent);
} finally {
if (backupId) {
- await page.request
- .delete(`/api/environments/0/volumes/backups/${backupId}`)
- .catch(() => undefined);
+ await removeApiResource(page, `/api/environments/0/volumes/backups/${backupId}`);
}
await removeVolumeViaApi(page, volumeName);
await deleteDestinationViaApi(page, destination.id);
@@ -383,7 +378,10 @@ test.describe('S3 Backups', () => {
const blocked = await page.request.delete(`/api/backups/s3/${destination.id}`);
expect(blocked.status()).toBe(409);
- await page.request.delete(`/api/environments/0/volumes/backups/${created.id}`);
+ const removed = await page.request.delete(
+ `/api/environments/0/volumes/backups/${created.id}`
+ );
+ expect(removed.ok(), await removed.text()).toBe(true);
backupId = undefined;
const remoteEnvironments = await countRemoteEnvironments(page);
@@ -397,9 +395,7 @@ test.describe('S3 Backups', () => {
}
} finally {
if (backupId) {
- await page.request
- .delete(`/api/environments/0/volumes/backups/${backupId}`)
- .catch(() => undefined);
+ await removeApiResource(page, `/api/environments/0/volumes/backups/${backupId}`);
}
await removeVolumeViaApi(page, volumeName);
await deleteDestinationViaApi(page, destination.id);
diff --git a/tests/spec/security.spec.ts b/tests/spec/security.spec.ts
index e003c10e1..9b7ce13bc 100644
--- a/tests/spec/security.spec.ts
+++ b/tests/spec/security.spec.ts
@@ -72,13 +72,13 @@ function exportButton(page: Page) {
return page.getByRole('button', { name: /Export CSV/ });
}
-async function exportCsv(page: Page) {
+async function exportCsv(page: Page, testInfo: { outputPath(name: string): string }) {
const downloadPromise = page.waitForEvent('download');
await exportButton(page).click();
const download = await downloadPromise;
expect(download.suggestedFilename()).toBe(EXPORT_FILENAME);
- const path = await download.path();
- if (!path) throw new Error('Download did not produce a file');
+ const path = testInfo.outputPath(EXPORT_FILENAME);
+ await download.saveAs(path);
return readFile(path, 'utf8');
}
@@ -260,7 +260,7 @@ test.describe('Security Page', () => {
test('exports every matching vulnerability from any page through the backend', async ({
page
- }) => {
+ }, testInfo) => {
const image = 'example/security:latest';
const rows = ['CVE-2026-0001', 'CVE-2026-0002', 'CVE-2026-0003', 'CVE-2026-0004'].map(
(vulnerabilityId) => ({
@@ -337,7 +337,7 @@ test.describe('Security Page', () => {
await expect(page.getByRole('row').filter({ hasText: 'CVE-2026-0003' })).toBeVisible();
const listRequestsBeforeExport = listRequests.length;
- const content = await exportCsv(page);
+ const content = await exportCsv(page, testInfo);
expect(content).toBe(EXPORT_BODY);
expect(exportRequests).toHaveLength(1);
@@ -355,7 +355,9 @@ test.describe('Security Page', () => {
expect(listRequests).toHaveLength(listRequestsBeforeExport);
});
- test('exports only ignored vulnerabilities when the ignored switch is on', async ({ page }) => {
+ test('exports only ignored vulnerabilities when the ignored switch is on', async ({
+ page
+ }, testInfo) => {
let exportRequest: URLSearchParams | undefined;
await mockSecurityPageData(page, []);
@@ -374,13 +376,15 @@ test.describe('Security Page', () => {
await page.getByRole('switch', { name: 'Show ignored' }).click();
await ignoredResponse;
- await exportCsv(page);
+ await exportCsv(page, testInfo);
expect(exportRequest?.get('ignored')).toBe('true');
expect(exportRequest?.has('start')).toBe(false);
expect(exportRequest?.has('limit')).toBe(false);
});
- test('blocks duplicate exports and recovers after a failed export', async ({ page }) => {
+ test('blocks duplicate exports and recovers after a failed export', async ({
+ page
+ }, testInfo) => {
let exportRequests = 0;
let mode: 'hold' | 'fail' | 'ok' = 'hold';
let releaseExport = () => {};
@@ -421,7 +425,7 @@ test.describe('Security Page', () => {
await expect(button).toBeEnabled();
mode = 'ok';
- await exportCsv(page);
+ await exportCsv(page, testInfo);
});
test('discards an export that finishes after switching environments', async ({ page }) => {
@@ -503,8 +507,9 @@ test.describe('Security Page', () => {
page.getByRole('button').filter({ hasText: remoteEnvironment.name }).first()
).toBeVisible();
+ const downloadPromise = page.waitForEvent('download', { timeout: 1500 }).catch(() => null);
releaseExport();
- const download = await page.waitForEvent('download', { timeout: 1500 }).catch(() => null);
+ const download = await downloadPromise;
expect(download).toBeNull();
await expect(page.getByText('Failed to export vulnerabilities', { exact: true })).toHaveCount(
0
diff --git a/tests/spec/settings-notifications.spec.ts b/tests/spec/settings-notifications.spec.ts
index ebd814159..ef269de6b 100644
--- a/tests/spec/settings-notifications.spec.ts
+++ b/tests/spec/settings-notifications.spec.ts
@@ -222,9 +222,7 @@ test.describe('Notification settings', () => {
// Handle Save & Test if needed
const saveAndTestButton = page.getByRole('button', { name: 'Save & Test', exact: true });
- if (await saveAndTestButton.isVisible().catch(() => false)) {
- await saveAndTestButton.click();
- }
+ await saveAndTestButton.click();
await expect.poll(wasTestEndpointCalled, { timeout: 10_000 }).toBe(true);
getErrorCheck();
@@ -244,9 +242,7 @@ test.describe('Notification settings', () => {
await page.getByRole('menuitem', { name: 'Simple', exact: true }).click();
const saveAndTestButton = page.getByRole('button', { name: 'Save & Test', exact: true });
- if (await saveAndTestButton.isVisible().catch(() => false)) {
- await saveAndTestButton.click();
- }
+ await saveAndTestButton.click();
await expect.poll(wasTestEndpointCalled, { timeout: 10_000 }).toBe(true);
getErrorCheck();
@@ -267,9 +263,7 @@ test.describe('Notification settings', () => {
await page.getByRole('menuitem', { name: 'Simple', exact: true }).click();
const saveAndTestButton = page.getByRole('button', { name: 'Save & Test', exact: true });
- if (await saveAndTestButton.isVisible().catch(() => false)) {
- await saveAndTestButton.click();
- }
+ await saveAndTestButton.click();
await expect.poll(wasTestEndpointCalled, { timeout: 10_000 }).toBe(true);
getErrorCheck();
@@ -291,9 +285,7 @@ test.describe('Notification settings', () => {
await page.getByRole('menuitem', { name: 'Simple', exact: true }).click();
const saveAndTestButton = page.getByRole('button', { name: 'Save & Test', exact: true });
- if (await saveAndTestButton.isVisible().catch(() => false)) {
- await saveAndTestButton.click();
- }
+ await saveAndTestButton.click();
await expect.poll(wasTestEndpointCalled, { timeout: 10_000 }).toBe(true);
getErrorCheck();
@@ -428,9 +420,7 @@ test.describe('Notification settings', () => {
await page.getByRole('menuitem', { name: 'Simple', exact: true }).click();
const saveAndTestButton = page.getByRole('button', { name: 'Save & Test', exact: true });
- if (await saveAndTestButton.isVisible().catch(() => false)) {
- await saveAndTestButton.click();
- }
+ await saveAndTestButton.click();
await expect.poll(wasTestEndpointCalled, { timeout: 10_000 }).toBe(true);
getErrorCheck();
@@ -451,9 +441,7 @@ test.describe('Notification settings', () => {
await page.getByRole('menuitem', { name: 'Simple', exact: true }).click();
const saveAndTestButton = page.getByRole('button', { name: 'Save & Test', exact: true });
- if (await saveAndTestButton.isVisible().catch(() => false)) {
- await saveAndTestButton.click();
- }
+ await saveAndTestButton.click();
await expect.poll(wasTestEndpointCalled, { timeout: 10_000 }).toBe(true);
getErrorCheck();
@@ -499,9 +487,7 @@ test.describe('Notification settings', () => {
await page.getByRole('menuitem', { name: 'Simple', exact: true }).click();
const saveAndTestButton = page.getByRole('button', { name: 'Save & Test', exact: true });
- if (await saveAndTestButton.isVisible().catch(() => false)) {
- await saveAndTestButton.click();
- }
+ await saveAndTestButton.click();
await expect.poll(wasTestEndpointCalled, { timeout: 10_000 }).toBe(true);
getErrorCheck();
diff --git a/tests/spec/system-upgrade.spec.ts b/tests/spec/system-upgrade.spec.ts
index 59a9b40bc..b623abc75 100644
--- a/tests/spec/system-upgrade.spec.ts
+++ b/tests/spec/system-upgrade.spec.ts
@@ -173,6 +173,7 @@ test.describe('Update All startup', () => {
test('a 409 conflict without an active job reports the conflict and does not retry', async ({
page
}) => {
+ await page.clock.install();
let startCalls = 0;
let statusCalls = 0;
await page.route(/\/api\/environments\/0\/system\/upgrade\/all$/, async (route) => {
@@ -199,7 +200,7 @@ test.describe('Update All startup', () => {
// Wait past one poll interval to prove neither polling nor a retry kicked in.
// The three status reads are the persistence-window grace, not polling.
- await page.waitForTimeout(4_000);
+ await page.clock.runFor(4_000);
expect(startCalls).toBe(1);
expect(statusCalls).toBe(3);
});
@@ -236,6 +237,7 @@ test.describe('Update All startup', () => {
});
test('closing the dialog during a pending start ignores the late response', async ({ page }) => {
+ await page.clock.install();
let releaseStart!: () => void;
const startReleased = new Promise<void>((resolve) => {
releaseStart = resolve;
@@ -260,7 +262,7 @@ test.describe('Update All startup', () => {
// The start response arrives after closure: it must not reopen or start polling.
releaseStart();
- await page.waitForTimeout(4_000);
+ await page.clock.runFor(4_000);
await expect(dialog).toBeHidden();
expect(statusCalls).toBe(0);
await expect(page.locator('li[data-sonner-toast]')).toHaveCount(0);
@@ -395,6 +397,7 @@ test.describe('Manager self-update recovery', () => {
});
test('status and activity 401s share one refresh before the upgrade reload', async ({ page }) => {
+ await page.clock.install();
await registerReloadCounter(page);
await registerTokenSeeding(page);
@@ -435,9 +438,13 @@ test.describe('Manager self-update recovery', () => {
});
let refreshCalls = 0;
+ let releaseRefresh!: () => void;
+ const refreshReleased = new Promise<void>((resolve) => {
+ releaseRefresh = resolve;
+ });
await page.route(/\/api\/auth\/refresh$/, async (route) => {
refreshCalls++;
- await new Promise((resolve) => setTimeout(resolve, 3500));
+ await refreshReleased;
await route.fulfill({
status: 200,
headers: {
@@ -459,6 +466,10 @@ test.describe('Manager self-update recovery', () => {
await fulfillJob(route, 'running', 'updating');
});
await page.route(/\/api\/environments\/0\/system\/upgrade\/all\/status$/, async (route) => {
+ if (route.request().headers()['cookie']?.includes(REFRESH_COOKIE)) {
+ await fulfillJob(route, 'completed', 'updated');
+ return;
+ }
await route.fulfill({
status: 401,
contentType: 'application/json',
@@ -466,13 +477,33 @@ test.describe('Manager self-update recovery', () => {
});
});
- await page.goto('/environments');
- await openAndConfirmUpdateAll(page);
- releaseActivity();
-
- await expect.poll(() => currentReloadCount(page), { timeout: 15_000 }).toBe(2);
- expect(refreshCalls).toBe(1);
- await expect(page).toHaveURL('/environments');
+ try {
+ await page.goto('/environments');
+ const statusUnauthorized = page.waitForResponse((response) => {
+ return (
+ new URL(response.url()).pathname === '/api/environments/0/system/upgrade/all/status' &&
+ response.status() === 401
+ );
+ });
+ await openAndConfirmUpdateAll(page);
+ releaseActivity();
+ await expect.poll(() => refreshCalls).toBe(1);
+ await page.clock.runFor(3500);
+ const statusResponse = await statusUnauthorized;
+ await statusResponse.finished();
+ // Queue this after the response event so its 401 handler has joined the
+ // in-flight refresh before that refresh is released.
+ await page.evaluate(() => undefined);
+ expect(refreshCalls).toBe(1);
+ releaseRefresh();
+
+ await expect.poll(() => currentReloadCount(page), { timeout: 15_000 }).toBe(2);
+ expect(refreshCalls).toBe(1);
+ await expect(page).toHaveURL('/environments');
+ } finally {
+ releaseActivity();
+ releaseRefresh();
+ }
});
test('a transient refresh failure keeps the token and recovers on the next poll', async ({
diff --git a/tests/spec/system-volume-backups.spec.ts b/tests/spec/system-volume-backups.spec.ts
index 28cf54e9f..6c8ebf314 100644
--- a/tests/spec/system-volume-backups.spec.ts
+++ b/tests/spec/system-volume-backups.spec.ts
@@ -1,3 +1,4 @@
+import { removeApiResource } from '../utils/fetch.util';
import { expect, test, type Page } from '../fixtures/test.fixture';
import type { Activity } from '../../frontend/src/lib/types/activity.type';
@@ -81,9 +82,10 @@ async function createVolumeViaApi(page: Page, volumeName: string) {
}
async function removeVolumeViaApi(page: Page, volumeName: string) {
- await page.request
- .delete(`/api/environments/0/volumes/${encodeURIComponent(volumeName)}?force=true`)
- .catch(() => undefined);
+ await removeApiResource(
+ page,
+ `/api/environments/0/volumes/${encodeURIComponent(volumeName)}?force=true`
+ );
}
async function mockSystemBackupPage(
diff --git a/tests/spec/token-refresh.spec.ts b/tests/spec/token-refresh.spec.ts
index 1b92d2c76..979ee98cc 100644
--- a/tests/spec/token-refresh.spec.ts
+++ b/tests/spec/token-refresh.spec.ts
@@ -59,13 +59,10 @@ async function injectExpired401Always(page: Page, urlPattern: string | RegExp) {
* Mock /auth/refresh to return a synthetic 200 and browser cookie. Returns a
* getter to assert how many refresh requests were made.
*/
-async function mockRefreshSuccess(page: Page, delayMs = 0): Promise<() => number> {
+async function mockRefreshSuccess(page: Page): Promise<() => number> {
let callCount = 0;
await page.route(/\/api\/auth\/refresh$/, async (route) => {
callCount++;
- if (delayMs > 0) {
- await new Promise((resolve) => setTimeout(resolve, delayMs));
- }
await route.fulfill({
status: 200,
headers: {
@@ -110,7 +107,11 @@ test('signed-in OIDC callbacks reach the callback exchange', async ({ page }) =>
test.describe('Token refresh behaviour', () => {
test('@cross-browser shows useful login errors and accepts the configured admin password', async ({
page
- }) => {
+ }, testInfo) => {
+ // Keep each browser's login attempts in its own rate-limit bucket.
+ await page.setExtraHTTPHeaders({
+ 'X-Forwarded-For': testInfo.project.name === 'firefox' ? '198.18.0.2' : '198.18.0.3'
+ });
await page.context().clearCookies();
let gatewayFailurePending = true;
await page.route(/\/api\/auth\/login$/, async (route) => {
diff --git a/tests/spec/volumes.spec.ts b/tests/spec/volumes.spec.ts
index 07a1d5e08..2b50a888a 100644
--- a/tests/spec/volumes.spec.ts
+++ b/tests/spec/volumes.spec.ts
@@ -1,5 +1,6 @@
+import { waitForDialogReady } from '../utils/playwright.util';
import { test, expect, type Page } from '../fixtures/test.fixture';
-import { fetchVolumeCountsWithRetry } from '../utils/fetch.util';
+import { removeApiResource, fetchVolumeCountsWithRetry } from '../utils/fetch.util';
import { VolumeUsageCounts } from 'types/volumes.type';
import { openRowActionsMenu } from '../utils/table-actions.util';
@@ -16,6 +17,12 @@ async function openCreateVolumeSheet(page: Page) {
await expect(page.getByRole('heading', { name: 'Volumes', level: 1 })).toBeVisible();
const createButton = page.getByRole('button', { name: 'Create Volume' }).first();
+ await expect(
+ createButton
+ .or(page.getByRole('button', { name: 'More actions', exact: true }))
+ .filter({ visible: true })
+ .first()
+ ).toBeVisible();
if (await createButton.isVisible().catch(() => false)) {
await createButton.click();
} else {
@@ -25,7 +32,7 @@ async function openCreateVolumeSheet(page: Page) {
await page.getByRole('menuitem', { name: 'Create Volume', exact: true }).click();
}
- await expect(page.getByRole('dialog')).toBeVisible();
+ await waitForDialogReady(page.getByRole('dialog'));
}
async function createVolumeViaUI(page: Page, volumeName: string) {
@@ -68,9 +75,7 @@ async function createVolumeViaApi(page: Page, volumeName: string) {
}
async function removeVolumeViaApi(page: Page, volumeName: string) {
- await page.request
- .delete(`/api/environments/0/volumes/${encodeURIComponent(volumeName)}`)
- .catch(() => undefined);
+ await removeApiResource(page, `/api/environments/0/volumes/${encodeURIComponent(volumeName)}`);
}
async function gotoVolumeDetail(page: Page, volumeName: string) {
@@ -100,8 +105,7 @@ async function ensureFacetOpen(page: Page, title: string) {
const trigger = page.getByTestId(triggerId).first();
const content = page.getByTestId(contentId).first();
- if (await content.isVisible().catch(() => false)) return { trigger, content };
-
+ await expect(trigger).toBeVisible();
if ((await trigger.getAttribute('data-state')) !== 'open') await trigger.click();
await content.waitFor({ state: 'visible' });
return { trigger, content };
@@ -272,6 +276,7 @@ test.describe('Volumes Page', () => {
const dialog = page.getByRole('dialog');
await expect(dialog).toBeVisible();
+ await waitForDialogReady(dialog);
await dialog.getByLabel('New volume name').fill(targetName);
const renameRequest = page.waitForResponse((response) => {
diff --git a/tests/utils/auth.util.ts b/tests/utils/auth.util.ts
index 813db8e51..7a96fdf13 100644
--- a/tests/utils/auth.util.ts
+++ b/tests/utils/auth.util.ts
@@ -1,4 +1,6 @@
import { expect, type Page } from '@playwright/test';
+import { readApiData } from './fetch.util';
+import { waitForDialogReady } from './playwright.util';
const DEFAULT_PASSWORD = 'arcane-admin';
const TEST_PASSWORD = 'Test-password-123';
@@ -9,19 +11,22 @@ async function login(page: Page): Promise<string> {
for (const password of [DEFAULT_PASSWORD, TEST_PASSWORD]) {
await page.getByLabel('Password').fill(password);
+ const responsePromise = page.waitForResponse(
+ (response) =>
+ response.request().method() === 'POST' &&
+ new URL(response.url()).pathname === '/api/auth/login'
+ );
await page.getByRole('button', { name: 'Sign in to Arcane', exact: true }).click();
-
- try {
- await page.waitForURL('/dashboard', { timeout: 5000 });
- return password;
- } catch {
- const invalidCredentialsAlert = page
- .getByRole('alert')
- .filter({ hasText: 'Invalid username or password' });
- if (await invalidCredentialsAlert.isVisible().catch(() => false)) {
- continue;
- }
+ const response = await responsePromise;
+ if (response.status() === 401) {
+ await expect(
+ page.getByRole('alert').filter({ hasText: 'Invalid username or password' })
+ ).toBeVisible();
+ continue;
}
+ expect(response.ok(), `Login failed: ${response.status()}`).toBe(true);
+ await page.waitForURL('/dashboard');
+ return password;
}
throw new Error('Unable to authenticate with known E2E credentials');
@@ -30,11 +35,13 @@ async function login(page: Page): Promise<string> {
async function changeDefaultPassword(page: Page, currentPassword: string, newPassword: string) {
const dialog = page.getByRole('dialog', { name: 'Change Default Password' });
- if (!(await dialog.isVisible().catch(() => false))) {
- return;
- }
+ const user = await readApiData<{ requiresPasswordChange: boolean }>(
+ await page.request.get('/api/auth/me'),
+ 'Get current user'
+ );
+ if (!user.requiresPasswordChange) return;
- await dialog.waitFor({ state: 'visible' });
+ await waitForDialogReady(dialog);
await dialog.getByRole('textbox', { name: 'Current Password' }).fill(currentPassword);
await dialog.getByRole('textbox', { name: 'New Password', exact: true }).fill('abcdefgh');
await dialog.getByRole('textbox', { name: 'Confirm New Password' }).fill('abcdefgh');
diff --git a/tests/utils/fetch.util.ts b/tests/utils/fetch.util.ts
index 4878a74dd..733d25a1e 100644
--- a/tests/utils/fetch.util.ts
+++ b/tests/utils/fetch.util.ts
@@ -1,4 +1,4 @@
-import type { Page } from '@playwright/test';
+import { expect, test, type APIRequestContext, type Page } from '@playwright/test';
import { ContainerSummary } from 'types/containers.type';
import { ImageUsageCounts } from 'types/image.type';
import { NetworkSummary, NetworkUsageCounts } from 'types/networks.type';
@@ -14,7 +14,10 @@ type JsonResponse = {
text(): Promise<string>;
};
-export async function readApiData<T>(response: JsonResponse, action: string): Promise<T> {
+async function readApiResponse<T>(
+ response: JsonResponse,
+ action: string
+): Promise<{ data: T; pagination?: { totalItems?: number } }> {
const responseText = await response.text();
let parsed: unknown;
@@ -29,11 +32,55 @@ export async function readApiData<T>(response: JsonResponse, action: string): Pr
}
const payload = parsed as { success?: boolean; data?: T };
- if (!response.ok() || payload.success === false || !('data' in payload)) {
+ if (
+ !response.ok() ||
+ payload.success === false ||
+ !('data' in payload) ||
+ payload.data === null ||
+ payload.data === undefined
+ ) {
throw new Error(`${action} failed with ${response.status()}: ${responseText}`);
}
- return payload.data as T;
+ return parsed as { data: T; pagination?: { totalItems?: number } };
+}
+
+export async function readApiData<T>(response: JsonResponse, action: string): Promise<T> {
+ return (await readApiResponse<T>(response, action)).data;
+}
+
+export async function readList<T>(response: JsonResponse, action: string): Promise<Paginated<T>> {
+ const payload = await readApiResponse<T[]>(response, action);
+ if (!Array.isArray(payload.data)) throw new Error(`${action} did not return a list`);
+ if (
+ payload.pagination !== undefined &&
+ (typeof payload.pagination !== 'object' ||
+ payload.pagination === null ||
+ !Number.isInteger(payload.pagination.totalItems) ||
+ Number(payload.pagination.totalItems) < 0)
+ ) {
+ throw new Error(`${action} returned invalid pagination`);
+ }
+ return { data: payload.data, pagination: payload.pagination };
+}
+
+async function readCounts<T>(
+ response: JsonResponse,
+ action: string,
+ keys: Array<keyof T>
+): Promise<T> {
+ const data = await readApiData<T>(response, action);
+ if (
+ typeof data !== 'object' ||
+ data === null ||
+ keys.some(
+ (key) =>
+ typeof data[key] !== 'number' || !Number.isInteger(data[key]) || Number(data[key]) < 0
+ )
+ ) {
+ throw new Error(`${action} returned invalid counts`);
+ }
+ return data;
}
async function retry<T>(fn: () => Promise<T>, maxRetries: number, delayMs = 1000): Promise<T> {
@@ -49,70 +96,94 @@ async function retry<T>(fn: () => Promise<T>, maxRetries: number, delayMs = 1000
}
}
-export async function fetchVolumesWithRetry(page: Page, maxRetries = 1): Promise<any[]> {
- return retry(async () => {
- const res = await page.request.get('/api/environments/0/volumes');
- const json = await res.json();
- return Array.isArray(json?.data) ? json.data : [];
- }, maxRetries);
+export async function fetchVolumesWithRetry(
+ page: Page,
+ maxRetries = 1
+): Promise<Record<string, unknown>[]> {
+ return retry(
+ async () =>
+ (
+ await readList<Record<string, unknown>>(
+ await page.request.get('/api/environments/0/volumes'),
+ 'List volumes'
+ )
+ ).data,
+ maxRetries
+ );
}
-export async function fetchVolumeCountsWithRetry(
+export async function fetchProjectsWithRetry(page: Page, maxRetries = 3): Promise<Project[]> {
+ return retry(
+ async () =>
+ (
+ await readList<Project>(
+ await page.request.get('/api/environments/0/projects'),
+ 'List projects'
+ )
+ ).data,
+ maxRetries
+ );
+}
+
+export async function fetchNetworksWithRetry(
page: Page,
maxRetries = 3
-): Promise<VolumeUsageCounts> {
+): Promise<NetworkSummary[]> {
return retry(
- async () => {
- const res = await page.request.get('/api/environments/0/volumes/counts');
- const json = await res.json().catch(() => null);
- // API returns { success: true, data: { inuse, unused, total } }
- const data = json?.data ?? { inuse: 0, unused: 0, total: 0 };
- return data as VolumeUsageCounts;
- },
- maxRetries,
- 800
+ async () =>
+ (
+ await readList<NetworkSummary>(
+ await page.request.get('/api/environments/0/networks'),
+ 'List networks'
+ )
+ ).data,
+ maxRetries
);
}
-const PROJECTS_ENDPOINT = '/api/environments/0/projects';
-export async function fetchProjectsWithRetry(page: Page, maxRetries = 3): Promise<Project[]> {
- return retry(async () => {
- const res = await page.request.get(PROJECTS_ENDPOINT);
- const body = await res.json().catch(() => null as any);
- if (Array.isArray(body)) return body;
- if (Array.isArray(body?.data)) return body.data;
- if (Array.isArray(body?.projects)) return body.projects;
- return [];
- }, maxRetries);
+export async function fetchImagesWithRetry(
+ page: Page,
+ maxRetries = 3
+): Promise<Record<string, unknown>[]> {
+ return retry(
+ async () =>
+ (
+ await readList<Record<string, unknown>>(
+ await page.request.get('/api/environments/0/images'),
+ 'List images'
+ )
+ ).data,
+ maxRetries
+ );
}
-export async function fetchProjectCountsWithRetry(
+export async function fetchVolumeCountsWithRetry(
page: Page,
maxRetries = 3
-): Promise<ProjectStatusCounts> {
+): Promise<VolumeUsageCounts> {
return retry(
- async () => {
- const res = await page.request.get('/api/environments/0/projects/counts');
- const json = await res.json().catch(() => null);
- const data = Array.isArray(json) ? json : (json?.data?.data ?? json?.data ?? []);
- return data as ProjectStatusCounts;
- },
+ async () =>
+ readCounts<VolumeUsageCounts>(
+ await page.request.get('/api/environments/0/volumes/counts'),
+ 'Get volumes counts',
+ ['inuse', 'unused', 'total']
+ ),
maxRetries,
800
);
}
-export async function fetchNetworksWithRetry(
+export async function fetchProjectCountsWithRetry(
page: Page,
maxRetries = 3
-): Promise<NetworkSummary[]> {
+): Promise<ProjectStatusCounts> {
return retry(
- async () => {
- const res = await page.request.get('/api/environments/0/networks');
- const json = await res.json().catch(() => null);
- const data = Array.isArray(json) ? json : (json?.data?.data ?? json?.data ?? []);
- return (data ?? []) as NetworkSummary[];
- },
+ async () =>
+ readCounts<ProjectStatusCounts>(
+ await page.request.get('/api/environments/0/projects/counts'),
+ 'Get projects counts',
+ ['runningProjects', 'stoppedProjects', 'totalProjects', 'archivedProjects']
+ ),
maxRetries,
800
);
@@ -123,38 +194,28 @@ export async function fetchNetworksCountsWithRetry(
maxRetries = 3
): Promise<NetworkUsageCounts> {
return retry(
- async () => {
- const res = await page.request.get('/api/environments/0/networks/counts');
- const json = await res.json().catch(() => null);
- // API returns { success: true, data: { inuse, unused, total } }
- const data = json?.data ?? { inuse: 0, unused: 0, total: 0 };
- return data as NetworkUsageCounts;
- },
+ async () =>
+ readCounts<NetworkUsageCounts>(
+ await page.request.get('/api/environments/0/networks/counts'),
+ 'Get networks counts',
+ ['inuse', 'unused', 'total']
+ ),
maxRetries,
800
);
}
-export async function fetchImagesWithRetry(page: Page, maxRetries = 3): Promise<any[]> {
- return retry(async () => {
- const res = await page.request.get('/api/environments/0/images');
- if (!res.ok()) throw new Error(`HTTP ${res.status()}`);
- const body = await res.json().catch(() => null as any);
- return Array.isArray(body?.data) ? body.data : [];
- }, maxRetries);
-}
-
export async function fetchImageCountsWithRetry(
page: Page,
maxRetries = 3
): Promise<ImageUsageCounts> {
return retry(
- async () => {
- const res = await page.request.get('/api/environments/0/images/counts');
- const json = await res.json().catch(() => null);
- const data = Array.isArray(json) ? json : (json?.data?.data ?? json?.data ?? []);
- return data as ImageUsageCounts;
- },
+ async () =>
+ readCounts<ImageUsageCounts>(
+ await page.request.get('/api/environments/0/images/counts'),
+ 'Get images counts',
+ ['imagesInuse', 'imagesUnused', 'totalImages', 'totalImageSize']
+ ),
maxRetries,
800
);
@@ -164,26 +225,71 @@ export async function fetchContainersWithRetry(
page: Page,
maxRetries = 3
): Promise<Paginated<ContainerSummary>> {
- return retry(async () => {
- const res = await page.request.get('/api/environments/0/containers');
- if (!res.ok()) throw new Error(`HTTP ${res.status()}`);
- const body = await res.json().catch(() => null as any);
- const data = Array.isArray(body?.data) ? (body.data as ContainerSummary[]) : [];
- const pagination = body?.pagination || { totalItems: data.length };
- return { data, pagination };
- }, maxRetries);
+ return retry(
+ async () =>
+ readList<ContainerSummary>(
+ await page.request.get('/api/environments/0/containers'),
+ 'List containers'
+ ),
+ maxRetries
+ );
}
export async function fetchApiKeysWithRetry(
page: Page,
maxRetries = 3
): Promise<Paginated<ApiKey>> {
- return retry(async () => {
- const res = await page.request.get('/api/api-keys');
- if (!res.ok()) throw new Error(`HTTP ${res.status()}`);
- const body = await res.json().catch(() => null as any);
- const data = Array.isArray(body?.data) ? (body.data as ApiKey[]) : [];
- const pagination = body?.pagination || { totalItems: data.length };
- return { data, pagination };
- }, maxRetries);
+ return retry(
+ async () => readList<ApiKey>(await page.request.get('/api/api-keys'), 'List apikeys'),
+ maxRetries
+ );
+}
+
+export async function removeApiResource(
+ page: Page,
+ path: string,
+ options?: Parameters<APIRequestContext['delete']>[1]
+) {
+ try {
+ const resourcePath = path.split('?')[0];
+ const asynchronous =
+ /\/projects\/[^/]+\/destroy$/.test(resourcePath) || /\/containers\/[^/]+$/.test(resourcePath);
+ if (
+ asynchronous ||
+ /\/environments\/[^/]+\/(images|networks|volumes)\/[^/]+$/.test(resourcePath)
+ ) {
+ const existing = await page.request.get(resourcePath.replace(/\/destroy$/, ''));
+ if (existing.status() === 404) return;
+ if (!existing.ok())
+ throw new Error(
+ `Cleanup lookup ${resourcePath}: ${existing.status()} ${await existing.text()}`
+ );
+ }
+ const response = await page.request.delete(path, options);
+ if (response.status() === 404) return;
+ if (response.ok()) {
+ if (asynchronous) {
+ await expect
+ .poll(
+ async () => {
+ const remaining = await page.request.get(resourcePath.replace(/\/destroy$/, ''));
+ if (!remaining.ok() && remaining.status() !== 404) {
+ throw new Error(
+ `Cleanup lookup ${resourcePath}: ${remaining.status()} ${await remaining.text()}`
+ );
+ }
+ return remaining.status();
+ },
+ { timeout: 60_000, message: `Wait for deletion of ${resourcePath}` }
+ )
+ .toBe(404);
+ }
+ return;
+ }
+ const detail = `DELETE ${path}: ${response.status()} ${await response.text()}`;
+ await test.info().attach('cleanup-error', { body: detail, contentType: 'text/plain' });
+ expect.soft(false, detail).toBe(true);
+ } catch (error) {
+ expect.soft(false, `DELETE ${path}: ${String(error)}`).toBe(true);
+ }
}
diff --git a/tests/utils/playwright.util.ts b/tests/utils/playwright.util.ts
index 18a4e12c9..129c8abbf 100644
--- a/tests/utils/playwright.util.ts
+++ b/tests/utils/playwright.util.ts
@@ -1,3 +1,4 @@
+import { expect, type Locator } from '@playwright/test';
import playwrightConfig from '../playwright.config';
export async function createTestApiKeys(count: number = 2) {
@@ -29,3 +30,16 @@ export async function deleteTestApiKeys() {
throw new Error(`Failed to delete test API keys: ${response.status} ${response.statusText}`);
}
}
+
+export async function waitForDialogReady(dialog: Locator) {
+ await expect(dialog).toBeVisible();
+ await dialog.evaluate(async (element) => {
+ await Promise.all(element.getAnimations().map((animation) => animation.finished));
+ });
+ await expect
+ .poll(
+ () => dialog.evaluate((element) => element.contains(element.ownerDocument.activeElement)),
+ { message: 'Dialog must finish opening and receive focus before input' }
+ )
+ .toBe(true);
+}