mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-10-18 15:22:31 +00:00
refactor: compose Journal remotes generically
This commit is contained in:
@@ -6,7 +6,7 @@ import {
|
|||||||
type FilePathWithPrefix,
|
type FilePathWithPrefix,
|
||||||
type ObsidianLiveSyncSettings,
|
type ObsidianLiveSyncSettings,
|
||||||
REMOTE_COUCHDB,
|
REMOTE_COUCHDB,
|
||||||
REMOTE_MINIO,
|
isJournalRemoteType,
|
||||||
type EntryMilestoneInfo,
|
type EntryMilestoneInfo,
|
||||||
type EntryDoc,
|
type EntryDoc,
|
||||||
} from "@vrtmrz/livesync-commonlib/compat/common/types";
|
} from "@vrtmrz/livesync-commonlib/compat/common/types";
|
||||||
@@ -61,7 +61,7 @@ async function verifyRemoteState(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
milestone = await dbRet.db.get(MILESTONE_DOCID);
|
milestone = await dbRet.db.get(MILESTONE_DOCID);
|
||||||
} else if (settings.remoteType === REMOTE_MINIO) {
|
} else if (isJournalRemoteType(settings.remoteType)) {
|
||||||
const journalReplicator = replicator as LiveSyncJournalReplicator;
|
const journalReplicator = replicator as LiveSyncJournalReplicator;
|
||||||
if (journalProtocolConfigurationForSettings(settings).journalFormat === "adaptive-v1") {
|
if (journalProtocolConfigurationForSettings(settings).journalFormat === "adaptive-v1") {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
REMOTE_COUCHDB,
|
REMOTE_COUCHDB,
|
||||||
REMOTE_MINIO,
|
REMOTE_MINIO,
|
||||||
REMOTE_P2P,
|
REMOTE_P2P,
|
||||||
|
REMOTE_WEBDAV,
|
||||||
} from "@vrtmrz/livesync-commonlib/compat/common/types";
|
} from "@vrtmrz/livesync-commonlib/compat/common/types";
|
||||||
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
|
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
|
||||||
import { runCommand } from "./runCommand";
|
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 () => {
|
it("mark-resolved with remote-id temporarily activates it and runs markResolved", async () => {
|
||||||
const core = createCoreMock();
|
const core = createCoreMock();
|
||||||
const settings = core.services.setting.currentSettings();
|
const settings = core.services.setting.currentSettings();
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
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";
|
import { ModuleReplicatorCouchDB } from "./ModuleReplicatorCouchDB.ts";
|
||||||
|
|
||||||
function createModule(
|
function createModule(
|
||||||
settings: { liveSync: boolean; syncOnStart: boolean; remoteType?: typeof REMOTE_COUCHDB | typeof REMOTE_MINIO },
|
settings: { liveSync: boolean; remoteType?: string; syncOnStart: boolean },
|
||||||
isReplicationReady = true
|
isReplicationReady = true
|
||||||
) {
|
) {
|
||||||
const openReplication = vi.fn(async () => true);
|
const openReplication = vi.fn(async () => true);
|
||||||
@@ -91,17 +91,18 @@ describe("ModuleReplicatorCouchDB resume replication activity", () => {
|
|||||||
expect(openReplication).not.toHaveBeenCalled();
|
expect(openReplication).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not start CouchDB replication for a registered Journal provider", async () => {
|
it.each([REMOTE_MINIO, REMOTE_WEBDAV])("does not claim or resume registered Journal provider %s", async (remoteType) => {
|
||||||
const { module, openReplication } = createModule({
|
const { module, openReplication, runFiniteReplicationActivity } = createModule({
|
||||||
liveSync: true,
|
liveSync: true,
|
||||||
|
remoteType,
|
||||||
syncOnStart: true,
|
syncOnStart: true,
|
||||||
remoteType: REMOTE_MINIO,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await expect(module._anyNewReplicator()).resolves.toBe(false);
|
await expect(module._anyNewReplicator()).resolves.toBe(false);
|
||||||
await module._everyAfterResumeProcess();
|
await module._everyAfterResumeProcess();
|
||||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||||
|
|
||||||
|
expect(runFiniteReplicationActivity).not.toHaveBeenCalled();
|
||||||
expect(openReplication).not.toHaveBeenCalled();
|
expect(openReplication).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user