Skip to content
20 linesCodeBlameRaw
1import assert from "node:assert/strict";
2import { test } from "node:test";
3
4import { Recent } from "./chat-cache.ts";
5
6test("the conversation cache keeps the most recently used, and no more", () => {
7 const recent = new Recent<number>(3);
8 recent.set("a", 1);
9 recent.set("b", 2);
10 recent.set("c", 3);
11 // Reading a moves it to the end, so b is the oldest.
12 assert.equal(recent.get("a")?.value, 1);
13 recent.set("d", 4);
14 assert.deepEqual(recent.keys(), ["c", "a", "d"]);
15 assert.equal(recent.has("b"), false);
16 // Setting again replaces and refreshes.
17 recent.set("c", 30);
18 assert.deepEqual(recent.keys(), ["a", "d", "c"]);
19 assert.equal(recent.get("c")?.value, 30);
20});