Files
AetherForge/server/web/e2e/remote-actions.spec.ts
AetherForge e37eb24369
Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Fix flaky stats-batch tests and extend Crucible E2E LOTL coverage.
Stop the stats batch timer in unit tests before reading pending coalesced state, teach the Playwright stub agent to emit lotl_tier stats, and prefer server/webroot so phase-8 E2E serves the current frontend build.
2026-06-07 00:52:55 -07:00

130 lines
4.4 KiB
TypeScript

import { expect, test } from '@playwright/test';
import { loginToDashboard } from './fixtures';
const OFFLINE_AGENT = {
id: 'e2e-offline-agent',
name: 'Offline Node',
wallet: '4' + 'A'.repeat(94),
ip: '192.168.1.99',
version: '1.0.0',
status: 'offline',
cpu_cores: 4,
memory_gb: 8,
last_seen: new Date(Date.now() - 3600_000).toISOString(),
created_at: new Date().toISOString(),
hashrate_15s: 0,
hashrate_1m: 0,
hashrate_15m: 0,
shares_total: 0,
shares_good: 0,
shares_bad: 0,
cpu_usage_pct: 0,
memory_usage_pct: 0,
uptime_seconds: 0,
platform: 'windows',
arch: 'amd64',
};
test.describe('Remote actions UI', () => {
test.beforeEach(async ({ page }) => {
await page.addInitScript((agent) => {
const RealWS = WebSocket;
const g = globalThis as typeof globalThis & { __afRealWebSocket?: typeof WebSocket };
g.__afRealWebSocket = RealWS;
globalThis.WebSocket = function (url: string | URL, protocols?: string | string[]) {
const urlStr = String(url);
if (!urlStr.includes('/ws/dashboard')) {
return new g.__afRealWebSocket!(url, protocols);
}
let openHandler: (() => void) | null = null;
let messageHandler: ((ev: MessageEvent) => void) | null = null;
let closeHandler: (() => void) | null = null;
const sock = {
readyState: 0,
send() {},
close() {
sock.readyState = 3;
closeHandler?.();
},
set onopen(fn: (() => void) | null) {
openHandler = fn;
},
get onopen() {
return openHandler;
},
set onmessage(fn: ((ev: MessageEvent) => void) | null) {
messageHandler = fn;
},
get onmessage() {
return messageHandler;
},
set onclose(fn: (() => void) | null) {
closeHandler = fn;
},
get onclose() {
return closeHandler;
},
set onerror(_fn: (() => void) | null) {},
get onerror() {
return null;
},
};
queueMicrotask(() => {
sock.readyState = 1;
openHandler?.();
messageHandler?.({
data: JSON.stringify({ type: 'init', payload: { agents: [agent] } }),
} as MessageEvent);
});
return sock as unknown as WebSocket;
} as unknown as typeof WebSocket;
globalThis.WebSocket.OPEN = 1;
globalThis.WebSocket.CONNECTING = 0;
globalThis.WebSocket.CLOSED = 3;
}, OFFLINE_AGENT);
await page.route(/\/api\/v1\/agents$/, async (route) => {
if (route.request().method() !== 'GET') {
await route.continue();
return;
}
await route.fulfill({ json: [OFFLINE_AGENT] });
});
await page.route('**/api/v1/builds', async (route) => {
await route.fulfill({ json: [] });
});
await page.route('**/api/v1/server/info', async (route) => {
await route.fulfill({
json: {
version: 'test',
suggested_url: 'http://127.0.0.1:8989',
agent_count: 1,
online_count: 0,
},
});
});
await loginToDashboard(page);
await page.getByRole('link', { name: /Crucible/i }).click();
await expect(page.getByRole('heading', { name: 'Crucible' })).toBeVisible({ timeout: 10_000 });
await expect(page.getByText('Offline Node')).toBeVisible({ timeout: 10_000 });
});
test('mining ops disabled when only offline agent selected', async ({ page }) => {
const card = page.locator('.crucible-node-card').filter({ hasText: 'Offline Node' });
await card.click();
await expect(card).toHaveClass(/selected/);
const miningPause = page.locator('.cop-mining').getByRole('button', { name: 'Pause', exact: true });
const miningResume = page.locator('.cop-mining').getByRole('button', { name: 'Resume', exact: true });
await expect(miningPause).toBeDisabled();
await expect(miningResume).toBeDisabled();
});
test('bulk pause disabled when offline agent selected via toolbar', async ({ page }) => {
const card = page.locator('.crucible-node-card').filter({ hasText: 'Offline Node' });
await card.click();
await expect(card).toHaveClass(/selected/);
await expect(page.locator('.fleet-bulk-bar')).toContainText('1 selected');
const bulkPause = page.locator('.fleet-bulk-bar').getByRole('button', { name: 'Pause', exact: true });
await expect(bulkPause).toBeDisabled();
});
});