|
@@ -10,13 +10,19 @@ import type { Provider } from "../../src/provider/provider"
|
|
|
|
|
|
|
|
Log.init({ print: false })
|
|
Log.init({ print: false })
|
|
|
|
|
|
|
|
-function createModel(opts: { context: number; output: number; cost?: Provider.Model["cost"] }): Provider.Model {
|
|
|
|
|
|
|
+function createModel(opts: {
|
|
|
|
|
+ context: number
|
|
|
|
|
+ output: number
|
|
|
|
|
+ input?: number
|
|
|
|
|
+ cost?: Provider.Model["cost"]
|
|
|
|
|
+}): Provider.Model {
|
|
|
return {
|
|
return {
|
|
|
id: "test-model",
|
|
id: "test-model",
|
|
|
providerID: "test",
|
|
providerID: "test",
|
|
|
name: "Test",
|
|
name: "Test",
|
|
|
limit: {
|
|
limit: {
|
|
|
context: opts.context,
|
|
context: opts.context,
|
|
|
|
|
+ input: opts.input,
|
|
|
output: opts.output,
|
|
output: opts.output,
|
|
|
},
|
|
},
|
|
|
cost: opts.cost ?? { input: 0, output: 0, cache: { read: 0, write: 0 } },
|
|
cost: opts.cost ?? { input: 0, output: 0, cache: { read: 0, write: 0 } },
|
|
@@ -70,6 +76,42 @@ describe("session.compaction.isOverflow", () => {
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+ test("respects input limit for input caps", async () => {
|
|
|
|
|
+ await using tmp = await tmpdir()
|
|
|
|
|
+ await Instance.provide({
|
|
|
|
|
+ directory: tmp.path,
|
|
|
|
|
+ fn: async () => {
|
|
|
|
|
+ const model = createModel({ context: 400_000, input: 272_000, output: 128_000 })
|
|
|
|
|
+ const tokens = { input: 271_000, output: 1_000, reasoning: 0, cache: { read: 2_000, write: 0 } }
|
|
|
|
|
+ expect(await SessionCompaction.isOverflow({ tokens, model })).toBe(true)
|
|
|
|
|
+ },
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ test("returns false when input/output are within input caps", async () => {
|
|
|
|
|
+ await using tmp = await tmpdir()
|
|
|
|
|
+ await Instance.provide({
|
|
|
|
|
+ directory: tmp.path,
|
|
|
|
|
+ fn: async () => {
|
|
|
|
|
+ const model = createModel({ context: 400_000, input: 272_000, output: 128_000 })
|
|
|
|
|
+ const tokens = { input: 200_000, output: 20_000, reasoning: 0, cache: { read: 10_000, write: 0 } }
|
|
|
|
|
+ expect(await SessionCompaction.isOverflow({ tokens, model })).toBe(false)
|
|
|
|
|
+ },
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ test("returns false when output within limit with input caps", async () => {
|
|
|
|
|
+ await using tmp = await tmpdir()
|
|
|
|
|
+ await Instance.provide({
|
|
|
|
|
+ directory: tmp.path,
|
|
|
|
|
+ fn: async () => {
|
|
|
|
|
+ const model = createModel({ context: 200_000, input: 120_000, output: 10_000 })
|
|
|
|
|
+ const tokens = { input: 50_000, output: 9_999, reasoning: 0, cache: { read: 0, write: 0 } }
|
|
|
|
|
+ expect(await SessionCompaction.isOverflow({ tokens, model })).toBe(false)
|
|
|
|
|
+ },
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
test("returns false when model context limit is 0", async () => {
|
|
test("returns false when model context limit is 0", async () => {
|
|
|
await using tmp = await tmpdir()
|
|
await using tmp = await tmpdir()
|
|
|
await Instance.provide({
|
|
await Instance.provide({
|