mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-24 16:02:55 +08:00
test(cli): cover provider-reported context output cap
Add regression coverage for capOutputTokens preferring the provider-reported context size (image/vision input priced by the provider) and falling back to the media-normalized floor when reported usage is smaller or absent.
This commit is contained in:
@@ -157,6 +157,42 @@ describe("Kilo request estimation", () => {
|
||||
expect(cap).toBeGreaterThanOrEqual(1_024)
|
||||
expect(cap).toBeLessThan(32_000)
|
||||
})
|
||||
|
||||
test("prefers provider-reported context over the client estimate for images", () => {
|
||||
// The client cannot price encoded image bytes, but the provider reported a
|
||||
// large vision-token cost for the last turn.
|
||||
const mdl = model({ context: 300_000, output: 32_000 })
|
||||
const messages = [
|
||||
{
|
||||
role: "user",
|
||||
content: [{ type: "image", image: `data:image/png;base64,${"x".repeat(600_000)}` }],
|
||||
},
|
||||
] satisfies ModelMessage[]
|
||||
|
||||
// Without reported usage the media-normalized estimate leaves output untouched.
|
||||
expect(KiloLLM.capOutputTokens({ model: mdl, messages, tools: {}, configured: 32_000 })).toBe(32_000)
|
||||
|
||||
// With the provider-reported context size, output is capped to fit real usage.
|
||||
expect(KiloLLM.capOutputTokens({ model: mdl, messages, tools: {}, configured: 32_000, reported: 280_000 })).toBe(
|
||||
17_952,
|
||||
)
|
||||
})
|
||||
|
||||
test("uses the media-normalized floor when reported usage is smaller", () => {
|
||||
const mdl = model({ context: 200_000, output: 32_000 })
|
||||
const messages = [{ role: "user" as const, content: "x".repeat(600_000) }]
|
||||
|
||||
const withoutReported = KiloLLM.capOutputTokens({ model: mdl, messages, tools: {}, configured: 32_000 })
|
||||
const withStaleReported = KiloLLM.capOutputTokens({
|
||||
model: mdl,
|
||||
messages,
|
||||
tools: {},
|
||||
configured: 32_000,
|
||||
reported: 1_000,
|
||||
})
|
||||
expect(withStaleReported).toBe(withoutReported)
|
||||
expect(withStaleReported).toBeLessThan(32_000)
|
||||
})
|
||||
})
|
||||
|
||||
describe("Kilo preflight compaction", () => {
|
||||
|
||||
Reference in New Issue
Block a user