|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { resolveMemorySessionSyncPlan } from "./manager-session-sync-state.js"; |
| 3 | + |
| 4 | +describe("memory session sync state", () => { |
| 5 | + it("tracks active paths and bulk hashes for full scans", () => { |
| 6 | + const plan = resolveMemorySessionSyncPlan({ |
| 7 | + needsFullReindex: false, |
| 8 | + files: ["/tmp/a.jsonl", "/tmp/b.jsonl"], |
| 9 | + targetSessionFiles: null, |
| 10 | + sessionsDirtyFiles: new Set(), |
| 11 | + existingRows: [ |
| 12 | + { path: "sessions/a.jsonl", hash: "hash-a" }, |
| 13 | + { path: "sessions/b.jsonl", hash: "hash-b" }, |
| 14 | + ], |
| 15 | + sessionPathForFile: (file) => `sessions/${file.split("/").at(-1)}`, |
| 16 | + }); |
| 17 | + |
| 18 | + expect(plan.indexAll).toBe(true); |
| 19 | + expect(plan.activePaths).toEqual(new Set(["sessions/a.jsonl", "sessions/b.jsonl"])); |
| 20 | + expect(plan.existingRows).toEqual([ |
| 21 | + { path: "sessions/a.jsonl", hash: "hash-a" }, |
| 22 | + { path: "sessions/b.jsonl", hash: "hash-b" }, |
| 23 | + ]); |
| 24 | + expect(plan.existingHashes).toEqual( |
| 25 | + new Map([ |
| 26 | + ["sessions/a.jsonl", "hash-a"], |
| 27 | + ["sessions/b.jsonl", "hash-b"], |
| 28 | + ]), |
| 29 | + ); |
| 30 | + }); |
| 31 | + |
| 32 | + it("treats targeted session syncs as refresh-only and skips unrelated pruning", () => { |
| 33 | + const plan = resolveMemorySessionSyncPlan({ |
| 34 | + needsFullReindex: false, |
| 35 | + files: ["/tmp/targeted-first.jsonl"], |
| 36 | + targetSessionFiles: new Set(["/tmp/targeted-first.jsonl"]), |
| 37 | + sessionsDirtyFiles: new Set(["/tmp/targeted-first.jsonl"]), |
| 38 | + existingRows: [ |
| 39 | + { path: "sessions/targeted-first.jsonl", hash: "hash-first" }, |
| 40 | + { path: "sessions/targeted-second.jsonl", hash: "hash-second" }, |
| 41 | + ], |
| 42 | + sessionPathForFile: (file) => `sessions/${file.split("/").at(-1)}`, |
| 43 | + }); |
| 44 | + |
| 45 | + expect(plan.indexAll).toBe(true); |
| 46 | + expect(plan.activePaths).toBeNull(); |
| 47 | + expect(plan.existingRows).toBeNull(); |
| 48 | + expect(plan.existingHashes).toBeNull(); |
| 49 | + }); |
| 50 | + |
| 51 | + it("keeps dirty-only incremental mode when no targeted sync is requested", () => { |
| 52 | + const plan = resolveMemorySessionSyncPlan({ |
| 53 | + needsFullReindex: false, |
| 54 | + files: ["/tmp/incremental.jsonl"], |
| 55 | + targetSessionFiles: null, |
| 56 | + sessionsDirtyFiles: new Set(["/tmp/incremental.jsonl"]), |
| 57 | + existingRows: [], |
| 58 | + sessionPathForFile: (file) => `sessions/${file.split("/").at(-1)}`, |
| 59 | + }); |
| 60 | + |
| 61 | + expect(plan.indexAll).toBe(false); |
| 62 | + expect(plan.activePaths).toEqual(new Set(["sessions/incremental.jsonl"])); |
| 63 | + }); |
| 64 | +}); |
0 commit comments