test(ai): replace provider sweep with explicit custom-route check

This commit is contained in:
Kit Langton 2026-11-26 14:24:46 -08:00
parent 9a6f97b2cd
commit 3e1e1b934d

View file

@ -251,64 +251,47 @@ describe("applyCachePolicy", () => {
),
)
it.effect("every registered Anthropic Messages route emits inline cache markers", () =>
it.effect("custom routes built on anthropic-messages emit inline cache markers regardless of route ID", () =>
Effect.gen(function* () {
const providers = yield* Effect.promise(() => import("../src/providers.js"))
const routes = Object.values(providers)
.flatMap((entry) => ("routes" in entry ? entry.routes : "route" in entry ? [entry.route] : []))
.filter((route) => route.protocol.endsWith("-messages") || route.id.endsWith("-messages"))
expect(routes.length).toBeGreaterThanOrEqual(12)
for (const route of routes) {
const model = route
.with({
endpoint: { baseURL: "https://messages.example.test/v1" },
auth: Auth.header("x-api-key", "test"),
})
.model({ id: "anthropic/claude-sonnet-4-6" })
const autoPrepared = yield* compileRequest(
ai.request({
model,
system: "Sys",
tools: [{ name: "t1", description: "t1", inputSchema: { type: "object", properties: {} } }],
prompt: "hi",
}),
)
expect({ route: route.id, body: autoPrepared.body }).toMatchObject({
route: route.id,
body: {
tools: [{ name: "t1", cache_control: { type: "ephemeral" } }],
system: [{ type: "text", text: "Sys", cache_control: { type: "ephemeral" } }],
messages: [
{
role: "user",
content: [{ type: "text", text: "hi", cache_control: { type: "ephemeral" } }],
},
],
},
const model = AnthropicMessages.route
.with({
id: "custom-messages",
provider: "custom",
endpoint: { baseURL: "https://messages.example.test/v1" },
auth: Auth.header("x-api-key", "test"),
})
.model({ id: "claude-sonnet-4-6" })
const scopedPrepared = yield* compileRequest(
ai.request({
model,
system: "Sys",
tools: [{ name: "t1", description: "t1", inputSchema: { type: "object", properties: {} } }],
prompt: "hi",
cache: { tools: true, ttl: "1h" },
}),
)
const autoPrepared = yield* compileRequest(
ai.request({
model,
system: "Sys",
tools: [{ name: "t1", description: "t1", inputSchema: { type: "object", properties: {} } }],
prompt: "hi",
}),
)
expect({ route: route.id, body: scopedPrepared.body }).toMatchObject({
route: route.id,
body: {
tools: [{ name: "t1", cache_control: { type: "ephemeral", ttl: "1h" } }],
system: [{ type: "text", text: "Sys", cache_control: undefined }],
},
})
}
expect(autoPrepared.route).toBe("custom-messages")
expect(autoPrepared.body).toMatchObject({
tools: [{ name: "t1", cache_control: { type: "ephemeral" } }],
system: [{ type: "text", text: "Sys", cache_control: { type: "ephemeral" } }],
messages: [{ role: "user", content: [{ type: "text", text: "hi", cache_control: { type: "ephemeral" } }] }],
})
const scopedPrepared = yield* compileRequest(
ai.request({
model,
system: "Sys",
tools: [{ name: "t1", description: "t1", inputSchema: { type: "object", properties: {} } }],
prompt: "hi",
cache: { tools: true, ttl: "1h" },
}),
)
expect(scopedPrepared.body).toMatchObject({
tools: [{ name: "t1", cache_control: { type: "ephemeral", ttl: "1h" } }],
system: [{ type: "text", text: "Sys", cache_control: undefined }],
})
}),
)