{"version":3,"file":"layers.test.d.ts","sourceRoot":"","sources":["../../../src/cache/__tests__/layers.test.ts"],"names":[],"mappings":"","sourcesContent":["// T-002, T-003\nimport { describe, expect, it } from \"vitest\";\nimport { assembleLayered, layerBytes, layerHash, layersInOrder } from \"../layers.js\";\nimport { validateLayers } from \"../policy.js\";\n\nconst tools = [{ name: \"a\", description: \"alpha\", parameters: {} }];\nconst baseInput = {\n\ttools,\n\tsystem: \"you are cave\",\n\tproject: \"CLAUDE.md contents\",\n\tmessages: [\"hi\"],\n\tpolicy: { retention: \"short\" as const, supportsBreakpoints: true },\n};\n\ndescribe(\"assembleLayered\", () => {\n\tit(\"emits layers in exact tools/system/project/messages order\", () => {\n\t\tconst p = assembleLayered(baseInput);\n\t\texpect(layersInOrder(p)).toEqual([\"tools\", \"system\", \"project\", \"messages\"]);\n\t});\n\n\tit(\"non-breakpoint provider accepts same 4-layer payload\", () => {\n\t\tconst p = assembleLayered({\n\t\t\t...baseInput,\n\t\t\tpolicy: { retention: \"short\", supportsBreakpoints: false },\n\t\t});\n\t\texpect(layersInOrder(p)).toEqual([\"tools\", \"system\", \"project\", \"messages\"]);\n\t\tfor (const layer of p.layers) {\n\t\t\texpect(layer.breakpoint).toBe(false);\n\t\t}\n\t});\n\n\tit(\"removing project context does not alter tools/system bytes\", () => {\n\t\tconst withProject = assembleLayered(baseInput);\n\t\tconst withoutProject = assembleLayered({ ...baseInput, project: undefined });\n\t\texpect(layerHash(withProject, \"tools\")).toBe(layerHash(withoutProject, \"tools\"));\n\t\texpect(layerHash(withProject, \"system\")).toBe(layerHash(withoutProject, \"system\"));\n\t\texpect(layersInOrder(withoutProject)).toEqual([\"tools\", \"system\", \"messages\"]);\n\t});\n\n\tit(\"rejects out-of-order layers\", () => {\n\t\texpect(() =>\n\t\t\tvalidateLayers([\n\t\t\t\t{ layer: \"system\", bytes: \"\" },\n\t\t\t\t{ layer: \"tools\", bytes: \"\" },\n\t\t\t]),\n\t\t).toThrow(/out of canonical order/);\n\t});\n\n\tit(\"rejects duplicate layer\", () => {\n\t\texpect(() =>\n\t\t\tvalidateLayers([\n\t\t\t\t{ layer: \"tools\", bytes: \"\" },\n\t\t\t\t{ layer: \"tools\", bytes: \"\" },\n\t\t\t]),\n\t\t).toThrow(/duplicate layer/);\n\t});\n\n\tit(\"enforces single breakpoint per layer\", () => {\n\t\texpect(() =>\n\t\t\tvalidateLayers([\n\t\t\t\t{ layer: \"tools\", bytes: \"a\", breakpoint: true },\n\t\t\t\t{ layer: \"system\", bytes: \"b\", breakpoint: true },\n\t\t\t\t// Two blocks in the same layer not allowed at all, but validate\n\t\t\t\t// also catches the breakpoint-count path with a hand-crafted list:\n\t\t\t]),\n\t\t).not.toThrow();\n\t});\n\n\tit(\"editing a tool does not change system/project bytes\", () => {\n\t\tconst before = assembleLayered(baseInput);\n\t\tconst after = assembleLayered({\n\t\t\t...baseInput,\n\t\t\ttools: [{ name: \"a\", description: \"alpha edited\", parameters: {} }],\n\t\t});\n\t\texpect(layerHash(before, \"tools\")).not.toBe(layerHash(after, \"tools\"));\n\t\texpect(layerHash(before, \"system\")).toBe(layerHash(after, \"system\"));\n\t\texpect(layerHash(before, \"project\")).toBe(layerHash(after, \"project\"));\n\t});\n\n\tit(\"layer bytes are non-empty string for present layers\", () => {\n\t\tconst p = assembleLayered(baseInput);\n\t\texpect(layerBytes(p, \"tools\").length).toBeGreaterThan(0);\n\t\texpect(layerBytes(p, \"system\")).toBe(\"you are cave\");\n\t});\n});\n"]}