test: dedupe startup migration log reads

This commit is contained in:
Peter Steinberger
2026-05-12 20:39:26 +01:00
parent ed4c287bf3
commit 652a56fc74
@@ -14,6 +14,14 @@ function makeCfg() {
>[0]["cfg"];
}
function firstLogMessage(log: ReturnType<typeof vi.fn>, label: string): string {
const [message] = log.mock.calls[0] ?? [];
if (typeof message !== "string") {
throw new Error(`expected ${label} message`);
}
return message;
}
describe("runStartupSessionMigration", () => {
it("logs changes when orphaned keys are canonicalized", async () => {
const log = makeLog();
@@ -28,7 +36,9 @@ describe("runStartupSessionMigration", () => {
});
expect(migrate).toHaveBeenCalledOnce();
expect(log.info).toHaveBeenCalledOnce();
expect(log.info.mock.calls.at(0)?.[0]).toContain("canonicalized orphaned session keys");
expect(firstLogMessage(log.info, "startup migration info")).toContain(
"canonicalized orphaned session keys",
);
expect(log.warn).not.toHaveBeenCalled();
});
@@ -45,7 +55,9 @@ describe("runStartupSessionMigration", () => {
});
expect(log.info).not.toHaveBeenCalled();
expect(log.warn).toHaveBeenCalledOnce();
expect(log.warn.mock.calls.at(0)?.[0]).toContain("session key migration warnings");
expect(firstLogMessage(log.warn, "startup migration warning")).toContain(
"session key migration warnings",
);
});
it("silently continues when no changes needed", async () => {
@@ -69,7 +81,8 @@ describe("runStartupSessionMigration", () => {
deps: { migrateOrphanedSessionKeys: migrate },
});
expect(log.warn).toHaveBeenCalledOnce();
expect(log.warn.mock.calls.at(0)?.[0]).toContain("migration failed during startup");
expect(log.warn.mock.calls.at(0)?.[0]).toContain("disk full");
const warning = firstLogMessage(log.warn, "startup migration failure warning");
expect(warning).toContain("migration failed during startup");
expect(warning).toContain("disk full");
});
});