Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/testing/datastore_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ export interface DatastoreVerifier {

/** Interface for datastore synchronization services. */
export interface DatastoreSyncService {
pullChanged(): Promise<void>;
pushChanged(): Promise<void>;
pullChanged(): Promise<number | void>;
pushChanged(): Promise<number | void>;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/domain/datastore/datastore_sync_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
export interface DatastoreSyncService {
/** Pull changed files from the remote datastore to the local cache. */
pullChanged(): Promise<void>;
pullChanged(): Promise<number | void>;
/** Push changed files from the local cache to the remote datastore. */
pushChanged(): Promise<void>;
pushChanged(): Promise<number | void>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ export class DefaultDatastorePathResolver implements DatastorePathResolver {

// Determine the base path for the datastore
if (isCustomDatastoreConfig(datastoreConfig)) {
// Custom: path was eagerly resolved during config resolution
this.datastoreBasePath = datastoreConfig.datastorePath;
// For remote datastores with a local cache (e.g. S3), use the cache
// path so reads/writes go to the same directory the sync service
// pushes from and pulls to. Fall back to datastorePath for custom
// datastores that don't use a separate cache.
this.datastoreBasePath = datastoreConfig.cachePath ??
datastoreConfig.datastorePath;
} else {
this.datastoreBasePath = datastoreConfig.path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,38 @@ Deno.test("DefaultDatastorePathResolver - default config (no external datastore)
);
});

Deno.test("DefaultDatastorePathResolver - custom datastore prefers cachePath over datastorePath", () => {
const config: DatastoreConfig = {
type: "s3",
config: { bucket: "my-bucket" },
datastorePath: "/repo/.swamp",
cachePath: "/home/user/.swamp/repos/abc",
};
const resolver = new DefaultDatastorePathResolver("/repo", config);
// Data should go to cachePath so the sync service can find it
assertEquals(
resolver.datastorePath("data"),
"/home/user/.swamp/repos/abc/data",
);
assertEquals(
resolver.resolvePath("data", "foo"),
"/home/user/.swamp/repos/abc/data/foo",
);
});

Deno.test("DefaultDatastorePathResolver - custom datastore falls back to datastorePath without cachePath", () => {
const config: DatastoreConfig = {
type: "custom",
config: {},
datastorePath: "/shared/datastore",
};
const resolver = new DefaultDatastorePathResolver("/repo", config);
assertEquals(
resolver.datastorePath("data"),
"/shared/datastore/data",
);
});

Deno.test("DefaultDatastorePathResolver - config returns the stored config", () => {
const config: DatastoreConfig = {
type: "filesystem",
Expand Down
18 changes: 11 additions & 7 deletions src/libswamp/datastores/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,21 @@ export function createDatastoreSyncDeps(
validateSyncSupport: () =>
Promise.resolve({ supported: true, type: config.type }),
pushSync: async () => {
await syncService.pushChanged();
return { filesPushed: 0 };
const count = await syncService.pushChanged();
return { filesPushed: typeof count === "number" ? count : 0 };
},
pullSync: async () => {
await syncService.pullChanged();
return { filesPulled: 0 };
const count = await syncService.pullChanged();
return { filesPulled: typeof count === "number" ? count : 0 };
},
fullSync: async () => {
await syncService.pullChanged();
await syncService.pushChanged();
return { filesPulled: 0, filesPushed: 0, errors: [] };
const pulled = await syncService.pullChanged();
const pushed = await syncService.pushChanged();
return {
filesPulled: typeof pulled === "number" ? pulled : 0,
filesPushed: typeof pushed === "number" ? pushed : 0,
errors: [],
};
},
};
}
Expand Down
Loading