diff --git a/src/gateway/server-startup-session-migration.test.ts b/src/gateway/server-startup-session-migration.test.ts index 8e08be146141..ad40ed8caf7c 100644 --- a/src/gateway/server-startup-session-migration.test.ts +++ b/src/gateway/server-startup-session-migration.test.ts @@ -14,6 +14,14 @@ function makeCfg() { >[0]["cfg"]; } +function firstLogMessage(log: ReturnType, 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"); }); });