- Replace `rehype-highlight`/`highlight.js` with `@pierre/diffs` highlighter in `ChatMarkdown` - Add LRU caching and in-flight dedupe for highlighted code, with streaming-aware behavior - Extract shared diff theme resolution utility and add unit tests for new LRU cache
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { LRUCache } from "./lruCache";
|
|
|
|
describe("LRUCache", () => {
|
|
it("returns null for missing keys", () => {
|
|
const cache = new LRUCache<string>(2, 100);
|
|
expect(cache.get("missing")).toBeNull();
|
|
});
|
|
|
|
it("evicts oldest by max entries", () => {
|
|
const cache = new LRUCache<string>(2, 1_000);
|
|
cache.set("a", "A", 10);
|
|
cache.set("b", "B", 10);
|
|
cache.set("c", "C", 10);
|
|
|
|
expect(cache.get("a")).toBeNull();
|
|
expect(cache.get("b")).toBe("B");
|
|
expect(cache.get("c")).toBe("C");
|
|
});
|
|
|
|
it("promotes on get and evicts least recently used", () => {
|
|
const cache = new LRUCache<string>(2, 1_000);
|
|
cache.set("a", "A", 10);
|
|
cache.set("b", "B", 10);
|
|
expect(cache.get("a")).toBe("A");
|
|
|
|
cache.set("c", "C", 10);
|
|
expect(cache.get("a")).toBe("A");
|
|
expect(cache.get("b")).toBeNull();
|
|
expect(cache.get("c")).toBe("C");
|
|
});
|
|
|
|
it("evicts by memory budget", () => {
|
|
const cache = new LRUCache<string>(10, 25);
|
|
cache.set("a", "A", 10);
|
|
cache.set("b", "B", 10);
|
|
cache.set("c", "C", 10);
|
|
|
|
expect(cache.get("a")).toBeNull();
|
|
expect(cache.get("b")).toBe("B");
|
|
expect(cache.get("c")).toBe("C");
|
|
});
|
|
});
|