- Activity lists restores from refresh runs, so the Refresh permission is enough to see them; an administrator's restore jobs add the database, the person and the snapshot - an undo is listed under the restore it reverses, and a redo under that undo; opening a restore or an undo opens its undo or redo dialog - the dialog has an explicit undo mode: it describes what is put back instead of the snapshot that was open, and an interrupted restore offers Roll back - a restore whose safety backup retention has forgotten shows "Safety backup expired" instead of a link, and the dialog says how long a safety copy is kept Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
69 lines
4.3 KiB
JavaScript
69 lines
4.3 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { STAGES, isFinal, outcomeOf, progressOf, relationLabels } from "../src/lib/restoreRun.ts";
|
|
|
|
const run = (status, restore_phase = null, blocked_reason = null) => ({ status, restore_phase, blocked_reason });
|
|
|
|
test("the four stages follow the restore job's phase", () => {
|
|
assert.deepEqual(STAGES, ["Checking", "Safety copy", "Applying", "Completed"]);
|
|
// the run is created first; the restore job appears a moment later
|
|
assert.equal(progressOf(run("capturing")).index, 0);
|
|
for (const phase of ["queued", "claimed", "checking"]) assert.equal(progressOf(run("restoring", phase)).index, 0, phase);
|
|
for (const phase of ["safety", "ready"]) assert.equal(progressOf(run("restoring", phase)).index, 1, phase);
|
|
assert.equal(progressOf(run("restoring", "applying")).index, 2);
|
|
assert.deepEqual(progressOf(run("completed", "completed")), { index: 4, state: "done" });
|
|
assert.equal(progressOf(run("restoring", "applying")).state, "running");
|
|
// the restore job finishes a moment before the run is marked completed: that gap must not look like a restart
|
|
assert.deepEqual(progressOf(run("restoring", "completed")), { index: 4, state: "done" });
|
|
assert.equal(isFinal(run("restoring")), false);
|
|
assert.equal(isFinal(run("completed")), true);
|
|
});
|
|
|
|
test("a run that stopped says at which stage and why it counts as failed or merely cancelled", () => {
|
|
assert.deepEqual(progressOf(run("restore_failed", "invalid_payload")), { index: 0, state: "failed" });
|
|
assert.deepEqual(progressOf(run("restore_failed", "safety_failed")), { index: 1, state: "failed" });
|
|
assert.deepEqual(progressOf(run("recovery_required", "apply_failed")), { index: 2, state: "failed" });
|
|
assert.deepEqual(progressOf(run("blocked", "checking", "access_revoked")), { index: 0, state: "failed" });
|
|
assert.deepEqual(progressOf(run("cancelled", "safety")), { index: 1, state: "cancelled" });
|
|
assert.equal(progressOf(run("expired")).state, "failed");
|
|
});
|
|
|
|
test("what the person is told never contains the database's own words", () => {
|
|
const done = outcomeOf(run("completed"), { target: "Development", orbit: "ledger", when: "Nov 15, 11:57 AM" });
|
|
assert.equal(done.tone, "good");
|
|
assert.match(done.detail, /Development now holds ledger as of Nov 15, 11:57 AM/);
|
|
assert.match(outcomeOf(run("restore_failed", "apply_failed"), { target: "Development" }).detail, /ask an administrator/i);
|
|
assert.match(outcomeOf(run("recovery_required"), { target: "Staging" }).title, /interrupted/i);
|
|
assert.match(outcomeOf(run("blocked", null, "access_revoked"), { target: "Staging" }).detail, /access to this restore was removed/);
|
|
assert.equal(outcomeOf(run("cancelled"), { target: "Staging" }).tone, "plain");
|
|
assert.equal(outcomeOf(run("restoring", "safety"), { target: "Staging" }).tone, "busy");
|
|
});
|
|
|
|
test("an undo is worded as putting the target back, and its own safety copy keeps it undoable", () => {
|
|
const done = outcomeOf({ ...run("completed"), undo: true }, { target: "Staging", orbit: "ledger", when: "Nov 15, 11:57 AM" });
|
|
assert.equal(done.tone, "good");
|
|
assert.match(done.title, /Staging was rolled back/);
|
|
assert.match(done.detail, /holds what it held before that restore/);
|
|
assert.match(outcomeOf({ ...run("restore_failed", "apply_failed"), undo: true }, { target: "Staging" }).title, /undo failed/i);
|
|
});
|
|
|
|
test("restore points are named by environment, and by target only when two share one", () => {
|
|
const rel = (id, env, name) => ({ id, target_environment: env, target_name: name, usable: true });
|
|
assert.deepEqual(
|
|
relationLabels([rel("a", "staging", "s1"), rel("b", "development", "d1")]).map((r) => r.label),
|
|
["Staging", "Development"],
|
|
);
|
|
assert.deepEqual(
|
|
relationLabels([rel("a", "staging", "s1"), rel("b", "staging", "s2")]).map((r) => r.label),
|
|
["Staging · s1", "Staging · s2"],
|
|
);
|
|
assert.equal(relationLabels([rel("a", null, "odd")])[0].label, "odd");
|
|
});
|
|
|
|
test("an interrupted restore offers a rollback only when its safety copy can be used", () => {
|
|
const names = { target: "Staging" };
|
|
const stuck = { status: "recovery_required", restore_phase: "apply_failed" };
|
|
assert.match(outcomeOf({ ...stuck, undo_available: true }, names).detail, /roll it back/i);
|
|
assert.match(outcomeOf(stuck, names).detail, /administrator has to recover/i);
|
|
});
|