|
1 | 1 | import { test, expect } from './coverage-fixtures.js' |
2 | 2 |
|
3 | | -// P2P (Swarm) admin page — renders in the no-auth test harness (isAdmin). |
4 | | -test.describe('P2P page', () => { |
5 | | - test.beforeEach(async ({ page }) => { |
6 | | - await page.goto('/app/p2p') |
| 3 | +// The standalone P2P (Swarm) page was merged into the Cluster page: /app/p2p now |
| 4 | +// redirects to /app/cluster, and the p2p content lives under the "Swarm (p2p)" |
| 5 | +// section. That section only mounts when p2p is enabled (a network token is |
| 6 | +// present), so we mock /api/p2p/token to return a non-empty token and assert the |
| 7 | +// swarm content renders under the cluster page. |
| 8 | +const P2P_TOKEN = 'test-network-token' |
| 9 | + |
| 10 | +async function mockSwarmEnabled(page) { |
| 11 | + await page.route('**/api/p2p/token', (route) => { |
| 12 | + route.fulfill({ |
| 13 | + status: 200, |
| 14 | + contentType: 'text/plain', |
| 15 | + body: P2P_TOKEN, |
| 16 | + }) |
| 17 | + }) |
| 18 | + await page.route('**/api/p2p/workers', (route) => { |
| 19 | + route.fulfill({ status: 200, contentType: 'application/json', body: '{"nodes":[]}' }) |
| 20 | + }) |
| 21 | + await page.route('**/api/p2p/federation', (route) => { |
| 22 | + route.fulfill({ status: 200, contentType: 'application/json', body: '{"nodes":[]}' }) |
| 23 | + }) |
| 24 | + await page.route('**/api/p2p/stats', (route) => { |
| 25 | + route.fulfill({ |
| 26 | + status: 200, |
| 27 | + contentType: 'application/json', |
| 28 | + body: JSON.stringify({ |
| 29 | + llama_cpp_workers: { online: 0, total: 0 }, |
| 30 | + federated: { online: 0, total: 0 }, |
| 31 | + mlx_workers: { online: 0, total: 0 }, |
| 32 | + }), |
| 33 | + }) |
7 | 34 | }) |
| 35 | + // The cluster page also probes /api/nodes for the distributed section; keep it |
| 36 | + // failing (distributed disabled) so only the swarm section renders here. |
| 37 | + await page.route('**/api/nodes', (route) => { |
| 38 | + route.fulfill({ status: 503, contentType: 'application/json', body: '{}' }) |
| 39 | + }) |
| 40 | +} |
8 | 41 |
|
9 | | - test('renders the P2P distribution overview and capability cards', async ({ page }) => { |
10 | | - await expect(page).toHaveURL(/\/app\/p2p$/) |
11 | | - await expect(page.getByRole('heading', { name: /P2P Distribution Not Enabled/i })).toBeVisible() |
12 | | - await expect(page.getByRole('heading', { name: 'Instance Federation' })).toBeVisible() |
13 | | - await expect(page.getByRole('heading', { name: 'Model Sharding' })).toBeVisible() |
14 | | - await expect(page.getByRole('heading', { name: 'Resource Sharing' })).toBeVisible() |
15 | | - await expect(page.getByRole('heading', { name: /How to Enable P2P/i })).toBeVisible() |
| 42 | +test.describe('P2P (Swarm) section on the Cluster page', () => { |
| 43 | + test('the old /app/p2p route lands on the cluster page', async ({ page }) => { |
| 44 | + await mockSwarmEnabled(page) |
| 45 | + // /app/p2p redirects to /app/cluster. |
| 46 | + await page.goto('/app/p2p') |
| 47 | + await expect(page).toHaveURL(/\/app\/cluster$/) |
| 48 | + await expect(page.getByRole('heading', { name: /Cluster/i })).toBeVisible() |
16 | 49 | }) |
17 | 50 |
|
18 | | - test('hardware selector offers build targets and responds to selection', async ({ page }) => { |
19 | | - const cpu = page.getByRole('button').filter({ hasText: /^CPU$/ }) |
20 | | - const cuda = page.getByRole('button').filter({ hasText: /^CUDA 12$/ }) |
21 | | - await expect(cpu).toBeVisible() |
22 | | - await expect(cuda).toBeVisible() |
23 | | - await cuda.click() // selecting a build target must not break the page |
24 | | - await expect(page.getByRole('heading', { name: /How to Enable P2P/i })).toBeVisible() |
| 51 | + test('renders the Swarm (p2p) section when p2p is enabled', async ({ page }) => { |
| 52 | + await mockSwarmEnabled(page) |
| 53 | + await page.goto('/app/cluster') |
| 54 | + await expect(page).toHaveURL(/\/app\/cluster$/) |
| 55 | + |
| 56 | + // The collapsible swarm section is titled "Swarm (p2p)". |
| 57 | + await expect(page.getByText(/Swarm \(p2p\)/i)).toBeVisible() |
| 58 | + |
| 59 | + // The enabled p2p content (Network Token panel + the federation / sharding |
| 60 | + // tabs) is rendered inside the swarm section. |
| 61 | + await expect(page.getByRole('heading', { name: /Network Token/i })).toBeVisible() |
| 62 | + await expect(page.getByText('Federation', { exact: true })).toBeVisible() |
| 63 | + await expect(page.getByText('Model Sharding', { exact: true })).toBeVisible() |
25 | 64 | }) |
26 | 65 | }) |
0 commit comments