From 1543a53263efa8cd224a21a9d5fdfe99e66f04b5 Mon Sep 17 00:00:00 2001 From: vorotamoroz Date: Sat, 1 Aug 2026 06:09:02 +0000 Subject: [PATCH] refactor: compose Journal remotes generically --- src/apps/cli/commands/runCommand.ts | 4 +-- src/apps/cli/commands/runCommand.unit.spec.ts | 27 +++++++++++++++++++ .../core/ModuleReplicatorCouchDB.unit.spec.ts | 11 ++++---- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/apps/cli/commands/runCommand.ts b/src/apps/cli/commands/runCommand.ts index d6f65c42..19838052 100644 --- a/src/apps/cli/commands/runCommand.ts +++ b/src/apps/cli/commands/runCommand.ts @@ -6,7 +6,7 @@ import { type FilePathWithPrefix, type ObsidianLiveSyncSettings, REMOTE_COUCHDB, - REMOTE_MINIO, + isJournalRemoteType, type EntryMilestoneInfo, type EntryDoc, } from "@vrtmrz/livesync-commonlib/compat/common/types"; @@ -61,7 +61,7 @@ async function verifyRemoteState( return false; } milestone = await dbRet.db.get(MILESTONE_DOCID); - } else if (settings.remoteType === REMOTE_MINIO) { + } else if (isJournalRemoteType(settings.remoteType)) { const journalReplicator = replicator as LiveSyncJournalReplicator; if (journalProtocolConfigurationForSettings(settings).journalFormat === "adaptive-v1") { try { diff --git a/src/apps/cli/commands/runCommand.unit.spec.ts b/src/apps/cli/commands/runCommand.unit.spec.ts index 4cfaf611..641038be 100644 --- a/src/apps/cli/commands/runCommand.unit.spec.ts +++ b/src/apps/cli/commands/runCommand.unit.spec.ts @@ -7,6 +7,7 @@ import { REMOTE_COUCHDB, REMOTE_MINIO, REMOTE_P2P, + REMOTE_WEBDAV, } from "@vrtmrz/livesync-commonlib/compat/common/types"; import { describe, expect, it, vi, beforeEach, afterEach } from "vitest"; import { runCommand } from "./runCommand"; @@ -750,6 +751,32 @@ describe("runCommand abnormal cases", () => { ); }); + it("uses the Adaptive verification path for a WebDAV remote", async () => { + const core = createCoreMock(); + const settings = core.services.setting.currentSettings(); + settings.remoteType = REMOTE_WEBDAV; + settings.webDAVactiveConnectionURI = "sls+webdav://dav.example/dav"; + settings.journalFormat = "adaptive-v1"; + settings.packReadPolicy = "whole-pack"; + + const ensureCheckpointCachesAreFresh = vi.fn(async () => {}); + core.services.replicator.getActiveReplicator.mockReturnValue({ + nodeid: "test-node-id", + initializeDatabaseForReplication: vi.fn(async () => {}), + client: { + ensureCheckpointCachesAreFresh, + }, + }); + + const result = await runCommand(makeOptions("mark-resolved", []), { + ...context, + core, + }); + + expect(result).toBe(true); + expect(ensureCheckpointCachesAreFresh).toHaveBeenCalledTimes(1); + }); + it("mark-resolved with remote-id temporarily activates it and runs markResolved", async () => { const core = createCoreMock(); const settings = core.services.setting.currentSettings(); diff --git a/src/modules/core/ModuleReplicatorCouchDB.unit.spec.ts b/src/modules/core/ModuleReplicatorCouchDB.unit.spec.ts index 682a942b..96640401 100644 --- a/src/modules/core/ModuleReplicatorCouchDB.unit.spec.ts +++ b/src/modules/core/ModuleReplicatorCouchDB.unit.spec.ts @@ -1,9 +1,9 @@ import { describe, expect, it, vi } from "vitest"; -import { REMOTE_COUCHDB, REMOTE_MINIO } from "@vrtmrz/livesync-commonlib/compat/common/types"; +import { REMOTE_COUCHDB, REMOTE_MINIO, REMOTE_WEBDAV } from "@vrtmrz/livesync-commonlib/compat/common/types"; import { ModuleReplicatorCouchDB } from "./ModuleReplicatorCouchDB.ts"; function createModule( - settings: { liveSync: boolean; syncOnStart: boolean; remoteType?: typeof REMOTE_COUCHDB | typeof REMOTE_MINIO }, + settings: { liveSync: boolean; remoteType?: string; syncOnStart: boolean }, isReplicationReady = true ) { const openReplication = vi.fn(async () => true); @@ -91,17 +91,18 @@ describe("ModuleReplicatorCouchDB resume replication activity", () => { expect(openReplication).not.toHaveBeenCalled(); }); - it("does not start CouchDB replication for a registered Journal provider", async () => { - const { module, openReplication } = createModule({ + it.each([REMOTE_MINIO, REMOTE_WEBDAV])("does not claim or resume registered Journal provider %s", async (remoteType) => { + const { module, openReplication, runFiniteReplicationActivity } = createModule({ liveSync: true, + remoteType, syncOnStart: true, - remoteType: REMOTE_MINIO, }); await expect(module._anyNewReplicator()).resolves.toBe(false); await module._everyAfterResumeProcess(); await new Promise((resolve) => setTimeout(resolve, 0)); + expect(runFiniteReplicationActivity).not.toHaveBeenCalled(); expect(openReplication).not.toHaveBeenCalled(); }); });