Lines 4–10 at 318 (were 4–10 at 192)
44import { buildBase, Graph, View } from "../../../src/engine/index.ts"; 55import { StableOverlaySet } from "../../../src/engine/state-source.ts"; 66import type { AtomId } from "../../../src/engine/types.ts"; 7−import { ViewCache } from "../views.ts";
7+import { VIEW_COUNT, ViewCache } from "../views.ts"; 99const VIEW_BUDGET = 24_000_000; Lines 25–31 at 318 (were 25–31 at 192)
2525 assert.equal(cache.view(set), view); 2626 assert.equal(set.iterations, 1, "cache hit must not construct a full-history key"); 2727 assert.equal(view.text("a.txt"), "one\n"); 28− for (let i = 0; i < 33; i++) cache.view(new Counted(["a0"]));
28+ for (let i = 0; i < VIEW_COUNT + 1; i++) cache.view(new Counted(["a0"])); 2929 assert.notEqual(cache.view(set), view, "indexed identities obey the same cache eviction limit"); 3030 assert.equal(set.iterations, 2); Lines 76–91 at 318 (were 76–91 at 192)
79−test("the cache retains exactly 32 views and evicts the least recently used one", () => {
79+test("the cache retains exactly VIEW_COUNT views and evicts the least recently used one", () => { 8080 withControlledWeights((control) => { 8181 const cache = new ViewCache(new Graph()); 82− control.setIncomingWeights(Array(33).fill(0));
82+ control.setIncomingWeights(Array(VIEW_COUNT + 1).fill(0)); 8383 const first = get(cache, "key-0"); 84− const retained = Array.from({ length: 31 }, (_, i) => get(cache, `key-${i + 1}`));
84+ const retained = Array.from({ length: VIEW_COUNT - 1 }, (_, i) => get(cache, `key-${i + 1}`)); 8585 assert.equal(get(cache, "key-0"), first); 86− const last = get(cache, "key-32");
86+ const last = get(cache, `key-${VIEW_COUNT}`); 8787 assert.equal(get(cache, "key-0"), first); 88− assert.equal(get(cache, "key-32"), last);
88+ assert.equal(get(cache, `key-${VIEW_COUNT}`), last); 8989 for (let i = 1; i < retained.length; i++) assert.equal(get(cache, `key-${i + 1}`), retained[i]); 9090 assert.notEqual(get(cache, "key-1"), retained[0]); Lines 103–122 at 318 (were 103–108 at 192)
106+test("trim reweighs growth with no further hit and evicts until the views fit (abso Capacity)", () => { 107+ withControlledWeights((control) => { 108+ const cache = new ViewCache(new Graph()); 109+ control.setIncomingWeights([10_000_000, 10_000_000]); 110+ const growing = get(cache, "growing"); 111+ const newer = get(cache, "newer"); 112+ // A call lays files out in the older view after the cache last weighed it, and nothing asks for it again. 113+ control.setWeight(growing, 16_000_000); 115+ assert.equal(get(cache, "newer"), newer); 116+ assert.notEqual(get(cache, "growing"), growing); 106120test("an oversized view is returned but not retained", () => { 107121 withControlledWeights((control) => { 108122 const cache = new ViewCache(new Graph()); Lines 144–187 at 318 (were 130–132 at 192)
130144 for (let i = 0; i < 40; i++) cache.keyed(`other-${i}`, () => set); 131145 assert.deepEqual(cache.view(set).files(), new View(graph, set).files()); 148+test("trim lets go of the least recently used file layouts across views before whole views (abso Capacity)", () => { 149+ const graph = new Graph(); 150+ const lines = (name: string) => Array.from({ length: 40 }, (_, i) => `${name} line ${i}\n`).join(""); 152+ buildBase({ "a.txt": lines("a"), "b.txt": lines("b"), "c.txt": lines("c") }, { author: "test", message: "base" }), 154+ const set = new Set(["a0"]); 155+ // a.txt in x first, then b.txt in y, then c.txt in x: a.txt is the least recently used. 156+ const use = (cache: ViewCache) => { 157+ const x = cache.keyed("x", () => set); 158+ const y = cache.keyed("y", () => set); 162+ return { x: x as View, y: y as View }; 164+ const probe = use(new ViewCache(graph)); 165+ const total = probe.x.weight() + probe.y.weight(); 166+ const cache = new ViewCache(graph, undefined, total - 1); 167+ const { x, y } = use(cache); 170+ [...x.laidOut()].map((f) => f.path), 174+ [...y.laidOut()].map((f) => f.path), 178+ cache.keyed("x", () => set), 180+ "both views are still cached", 183+ cache.keyed("y", () => set), 186+ assert.equal(x.text("a.txt"), lines("a"), "a.txt is laid out again, the same");