Skip to content

Commit 652a56f

Browse files
committed
test: dedupe startup migration log reads
1 parent ed4c287 commit 652a56f

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

src/gateway/server-startup-session-migration.test.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ function makeCfg() {
1414
>[0]["cfg"];
1515
}
1616

17+
function firstLogMessage(log: ReturnType<typeof vi.fn>, label: string): string {
18+
const [message] = log.mock.calls[0] ?? [];
19+
if (typeof message !== "string") {
20+
throw new Error(`expected ${label} message`);
21+
}
22+
return message;
23+
}
24+
1725
describe("runStartupSessionMigration", () => {
1826
it("logs changes when orphaned keys are canonicalized", async () => {
1927
const log = makeLog();
@@ -28,7 +36,9 @@ describe("runStartupSessionMigration", () => {
2836
});
2937
expect(migrate).toHaveBeenCalledOnce();
3038
expect(log.info).toHaveBeenCalledOnce();
31-
expect(log.info.mock.calls.at(0)?.[0]).toContain("canonicalized orphaned session keys");
39+
expect(firstLogMessage(log.info, "startup migration info")).toContain(
40+
"canonicalized orphaned session keys",
41+
);
3242
expect(log.warn).not.toHaveBeenCalled();
3343
});
3444

@@ -45,7 +55,9 @@ describe("runStartupSessionMigration", () => {
4555
});
4656
expect(log.info).not.toHaveBeenCalled();
4757
expect(log.warn).toHaveBeenCalledOnce();
48-
expect(log.warn.mock.calls.at(0)?.[0]).toContain("session key migration warnings");
58+
expect(firstLogMessage(log.warn, "startup migration warning")).toContain(
59+
"session key migration warnings",
60+
);
4961
});
5062

5163
it("silently continues when no changes needed", async () => {
@@ -69,7 +81,8 @@ describe("runStartupSessionMigration", () => {
6981
deps: { migrateOrphanedSessionKeys: migrate },
7082
});
7183
expect(log.warn).toHaveBeenCalledOnce();
72-
expect(log.warn.mock.calls.at(0)?.[0]).toContain("migration failed during startup");
73-
expect(log.warn.mock.calls.at(0)?.[0]).toContain("disk full");
84+
const warning = firstLogMessage(log.warn, "startup migration failure warning");
85+
expect(warning).toContain("migration failed during startup");
86+
expect(warning).toContain("disk full");
7487
});
7588
});

0 commit comments

Comments
 (0)