Accessibility pass, command palette actions, row detail panel, server activity, map, wall display and setup guide

Accessibility: skip link, labelled landmarks, visible focus, page-change
announcements, sortable headings as real buttons, every label tied to its
field, named row checkboxes, and text contrast raised to 4.5:1 in both themes.
Command palette: also runs actions (silence/end maintenance, theme, density,
wall display, sign out) and is a proper dialog; g-then-letter shortcuts, "/" and
"?". Row detail panel for six tables. Server Activity card, with the health
check now recording offline/back-online and disk events in the audit log. Map
page of hosts, servers, DNS names and monitors. Full-screen wall display. A
getting-started checklist on the admin dashboard.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-15 21:10:56 +02:00
1 parent f7f5e1cd41
commit 57fd4f8c52
36 files changed
+2790 -210

No files matched your search

+163
View File
@@ -0,0 +1,163 @@
/**
* A server's activity timeline: what the health check wrote down, what people changed, and its maintenance windows.
*
* Run with: npm test --workspace server
*/
import { test, describe, before, after } from "node:test";
import assert from "node:assert/strict";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import type { AddressInfo } from "node:net";
import type { Server } from "node:http";
const dir = mkdtempSync(join(tmpdir(), "hm-activity-"));
process.env.DATABASE_PATH = join(dir, "test.sqlite");
process.env.SESSION_DIR = join(dir, "sessions");
process.env.CREDENTIALS_ENCRYPTION_KEY = "ab".repeat(32);
const express = (await import("express")).default;
const { db } = await import("../src/db/client.js");
const { users, servers, maintenanceWindows, auditLog } = await import("../src/db/schema.js");
const { runMigrations } = await import("../src/db/migrate.js");
const { recordAudit } = await import("../src/services/audit.js");
const { recordServerTransitions } = await import("../src/services/healthMonitor.js");
const { getServerActivity, describeAudit, auditTimeToIso } = await import("../src/services/serverActivity.js");
const { serversRouter } = await import("../src/routes/servers.js");
await runMigrations();
describe("reading audit entries", () => {
test("SQLite's UTC timestamp becomes ISO", () => {
assert.equal(auditTimeToIso("2026-10-03 14:05:09"), "2026-10-03T14:05:09.000Z");
assert.equal(auditTimeToIso("2026-10-03T14:05:09.123Z"), "2026-10-03T14:05:09.123Z");
});
test("known actions read as sentences, unknown ones still say something", () => {
assert.equal(describeAudit("server", "went_offline", { message: "x" }).tone, "bad");
assert.equal(describeAudit("server", "back_online", {}).tone, "good");
assert.equal(describeAudit("server", "rotate_token", {}).title, "Agent token replaced");
assert.equal(describeAudit("server", "add_link", { label: "Cockpit" }).detail, "Cockpit");
assert.equal(describeAudit("task", "run_now", {}).title, "Task: run now");
});
});
describe("the timeline", () => {
let serverId = 0;
let otherId = 0;
before(async () => {
serverId = (await db.insert(servers).values({ name: "elsa", apiTokenHash: "a", apiTokenPrefix: "a" }).returning())[0].id;
otherId = (await db.insert(servers).values({ name: "other", apiTokenHash: "b", apiTokenPrefix: "b" }).returning())[0].id;
});
test("the health check's moments are written down for the server they are about, and only server ones", async () => {
await recordServerTransitions(
[
{ key: `offline:server:${serverId}`, message: "elsa hasn't reported for 2 hours" },
{ key: `disk:server:${serverId}:/data`, message: "/data is 93% full" },
{ key: "disk:proxmox:4:local", message: "not a server" },
{ key: `offline:server:${otherId}`, message: "other is quiet" },
],
[],
);
await recordServerTransitions([], [{ key: `offline:server:${serverId}`, message: "back" }]);
const events = await getServerActivity(serverId);
const titles = events.map((e) => e.title);
assert.ok(titles.includes("Stopped reporting — marked offline"));
assert.ok(titles.includes("A disk got nearly full"));
assert.ok(titles.includes("Reporting again"));
assert.equal(events.find((e) => e.title === "A disk got nearly full")!.detail, "/data is 93% full");
assert.equal(events.find((e) => e.title === "Reporting again")!.tone, "good");
assert.equal(events.every((e) => e.actor === "system"), true, "the app's own doing is marked as such");
assert.equal((await getServerActivity(otherId)).length, 1, "the other server has only its own");
});
test("changes people made appear with who made them", async () => {
const [tobias] = await db.insert(users).values({ oidcSub: "tobias", name: "Tobias", role: "admin" }).returning();
await recordAudit({ category: "server", action: "rotate_token", targetType: "server", targetId: serverId, actor: tobias });
const found = (await getServerActivity(serverId)).find((e) => e.title === "Agent token replaced")!;
assert.equal(found.actor, "Tobias");
assert.equal(found.kind, "change");
});
test("maintenance windows appear as a start and, once over, an end; maintenance audit entries are not doubled", async () => {
const now = new Date();
const H = 3600_000;
await db.insert(maintenanceWindows).values([
{ targetType: "server", targetId: serverId, reason: "patching", startedAt: new Date(now.getTime() - 5 * H).toISOString(), endsAt: new Date(now.getTime() - 4 * H).toISOString(), createdBy: "Tobias" },
{ targetType: "server", targetId: serverId, reason: "tonight", startedAt: new Date(now.getTime() + 5 * H).toISOString(), endsAt: new Date(now.getTime() + 6 * H).toISOString(), createdBy: "Uptime Kuma sync" },
// Set up, then cancelled before it began.
{ targetType: "server", targetId: serverId, reason: "cancelled", startedAt: new Date(now.getTime() + 9 * H).toISOString(), endsAt: new Date(now.getTime() + 9 * H).toISOString() },
]);
await recordAudit({ category: "maintenance", action: "start", targetType: "server", targetId: serverId, detail: { minutes: 60 } });
const events = await getServerActivity(serverId);
const maint = events.filter((e) => e.kind === "maintenance");
assert.deepEqual(maint.map((e) => e.title).sort(), ["Maintenance ended", "Maintenance scheduled", "Maintenance started — alerts silenced"]);
assert.ok(!events.some((e) => e.detail?.includes("cancelled")), "a cancelled window is not an event");
assert.equal(events.filter((e) => e.title.toLowerCase().includes("maintenance")).length, 3, "the audit entry did not add a fourth");
});
test("newest first", async () => {
const events = await getServerActivity(serverId);
const sorted = [...events].sort((a, b) => b.at.localeCompare(a.at));
assert.deepEqual(events.map((e) => e.at), sorted.map((e) => e.at));
// the scheduled window is in the future, so it leads
assert.equal(events[0].title, "Maintenance scheduled");
});
});
describe("GET /api/servers/:id/activity", () => {
let app: Server;
let base = "";
let serverId = 0;
let role: "viewer" | "operator" = "viewer";
before(async () => {
await db.insert(users).values([
{ oidcSub: "viewer", name: "Viewer", role: "viewer" },
{ oidcSub: "operator", name: "Operator", role: "operator" },
]);
serverId = (await db.insert(servers).values({ name: "route", apiTokenHash: "r", apiTokenPrefix: "r" }).returning())[0].id;
await db.insert(auditLog).values({ category: "server", action: "create", targetType: "server", targetId: String(serverId), actorLabel: "Someone" });
const a = express();
a.use(express.json());
a.use((req, _res, next) => {
(req as unknown as { session: unknown }).session = { user: { sub: role } };
next();
});
a.use("/api/servers", serversRouter);
app = await new Promise<Server>((resolve) => {
const s = a.listen(0, "127.0.0.1", () => resolve(s));
});
base = `http://127.0.0.1:${(app.address() as AddressInfo).port}/api/servers`;
});
after(() => {
app.close();
try {
rmSync(dir, { recursive: true, force: true });
} catch {
// Windows keeps the database file locked until the process exits.
}
});
test("a viewer is refused; an operator gets the timeline", async () => {
role = "viewer";
assert.equal((await fetch(`${base}/${serverId}/activity`)).status, 403);
role = "operator";
const res = await fetch(`${base}/${serverId}/activity`);
assert.equal(res.status, 200);
const body = await res.json();
assert.equal(body.events[0].title, "Server added");
assert.equal(body.events[0].actor, "Someone");
});
test("an unknown server is a 404 and a bad id a 400", async () => {
role = "operator";
assert.equal((await fetch(`${base}/99999/activity`)).status, 404);
assert.equal((await fetch(`${base}/abc/activity`)).status, 400);
});
});
+114
View File
@@ -0,0 +1,114 @@
/**
* The Map page's graph: Proxmox hosts → servers → DNS names and monitors, with nothing guessed.
*
* Run with: npm test --workspace server
*/
import { test, describe, before, after } from "node:test";
import assert from "node:assert/strict";
import { mkdtempSync, rmSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import http from "node:http";
import type { AddressInfo } from "node:net";
const dir = mkdtempSync(join(tmpdir(), "hm-topology-"));
process.env.DATABASE_PATH = join(dir, "test.sqlite");
process.env.SESSION_DIR = join(dir, "sessions");
process.env.CREDENTIALS_ENCRYPTION_KEY = "ab".repeat(32);
const { db } = await import("../src/db/client.js");
const { servers, integrations, dnsProviders, dnsZonesCache, dnsRecordsCache } = await import("../src/db/schema.js");
const { runMigrations } = await import("../src/db/migrate.js");
const { buildTopology } = await import("../src/services/topology.js");
await runMigrations();
const metric = (id: number, host: string, status: number) =>
`monitor_status{monitor_id="${id}",monitor_name="m${id}",monitor_type="ping",monitor_url="",monitor_hostname="${host}",monitor_port=""} ${status}`;
describe("buildTopology", () => {
let kuma: http.Server;
let kumaStatus = 200;
before(async () => {
kuma = await new Promise<http.Server>((resolve) => {
const s = http.createServer((req, res) => {
res.statusCode = kumaStatus;
res.end(req.url === "/metrics" ? [metric(1, "elsa.lab.example", 1), metric(2, "elsa.lab.example", 0), metric(3, "unknown.example", 1)].join("\n") : "");
});
s.listen(0, "127.0.0.1", () => resolve(s));
});
const kumaUrl = `http://127.0.0.1:${(kuma.address() as AddressInfo).port}`;
const [pve] = await db.insert(integrations).values({ type: "proxmox", name: "Felicia", baseUrl: "https://pve.lab", config: "{}" }).returning();
await db.insert(integrations).values({ type: "uptimekuma", name: "Kuma", baseUrl: kumaUrl, config: JSON.stringify({ url: kumaUrl, password: "k" }) });
const recent = new Date().toISOString();
await db.insert(servers).values([
{ name: "elsa", hostname: "elsa.lab.example", apiTokenHash: "a", apiTokenPrefix: "a", lastSeenAt: recent, ipAddresses: JSON.stringify(["10.0.0.5"]), proxmoxIntegrationId: pve.id, proxmoxNode: "pve1", proxmoxGuestType: "qemu", proxmoxVmid: 100 },
{ name: "anna", hostname: null, apiTokenHash: "b", apiTokenPrefix: "b", lastSeenAt: new Date(Date.now() - 5 * 24 * 3600_000).toISOString(), ipAddresses: JSON.stringify(["10.0.0.6"]) },
{ name: "never", hostname: null, apiTokenHash: "c", apiTokenPrefix: "c" },
]);
const [provider] = await db.insert(dnsProviders).values({ providerType: "technitium", name: "Ginny", config: "{}" }).returning();
await db.insert(dnsZonesCache).values({ providerId: provider.id, zoneId: "z1", zoneName: "lab.example" });
await db.insert(dnsRecordsCache).values([
{ providerId: provider.id, zoneId: "z1", recordId: "1", type: "A", name: "elsa", content: "10.0.0.5" },
{ providerId: provider.id, zoneId: "z1", recordId: "2", type: "A", name: "www.lab.example", content: "10.0.0.5" },
{ providerId: provider.id, zoneId: "z1", recordId: "3", type: "A", name: "@", content: "10.0.0.6" },
{ providerId: provider.id, zoneId: "z1", recordId: "4", type: "A", name: "stranger", content: "10.9.9.9" },
{ providerId: provider.id, zoneId: "z1", recordId: "5", type: "TXT", name: "txt", content: "10.0.0.5" },
]);
});
after(() => {
kuma.close();
try {
rmSync(dir, { recursive: true, force: true });
} catch {
// Windows keeps the database file locked until the process exits.
}
});
const has = (map: { edges: { from: string; to: string }[] }, from: string, to: string) => map.edges.some((e) => e.from === from && e.to === to);
test("every server is a node, with its state; a Proxmox link adds the host above it", async () => {
const map = await buildTopology();
const status = (label: string) => map.nodes.find((n) => n.kind === "server" && n.label === label)!.status;
assert.equal(status("elsa"), "ok");
assert.equal(status("anna"), "bad", "last heard from five days ago");
assert.equal(status("never"), "unknown", "never reported");
const host = map.nodes.find((n) => n.kind === "host")!;
assert.equal(host.label, "pve1");
assert.equal(host.sub, "Felicia");
const elsa = map.nodes.find((n) => n.label === "elsa" && n.kind === "server")!;
assert.ok(has(map, host.id, elsa.id));
});
test("a DNS name is shown only where an A or AAAA record holds the server's own address, written out in full", async () => {
const map = await buildTopology();
const dns = map.nodes.filter((n) => n.kind === "dns").map((n) => n.label).sort();
assert.deepEqual(dns, ["elsa.lab.example", "lab.example", "www.lab.example"]);
const elsa = map.nodes.find((n) => n.kind === "server" && n.label === "elsa")!;
assert.ok(has(map, elsa.id, "dns:elsa.lab.example"));
assert.ok(has(map, elsa.id, "dns:www.lab.example"));
assert.ok(has(map, map.nodes.find((n) => n.kind === "server" && n.label === "anna")!.id, "dns:lab.example"), "an apex record is the zone's own name");
assert.ok(!map.nodes.some((n) => n.label.includes("stranger")), "an address no server has is left out");
});
test("monitors watching a server hang off it, with their status; ones watching nothing known are left out", async () => {
const map = await buildTopology();
const monitors = map.nodes.filter((n) => n.kind === "monitor");
assert.deepEqual(monitors.map((m) => [m.label, m.status]).sort(), [["m1", "ok"], ["m2", "bad"]]);
for (const m of monitors) assert.ok(map.edges.some((e) => e.to === m.id && e.from.startsWith("server:")));
});
test("when Uptime Kuma can't be read the rest of the map is still there, with a note", async () => {
kumaStatus = 500;
const map = await buildTopology();
assert.equal(map.nodes.filter((n) => n.kind === "monitor").length, 0);
assert.ok(map.nodes.filter((n) => n.kind === "server").length === 3);
assert.match(map.notes.join(" "), /Couldn't read Uptime Kuma “Kuma”/);
kumaStatus = 200;
});
});