Repository Public
1import { expect, test, type BrowserContext, type Page } from "@playwright/test";2import { MODEL, NODE, SERVICE, emitEvent, seedCluster, touchNodes } from "../lib/fixtures";3import { endpointLive, signedIn, type Problems } from "../lib/harness";45// Real-data checks for the cluster endpoint group (nodes, metrics, services, models, network, storage, overview,6// search). Each test first asks the API whether its endpoint is live and skips itself while it still answers 501;7// the fixtures are synthetic rows written by SQL (aliases e2e-node-0x).8test.describe.serial("cluster data against live endpoints", () => {9 let context: BrowserContext;10 let page: Page;11 let problems: Problems;1213 test.beforeAll(async ({ browser }) => {14 ({ context, page, problems } = await signedIn(browser, "e2e-owner"));15 seedCluster();16 });17 test.beforeEach(() => {18 touchNodes();19 });20 test.afterAll(async () => {21 await context.close();22 });2324 const need = async (path: string) => {25 test.skip(!(await endpointLive(page, path)), `GET ${path} is not live yet (501/503): covered by the not-available state in 05-screens`);26 };2728 test("nodes list: freshness per node, filters, search", async () => {29 await need("/nodes");30 await page.goto("/nodes");31 await expect(page.getByTestId("screen-nodes")).toBeVisible();32 await expect(page.getByTestId(`node-row-${NODE.fresh.alias}`)).toContainText("À jour");33 await expect(page.getByTestId(`node-row-${NODE.stale.alias}`)).toContainText("En retard");34 await expect(page.getByTestId(`node-row-${NODE.offline.alias}`)).toContainText("Hors ligne");35 // a node that never reported shows explicit states, not zeros36 const offlineRow = page.locator("tr", { has: page.getByTestId(`node-row-${NODE.offline.alias}`) });37 await expect(offlineRow).not.toContainText(/\b0 %/);38 await page.getByTestId("nodes-search").fill("node-02");39 await expect(page.getByTestId(`node-row-${NODE.stale.alias}`)).toBeVisible();40 await expect(page.getByTestId(`node-row-${NODE.fresh.alias}`)).toHaveCount(0);41 await expect(page).toHaveURL(/q=node-02/);42 await page.getByTestId("nodes-search").fill("");43 await expect(page.getByTestId(`node-row-${NODE.fresh.alias}`)).toBeVisible();44 });4546 test("nodes list updates from a node.state event without reload", async () => {47 await need("/nodes");48 await page.goto("/nodes");49 const row = page.locator("tr", { has: page.getByTestId(`node-row-${NODE.fresh.alias}`) });50 await expect(row).toContainText("44 %"); // cpu.usage 43.5 from the fixture51 emitEvent("node.state", { node_id: NODE.fresh.id, alias: NODE.fresh.alias, freshness: "fresh", maintenance: false, observed_at: new Date().toISOString(), headline: { cpu_usage_pct: 97, mem_used_pct: 38, load1: 9.5 } });52 await expect(row).toContainText("97 %");53 });5455 test("node detail: identity, perf levels by their real names, explicit unsupported metrics", async () => {56 await need(`/nodes/${NODE.fresh.id}`);57 await page.goto(`/nodes/${NODE.fresh.id}`);58 await expect(page.getByTestId("screen-node-detail")).toBeVisible();59 await expect(page.locator("h1")).toContainText(NODE.fresh.alias);60 await expect(page.getByTestId("node-state")).toHaveAttribute("data-freshness", "fresh");61 const levels = page.getByTestId("node-perf-levels");62 await expect(levels).toContainText("Super");63 await expect(levels).toContainText("Performance");64 await expect(levels).toContainText("Efficiency");65 const latest = page.getByTestId("node-latest");66 await expect(latest).toContainText("Température");67 await expect(latest.locator('[data-availability="unsupported"]').first()).toBeVisible();68 await expect(page.getByTestId("data-stamp").first()).toBeVisible();69 });7071 test("node detail: metric chart with a gap, keyboard cursor and table view", async () => {72 await need(`/nodes/${NODE.fresh.id}/metrics?metrics=cpu.usage`);73 await page.goto(`/nodes/${NODE.fresh.id}?tab=metrics`);74 const metrics = page.getByTestId("node-metrics");75 await expect(metrics).toBeVisible();76 const chart = metrics.locator("figure.mcc-chart").first();77 await expect(chart.locator("canvas")).toBeVisible();78 const plot = chart.getByRole("group");79 await plot.focus();80 await page.keyboard.press("End");81 await page.keyboard.press("ArrowLeft");82 await expect(chart.locator(".mcc-chart-cursor")).toContainText(/\d{2}:\d{2}:\d{2} — .+: \d/);83 await chart.getByRole("button", { name: "Tableau" }).click();84 await expect(chart.getByRole("table")).toBeVisible();85 await expect(chart.getByRole("columnheader", { name: "Horodatage" })).toBeVisible();86 await chart.getByRole("button", { name: "Graphique" }).click();87 await expect(chart.locator("canvas")).toBeVisible();88 });8990 test("node detail: processes, storage and agent tabs", async () => {91 await need(`/nodes/${NODE.fresh.id}/processes`);92 await page.goto(`/nodes/${NODE.fresh.id}?tab=processes`);93 await expect(page.getByTestId("node-processes")).toContainText("e2e-worker");94 await page.goto(`/nodes/${NODE.fresh.id}?tab=storage`);95 await expect(page.getByTestId("node-volumes")).toContainText("/Volumes/e2e-ssd");96 await expect(page.getByTestId("node-interfaces")).toContainText("en0");97 await page.goto(`/nodes/${NODE.fresh.id}?tab=agent`);98 await expect(page.getByTestId("node-agent")).toContainText("1.0.0-e2e");99 });100101 test("compare: specs side by side and overlaid chart", async () => {102 await need(`/metrics/compare?metric=cpu.usage&node_ids=${NODE.fresh.id},${NODE.stale.id}`);103 await page.goto(`/nodes/compare?ids=${NODE.fresh.id},${NODE.stale.id}`);104 await expect(page.getByTestId("screen-nodes-compare")).toBeVisible();105 const specs = page.getByTestId("compare-specs");106 await expect(specs).toContainText(NODE.fresh.alias);107 await expect(specs).toContainText(NODE.stale.alias);108 await expect(specs).toContainText("Apple M6");109 await expect(specs).toContainText("Apple M4");110 await expect(page.getByTestId("compare-chart")).toBeVisible();111 });112113 test("overview: availability by freshness and capacity with coverage", async () => {114 await need("/cluster/overview");115 await page.goto("/");116 await expect(page.getByTestId("screen-overview")).toBeVisible();117 const counts = page.getByTestId("ov-nodes-counts");118 await expect(counts.getByRole("link", { name: "1 À jour" })).toBeVisible();119 await expect(counts.getByRole("link", { name: "1 En retard" })).toBeVisible();120 await expect(counts.getByRole("link", { name: "1 Hors ligne" })).toBeVisible();121 // capacity is a total over the nodes that report it, and says how many do (never a silent partial sum)122 await expect(page.getByTestId("ov-capacity-cpu")).toContainText(/\d+\s+cœurs/);123 await expect(page.getByTestId("ov-coverage").first()).toContainText(/\d nœuds? sur 3 rapporte/);124 await expect(page.getByTestId("cluster-state")).toContainText("1/3");125 });126127 test("services: catalogue and detail", async () => {128 await need("/services");129 await page.goto("/services");130 await expect(page.getByTestId("screen-services")).toBeVisible();131 await expect(page.getByRole("link", { name: "e2e-api" })).toBeVisible();132 await expect(page.getByText("test.e2e.agentd")).toBeVisible();133 await page.goto(`/services/${SERVICE.api}`);134 await expect(page.getByTestId("screen-service-detail")).toBeVisible();135 await expect(page.getByTestId("service-state")).toHaveAttribute("data-state", "online");136 await expect(page.getByTestId("service-history")).toBeVisible();137 await page.goto(`/services/${SERVICE.agentd}`);138 await expect(page.getByTestId("service-state")).toHaveAttribute("data-state", "errored");139 await expect(page.getByTestId("service-unmanaged")).toBeVisible();140 });141142 test("models: request metrics are shown as not instrumented, with the reason", async () => {143 await need("/models");144 await page.goto("/models");145 await expect(page.getByTestId("screen-models")).toBeVisible();146 const server = page.locator(`[data-testid="model-server"][data-server-id="${MODEL.mlx}"]`);147 await expect(server).toContainText("e2e-org/E2E-Model-7B-4bit");148 const support = server.getByTestId("model-metrics-support");149 for (const metric of ["tokens_per_s", "ttft", "latency", "queue"]) {150 const row = support.locator(`[data-metric="${metric}"]`);151 await expect(row).toHaveAttribute("data-availability", /unsupported|unavailable/);152 await expect(row).not.toHaveText(/^\s*0\s*$/);153 }154 });155156 test("storage: volumes with usage, NAS offline, backup unknown — said honestly", async () => {157 await need("/storage/volumes");158 await page.goto("/storage");159 await expect(page.getByTestId("screen-storage")).toBeVisible();160 const node = page.locator(`[data-testid="storage-node"][data-node-alias="${NODE.fresh.alias}"]`);161 await expect(node).toContainText("/Volumes/e2e-ssd");162 await expect(node.getByRole("meter").first()).toBeVisible();163 await expect(page.getByTestId("storage-nas")).toContainText("e2e-nas");164 await expect(page.getByTestId("nas-state").first()).toHaveAttribute("data-state", "offline");165 await expect(page.getByTestId("backup-status").first()).toHaveAttribute("data-status", "unknown");166 await expect(page.getByTestId("backups-honesty")).toBeVisible();167 });168169 test("network: topology drawn with an equivalent table", async () => {170 await need("/network/topology");171 await page.goto("/network");172 await expect(page.getByTestId("screen-network")).toBeVisible();173 await expect(page.getByTestId("network-topology")).toBeVisible();174 await expect(page.getByTestId("network-interfaces")).toContainText("en0");175 });176177 test("universal search finds a node", async () => {178 await need("/search?q=e2e-node");179 await page.goto("/");180 await page.keyboard.press("ControlOrMeta+k");181 await page.getByTestId("palette-input").fill("e2e-node-01");182 const hit = page.getByRole("option", { name: new RegExp(NODE.fresh.alias) }).first();183 await expect(hit).toBeVisible();184 await hit.click();185 await expect(page).toHaveURL(new RegExp(`/nodes/${NODE.fresh.id}`));186 });187188 test("dashboard layout persists per user", async () => {189 await need("/me/dashboards");190 await page.goto("/");191 await expect(page.getByTestId("screen-overview")).toHaveAttribute("data-persistable", "true");192 await page.getByTestId("ov-customize").click();193 await page.getByTestId("ov-remove-models").click();194 await page.getByTestId("ov-save").click();195 await expect(page.getByTestId("ov-cell-models")).toHaveCount(0);196 await page.reload();197 await expect(page.getByTestId("ov-cell-nodes")).toBeVisible();198 await expect(page.getByTestId("ov-cell-models")).toHaveCount(0);199 // keyboard rearrangement, then back to the default layout200 await page.getByTestId("ov-customize").click();201 const cell = page.getByTestId("ov-cell-alerts");202 const before = await cell.getAttribute("data-w");203 await page.getByTestId("ov-move-alerts").focus();204 await page.keyboard.press("Shift+ArrowLeft"); // Shift + arrows resize205 await expect(cell).not.toHaveAttribute("data-w", before ?? "");206 await expect(page.getByTestId("ov-live")).not.toBeEmpty();207 await page.getByTestId("ov-reset").click();208 const confirm = page.getByRole("dialog").getByRole("button", { name: /réinitialiser/i }).last();209 if (await confirm.isVisible().catch(() => false)) await confirm.click();210 await expect(page.getByTestId("ov-cell-models")).toBeVisible();211 });212213 test("no CSP violation and no console error", async () => {214 problems.assertClean();215 });216});217