Skip to content

Commit 5836194

Browse files
committed
Add restore backup path wiring coverage
(cherry picked from commit d120dc0)
1 parent 3954943 commit 5836194

File tree

1 file changed

+47
-8
lines changed

1 file changed

+47
-8
lines changed

test/restore-backup-entry.test.ts

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ import { restoreAccountsFromBackupEntry } from "../lib/storage/restore-backup-en
33

44
describe("restore backup entry", () => {
55
it("passes path, options, and injected deps through to the restore helper", async () => {
6-
const restoreAccountsFromBackupPath = vi.fn(async () => ({
6+
const restoredStorage = {
77
version: 3,
88
accounts: [],
99
activeIndex: 0,
1010
activeIndexByFamily: {},
11-
}));
11+
};
12+
const realpath = vi.fn(async (path: string) => path);
13+
const restoreAccountsFromBackupPath = vi.fn(async (path: string, options) => {
14+
await options.realpath(path);
15+
return restoredStorage;
16+
});
1217
const loadAccountsFromPath = vi.fn(async () => ({ normalized: null }));
1318
const saveAccounts = vi.fn(async () => undefined);
1419

@@ -18,7 +23,7 @@ describe("restore backup entry", () => {
1823
restoreAccountsFromBackupPath,
1924
getNamedBackupRoot: () => "/tmp/backups",
2025
getStoragePath: () => "/tmp/accounts.json",
21-
realpath: vi.fn(async (path) => path),
26+
realpath,
2227
loadAccountsFromPath,
2328
saveAccounts,
2429
});
@@ -28,15 +33,49 @@ describe("restore backup entry", () => {
2833
expect.objectContaining({
2934
persist: false,
3035
backupRoot: "/tmp/backups",
36+
realpath,
3137
loadAccountsFromPath,
3238
saveAccounts,
3339
}),
3440
);
35-
expect(result).toEqual({
36-
version: 3,
37-
accounts: [],
38-
activeIndex: 0,
39-
activeIndexByFamily: {},
41+
expect(realpath).toHaveBeenCalledWith("/tmp/backup.json");
42+
expect(result).toEqual(restoredStorage);
43+
});
44+
45+
it("keeps windows-style backup paths and realpath wiring intact", async () => {
46+
const windowsBackupPath = "C:\\codex\\backups\\snapshot.json";
47+
const windowsBackupRoot = "C:\\codex\\backups";
48+
const realpath = vi.fn(async (path: string) => path);
49+
const restoreAccountsFromBackupPath = vi.fn(async (path: string, options) => {
50+
const resolvedPath = await options.realpath(path);
51+
return {
52+
version: 3,
53+
accounts: [{ email: resolvedPath }],
54+
activeIndex: 0,
55+
activeIndexByFamily: {},
56+
};
57+
});
58+
59+
const result = await restoreAccountsFromBackupEntry({
60+
path: windowsBackupPath,
61+
options: { persist: true },
62+
restoreAccountsFromBackupPath,
63+
getNamedBackupRoot: () => windowsBackupRoot,
64+
getStoragePath: () => "C:\\codex\\accounts.json",
65+
realpath,
66+
loadAccountsFromPath: vi.fn(async () => ({ normalized: null })),
67+
saveAccounts: vi.fn(async () => undefined),
4068
});
69+
70+
expect(restoreAccountsFromBackupPath).toHaveBeenCalledWith(
71+
windowsBackupPath,
72+
expect.objectContaining({
73+
persist: true,
74+
backupRoot: windowsBackupRoot,
75+
realpath,
76+
}),
77+
);
78+
expect(realpath).toHaveBeenCalledWith(windowsBackupPath);
79+
expect(result.accounts).toEqual([{ email: windowsBackupPath }]);
4180
});
4281
});

0 commit comments

Comments
 (0)