{"draft":null,"from":252,"to":253,"files":[{"path":"src/engine/test/state-cache.test.ts","added":58,"removed":0,"diff":"--- a/src/engine/test/state-cache.test.ts\n+++ b/src/engine/test/state-cache.test.ts\n@@ -105,3 +105,61 @@\n \tassert.equal(cache.retainedBytes, 0);\n \tsource.db.close();\n });\n+\n+test(\"a rollback drops only what its transaction wrote; a nested commit's writes go with an outer rollback (abso Capacity)\", () => {\n+\tconst source = new SqlState();\n+\ttry {\n+\t\tconst cache = new CachedStateStorage(source, 8192, 16);\n+\t\tsource.write(\"rows\", \"kept\", \"k\");\n+\t\tsource.write(\"rows\", \"inner\", \"i0\");\n+\t\tsource.write(\"rows\", \"outer\", \"o0\");\n+\t\tfor (const key of [\"kept\", \"inner\", \"outer\"]) cache.read(\"rows\", key);\n+\t\tconst reads = source.reads;\n+\t\t// A projection scratch scope: rolled back on purpose, and the rows read around it stay cached.\n+\t\tassert.throws(\n+\t\t\t() =>\n+\t\t\t\tcache.transaction(() => {\n+\t\t\t\t\tcache.write(\"scratch\", \"x\", \"temporary\");\n+\t\t\t\t\tthrow new Error(\"scratch rollback\");\n+\t\t\t\t}),\n+\t\t\t/scratch rollback/,\n+\t\t);\n+\t\tassert.equal(cache.read(\"rows\", \"kept\"), \"k\");\n+\t\tassert.equal(source.reads, reads, \"the rows read before were not read again\");\n+\t\tassert.equal(cache.read(\"scratch\", \"x\"), undefined);\n+\t\t// A nested transaction commits, then the outer one rolls back: both writes are undone, and the cache forgets both.\n+\t\tassert.throws(\n+\t\t\t() =>\n+\t\t\t\tcache.transaction(() => {\n+\t\t\t\t\tcache.write(\"rows\", \"outer\", \"o1\");\n+\t\t\t\t\tcache.transaction(() => cache.write(\"rows\", \"inner\", \"i1\"));\n+\t\t\t\t\tassert.equal(cache.read(\"rows\", \"inner\"), \"i1\");\n+\t\t\t\t\tthrow new Error(\"outer rollback\");\n+\t\t\t\t}),\n+\t\t\t/outer rollback/,\n+\t\t);\n+\t\tassert.equal(cache.read(\"rows\", \"inner\"), \"i0\");\n+\t\tassert.equal(cache.read(\"rows\", \"outer\"), \"o0\");\n+\t\tassert.equal(cache.read(\"rows\", \"kept\"), \"k\");\n+\t} finally {\n+\t\tsource.db.close();\n+\t}\n+});\n+\n+test(\"a row over the per-row limit is read but not kept, and pushes nothing out (abso Capacity)\", () => {\n+\tconst source = new SqlState();\n+\ttry {\n+\t\tconst cache = new CachedStateStorage(source, 8192, 64, 1024);\n+\t\tsource.write(\"rows\", \"small\", \"s\");\n+\t\tsource.write(\"rows\", \"big\", \"x\".repeat(2000));\n+\t\tcache.read(\"rows\", \"small\");\n+\t\tconst reads = source.reads;\n+\t\tassert.equal((cache.read(\"rows\", \"big\") as string).length, 2000);\n+\t\tassert.equal(cache.read(\"rows\", \"small\"), \"s\");\n+\t\tassert.equal(source.reads, reads + 1, \"the big row was read from storage once and the small one stayed cached\");\n+\t\tassert.equal((cache.read(\"rows\", \"big\") as string).length, 2000);\n+\t\tassert.equal(source.reads, reads + 2, \"the big row isn't kept\");\n+\t} finally {\n+\t\tsource.db.close();\n+\t}\n+});"}],"unmatched":[]}