mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 15:42:24 +00:00
refactor(admin): read the off-host card from evidence, sort the worst row first
Four smaller things around the same card. The configured flag came from the environment of whichever process serves the request. A hand-rolled split that gives BACKUP_S3_* to the worker and not to the web process would have shown an operator "nothing leaves this host" over a ledger full of fresh rows. The ledger is queried either way now, and a row in it outranks an environment read: a row is proof an upload happened. Rows sorted by username put the one account that needs attention wherever the alphabet leaves it, which on a hundred-account cohort is the crowd problem the card exists to end, moved from a count into a list. Worst verdict first, alphabetical within a verdict, decided server-side so the tests and the accessibility fixture see the order the operator does. The card's docblock claimed the worker holds PutObject and GetObject. The runbook is right and the multipart path needs AbortMultipartUpload too, so the prose no longer documents a grant that would break the uploader. And the byte formatter moved to lib. The off-host card was importing it out of a thousand-line client component, which costs nothing while both cards render on one route and becomes a cost the moment either moves.
This commit is contained in:
1 parent
9d18b8fd25
commit
a7faae8ded
6 files changed
+120
-54
No files matched your search
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* The bucket is never touched here, and that is the assertion that matters —
|
||||
* the verdicts come from the ledger the worker writes, so an operator whose
|
||||
* worker holds PutObject and nothing else still gets a true answer.
|
||||
* worker holds no listing grant on the bucket still gets a true answer.
|
||||
*/
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
@@ -107,28 +107,35 @@ describe("GET /api/admin/backups — off-host freshness", () => {
|
||||
|
||||
expect(body.offhost.configured).toBe(true);
|
||||
expect(body.offhost.periodHours).toBe(24);
|
||||
// Worst first, alphabetical within a verdict. The database hands them
|
||||
// back by username; the one account that needs attention must not be
|
||||
// wherever the alphabet leaves it on a hundred-account cohort.
|
||||
expect(
|
||||
body.offhost.rows.map((row) => [row.username, row.freshness]),
|
||||
).toEqual([
|
||||
["account-one", "fresh"],
|
||||
["account-two", "due"],
|
||||
["account-three", "stale"],
|
||||
["account-two", "due"],
|
||||
["account-four", "never"],
|
||||
["account-five", "unknown"],
|
||||
["account-one", "fresh"],
|
||||
]);
|
||||
expect(body.offhost.rows[0]?.sizeBytes).toBe(4096);
|
||||
expect(typeof body.offhost.rows[0]?.sizeBytes).toBe("number");
|
||||
expect(body.offhost.rows[0]?.ageHours).toBe(3);
|
||||
expect(body.offhost.rows[3]?.lastSuccessAt).toBeNull();
|
||||
expect(body.offhost.rows[3]?.sizeBytes).toBeNull();
|
||||
expect(body.offhost.rows[3]?.lastAttemptAt).not.toBeNull();
|
||||
const byName = new Map(body.offhost.rows.map((row) => [row.username, row]));
|
||||
expect(byName.get("account-one")?.sizeBytes).toBe(4096);
|
||||
expect(typeof byName.get("account-one")?.sizeBytes).toBe("number");
|
||||
expect(byName.get("account-one")?.ageHours).toBe(3);
|
||||
expect(byName.get("account-four")?.lastSuccessAt).toBeNull();
|
||||
expect(byName.get("account-four")?.sizeBytes).toBeNull();
|
||||
expect(byName.get("account-four")?.lastAttemptAt).not.toBeNull();
|
||||
// `unknown` is the honest one: the ledger has no history for this
|
||||
// account, which is not the same claim as "the bucket is empty".
|
||||
expect(body.offhost.rows[4]?.lastAttemptAt).toBeNull();
|
||||
expect(byName.get("account-five")?.lastAttemptAt).toBeNull();
|
||||
});
|
||||
|
||||
it("says so and reads no account when off-host backup is not configured", async () => {
|
||||
it("says so when neither the environment nor the ledger knows of any upload", async () => {
|
||||
configuredMock.mockReturnValue(false);
|
||||
findManyMock.mockResolvedValue([
|
||||
{ id: "u1", username: "account-one", offhostBackupState: null },
|
||||
]);
|
||||
|
||||
const body = await read();
|
||||
|
||||
@@ -137,9 +144,30 @@ describe("GET /api/admin/backups — off-host freshness", () => {
|
||||
periodHours: 24,
|
||||
rows: [],
|
||||
});
|
||||
// Not merely empty output — the query never runs, so an unconfigured host
|
||||
// does not pay for a table scan to be told nothing is set up.
|
||||
expect(findManyMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("lets a ledger row outrank this process's own environment", async () => {
|
||||
// A hand-rolled split deployment can give BACKUP_S3_* to the worker and
|
||||
// not to the web process. The rows are proof uploads are happening;
|
||||
// saying "nothing leaves this host" over them would be this process
|
||||
// reporting on a job it cannot see.
|
||||
configuredMock.mockReturnValue(false);
|
||||
findManyMock.mockResolvedValue([
|
||||
{
|
||||
id: "u1",
|
||||
username: "account-one",
|
||||
offhostBackupState: {
|
||||
lastAttemptAt: new Date(),
|
||||
lastSuccessAt: new Date(),
|
||||
sizeBytes: BigInt(4096),
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
const body = await read();
|
||||
|
||||
expect(body.offhost.configured).toBe(true);
|
||||
expect(body.offhost.rows.map((row) => row.freshness)).toEqual(["fresh"]);
|
||||
});
|
||||
|
||||
it("never ships a credential or an object key with the verdicts", async () => {
|
||||
|
||||
Reference in new issue
Block a user