{"draft":null,"from":239,"to":318,"files":[{"path":"worker/project/test/view-cache.test.ts","added":55,"removed":0,"diff":"--- a/worker/project/test/view-cache.test.ts\n+++ b/worker/project/test/view-cache.test.ts\n@@ -103,6 +103,20 @@\n \t});\n });\n \n+test(\"trim reweighs growth with no further hit and evicts until the views fit (abso Capacity)\", () => {\n+\twithControlledWeights((control) => {\n+\t\tconst cache = new ViewCache(new Graph());\n+\t\tcontrol.setIncomingWeights([10_000_000, 10_000_000]);\n+\t\tconst growing = get(cache, \"growing\");\n+\t\tconst newer = get(cache, \"newer\");\n+\t\t// A call lays files out in the older view after the cache last weighed it, and nothing asks for it again.\n+\t\tcontrol.setWeight(growing, 16_000_000);\n+\t\tcache.trim();\n+\t\tassert.equal(get(cache, \"newer\"), newer);\n+\t\tassert.notEqual(get(cache, \"growing\"), growing);\n+\t});\n+});\n+\n test(\"an oversized view is returned but not retained\", () => {\n \twithControlledWeights((control) => {\n \t\tconst cache = new ViewCache(new Graph());\n@@ -130,3 +144,44 @@\n \tfor (let i = 0; i < 40; i++) cache.keyed(`other-${i}`, () => set);\n \tassert.deepEqual(cache.view(set).files(), new View(graph, set).files());\n });\n+\n+test(\"trim lets go of the least recently used file layouts across views before whole views (abso Capacity)\", () => {\n+\tconst graph = new Graph();\n+\tconst lines = (name: string) => Array.from({ length: 40 }, (_, i) => `${name} line ${i}\\n`).join(\"\");\n+\tgraph.add(\n+\t\tbuildBase({ \"a.txt\": lines(\"a\"), \"b.txt\": lines(\"b\"), \"c.txt\": lines(\"c\") }, { author: \"test\", message: \"base\" }),\n+\t);\n+\tconst set = new Set([\"a0\"]);\n+\t// a.txt in x first, then b.txt in y, then c.txt in x: a.txt is the least recently used.\n+\tconst use = (cache: ViewCache) => {\n+\t\tconst x = cache.keyed(\"x\", () => set);\n+\t\tconst y = cache.keyed(\"y\", () => set);\n+\t\tx.text(\"a.txt\");\n+\t\ty.text(\"b.txt\");\n+\t\tx.text(\"c.txt\");\n+\t\treturn { x: x as View, y: y as View };\n+\t};\n+\tconst probe = use(new ViewCache(graph));\n+\tconst total = probe.x.weight() + probe.y.weight();\n+\tconst cache = new ViewCache(graph, undefined, total - 1);\n+\tconst { x, y } = use(cache);\n+\tcache.trim();\n+\tassert.deepEqual(\n+\t\t[...x.laidOut()].map((f) => f.path),\n+\t\t[\"c.txt\"],\n+\t);\n+\tassert.deepEqual(\n+\t\t[...y.laidOut()].map((f) => f.path),\n+\t\t[\"b.txt\"],\n+\t);\n+\tassert.equal(\n+\t\tcache.keyed(\"x\", () => set),\n+\t\tx,\n+\t\t\"both views are still cached\",\n+\t);\n+\tassert.equal(\n+\t\tcache.keyed(\"y\", () => set),\n+\t\ty,\n+\t);\n+\tassert.equal(x.text(\"a.txt\"), lines(\"a\"), \"a.txt is laid out again, the same\");\n+});"}],"unmatched":[]}