This commit is contained in:
Andras Schmelczer 2026-09-27 11:09:36 +01:00
commit ff1f474324

View file

@ -1,6 +1,13 @@
import type { UploadQueue } from "../sync-client/src/sync-operations/upload-queue";
import type { ContentSync } from "../sync-client/src/sync-operations/content-sync";
import { fetchRemoteChanges, type RemoteApplicationOptions } from "../sync-client/src/sync-operations/remote-changes";
import type { EventBatch } from "../sync-client/src/services/types/EventBatch";
import type { FileManifest } from "../sync-client/src/services/types/FileManifest";
import type { VaultSnapshot } from "../sync-client/src/services/types/VaultSnapshot";
import { SyncPhase } from "../sync-client/src/sync-operations/sync-scheduler";
import {
Database,
emptyState,
createEmptyDatabase,
type StoredDatabase
} from "../sync-client/src/persistence/database";
import { Settings } from "../sync-client/src/persistence/settings";
@ -35,7 +42,7 @@ export async function fixture(
const disk = recovered?.disk ?? new MemoryDisk();
const initial = recovered
? (recovered.persistence.snapshot().database as StoredDatabase)
: emptyState("test");
: createEmptyDatabase("test");
if (!recovered) {
initial.lastSeenUpdateId = 0;
for (const [path, content] of Object.entries(contents)) {
@ -99,19 +106,14 @@ export async function fixture(
{ entries: changes, save: async () => {} }
);
const internals = syncer as unknown as {
finishPending: () => Promise<void>;
preparePush: () => Promise<boolean>;
scan: (
content: ContentSync;
uploads: UploadQueue;
prepareNextUpload: () => Promise<boolean>;
refreshLocalFiles: (
initial?: import("../sync-client/src/services/types/VaultSnapshot").VaultSnapshot
) => Promise<void>;
incorporateEventBatch: (
batch: import("../sync-client/src/services/types/EventBatch").EventBatch
) => Promise<void>;
stopped: boolean;
reconcile: (remote: {
fileManifestId: number;
entries: Record<string, string>;
}) => Promise<void>;
scheduler: { phase: SyncPhase };
applyRemoteChanges: (remote: FileManifest, options?: RemoteApplicationOptions) => Promise<void>;
};
return {
disk,
@ -119,7 +121,18 @@ export async function fixture(
files,
settings,
syncer,
internals,
internals: {
content: internals.content,
uploads: internals.uploads,
scheduler: internals.scheduler,
prepareNextUpload: () => internals.prepareNextUpload(),
refreshLocalFiles: (initial?: VaultSnapshot) => internals.refreshLocalFiles(initial),
applyRemoteChanges: (manifest: FileManifest) => internals.applyRemoteChanges(manifest),
applyEventBatch: async (batch: EventBatch) => {
const remote = await fetchRemoteChanges(service as SyncService, database.state, batch);
await internals.applyRemoteChanges(remote.manifest, remote);
}
},
persistence,
changes,
contentCache