Reprocess stored documents after reflection filters change

This commit is contained in:
vorotamoroz
2026-07-22 06:23:16 +00:00
parent aad0e56f09
commit 87152244d7
5 changed files with 159 additions and 7 deletions
@@ -1,5 +1,7 @@
import { describe, expect, it, vi } from "vitest";
import { createServiceContext } from "@vrtmrz/livesync-commonlib/context";
import { EVENT_SETTING_SAVED, eventHub } from "@/common/events";
import type { ObsidianLiveSyncSettings } from "@vrtmrz/livesync-commonlib/compat/common/types";
const chunkMocks = vi.hoisted(() => ({
purgeUnreferencedChunks: vi.fn(async (_db: unknown, countOnly: boolean) => (countOnly ? 2 : 0)),
@@ -58,6 +60,60 @@ describe("ModuleReplicator", () => {
expect(ensurePBKDF2Salt).toHaveBeenCalledWith({}, false, false);
});
it("reprocesses stored documents when the normal-file target filters change", async () => {
eventHub.offAll();
const settings = {
handleFilenameCaseSensitive: false,
ignoreFiles: ".gitignore",
maxMTimeForReflectEvents: 0,
syncOnlyRegEx: "^E2E/allowed/.*",
syncIgnoreRegEx: "",
syncInternalFiles: false,
syncMaxSizeInMB: 0,
suspendParseReplicationResult: false,
useIgnoreFiles: false,
} as ObsidianLiveSyncSettings;
const services = {
context: createServiceContext(),
API: {
addLog: vi.fn(),
addCommand: vi.fn(),
registerWindow: vi.fn(),
addRibbonIcon: vi.fn(),
registerProtocolHandler: vi.fn(),
},
appLifecycle: {
getUnresolvedMessages: { addHandler: vi.fn() },
isSuspended: vi.fn(() => false),
},
};
const core = {
_services: services,
services,
settings,
} as any;
const module = new ModuleReplicator(core);
const reprocessStoredDocuments = vi.fn(async () => 1);
Object.assign(module.processor, { reprocessStoredDocuments });
try {
await (module as any)._everyOnloadAfterLoadSettings();
eventHub.emitEvent(EVENT_SETTING_SAVED, { ...settings });
await Promise.resolve();
expect(reprocessStoredDocuments).not.toHaveBeenCalled();
Object.assign(settings, { syncOnlyRegEx: "" });
eventHub.emitEvent(EVENT_SETTING_SAVED, { ...settings });
await vi.waitFor(() => expect(reprocessStoredDocuments).toHaveBeenCalledOnce());
settings.syncMaxSizeInMB = 10;
eventHub.emitEvent(EVENT_SETTING_SAVED, { ...settings });
await vi.waitFor(() => expect(reprocessStoredDocuments).toHaveBeenCalledTimes(2));
} finally {
eventHub.offAll();
}
});
});
describe("ModuleReplicator legacy cleanup", () => {