Files
boss/tests/state-store-maintenance-script.test.ts

57 lines
1.8 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import os from "node:os";
import path from "node:path";
import { execFile } from "node:child_process";
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { promisify } from "node:util";
const execFileAsync = promisify(execFile);
const scriptPath = new URL("../scripts/boss-state-store-maintenance.mjs", import.meta.url);
test("state store maintenance script exposes migration, backup, export, and rollback commands", async () => {
const source = await readFile(scriptPath, "utf8");
for (const command of [
"describe",
"backup-file",
"export-file",
"migrate-file-to-postgres",
"rollback-postgres-to-file",
]) {
assert.match(source, new RegExp(command));
}
assert.match(source, /BOSS_DATABASE_URL/);
assert.match(source, /boss_state_snapshots/);
});
test("backup-file dry run validates local state without requiring postgres", async () => {
const root = await mkdtemp(path.join(os.tmpdir(), "boss-state-maintenance-"));
try {
const stateFile = path.join(root, "boss-state.json");
await writeFile(stateFile, JSON.stringify({ schemaVersion: 1, migratedAt: "2026-04-27T00:00:00.000Z" }), "utf8");
const { stdout } = await execFileAsync(process.execPath, [
scriptPath.pathname,
"backup-file",
"--input",
stateFile,
"--dry-run",
], {
env: {
...process.env,
BOSS_STATE_FILE: stateFile,
},
});
const payload = JSON.parse(stdout);
assert.equal(payload.ok, true);
assert.equal(payload.action, "backup-file");
assert.equal(payload.dryRun, true);
assert.equal(payload.source, stateFile);
assert.equal(payload.bytes > 0, true);
} finally {
await rm(root, { recursive: true, force: true });
}
});