summaryrefslogtreecommitdiffhomepage
path: root/src/features/conversation-cache/logic.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/features/conversation-cache/logic.test.ts')
-rw-r--r--src/features/conversation-cache/logic.test.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/features/conversation-cache/logic.test.ts b/src/features/conversation-cache/logic.test.ts
index 880c32e..7a31783 100644
--- a/src/features/conversation-cache/logic.test.ts
+++ b/src/features/conversation-cache/logic.test.ts
@@ -138,3 +138,26 @@ describe("selectEvictions", () => {
expect(result).toEqual(["b"]);
});
});
+
+describe("reconcileCache — turnId provenance upgrade", () => {
+ it("upgrades a cached row lacking turnId when the incoming copy carries it", () => {
+ const cached: StoredChunk[] = [{ seq: 1, role: "user", chunk: { type: "text", text: "hi" } }];
+ const incoming: StoredChunk[] = [
+ { seq: 1, role: "user", chunk: { type: "text", text: "hi" }, turnId: "t1" },
+ { seq: 2, role: "assistant", chunk: { type: "text", text: "yo" }, turnId: "t1" },
+ ];
+ const { merged, toAppend } = reconcileCache(cached, incoming);
+ expect(merged.map((c) => c.turnId)).toEqual(["t1", "t1"]);
+ expect(toAppend.map((c) => c.seq)).toEqual([1, 2]);
+ });
+
+ it("does not rewrite a cached row that already has a turnId", () => {
+ const cached: StoredChunk[] = [
+ { seq: 1, role: "user", chunk: { type: "text", text: "hi" }, turnId: "t1" },
+ ];
+ const { toAppend } = reconcileCache(cached, [
+ { seq: 1, role: "user", chunk: { type: "text", text: "hi" }, turnId: "t1" },
+ ]);
+ expect(toAppend).toEqual([]);
+ });
+});