|
| 1 | +import assert from "node:assert/strict" |
| 2 | +import test from "node:test" |
| 3 | +import { computeInputBudget } from "../lib/messages/inject/utils" |
| 4 | + |
| 5 | +test("computeInputBudget uses limit.input when defined (split-budget OpenAI models)", () => { |
| 6 | + // gpt-5.4-mini, gpt-5.5: 400K context, 272K input, 128K output |
| 7 | + assert.equal(computeInputBudget({ context: 400000, input: 272000, output: 128000 }), 272000) |
| 8 | + // gpt-5.4: 1.05M context, 922K input, 128K output |
| 9 | + assert.equal(computeInputBudget({ context: 1050000, input: 922000, output: 128000 }), 922000) |
| 10 | +}) |
| 11 | + |
| 12 | +test("computeInputBudget subtracts output from context when limit.input is undefined (shared-pool models)", () => { |
| 13 | + // claude-opus-4-7: 1M context, 128K output, no explicit input limit |
| 14 | + assert.equal(computeInputBudget({ context: 1000000, output: 128000 }), 872000) |
| 15 | + // claude-haiku-4-5: 200K context, 64K output |
| 16 | + assert.equal(computeInputBudget({ context: 200000, output: 64000 }), 136000) |
| 17 | + // gpt-4o: 128K context, 16384 output |
| 18 | + assert.equal(computeInputBudget({ context: 128000, output: 16384 }), 111616) |
| 19 | +}) |
| 20 | + |
| 21 | +test("computeInputBudget treats missing output as 0", () => { |
| 22 | + assert.equal(computeInputBudget({ context: 200000 }), 200000) |
| 23 | +}) |
| 24 | + |
| 25 | +test("computeInputBudget returns undefined when context is unknown", () => { |
| 26 | + assert.equal(computeInputBudget({ context: 0, input: 100, output: 50 }), undefined) |
| 27 | +}) |
| 28 | + |
| 29 | +test("computeInputBudget never returns negative when output exceeds context", () => { |
| 30 | + assert.equal(computeInputBudget({ context: 100, output: 200 }), 0) |
| 31 | +}) |
| 32 | + |
| 33 | +test("computeInputBudget prefers explicit input over the context-minus-output fallback", () => { |
| 34 | + // If both `input` and `output` are present, `input` wins regardless of what |
| 35 | + // `context - output` would compute to. Defensive against models where the |
| 36 | + // numbers don't satisfy `input + output = context`. |
| 37 | + assert.equal(computeInputBudget({ context: 1000, input: 500, output: 200 }), 500) |
| 38 | +}) |
0 commit comments