{"version":3,"file":"tool-serializer.test.d.ts","sourceRoot":"","sources":["../../../src/cache/__tests__/tool-serializer.test.ts"],"names":[],"mappings":"","sourcesContent":["// T-005, T-006\nimport { describe, expect, it } from \"vitest\";\nimport { serializeToolSchemas, toolSchemaHash } from \"../tool-serializer.js\";\n\nconst baseTools = [\n\t{\n\t\tname: \"bash\",\n\t\tdescription: \"Run a shell command\",\n\t\tparameters: { type: \"object\", properties: { cmd: { type: \"string\" } } },\n\t},\n\t{\n\t\tname: \"read\",\n\t\tdescription: \"Read a file\",\n\t\tparameters: { type: \"object\", properties: { path: { type: \"string\" } } },\n\t},\n\t{\n\t\tname: \"apply_sr_diff\",\n\t\tdescription: \"Exact-match search/replace edit\",\n\t\tparameters: { type: \"object\", properties: { file: { type: \"string\" } } },\n\t},\n];\n\ndescribe(\"serializeToolSchemas\", () => {\n\tit(\"produces byte-stable SHA256 across 1000 invocations\", () => {\n\t\tconst first = toolSchemaHash(baseTools);\n\t\tfor (let i = 0; i < 1000; i++) {\n\t\t\texpect(toolSchemaHash(baseTools)).toBe(first);\n\t\t}\n\t});\n\n\tit(\"reordering tools at call site does not change bytes\", () => {\n\t\tconst a = serializeToolSchemas(baseTools);\n\t\tconst shuffled = [baseTools[2], baseTools[0], baseTools[1]];\n\t\tconst b = serializeToolSchemas(shuffled);\n\t\texpect(a).toBe(b);\n\t});\n\n\tit(\"editing one tool description isolates to tools-layer hash (it changes)\", () => {\n\t\tconst original = toolSchemaHash(baseTools);\n\t\tconst edited = baseTools.map((t) => (t.name === \"read\" ? { ...t, description: \"Read a file from disk\" } : t));\n\t\tconst editedHash = toolSchemaHash(edited);\n\t\texpect(editedHash).not.toBe(original);\n\t});\n\n\tit(\"strips absolute paths and ISO timestamps from descriptions\", () => {\n\t\tconst tools = [\n\t\t\t{\n\t\t\t\tname: \"log\",\n\t\t\t\tdescription: \"Written at 2025-03-15T12:34:56Z from /Users/alice/project\",\n\t\t\t\tparameters: {},\n\t\t\t},\n\t\t];\n\t\tconst json = serializeToolSchemas(tools);\n\t\texpect(json).not.toContain(\"2025-03-15\");\n\t\texpect(json).not.toContain(\"/Users/alice\");\n\t\texpect(json).toContain(\"<ts>\");\n\t\texpect(json).toContain(\"<path>\");\n\t});\n\n\tit(\"sorts object keys deeply for deterministic output\", () => {\n\t\tconst a = serializeToolSchemas([\n\t\t\t{ name: \"t\", description: \"d\", parameters: { b: 1, a: 2, nested: { z: 1, y: 2 } } },\n\t\t]);\n\t\tconst b = serializeToolSchemas([\n\t\t\t{ name: \"t\", description: \"d\", parameters: { nested: { y: 2, z: 1 }, a: 2, b: 1 } },\n\t\t]);\n\t\texpect(a).toBe(b);\n\t});\n});\n"]}