|
1 | | -import { expect, it } from "vitest"; |
| 1 | +import { expect, it, vi } from "vitest"; |
2 | 2 | import { migrateAgentStorage } from "./migrate-storage"; |
3 | 3 | import { readRecords, readTeams, STORAGE_KEY, TEAMS_KEY } from "./store"; |
4 | 4 | import { memoryStorage } from "./test-fakes"; |
@@ -30,28 +30,40 @@ it("moves settings and teams byte for byte, then restarts without resurrecting o |
30 | 30 | }); |
31 | 31 |
|
32 | 32 | it("preserves the source on write failure and resumes an interrupted copy", () => { |
| 33 | + const error = vi.spyOn(console, "error").mockImplementation(() => {}); |
33 | 34 | const storage = memoryStorage(); |
34 | 35 | storage.setItem("buzz.agents2.v1", "exact bytes"); |
35 | | - expect(() => |
36 | | - migrateAgentStorage({ |
37 | | - ...storage, |
38 | | - setItem: () => { |
39 | | - throw new Error("full"); |
40 | | - }, |
41 | | - }), |
42 | | - ).toThrow("full"); |
| 36 | + migrateAgentStorage({ |
| 37 | + ...storage, |
| 38 | + setItem: () => { |
| 39 | + throw new Error("full"); |
| 40 | + }, |
| 41 | + }); |
| 42 | + expect(error).toHaveBeenCalledWith( |
| 43 | + "Cannot migrate buzz.agents2.v1", |
| 44 | + expect.objectContaining({ message: "full" }), |
| 45 | + ); |
43 | 46 | expect(storage.getItem("buzz.agents2.v1")).toBe("exact bytes"); |
| 47 | + expect(storage.getItem(STORAGE_KEY)).toBeNull(); |
| 48 | + error.mockRestore(); |
44 | 49 | storage.setItem(STORAGE_KEY, "exact bytes"); |
45 | 50 | migrateAgentStorage(storage); |
46 | 51 | expect(storage.getItem("buzz.agents2.v1")).toBeNull(); |
47 | 52 | expect(storage.getItem(STORAGE_KEY)).toBe("exact bytes"); |
48 | 53 | }); |
49 | 54 |
|
50 | | -it("refuses to overwrite conflicting settings", () => { |
| 55 | +it("refuses to overwrite conflicting settings without stopping startup", () => { |
| 56 | + const error = vi.spyOn(console, "error").mockImplementation(() => {}); |
51 | 57 | const storage = memoryStorage(); |
52 | 58 | storage.setItem("buzz.agents2.v1", "old"); |
53 | 59 | storage.setItem(STORAGE_KEY, "new"); |
54 | | - expect(() => migrateAgentStorage(storage)).toThrow("different data"); |
| 60 | + storage.setItem("buzz.agents2.teams.v1", "teams"); |
| 61 | + migrateAgentStorage(storage); |
| 62 | + expect(error).toHaveBeenCalledWith( |
| 63 | + expect.stringContaining("already contains different data"), |
| 64 | + ); |
55 | 65 | expect(storage.getItem("buzz.agents2.v1")).toBe("old"); |
56 | 66 | expect(storage.getItem(STORAGE_KEY)).toBe("new"); |
| 67 | + expect(storage.getItem(TEAMS_KEY)).toBe("teams"); |
| 68 | + error.mockRestore(); |
57 | 69 | }); |
0 commit comments