Preserve CLI database continuity after reconstruction

This commit is contained in:
vorotamoroz committed 2026-11-01 05:06:42 +00:00
1 parent 0e458e5e20
commit d50ee9a83e
21 files changed
+1585 -60

No files matched your search

@@ -1,6 +1,8 @@
import { describe, expect, it, vi, beforeEach } from "vitest";
import type { IStorageEventWatchHandlers } from "@vrtmrz/livesync-commonlib/compat/managers/adapters";
import type { NodeFile } from "@/apps/cli/adapters/NodeTypes";
import { fs, os, path } from "@vrtmrz/livesync-commonlib/node";
import { runtimeScopeDirectory } from "../runtimeState";
// ── chokidar mock ──────────────────────────────────────────────────────────────
// Must be hoisted before imports that pull in chokidar.
@@ -44,6 +46,27 @@ describe("CLIStorageEventManagerAdapter", () => {
});
});
it("keeps pending snapshots with the selected database and Vault pair", async () => {
const directory = fs.mkdtempSync(path.join(os.tmpdir(), "livesync-snapshot-"));
let database = "first";
let vault = "vault-a";
const adapter = new CLIStorageEventManagerAdapter(directory, undefined, false, undefined, () =>
path.join(runtimeScopeDirectory(directory, database, vault), "storage-events.json")
);
try {
await adapter.persistence.saveSnapshot([{ type: "SENTINEL_FLUSH" }]);
database = "second";
expect(await adapter.persistence.loadSnapshot()).toBeNull();
database = "first";
vault = "vault-b";
expect(await adapter.persistence.loadSnapshot()).toBeNull();
vault = "vault-a";
expect(await adapter.persistence.loadSnapshot()).toEqual([{ type: "SENTINEL_FLUSH" }]);
} finally {
fs.rmSync(directory, { recursive: true, force: true });
}
});
it("beginWatch is no-op when watchEnabled=false", async () => {
const adapter = new CLIStorageEventManagerAdapter("/base", undefined, false);
const handlers = makeHandlers();