{"draft":null,"from":262,"to":263,"files":[{"path":"worker/project/test/view-cache.test.ts","added":41,"removed":0,"diff":"--- a/worker/project/test/view-cache.test.ts\n+++ b/worker/project/test/view-cache.test.ts\n@@ -144,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":[]}