Speedtest Tracker, Costs, "Having trouble" on status pages, grouped Integrations and Dashboard

- Speedtest Tracker integration: charts, alerts for a slow line (median of the
  last three tests under a share of what is paid for) and for failing tests.
- Costs page (Records): things paid for by hand plus Hetzner's estimate, totals
  per currency, bills rolled forward into Coming up as Renewals.
- Status pages: a "Having trouble" state for things that answer but have an open
  alert; Speedtest reads as the internet.
- Integrations page and kind picker grouped like the sidebar (one shared types
  file); Notifications "What to send" shown one group at a time; Dashboard
  integration sections follow the menu groups, with tiles for integrations that
  have no widget.
- Docs, tests, and ROLES.md menu table brought up to date.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-26 23:23:46 +01:00
1 parent 78822346b1
commit f86661f6c9
49 files changed
+18156 -238

No files matched your search

+78 -3
View File
@@ -32,14 +32,22 @@ const { eq } = await import("drizzle-orm");
await runMigrations();
// The alerts the page sees: none, unless a test says so (the real collector asks every integration, which is not what these tests are about).
type TestAlert = { id: string; severity: "critical" | "warning" | "info"; silenced: boolean; target: { type: "server" | "integration"; id: number; name: string } | null };
let testAlerts: TestAlert[] = [];
sp.setAlertsLoaderForTests(async () => testAlerts as never);
const NOW = new Date("2026-10-17T12:00:00.000Z");
const minutesAgo = (m: number) => new Date(NOW.getTime() - m * 60_000).toISOString();
describe("how the whole page reads", () => {
const c = (up: number, down: number, maintenance: number, unknown: number) => ({ up, down, maintenance, unknown });
test("anything down is a problem; otherwise anything being worked on says so; nothing known at all is unknown", () => {
const c = (up: number, down: number, maintenance: number, unknown: number, trouble = 0) => ({ up, trouble, down, maintenance, unknown });
test("anything down is a problem; then anything having trouble; then anything being worked on; nothing known at all is unknown", () => {
assert.equal(sp.pageLevel(c(5, 0, 0, 0)), "ok");
assert.equal(sp.pageLevel(c(4, 1, 1, 1)), "issue");
assert.equal(sp.pageLevel(c(4, 1, 0, 0, 2)), "issue", "down outranks trouble");
assert.equal(sp.pageLevel(c(4, 0, 1, 0, 1)), "trouble", "trouble outranks being worked on");
assert.equal(sp.pageLevel(c(0, 0, 0, 0, 2)), "trouble");
assert.equal(sp.pageLevel(c(4, 0, 1, 1)), "maintenance");
assert.equal(sp.pageLevel(c(4, 0, 0, 1)), "ok", "one thing that can't be told doesn't spoil the rest");
assert.equal(sp.pageLevel(c(0, 0, 0, 3)), "unknown");
@@ -193,7 +201,7 @@ describe("how each thing reads", () => {
const page = await sp.buildPublicStatus(link, NOW);
assert.equal(page.title, "Our home");
assert.equal(page.message, "Movies are being updated tonight.");
assert.deepEqual(page.counts, { up: 4, down: 2, maintenance: 2, unknown: 3 });
assert.deepEqual(page.counts, { up: 4, trouble: 0, down: 2, maintenance: 2, unknown: 3 });
assert.equal(page.level, "issue");
assert.deepEqual(page.items.map((i) => i.label), ["Files", "Backups", "Printer", "Photos", "Laptop", "Automation", "Movies", "Music", "Podcasts", "Books", "Gone"], "in the order they were put");
assert.equal(page.items.find((i) => i.label === "Music")!.uptime30d, 80, "30-day uptime from Uptime Kuma, to one decimal");
@@ -204,6 +212,73 @@ describe("how each thing reads", () => {
assert.equal(bare.message, null);
});
describe("having trouble: it answers, but something is not right", () => {
const alert = (target: TestAlert["target"], extra: Partial<TestAlert> = {}): TestAlert => ({ id: `services:x:${Math.random()}`, severity: "warning", silenced: false, target, ...extra });
const server = (id: number) => ({ type: "server" as const, id, name: "private server name" });
const integration = (id: number) => ({ type: "integration" as const, id, name: "private integration name" });
const read = async () => stateOf(await sp.buildPublicStatus(link, NOW));
after(() => {
testAlerts = [];
});
test("a server that reports, with a warning or critical alert nobody has put aside, is having trouble; a server that is down stays down", async () => {
testAlerts = [alert(server(ids.up), { severity: "critical" }), alert(server(ids.down))];
const s = await read();
assert.equal(s.Files, "trouble");
assert.equal(s.Backups, "down", "down outranks trouble");
testAlerts = [alert(server(ids.up))];
assert.equal((await read()).Files, "trouble");
});
test("an alert that is silenced (maintenance, snoozed, closed), only information, or about something else says nothing", async () => {
testAlerts = [alert(server(ids.up), { silenced: true }), alert(server(ids.up), { severity: "info" }), alert(server(ids.never)), alert(null), alert({ type: "integration", id: ids.up, name: "x" })];
assert.equal((await read()).Files, "up", "an integration with the server's number is not the server");
});
test("an integration that works, with an alert open, is having trouble; one that fails is down; one under maintenance is being worked on", async () => {
testAlerts = [alert(integration(sem))];
assert.equal((await read()).Automation, "trouble");
await trackIntegrationHealth("semaphore", false);
assert.equal((await read()).Automation, "down");
await trackIntegrationHealth("semaphore", true);
await db.insert(maintenanceWindows).values({ targetType: "integration", targetId: sem, reason: "x", startedAt: minutesAgo(10), endsAt: new Date(NOW.getTime() + 3600_000).toISOString() });
assert.equal((await read()).Automation, "maintenance");
await db.delete(maintenanceWindows).where(eq(maintenanceWindows.targetId, sem));
});
test("the internet, through Speedtest Tracker: slow is trouble, speed tests that keep failing is down, fine is up", async () => {
const st = (await db.insert(integrations).values({ type: "speedtest", name: "Line", baseUrl: "http://x", config: "{}", enabled: true }).returning())[0].id;
await trackIntegrationHealth("speedtest", true);
await sp.setStatusItems(linkId, [...(await sp.getStatusItems(linkId)).map((i) => ({ label: i.label, kind: i.kind, targetId: i.targetId, monitorId: i.monitorId })), { label: "Internet", kind: "integration", targetId: st }]);
testAlerts = [];
assert.equal((await read()).Internet, "up");
testAlerts = [alert(integration(st), { id: `monitoring:speedtest-slow:${st}` })];
assert.equal((await read()).Internet, "trouble");
testAlerts = [alert(integration(st), { id: `monitoring:speedtest-failing:${st}` })];
assert.equal((await read()).Internet, "down");
testAlerts = [];
});
test("the page says how many are in trouble and reads as trouble when nothing is down; and no alert text, name or id reaches the public", async () => {
await sp.setStatusItems(linkId, (await sp.getStatusItems(linkId)).filter((i) => ["Files", "Automation", "Movies"].includes(i.label)).map((i) => ({ label: i.label, kind: i.kind, targetId: i.targetId, monitorId: i.monitorId })));
testAlerts = [alert(server(ids.up), { id: "services:secret-alert-id" })];
const page = await sp.buildPublicStatus(link, NOW);
assert.deepEqual(page.counts, { up: 2, trouble: 1, down: 0, maintenance: 0, unknown: 0 });
assert.equal(page.level, "trouble");
const text = JSON.stringify(page);
for (const secret of ["private server name", "secret-alert-id", "private integration name"]) assert.ok(!text.includes(secret), secret);
testAlerts = [];
});
test("alerts that cannot be read say nothing is in trouble, and the page still works", async () => {
sp.setAlertsLoaderForTests(async () => {
throw new Error("alerts are down");
});
assert.equal((await read()).Files, "up");
sp.setAlertsLoaderForTests(async () => testAlerts as never);
});
});
test("the public is given names and states and nothing else", async () => {
const text = JSON.stringify(await sp.buildPublicStatus(link, NOW));
for (const secret of ["10.1.2.3", "kuma.lab", "sem.lab", "private name", "m-up", "apiToken", "elsa", "tok"]) assert.ok(!text.includes(secret), `the page leaks "${secret}"`);