From 66d687f1c284d3c455418baf1d7c34d8e857b0c5 Mon Sep 17 00:00:00 2001 From: le king fu Date: Mon, 26 Oct 2026 21:25:28 -0400 Subject: [PATCH] test: pin cleanLogLine at each of the four Journal sites of db.ts (#497) A path glued to ";" keeps "jean" through withoutFolders alone: one test per site (failed close, failed checksum repair, stopped catch-up and its copy, failed preparation) turns red if that site goes back to the heuristic alone. Co-Authored-By: Claude Opus 5.5 --- src/services/db.test.ts | 61 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/services/db.test.ts b/src/services/db.test.ts index 3139dc4..f305085 100644 --- a/src/services/db.test.ts +++ b/src/services/db.test.ts @@ -933,6 +933,67 @@ describe("cleanLogLine: the known folders first, then withoutFolders (#497)", () }); }); +describe("the four Journal sites of db.ts take both curtains (#497)", () => { + // Glued to `;`, which starts no path: withoutFolders alone keeps `jean`. + const GLUED = "x;/home/jean dupont/notes/x.db"; + + beforeEach(() => { + setKnownFolders({ home: "/home/jean dupont" }); + vi.mocked(logWarn).mockClear(); + vi.mocked(logError).mockClear(); + }); + afterEach(() => { + setKnownFolders({}); + }); + + it("a failed close of the previous connection", async () => { + vi.mocked(h.fakeDb.close).mockImplementation(async () => { + throw new Error(`close refused for ${GLUED}`); + }); + h.fakeDb = makeFakeDb("next"); + + await connectToProfile("next.db"); + + expect(vi.mocked(logWarn).mock.calls.map((call) => call[0])).toEqual([ + "DB: closing the previous connection failed, continuing without it: close refused for x.db", + ]); + }); + + it("a failed checksum repair", async () => { + vi.mocked(invoke).mockImplementationOnce(async () => { + throw `Cannot open database: unable to open database file: ${GLUED}`; + }); + + await connectToProfile("profile_0a1b2c3d.db"); + + expect(vi.mocked(logError).mock.calls.map((call) => call[0])).toEqual([ + "Migration repair failed: Cannot open database: unable to open database file: x.db", + ]); + }); + + it("a stopped catch-up, and the copy it names", () => { + const lines = describePreparation( + "x.db", + report({ catch_up_error: `backup_failed: unable to open database: ${GLUED}`, catch_up_backup: GLUED }) + ); + expect(lines.errors).toEqual([ + "Profile x.db: database update stopped: backup_failed: unable to open database: x.db; copy of the previous state kept as x.db", + ]); + }); + + it("a failed preparation", async () => { + h.prepare = async () => { + throw new Error(`Cannot read ${GLUED}`); + }; + + await connectToProfile("profile_0a1b2c3d.db"); + + expect(vi.mocked(logError).mock.calls.map((call) => call[0])).toEqual([ + "Profile profile_0a1b2c3d.db: database preparation failed: Cannot read x.db", + ]); + }); +}); + // --------------------------------------------------------------------------- // connectToProfile waits for the known folders (#497). initKnownFolders() // runs once per module instance, so each test takes a fresh db.ts with its own