mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-26 23:28:43 +00:00
test(ai): replace provider sweep with explicit custom-route check
This commit is contained in:
parent
9a6f97b2cd
commit
3e1e1b934d
1 changed files with 37 additions and 54 deletions
|
|
@ -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 }],
|
||||
})
|
||||
}),
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue