Add web auth, infinite-scroll, agent admission and review fixes across agent/server/web

This commit is contained in:
Stanislav Rossovskii
2026-05-28 23:45:12 +04:00
parent 37b1a1d6d6
commit 1026e9ebbe
75 changed files with 3021 additions and 916 deletions

View File

@@ -3,6 +3,60 @@ import { createServer } from "node:http";
const PORT = Number(process.env.MOCK_PORT ?? 8765);
const now = new Date().toISOString();
const eventItems = [
{
event_id: "00000000-0000-7000-8000-000000000001",
agent_id: "agent-1",
check_id: "disk",
observed_at: now,
received_at: now,
status: "ok",
exit_code: 0,
duration_ms: 12,
output: "disk ok",
output_truncated: false,
notifications_enabled: true,
},
{
event_id: "00000000-0000-7000-8000-000000000002",
agent_id: "agent-1",
check_id: "load",
observed_at: now,
received_at: now,
status: "warning",
exit_code: 1,
duration_ms: 34,
output: "load high",
output_truncated: false,
notifications_enabled: true,
},
{
event_id: "00000000-0000-7000-8000-000000000003",
agent_id: "agent-2",
check_id: "agent_liveness",
observed_at: now,
received_at: now,
status: "critical",
exit_code: 2,
duration_ms: 0,
output: "agent is dead",
output_truncated: false,
notifications_enabled: true,
},
...Array.from({ length: 12 }, (_, i) => ({
event_id: `00000000-0000-7000-8000-0000000001${String(i).padStart(2, "0")}`,
agent_id: "agent-1",
check_id: "disk",
observed_at: now,
received_at: now,
status: "ok",
exit_code: 0,
duration_ms: 10 + i,
output: `disk extra ${i + 1}`,
output_truncated: false,
notifications_enabled: true,
})),
];
const fixtures = {
"/api/v1/health": { status: "ok" },
@@ -12,6 +66,7 @@ const fixtures = {
checks_ok: 2,
checks_warning: 1,
checks_critical: 1,
checks_unknown: 0,
open_incidents: 2,
generated_at: now,
},
@@ -128,48 +183,8 @@ const fixtures = {
next_cursor: null,
},
"/api/v1/events/query": {
items: [
{
event_id: "00000000-0000-7000-8000-000000000001",
agent_id: "agent-1",
check_id: "disk",
observed_at: now,
received_at: now,
status: "ok",
exit_code: 0,
duration_ms: 12,
output: "disk ok",
output_truncated: false,
notifications_enabled: true,
},
{
event_id: "00000000-0000-7000-8000-000000000002",
agent_id: "agent-1",
check_id: "load",
observed_at: now,
received_at: now,
status: "warning",
exit_code: 1,
duration_ms: 34,
output: "load high",
output_truncated: false,
notifications_enabled: true,
},
{
event_id: "00000000-0000-7000-8000-000000000003",
agent_id: "agent-2",
check_id: "agent_liveness",
observed_at: now,
received_at: now,
status: "critical",
exit_code: 2,
duration_ms: 0,
output: "agent is dead",
output_truncated: false,
notifications_enabled: true,
},
],
next_cursor: null,
items: eventItems,
next_cursor: "10",
},
"/api/v1/notifiers/outbox": {
items: [
@@ -205,15 +220,12 @@ const server = createServer((req, res) => {
if (url.pathname === "/api/v1/events/query" && body) {
const agentId = url.searchParams.get("agent_id");
const checkId = url.searchParams.get("check_id");
body = {
...body,
items: body.items.filter((item) => {
if (agentId && item.agent_id !== agentId) return false;
if (checkId && item.check_id !== checkId) return false;
return true;
}),
next_cursor: null,
};
const items = body.items.filter((item) => {
if (agentId && item.agent_id !== agentId) return false;
if (checkId && item.check_id !== checkId) return false;
return true;
});
body = paginate(body, items, url);
}
if (url.pathname === "/api/v1/incidents" && body) {
const state = url.searchParams.get("state");
@@ -239,3 +251,16 @@ const server = createServer((req, res) => {
server.listen(PORT, "127.0.0.1", () => {
console.log(`mock server on ${PORT}`);
});
function paginate(body, items, url) {
const limit = Number(url.searchParams.get("limit") ?? 100);
const start = Number(url.searchParams.get("cursor") ?? 0);
const safeLimit = Number.isFinite(limit) && limit > 0 ? limit : 100;
const safeStart = Number.isFinite(start) && start > 0 ? start : 0;
const next = safeStart + safeLimit;
return {
...body,
items: items.slice(safeStart, next),
next_cursor: next < items.length ? String(next) : null,
};
}

View File

@@ -107,6 +107,14 @@ test("events page", async ({ page }) => {
await expect(page.getByRole("link", { name: /check_id=.*disk/ })).toBeVisible();
});
test("events page loads the next cursor page on scroll", async ({ page }) => {
await page.goto("/events");
await expect(page.locator("tbody")).toContainText("disk extra 7");
await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
await expect(page.locator("tbody")).toContainText("disk extra 11");
await expect(page).toHaveURL(/\/events$/);
});
test("outbox page", async ({ page }) => {
await page.goto("/outbox");
await expect(page.locator("body")).toContainText("debug");