Prevent old reflection replay during CLI reconstruction

This commit is contained in:
vorotamoroz committed 2026-11-05 11:17:19 +00:00
1 parent daa67bea51
commit 4f0258d828
7 files changed
+173 -39

No files matched your search

+34
View File
@@ -14,6 +14,7 @@ import {
type FilePathWithPrefix,
type ObsidianLiveSyncSettings,
} from "@vrtmrz/livesync-commonlib/compat/common/types";
import { ReplicateResultProcessor } from "@/serviceFeatures/replication/ReplicateResultProcessor";
import { ServiceFileHandler } from "@/serviceModules/FileHandler";
import { ServiceFileAccessCLI } from "./serviceModules/ServiceFileAccessImpl";
import { runCommand } from "./commands/runCommand";
@@ -103,6 +104,39 @@ describe("CLI database preparation", () => {
await expect(main(standardIo, runner)).rejects.toThrow(`__EXIT__:${exitCode}`);
}
it.each(["fetch", "rebuild"] as const)("does not replay the old reflection snapshot before %s", async (command) => {
const restore = vi.spyOn(ReplicateResultProcessor.prototype, "restoreFromSnapshot");
const runner = vi.fn<CliCommandRunner>(async () => false);
await start(command, runner, 1, true);
expect(runner).toHaveBeenCalledOnce();
expect(restore).not.toHaveBeenCalled();
});
it.each(["fetch", "rebuild"] as const)("invalidates old reflection work after the %s database reset", async (command) => {
const snapshotKey = "replicationResultProcessorSnapshot";
const oldSnapshot = { queued: [{ _id: "old", _rev: "1-old" }], processing: [] };
let retainedBeforeReset: unknown;
let retainedAfterReset: unknown;
let reset: boolean | undefined;
const runner = vi.fn<CliCommandRunner>(async (_options, { core }) => {
await core.services.keyValueDB.kvDB.set(snapshotKey, oldSnapshot);
retainedBeforeReset = await core.services.keyValueDB.kvDB.get(snapshotKey);
reset = await core.services.database.resetDatabase();
retainedAfterReset = await core.services.keyValueDB.kvDB.get(snapshotKey);
return false;
});
await start(command, runner, 1, true);
expect(runner).toHaveBeenCalledOnce();
expect(reset).toBe(true);
expect(retainedBeforeReset).toEqual(oldSnapshot);
expect(retainedAfterReset).toEqual({ queued: [], processing: [] });
expect(await readFile(join(vaultPath, "notes/local.md"), "utf8")).toBe("local content");
});
it.each([
{ handleFilenameCaseSensitive: true, pathNormalizationVersion: 0 as const },
{ handleFilenameCaseSensitive: true, pathNormalizationVersion: 1 as const },
+10 -2
View File
@@ -77,13 +77,21 @@ const VAULT_SYNC_MODES: Readonly<Partial<Record<CLICommand, CLIVaultSyncMode>>>
watchFiles: false,
reflectReplicationResults: false,
scanOnStartup: false,
startupDatabaseOptions: { ignoreSuspending: false, continueOnFileFailure: false },
startupDatabaseOptions: {
ignoreSuspending: false,
continueOnFileFailure: false,
discardReplicationResultSnapshotOnReset: true,
},
},
fetch: {
watchFiles: false,
reflectReplicationResults: true,
scanOnStartup: false,
startupDatabaseOptions: { ignoreSuspending: false, continueOnFileFailure: false },
startupDatabaseOptions: {
ignoreSuspending: false,
continueOnFileFailure: false,
discardReplicationResultSnapshotOnReset: true,
},
},
};