Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Sync PROBLEMS.md and tests/README.md with 734 Vitest count, fleet evolution checklist, erasure-coded propagation deferred row; retry dashboard login and wait for agents API in LOTL E2E.
82 lines
2.9 KiB
TypeScript
82 lines
2.9 KiB
TypeScript
import { expect, type APIRequestContext, type Page } from '@playwright/test';
|
|
|
|
/** Matches server/internal/api/integration_test.go testAuthUser / testAuthPass. */
|
|
export const E2E_USER = process.env.AETHERFORGE_E2E_USER || 'testuser';
|
|
export const E2E_PASS = process.env.AETHERFORGE_E2E_PASS || 'testpass';
|
|
|
|
/** Seed this into the server data dir as users.json before first start (see tests/README.md). */
|
|
export const E2E_USERS_JSON = JSON.stringify({ [E2E_USER]: E2E_PASS });
|
|
|
|
export function e2eAuthHeaders(): Record<string, string> {
|
|
const token = Buffer.from(`${E2E_USER}:${E2E_PASS}`).toString('base64');
|
|
return {
|
|
Authorization: `Basic ${token}`,
|
|
'X-AetherForge-Client': 'dashboard',
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Reads fleet_secret for stub agent auth.
|
|
* Prefer AETHERFORGE_FLEET_SECRET (test-suite.ps1 seeds from data/config.json).
|
|
*/
|
|
export async function fetchFleetSecret(request: APIRequestContext): Promise<string> {
|
|
const fromEnv = process.env.AETHERFORGE_FLEET_SECRET?.trim();
|
|
if (fromEnv) return fromEnv;
|
|
|
|
const res = await request.get('/api/v1/config', {
|
|
headers: e2eAuthHeaders(),
|
|
timeout: 10_000,
|
|
});
|
|
if (!res.ok()) {
|
|
throw new Error(`config fetch failed: ${res.status()}`);
|
|
}
|
|
const body = (await res.json()) as { server?: { fleet_secret?: string } };
|
|
const secret = body.server?.fleet_secret?.trim() ?? '';
|
|
if (!secret) {
|
|
throw new Error(
|
|
'fleet_secret missing — set AETHERFORGE_FLEET_SECRET from data/config.json in the E2E runner',
|
|
);
|
|
}
|
|
return secret;
|
|
}
|
|
|
|
/** Poll /api/v1/health until status ok or timeout (mirrors test-suite.ps1 phase 8). */
|
|
export async function waitForServerHealth(
|
|
request: APIRequestContext,
|
|
opts?: { timeoutMs?: number; intervalMs?: number },
|
|
): Promise<boolean> {
|
|
const timeoutMs = opts?.timeoutMs ?? 30_000;
|
|
const intervalMs = opts?.intervalMs ?? 1_000;
|
|
const deadline = Date.now() + timeoutMs;
|
|
while (Date.now() < deadline) {
|
|
try {
|
|
const res = await request.get('/api/v1/health', { timeout: 2_000 });
|
|
if (res.ok()) {
|
|
const body = (await res.json()) as { status?: string };
|
|
if (body.status === 'ok') return true;
|
|
}
|
|
} catch {
|
|
/* retry */
|
|
}
|
|
await new Promise((r) => setTimeout(r, intervalMs));
|
|
}
|
|
return false;
|
|
}
|
|
|
|
export async function loginToDashboard(page: Page): Promise<void> {
|
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
await page.goto('/', { waitUntil: 'load', timeout: 30_000 });
|
|
try {
|
|
await expect(page.getByRole('heading', { name: 'AetherForge' })).toBeVisible({ timeout: 20_000 });
|
|
break;
|
|
} catch (err) {
|
|
if (attempt === 1) throw err;
|
|
await page.waitForTimeout(1_500);
|
|
}
|
|
}
|
|
await page.getByLabel('Username').fill(E2E_USER);
|
|
await page.getByLabel('Password').fill(E2E_PASS);
|
|
await page.getByRole('button', { name: /enter command deck/i }).click();
|
|
await expect(page.getByRole('heading', { name: 'Command Deck' })).toBeVisible({ timeout: 20_000 });
|
|
}
|