jsonl.test.ts 1.2 KB

123456789101112131415161718192021222324
  1. import { expect, test } from "bun:test"
  2. import { MAX_FRECENCY_ENTRIES, parseFrecency } from "../../src/prompt/frecency"
  3. import { MAX_STASH_ENTRIES, parsePromptStash } from "../../src/prompt/stash"
  4. test("stash JSONL skips corruption and retains newest entries", () => {
  5. const entries = Array.from({ length: MAX_STASH_ENTRIES + 2 }, (_, index) =>
  6. JSON.stringify({ prompt: { text: String(index), files: [], agents: [], pasted: [] }, timestamp: index }),
  7. )
  8. entries.splice(2, 0, "broken")
  9. const result = parsePromptStash(entries.join("\n"))
  10. expect(result).toHaveLength(MAX_STASH_ENTRIES)
  11. expect(result[0]?.prompt.text).toBe("2")
  12. })
  13. test("frecency JSONL skips corruption, keeps latest path state, and limits entries", () => {
  14. const entries = Array.from({ length: MAX_FRECENCY_ENTRIES + 1 }, (_, index) =>
  15. JSON.stringify({ path: String(index), frequency: 1, lastOpen: index }),
  16. )
  17. entries.push("broken", JSON.stringify({ path: "1000", frequency: 2, lastOpen: 2000 }))
  18. const result = parseFrecency(entries.join("\n"))
  19. expect(result).toHaveLength(MAX_FRECENCY_ENTRIES)
  20. expect(result[0]).toEqual({ path: "1000", frequency: 2, lastOpen: 2000 })
  21. expect(result.some((entry) => entry.path === "0")).toBe(false)
  22. })