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);
});
});