test(pi-ai): add tests for convertTools cache_control breakpoint
This commit is contained in:
parent
49c05eaaa7
commit
aa6dce948c
1 changed files with 56 additions and 0 deletions
56
packages/pi-ai/src/providers/anthropic-shared.test.ts
Normal file
56
packages/pi-ai/src/providers/anthropic-shared.test.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import { describe, it } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { convertTools } from "./anthropic-shared.js";
|
||||
|
||||
const makeTool = (name: string) => ({
|
||||
name,
|
||||
description: `desc for ${name}`,
|
||||
parameters: {
|
||||
type: "object" as const,
|
||||
properties: { arg: { type: "string" } },
|
||||
required: ["arg"],
|
||||
},
|
||||
});
|
||||
|
||||
describe("convertTools cache_control", () => {
|
||||
it("adds cache_control to the last tool when cacheControl is provided", () => {
|
||||
const tools = [makeTool("Read"), makeTool("Write"), makeTool("Edit")];
|
||||
const cacheControl = { type: "ephemeral" as const };
|
||||
const result = convertTools(tools, false, cacheControl);
|
||||
|
||||
assert.equal(result.length, 3);
|
||||
assert.equal((result[0] as any).cache_control, undefined);
|
||||
assert.equal((result[1] as any).cache_control, undefined);
|
||||
assert.deepEqual((result[2] as any).cache_control, { type: "ephemeral" });
|
||||
});
|
||||
|
||||
it("does not add cache_control when cacheControl is undefined", () => {
|
||||
const tools = [makeTool("Read"), makeTool("Write")];
|
||||
const result = convertTools(tools, false);
|
||||
|
||||
for (const tool of result) {
|
||||
assert.equal((tool as any).cache_control, undefined);
|
||||
}
|
||||
});
|
||||
|
||||
it("handles empty tools array without error", () => {
|
||||
const result = convertTools([], false, { type: "ephemeral" });
|
||||
assert.equal(result.length, 0);
|
||||
});
|
||||
|
||||
it("passes through ttl when provided", () => {
|
||||
const tools = [makeTool("Read")];
|
||||
const cacheControl = { type: "ephemeral" as const, ttl: "1h" as const };
|
||||
const result = convertTools(tools, false, cacheControl);
|
||||
|
||||
assert.deepEqual((result[0] as any).cache_control, { type: "ephemeral", ttl: "1h" });
|
||||
});
|
||||
|
||||
it("single tool gets cache_control", () => {
|
||||
const tools = [makeTool("Read")];
|
||||
const result = convertTools(tools, false, { type: "ephemeral" });
|
||||
|
||||
assert.equal(result.length, 1);
|
||||
assert.deepEqual((result[0] as any).cache_control, { type: "ephemeral" });
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue