Nextcloud cron and Nextcloud's own checks; bulk close and open again

Nextcloud: its own "Cron last run" setup check (GET /settings/setupcheck,
Nextcloud 28+, found by class name) raises an alert when background jobs have
stopped; other checks that report an error are one alert, warnings are shown
on the page. The core version Nextcloud says is available is shown too. Before
28, cron and the checks are unknown, never "fine".

Alerts page: bulk Close... (one reason, written on each incident, undoable) and
Open again. Bulk Wake now leaves closed alerts alone.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-25 22:12:10 +01:00
1 parent 5ae61a1ece
commit 65214f6f0f
25 files changed
+8108 -35

No files matched your search

+96
View File
@@ -204,3 +204,99 @@ describe("until it gets worse", () => {
assert.deepEqual(reminders.map((r) => [r.key, r.reason]), [["k:x5", "ended"]]);
});
});
describe("closing several at once", () => {
const notesOf = async (alertId: string) => {
const incidentId = (await openIncidentIds([alertId])).get(alertId)!;
return (await getIncident(incidentId))!.notes.map((n) => n.body);
};
const clear = async () => {
await db.delete(alertSnoozes);
};
test("several are closed with one reason; each incident says so; the one that has gone is skipped; they are held back", async () => {
await clear();
const a = await idOfHeartbeat("jobA");
const b = await idOfHeartbeat("jobB");
const r = await call("POST", "/bulk", { action: "close", alertIds: [a.id, b.id, "monitoring:nothing:1"], note: " Both retired with the old host. " });
assert.equal(r.status, 200);
assert.equal(r.body.changed, 2);
assert.deepEqual(r.body.skipped.map((x: { reason: string }) => x.reason), ["it isn't there any more"]);
const rows = await db.select().from(alertSnoozes);
assert.deepEqual(rows.map((x) => [x.kind, x.note, x.snoozedBy]), [["closed", "Both retired with the old host.", "Olga"], ["closed", "Both retired with the old host.", "Olga"]]);
assert.deepEqual(rows.map((x) => x.severity), [a.severity, b.severity]);
assert.ok((await notesOf(a.id)).includes("Closed: Both retired with the old host. (closed together with 1 other)"));
invalidateAlertsCache();
const report = await getAlerts(true);
assert.ok([a.id, b.id].every((id) => report.alerts.find((x) => x.id === id)?.closed?.by === "Olga"));
await call("POST", "/bulk", r.body.undo);
});
test("undo opens them again and says so on each incident; an alert that was closed before the bulk keeps its own closing and note", async () => {
await clear();
const a = await idOfHeartbeat("jobA");
const b = await idOfHeartbeat("jobB");
await call("PUT", "/close", { alertId: a.id, note: "mine from before" });
const r = await call("POST", "/bulk", { action: "close", alertIds: [a.id, b.id], note: "bulk" });
assert.equal(r.body.changed, 2);
assert.equal(r.body.undo.closed, true);
assert.equal((await db.select().from(alertSnoozes).where(eq(alertSnoozes.alertId, a.id)))[0].note, "bulk", "replaced");
const undone = (id: string) => notesOf(id).then((n) => n.filter((x) => x === "Opened again (closing it was undone).").length);
const [beforeA, beforeB] = [await undone(a.id), await undone(b.id)];
await call("POST", "/bulk", r.body.undo);
const rows = await db.select().from(alertSnoozes);
assert.deepEqual(rows.map((x) => [x.alertId, x.note]), [[a.id, "mine from before"]], "a is closed as it was; b is open again");
assert.equal(await undone(b.id), beforeB + 1, "b is open again and says so");
assert.equal(await undone(a.id), beforeA, "a was not opened by the undo, so says nothing");
await clear();
});
test("open again: only closed alerts are opened, one that is merely snoozed is left as it is, and the incident says so; undo closes them again", async () => {
await clear();
const a = await idOfHeartbeat("jobA");
const b = await idOfHeartbeat("jobB");
await call("PUT", "/close", { alertId: a.id, note: "accepted" });
await call("PUT", "/snooze", { alertId: b.id, until: new Date(Date.now() + 3_600_000).toISOString() });
const r = await call("POST", "/bulk", { action: "reopen", alertIds: [a.id, b.id] });
assert.equal(r.body.changed, 1);
assert.deepEqual(r.body.skipped.map((x: { reason: string }) => x.reason), ["it wasn't closed"]);
assert.deepEqual((await db.select().from(alertSnoozes)).map((x) => [x.alertId, x.kind]), [[b.id, "snooze"]]);
assert.equal((await notesOf(a.id)).at(-1), "Opened again.");
await call("POST", "/bulk", r.body.undo);
const back = (await db.select().from(alertSnoozes).where(eq(alertSnoozes.alertId, a.id)))[0];
assert.deepEqual([back.kind, back.note], ["closed", "accepted"]);
await clear();
});
test("waking snoozed alerts leaves a closed one alone and says to use Open again", async () => {
await clear();
const a = await idOfHeartbeat("jobA");
await call("PUT", "/close", { alertId: a.id });
const r = await call("POST", "/bulk", { action: "unsnooze", alertIds: [a.id] });
assert.equal(r.body.changed, 0);
assert.match(r.body.skipped[0].reason, /closed, not snoozed — use Open again/);
assert.equal((await db.select().from(alertSnoozes)).length, 1, "still closed");
await clear();
});
test("a note that is too long is refused and nothing is closed; a viewer cannot; both are in the audit log and the change log", async () => {
await clear();
const a = await idOfHeartbeat("jobA");
const long = await call("POST", "/bulk", { action: "close", alertIds: [a.id], note: "x".repeat(501) });
assert.equal(long.status, 400);
assert.equal((await db.select().from(alertSnoozes)).length, 0);
who = "viewer";
assert.equal((await call("POST", "/bulk", { action: "close", alertIds: [a.id] })).status, 403);
assert.equal((await call("POST", "/bulk", { action: "reopen", alertIds: [a.id] })).status, 403);
who = "operator";
await call("POST", "/bulk", { action: "close", alertIds: [a.id], note: "n" });
await call("POST", "/bulk", { action: "reopen", alertIds: [a.id] });
const actions = (await db.select().from(auditLog)).map((e) => `${e.category}/${e.action}`);
assert.ok(actions.includes("alert/bulk_close") && actions.includes("alert/bulk_reopen"));
const titles = (await getChangeLog({ days: 1, limit: 400 })).entries.map((e) => e.title);
assert.ok(titles.some((t) => /alerts? closed at once$/.test(t)), "close");
assert.ok(titles.some((t) => /closed alerts? opened again at once$/.test(t)), "reopen");
assert.ok(titles.some((t) => /^Closing several alerts at once was undone$/.test(t)), "undo");
await clear();
});
});