Say what the last Duplicati report was, so a machine with no jobs explains itself

Each machine's card shows whether the last report was a backup, another
operation that was set aside, or one that could not be read (with the reason),
and counts of each since it was added. Administrators can see the start of an
unreadable report.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-11-09 23:33:03 +01:00
1 parent 64961b1141
commit e517de35af
11 files changed
+9248 -9

No files matched your search

+87
View File
@@ -198,6 +198,79 @@ describe("where a backup stands, and what is an alert", () => {
});
});
describe("what the last report was", () => {
test("why a body is not a report, in a sentence, with the start of it", () => {
assert.deepEqual(d.explainUnreadable(""), { reason: "the body was empty (or not text) — Duplicati should post its result as text or JSON", sample: null });
assert.equal(d.explainUnreadable(undefined).sample, null);
const cut = d.explainUnreadable('{"Data": {"MainOperation": "Backup"');
assert.match(cut.reason, /not valid JSON/);
assert.equal(cut.sample, '{"Data": {"MainOperation": "Backup"');
const noResult = d.explainUnreadable(JSON.stringify({ Data: { MainOperation: "Backup", Duration: "00:01:00" }, Extra: {} }));
assert.match(noResult.reason, /JSON without a ParsedResult field \(it has: MainOperation, Duration\)/);
assert.match(d.explainUnreadable("hello there").reason, /not JSON, and no "ParsedResult:" line/);
});
test("the sample is the start of what was sent, never more than 600 characters", () => {
assert.equal(d.explainUnreadable("x".repeat(5000)).sample?.length, 600);
});
test("the counts grow by the kind of report, and the last one is what is shown", () => {
const a = d.nextActivity(null, "t1", { outcome: "set_aside", operation: "Compact", result: "Success", job: "Docs", reason: null, sample: null });
assert.deepEqual([a.outcome, a.counts], ["set_aside", { recorded: 0, setAside: 1, unreadable: 0 }]);
const b = d.nextActivity(a, "t2", { outcome: "unreadable", operation: null, result: null, job: null, reason: "x", sample: "y" });
const c = d.nextActivity(b, "t3", { outcome: "recorded", operation: "Backup", result: "Success", job: "Docs", reason: null, sample: null });
assert.deepEqual([c.at, c.outcome, c.counts], ["t3", "recorded", { recorded: 1, setAside: 1, unreadable: 1 }]);
});
test("what is stored is read back as it was, and junk in the column is none", () => {
const a = d.nextActivity(null, "t1", { outcome: "recorded", operation: "Backup", result: "Success", job: "Docs", reason: null, sample: null });
assert.deepEqual(d.unpackActivity(JSON.stringify(a)), a);
for (const junk of [null, "", "nope", "[]", "{}", '{"outcome":"recorded"}']) assert.equal(d.unpackActivity(junk), null, String(junk));
});
describe("with reports that arrive", () => {
let token = "";
let id = 0;
before(async () => {
const made = await d.createSource({ name: "Quiet", serverId: null, createdBy: "Ada" });
token = made.token;
id = made.row.id;
});
const activity = async () => d.unpackActivity((await db.select().from(duplicatiSources).where(eq(duplicatiSources.id, id)))[0].lastReport);
test("before any report there is nothing to say", async () => {
assert.equal(await activity(), null);
});
test("a report about something other than a backup is said to be set aside, with what it was", async () => {
await d.recordReport(token, report({ MainOperation: "Compact", ParsedResult: "Success" }, "Docs"), new Date("2026-10-26T04:00:00Z"));
const a = (await activity())!;
assert.deepEqual([a.outcome, a.operation, a.result, a.job, a.counts], ["set_aside", "Compact", "Success", "Docs", { recorded: 0, setAside: 1, unreadable: 0 }]);
assert.equal((await db.select().from(duplicatiBackups).where(eq(duplicatiBackups.sourceId, id))).length, 0, "and no job was made");
});
test("a report that cannot be read says why, and keeps the start of it", async () => {
await d.recordReport(token, "this is not what Duplicati sends", new Date("2026-10-26T05:00:00Z"));
const a = (await activity())!;
assert.deepEqual([a.outcome, a.sample, a.counts.unreadable], ["unreadable", "this is not what Duplicati sends", 1]);
assert.match(a.reason ?? "", /ParsedResult/);
});
test("a backup is said to be recorded, with the job and how it ended; the counts carry on; 'last heard' is the time of the last of any kind", async () => {
await d.recordReport(token, report({ ParsedResult: "Warning" }, "Docs"), new Date("2026-10-26T06:00:00Z"));
const a = (await activity())!;
assert.deepEqual([a.outcome, a.operation, a.result, a.job, a.counts], ["recorded", "Backup", "Warning", "Docs", { recorded: 1, setAside: 1, unreadable: 1 }]);
assert.equal((await db.select().from(duplicatiSources).where(eq(duplicatiSources.id, id)))[0].lastReportAt, "2026-10-26T06:00:00.000Z");
});
test("an address nobody knows leaves nothing behind", async () => {
const before = await activity();
assert.deepEqual(await d.recordReport("hlm_d_not-a-real-token-at-all", report()), { recorded: false, reason: "unknown_token" });
assert.deepEqual(await activity(), before);
});
});
});
describe("what the warnings said", () => {
test("a report's warnings are kept as one line each, the first twenty, each cut at 500 characters; the first is the message", () => {
const r = d.parseReport(report({ ParsedResult: "Warning", WarningsActualLength: 3, Warnings: ["Failed to process path: C:\\locked.db\n access denied", " second ", { code: "x" }] }))!;
@@ -418,6 +491,20 @@ describe("the address Duplicati posts to, the pages, the alerts and /metrics", (
who = "admin";
});
test("the page says what the last report was; only an administrator is given the start of one that could not be read", async () => {
await call("POST", `/duplicati-report/${token}`, "something that is not a report at all", { "content-type": "text/plain" });
const source = async () => ((await (await call("GET", "/duplicati")).json()) as any).sources[0];
who = "admin";
const asAdmin = await source();
assert.deepEqual([asAdmin.lastReport.outcome, asAdmin.lastReport.sample, asAdmin.lastReport.counts.unreadable >= 1], ["unreadable", "something that is not a report at all", true]);
for (const role of ["operator", "viewer"]) {
who = role;
const other = await source();
assert.deepEqual([other.lastReport.outcome, other.lastReport.sample, /ParsedResult/.test(other.lastReport.reason)], ["unreadable", null, true], role);
}
who = "admin";
});
test("a job set to alert on warnings raises one in the Backups kind, with the first message, and the page says what is wrong; switched off, it stops", async () => {
invalidateAlertsCache();
const a = (await getAlerts(true)).alerts.find((x) => /^backup:duplicati-warnings:\d+:server:/.test(x.id))!;