test: simplify session compact line count

This commit is contained in:
Peter Steinberger
2026-05-08 23:20:19 +01:00
parent 5d335dd603
commit 00d64a7148

View File

@@ -11,6 +11,16 @@ import {
const { createSessionStoreDir, openClient } = setupGatewaySessionsTestHarness();
function collectNonEmptyLines(text: string): string[] {
const lines: string[] = [];
for (const line of text.split(/\r?\n/)) {
if (line.trim().length > 0) {
lines.push(line);
}
}
return lines;
}
test("lists and patches session store via sessions.* RPC", async () => {
const { dir, storePath } = await createSessionStoreDir();
const now = Date.now();
@@ -378,9 +388,9 @@ test("lists and patches session store via sessions.* RPC", async () => {
});
expect(compacted.ok).toBe(true);
expect(compacted.payload?.compacted).toBe(true);
const compactedLines = (await fs.readFile(path.join(dir, "sess-main.jsonl"), "utf-8"))
.split(/\r?\n/)
.filter((l) => l.trim().length > 0);
const compactedLines = collectNonEmptyLines(
await fs.readFile(path.join(dir, "sess-main.jsonl"), "utf-8"),
);
expect(compactedLines).toHaveLength(3);
const filesAfterCompact = await fs.readdir(dir);
expect(filesAfterCompact).toContainEqual(expect.stringMatching(/^sess-main\.jsonl\.bak\./));