fix (agents): honor configured contextWindow overrides

This commit is contained in:
Vignesh Natarajan
2026-02-15 13:11:44 -08:00
parent 69418cca20
commit 150c5815eb
2 changed files with 91 additions and 4 deletions

View File

@@ -0,0 +1,41 @@
import { describe, expect, it } from "vitest";
import { applyConfiguredContextWindows } from "./context.js";
describe("applyConfiguredContextWindows", () => {
it("overrides discovered cache values with explicit models.providers contextWindow", () => {
const cache = new Map<string, number>([["anthropic/claude-opus-4-6", 1_000_000]]);
applyConfiguredContextWindows({
cache,
modelsConfig: {
providers: {
openrouter: {
models: [{ id: "anthropic/claude-opus-4-6", contextWindow: 200_000 }],
},
},
},
});
expect(cache.get("anthropic/claude-opus-4-6")).toBe(200_000);
});
it("adds config-only model context windows and ignores invalid entries", () => {
const cache = new Map<string, number>();
applyConfiguredContextWindows({
cache,
modelsConfig: {
providers: {
openrouter: {
models: [
{ id: "custom/model", contextWindow: 150_000 },
{ id: "bad/model", contextWindow: 0 },
{ id: "", contextWindow: 300_000 },
],
},
},
},
});
expect(cache.get("custom/model")).toBe(150_000);
expect(cache.has("bad/model")).toBe(false);
});
});