mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-13 23:56:07 +00:00
test: tighten memory session file assertions
This commit is contained in:
@@ -111,20 +111,18 @@ describe("buildSessionEntry", () => {
|
||||
fsSync.writeFileSync(filePath, jsonlLines.join("\n"));
|
||||
|
||||
const entry = await buildSessionEntry(filePath);
|
||||
expect(entry).not.toBeNull();
|
||||
|
||||
// The content should have 3 lines (3 message records)
|
||||
const contentLines = entry!.content.split("\n");
|
||||
const contentLines = entry?.content.split("\n");
|
||||
expect(contentLines).toHaveLength(3);
|
||||
expect(contentLines[0]).toContain("User: Hello world");
|
||||
expect(contentLines[1]).toContain("Assistant: Hi there");
|
||||
expect(contentLines[2]).toContain("User: Tell me a joke");
|
||||
expect(contentLines?.[0]).toContain("User: Hello world");
|
||||
expect(contentLines?.[1]).toContain("Assistant: Hi there");
|
||||
expect(contentLines?.[2]).toContain("User: Tell me a joke");
|
||||
|
||||
// lineMap should map each content line to its original JSONL line (1-indexed)
|
||||
// Content line 0 → JSONL line 4 (the first user message)
|
||||
// Content line 1 → JSONL line 6 (the assistant message)
|
||||
// Content line 2 → JSONL line 7 (the second user message)
|
||||
expect(entry!.lineMap).toEqual([4, 6, 7]);
|
||||
expect(entry?.lineMap).toEqual([4, 6, 7]);
|
||||
});
|
||||
|
||||
it("returns empty lineMap when no messages are found", async () => {
|
||||
@@ -136,9 +134,8 @@ describe("buildSessionEntry", () => {
|
||||
fsSync.writeFileSync(filePath, jsonlLines.join("\n"));
|
||||
|
||||
const entry = await buildSessionEntry(filePath);
|
||||
expect(entry).not.toBeNull();
|
||||
expect(entry!.content).toBe("");
|
||||
expect(entry!.lineMap).toEqual([]);
|
||||
expect(entry?.content).toBe("");
|
||||
expect(entry?.lineMap).toEqual([]);
|
||||
});
|
||||
|
||||
it("indexes usage-counted reset/deleted archives but still skips bak and checkpoint artifacts", async () => {
|
||||
@@ -172,10 +169,8 @@ describe("buildSessionEntry", () => {
|
||||
|
||||
// .bak and compaction checkpoints remain opaque pre-archive / snapshot
|
||||
// artifacts and stay empty so they do not get double-indexed.
|
||||
expect(bakEntry).not.toBeNull();
|
||||
expect(bakEntry?.content).toBe("");
|
||||
expect(bakEntry?.lineMap).toEqual([]);
|
||||
expect(checkpointEntry).not.toBeNull();
|
||||
expect(checkpointEntry?.content).toBe("");
|
||||
expect(checkpointEntry?.lineMap).toEqual([]);
|
||||
});
|
||||
@@ -199,7 +194,6 @@ describe("buildSessionEntry", () => {
|
||||
|
||||
const entry = await buildSessionEntry(archivePath);
|
||||
|
||||
expect(entry).not.toBeNull();
|
||||
expect(entry?.content).toBe("");
|
||||
expect(entry?.lineMap).toEqual([]);
|
||||
expect(entry?.generatedByCronRun).toBe(true);
|
||||
@@ -221,7 +215,6 @@ describe("buildSessionEntry", () => {
|
||||
|
||||
const entry = await buildSessionEntry(archivePath);
|
||||
|
||||
expect(entry).not.toBeNull();
|
||||
expect(entry?.content).toBe("");
|
||||
expect(entry?.lineMap).toEqual([]);
|
||||
expect(entry?.generatedByCronRun).toBe(true);
|
||||
@@ -239,8 +232,7 @@ describe("buildSessionEntry", () => {
|
||||
fsSync.writeFileSync(filePath, jsonlLines.join("\n"));
|
||||
|
||||
const entry = await buildSessionEntry(filePath);
|
||||
expect(entry).not.toBeNull();
|
||||
expect(entry!.lineMap).toEqual([3, 5]);
|
||||
expect(entry?.lineMap).toEqual([3, 5]);
|
||||
});
|
||||
|
||||
it("strips inbound metadata when a user envelope is split across text blocks", async () => {
|
||||
@@ -269,8 +261,7 @@ describe("buildSessionEntry", () => {
|
||||
fsSync.writeFileSync(filePath, jsonlLines.join("\n"));
|
||||
|
||||
const entry = await buildSessionEntry(filePath);
|
||||
expect(entry).not.toBeNull();
|
||||
expect(entry!.content).toBe("User: Actual user text");
|
||||
expect(entry?.content).toBe("User: Actual user text");
|
||||
});
|
||||
|
||||
it("skips inter-session user messages", async () => {
|
||||
@@ -296,8 +287,7 @@ describe("buildSessionEntry", () => {
|
||||
fsSync.writeFileSync(filePath, jsonlLines.join("\n"));
|
||||
|
||||
const entry = await buildSessionEntry(filePath);
|
||||
expect(entry).not.toBeNull();
|
||||
expect(entry!.content).toBe("Assistant: User-facing summary.\nUser: Actual user follow-up.");
|
||||
expect(entry!.lineMap).toEqual([2, 3]);
|
||||
expect(entry?.content).toBe("Assistant: User-facing summary.\nUser: Actual user follow-up.");
|
||||
expect(entry?.lineMap).toEqual([2, 3]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user