feat: add managed database capture and operator restore

PostgreSQL and MySQL backups run through paired outposts, with operator sign-in, off-site copies, and legacy import. Retention stays on each orbit, so the unused retention console is removed.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-10 23:26:49 +07:00
parent 30a1a9b8f0
commit 6320b6f244
96 changed files with 11061 additions and 725 deletions

View File

@@ -1,26 +1,179 @@
import assert from "node:assert/strict";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { chromium } from "playwright";
const { chromium } = await import(process.env.PLAYWRIGHT_MODULE ?? "playwright");
const base = process.env.TESSERA_URL ?? "http://127.0.0.1:8787/";
const outFlow = process.env.FLOW_SHOT ?? join(tmpdir(), "tessera-galaxy-flowing.png");
const outLock = process.env.LOCK_SHOT ?? join(tmpdir(), "tessera-galaxy-locked.png");
const browser = await chromium.launch({ headless: true });
const fixture = process.env.TESSERA_GALAXY_FIXTURE === "1";
const verify = fixture && process.env.VERIFY_ANIMATION !== "0";
const throttle = Number(process.env.CPU_THROTTLE ?? 4);
const viewport = {
width: Number(process.env.VIEWPORT_WIDTH ?? 1440),
height: Number(process.env.VIEWPORT_HEIGHT ?? 900),
};
const browser = await chromium.launch({
headless: true,
executablePath: process.env.CHROMIUM_PATH,
});
try {
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });
const page = await browser.newPage({ viewport });
page.setDefaultTimeout(5000);
const errors = [];
page.on("pageerror", error => errors.push(error.message));
if (fixture) {
const orbits = Array.from({ length: 55 }, (_, index) => ({
id: `orbit-${index}`, name: `Load test orbit ${index + 1}`, provider: "filesystem",
last_status: index === 2 ? "running" : index === 3 ? "failed" : "completed", dry_run: false,
}));
const snapshots = orbits.flatMap(orbit => [1, 2, 3].map(day => ({
id: `${orbit.id}-snapshot-${day}`, orbit_id: orbit.id, orbit_name: orbit.name,
taken_at: `2026-01-0${day}T00:00:00Z`, size_bytes: 4096 * day,
})));
await page.route("**/health", route => route.fulfill({ body: "ok" }));
await page.route("**/api/v1/orbits", route => route.fulfill({ json: orbits }));
await page.route("**/api/v1/snapshots", async route => {
if (snapshots.length > orbits.length * 3) await new Promise(resolve => setTimeout(resolve, 1500));
await route.fulfill({ json: snapshots });
});
await page.route("**/api/v1/orbits/*/run", route => {
const id = new URL(route.request().url()).pathname.split("/").at(-2);
if (id === "orbit-1") return route.fulfill({ status: 500, body: "fixture capture failed" });
const orbit = orbits.find(orbit => orbit.id === id);
const snapshot = {
id: `${id}-captured`, orbit_id: id, orbit_name: orbit.name,
taken_at: new Date().toISOString(), size_bytes: 8192,
};
snapshots.push(snapshot);
return route.fulfill({ status: 204, headers: { "X-Tessera-Snapshot-Id": snapshot.id } });
});
}
const cdp = await page.context().newCDPSession(page);
await cdp.send("Emulation.setCPUThrottlingRate", { rate: throttle });
async function frameTimes(mode) {
const stats = await page.evaluate(async () => {
const samples = [];
let previous = await new Promise(requestAnimationFrame);
for (let i = 0; i < 90; i++) {
const now = await new Promise(requestAnimationFrame);
samples.push(now - previous);
previous = now;
}
samples.sort((a, b) => a - b);
return { median: samples[45], p95: samples[85] };
});
console.log(`${mode} at ${viewport.width}×${viewport.height}, ${throttle}× CPU throttle: median ${stats.median.toFixed(1)}ms, p95 ${stats.p95.toFixed(1)}ms`);
const limit = process.env.FRAME_P95_MAX_MS;
if (limit) assert.ok(stats.p95 <= Number(limit), `${mode} p95 exceeded ${limit}ms`);
}
if (verify) {
await page.addInitScript(() => {
const requestFullscreen = Element.prototype.requestFullscreen;
window.fullscreenRequests = 0;
Element.prototype.requestFullscreen = function (...args) {
window.fullscreenRequests++;
return requestFullscreen?.apply(this, args) ?? Promise.reject(new Error("Fullscreen unavailable"));
};
});
}
const [orbitResponse] = await Promise.all([
page.waitForResponse((response) => new URL(response.url()).pathname === "/api/v1/orbits" && response.ok()),
page.goto(base),
]);
await page.getByText("Hub online", { exact: true }).waitFor();
await frameTimes("Workspace flowing");
if (fixture) {
await page.getByRole("button", { name: "Big screen", exact: true }).click();
await page.getByRole("button", { name: "Exit big screen" }).waitFor();
if (verify) {
assert.equal(await page.evaluate(() => window.fullscreenRequests), 0, "Big Screen requested browser fullscreen");
assert.equal(await page.evaluate(() => document.fullscreenElement !== null), false);
}
await frameTimes("Big Screen flowing");
await page.getByRole("button", { name: "Exit big screen" }).click();
}
await page.screenshot({ path: outFlow });
const firstOrbit = page.locator(".register-row").first();
const firstOrbit = fixture ? page.locator("#register-orbit-0") : page.locator(".register-row").first();
if ((await orbitResponse.json()).length) await firstOrbit.click();
else await page.getByRole("button", { name: "Pause motion" }).click();
await page.getByRole("button", { name: "Resume motion" }).waitFor();
if (verify || !fixture) {
await page.waitForFunction(checkSelection => {
const frame = document.querySelector(".galaxy-frame");
return (!checkSelection || frame.querySelector(".scene-labels .is-selected")) &&
Number(getComputedStyle(frame).getPropertyValue("--lock-reveal")) > 0.99;
}, verify);
}
await page.screenshot({ path: outLock });
if (verify) {
const lock = page.getByRole("button", { name: "Pause motion" });
const resume = page.getByRole("button", { name: "Resume motion" });
const frame = page.locator(".galaxy-frame");
// A reversal should reuse the label node and leave no interactive moons in Flowing.
const sameLabel = await page.evaluate(async () => {
const label = document.querySelector(".scene-labels .is-selected");
const button = document.querySelector(".scene-controls button");
button.click();
await new Promise(requestAnimationFrame);
await new Promise(requestAnimationFrame);
button.click();
return label === document.querySelector(".scene-labels .is-selected");
});
assert.ok(sameLabel);
await resume.waitFor();
await page.getByRole("button", { name: "Capture Load test orbit 1", exact: true }).click();
await page.getByText("Snapshot secured from Load test orbit 1.", { exact: true }).waitFor();
await page.waitForFunction(() => Number(document.querySelector(".capture-arrival").getAttribute("opacity")) > 0.1);
await page.waitForFunction(() => Number(
document.querySelector("[data-vault-core]").style.getPropertyValue("--capture-absorption"),
) > 0.2);
await page.waitForFunction(() => {
const flash = document.querySelector("#snapshot-orbit-0-captured .snapshot-row-flash");
const moon = document.querySelector('[data-snapshot-marker="orbit-0-captured"] .snapshot-flash');
return flash && moon && Number(getComputedStyle(flash).opacity) > 0.2 && Number(getComputedStyle(moon).opacity) > 0.2;
});
await page.locator("#register-orbit-1").click();
await page.getByRole("button", { name: "Capture Load test orbit 2", exact: true }).click();
await page.getByText("Capture failed for Load test orbit 2.", { exact: true }).waitFor();
await page.waitForFunction(() => Number(document.querySelector(".capture-flare").getAttribute("opacity")) > 0.1);
assert.equal(await page.locator(".capture-arrival").getAttribute("opacity"), "0");
const workspaceWidth = await frame.evaluate(element => element.getBoundingClientRect().width);
await page.getByRole("button", { name: "Big screen", exact: true }).click();
await page.waitForFunction(width => {
const frame = document.querySelector(".galaxy-frame");
const current = frame.getBoundingClientRect().width;
return current > width + 3 && current < frame.clientWidth - 3;
}, workspaceWidth);
await page.setViewportSize({ width: 1366, height: 820 });
await page.keyboard.press("Escape");
await page.getByRole("button", { name: "Big screen", exact: true }).waitFor();
await page.waitForFunction(() => !document.querySelector(".galaxy-frame").style.transform);
await page.setViewportSize(viewport);
await page.waitForFunction(width =>
Math.abs(document.querySelector(".galaxy-frame").getBoundingClientRect().width - width) < 1, workspaceWidth);
await resume.click();
await lock.waitFor();
assert.equal(await page.locator(".lock-details").getAttribute("pointer-events"), "none");
await page.emulateMedia({ reducedMotion: "reduce" });
await page.getByRole("button", { name: "Reduced motion" }).waitFor();
assert.equal(await frame.getAttribute("data-flowing"), "false");
assert.equal(await page.locator(".scene-labels .is-selected").evaluate(label => getComputedStyle(label).opacity), "1");
await page.getByRole("button", { name: "Big screen", exact: true }).click();
assert.equal(await frame.evaluate(element => element.style.transform), "");
assert.deepEqual(errors, []);
console.log("verified lock reversal, confirmed and failed capture, Big Screen resize, and reduced motion");
}
console.log("saved", outFlow, outLock);
} finally {
await browser.close();

View File

@@ -1,6 +1,6 @@
import assert from "node:assert/strict";
import test from "node:test";
import { assignOrbitSlots, orbitPose, groupSnapshots, moonPoses } from "../src/lib/galaxyLayout.ts";
import { capturePhases, assignOrbitSlots, orbitPose, groupSnapshots, moonPoses } from "../src/lib/galaxyLayout.ts";
import { placeLabels } from "../src/lib/galaxyLabelLayout.ts";
test("slot identities survive reordering, insertion and removal", () => {
@@ -62,3 +62,25 @@ test("labels respect screen bounds and preserve priority in a crowded scene", ()
assert.deepEqual(labels.map((l) => l.id), ["focused"]);
assert.ok(labels[0].x >= 0 && labels[0].x + 72 <= 140);
});
test("capture flares before flight, then absorbs and highlights the snapshot", () => {
const flare = capturePhases(0.06);
assert.equal(flare.flare, 1);
assert.equal(flare.flight, 0);
assert.equal(flare.highlight, 0);
const arrival = capturePhases(0.84);
assert.equal(arrival.flight, 1);
assert.equal(arrival.absorption, 1);
assert.equal(arrival.highlight, 0);
assert.equal(capturePhases(0.94).absorption, 0);
assert.equal(capturePhases(0.94).highlight, 0);
assert.equal(capturePhases(0.97).highlight, 1);
assert.deepEqual(capturePhases(1), { flare: 0, flight: 1, absorption: 0, highlight: 0, failure: 0 });
});
test("the selected label searches farther when nearby orbit markers crowd it out", () => {
const selected = { id: "focused", x: 140, y: 140, width: 60 };
const cluster = { x: 61, y: 61, width: 158, height: 158 };
assert.deepEqual(placeLabels([selected], 300, 300, [cluster]), []);
assert.equal(placeLabels([selected], 300, 300, [cluster], selected.id)[0]?.id, selected.id);
});

View File

@@ -0,0 +1,38 @@
import assert from "node:assert/strict";
import test from "node:test";
import { formatWhen } from "../src/lib/format.ts";
import { createVaultSearch } from "../src/lib/vaultSearch.ts";
const navigation = [{ id: "orbits", label: "Orbits", icon: "" }];
const orbit = (id, name = "Orbits", provider = "filesystem") => ({ id, name, provider });
const snapshot = (id, taken_at, orbit_name = "Orbits") => ({ id, taken_at, orbit_name });
test("ranks exact, prefix, and substring matches case-insensitively", () => {
const orbits = [orbit("a", "Nightly Vault"), orbit("b", "Vault mirror"), orbit("c", "vault")];
const search = createVaultSearch(navigation, orbits);
const [group] = search(" VAULT ");
assert.deepEqual(group.results.map(({ id }) => id), ["c", "b", "a"]);
assert.equal(search("FILESYSTEM")[0].results.length, 3);
});
test("keeps duplicate names distinguishable and sorts equivalent snapshots newest first", () => {
const orbits = [orbit("alpha"), orbit("beta", "Orbits", "postgres")];
const snapshots = [snapshot("old", "2025-01-01T00:00:00Z"), snapshot("new", "2025-02-01T00:00:00Z")];
const search = createVaultSearch(navigation, orbits, snapshots);
const [, orbitGroup, snapshotGroup] = search("orbits");
assert.equal(new Set(orbitGroup.results.map(({ detail }) => detail)).size, 2);
assert.deepEqual(snapshotGroup.results.map(({ id }) => id), ["new", "old"]);
assert.equal(search(formatWhen(snapshots[0].taken_at))[0].results[0].id, "old");
assert.equal(search("beta")[0].results[0].id, "beta");
});
test("reserves a place for every matching category within the eight-result limit", () => {
const orbits = Array.from({ length: 12 }, (_, index) => orbit(`orbit-${index}`));
const snapshots = [snapshot("snap", "2025-02-01T00:00:00Z")];
const search = createVaultSearch(navigation, orbits, snapshots);
const groups = search("orbits");
assert.deepEqual(groups.map(({ label }) => label), ["Navigation", "Orbits", "Snapshots"]);
assert.equal(groups.flatMap(({ results }) => results).length, 8);
assert.deepEqual(search(" ").map(({ label }) => label), ["Navigation"]);
assert.deepEqual(search("no match"), []);
});