Skip to content

Commit c328fc7

Browse files
committed
Exercise sync target retry wiring
1 parent 60cabf8 commit c328fc7

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

test/experimental-sync-target-entry.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,38 @@ describe("experimental sync target entry", () => {
2424
destination: null,
2525
});
2626
});
27+
28+
it("wires windows-safe retry options through readJson", async () => {
29+
const sleep = vi.fn(async () => undefined);
30+
const readFileWithRetry = vi.fn(async () => '{"hello":"world"}');
31+
const normalizeAccountStorage = vi.fn(() => null);
32+
let capturedReadJson: ((path: string) => Promise<unknown>) | undefined;
33+
34+
const loadExperimentalSyncTargetState = vi.fn(async (args) => {
35+
capturedReadJson = args.readJson;
36+
const parsed = await args.readJson("C:\\state.json");
37+
args.normalizeAccountStorage(parsed);
38+
return {
39+
kind: "target" as const,
40+
detection: { kind: "target" as const },
41+
destination: null,
42+
};
43+
});
44+
45+
await loadExperimentalSyncTargetEntry({
46+
loadExperimentalSyncTargetState,
47+
detectTarget: () => ({ kind: "target" }) as never,
48+
readFileWithRetry,
49+
normalizeAccountStorage,
50+
sleep,
51+
});
52+
53+
expect(capturedReadJson).toBeDefined();
54+
expect(readFileWithRetry).toHaveBeenCalledWith("C:\\state.json", {
55+
retryableCodes: new Set(["EBUSY", "EPERM", "EAGAIN", "ENOTEMPTY", "EACCES"]),
56+
maxAttempts: 4,
57+
sleep,
58+
});
59+
expect(normalizeAccountStorage).toHaveBeenCalledWith({ hello: "world" });
60+
});
2761
});

0 commit comments

Comments
 (0)