diff --git a/lib/storage.ts b/lib/storage.ts index 41e83034..e5aa56ad 100644 --- a/lib/storage.ts +++ b/lib/storage.ts @@ -61,6 +61,7 @@ import { collectNamedBackups, type NamedBackupSummary, } from "./storage/named-backups.js"; +import { getNamedBackupsEntry } from "./storage/named-backups-entry.js"; import { findProjectRoot, getConfigDir, @@ -794,7 +795,9 @@ export function buildNamedBackupPath(name: string): string { } export async function getNamedBackups(): Promise { - return collectNamedBackups(getStoragePath(), { + return getNamedBackupsEntry({ + getStoragePath, + collectNamedBackups, loadAccountsFromPath: (path) => loadAccountsFromPath(path, { normalizeAccountStorage, diff --git a/lib/storage/named-backups-entry.ts b/lib/storage/named-backups-entry.ts new file mode 100644 index 00000000..a3ce917d --- /dev/null +++ b/lib/storage/named-backups-entry.ts @@ -0,0 +1,23 @@ +import type { NamedBackupSummary } from "../storage.js"; + +export async function getNamedBackupsEntry(params: { + getStoragePath: () => string; + collectNamedBackups: ( + storagePath: string, + deps: { + loadAccountsFromPath: ( + path: string, + ) => Promise<{ normalized: { accounts: unknown[] } | null }>; + logDebug: (message: string, details: Record) => void; + }, + ) => Promise; + loadAccountsFromPath: ( + path: string, + ) => Promise<{ normalized: { accounts: unknown[] } | null }>; + logDebug: (message: string, details: Record) => void; +}): Promise { + return params.collectNamedBackups(params.getStoragePath(), { + loadAccountsFromPath: params.loadAccountsFromPath, + logDebug: params.logDebug, + }); +} diff --git a/test/named-backups-entry.test.ts b/test/named-backups-entry.test.ts new file mode 100644 index 00000000..09824015 --- /dev/null +++ b/test/named-backups-entry.test.ts @@ -0,0 +1,23 @@ +import { describe, expect, it, vi } from "vitest"; +import { getNamedBackupsEntry } from "../lib/storage/named-backups-entry.js"; + +describe("named backups entry", () => { + it("passes storage path and dependencies through to named backup collection", async () => { + const collectNamedBackups = vi.fn(async () => []); + const loadAccountsFromPath = vi.fn(async () => ({ normalized: null })); + const logDebug = vi.fn(); + + const result = await getNamedBackupsEntry({ + getStoragePath: () => "/tmp/accounts.json", + collectNamedBackups, + loadAccountsFromPath, + logDebug, + }); + + expect(collectNamedBackups).toHaveBeenCalledWith("/tmp/accounts.json", { + loadAccountsFromPath, + logDebug, + }); + expect(result).toEqual([]); + }); +});