






















1-import { mkdtempSync, rmSync } from "node:fs";
1+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
22import { tmpdir } from "node:os";
33import { join } from "node:path";
44import { importFreshModule } from "openclaw/plugin-sdk/test-fixtures";
@@ -92,6 +92,112 @@ describe("openrouter-model-capabilities", () => {
9292});
9393});
949495+it("uses endpoint-specific OpenRouter context length when top_provider reports one", async () => {
96+await withOpenRouterStateDir(async () => {
97+vi.stubGlobal(
98+"fetch",
99+vi.fn(
100+async () =>
101+new Response(
102+JSON.stringify({
103+data: [
104+{
105+id: "nvidia/nemotron-3-super-120b-a12b:free",
106+name: "Nemotron 3 Super 120B Free",
107+architecture: { modality: "text->text" },
108+context_length: 1_000_000,
109+top_provider: {
110+context_length: 262_144,
111+max_completion_tokens: 262_144,
112+},
113+pricing: { prompt: "0", completion: "0" },
114+},
115+],
116+}),
117+{
118+status: 200,
119+headers: { "content-type": "application/json" },
120+},
121+),
122+),
123+);
124+125+const module = await importOpenRouterModelCapabilities("top-provider-context-length");
126+await module.loadOpenRouterModelCapabilities("nvidia/nemotron-3-super-120b-a12b:free");
127+128+expect(
129+module.getOpenRouterModelCapabilities("nvidia/nemotron-3-super-120b-a12b:free"),
130+).toMatchObject({
131+contextWindow: 262_144,
132+maxTokens: 262_144,
133+});
134+});
135+});
136+137+it("does not reuse older disk caches with precomputed OpenRouter context windows", async () => {
138+await withOpenRouterStateDir(async (stateDir) => {
139+const modelId = "nvidia/nemotron-3-super-120b-a12b:free";
140+const cacheDir = join(stateDir, "cache");
141+mkdirSync(cacheDir, { recursive: true });
142+writeFileSync(
143+join(cacheDir, "openrouter-models.json"),
144+JSON.stringify({
145+version: 2,
146+models: {
147+[modelId]: {
148+name: "Nemotron 3 Super 120B Free",
149+input: ["text"],
150+reasoning: false,
151+contextWindow: 1_000_000,
152+maxTokens: 262_144,
153+cost: {
154+input: 0,
155+output: 0,
156+cacheRead: 0,
157+cacheWrite: 0,
158+},
159+},
160+},
161+}),
162+);
163+164+const fetchSpy = vi.fn(
165+async () =>
166+new Response(
167+JSON.stringify({
168+data: [
169+{
170+id: modelId,
171+name: "Nemotron 3 Super 120B Free",
172+architecture: { modality: "text->text" },
173+context_length: 1_000_000,
174+top_provider: {
175+context_length: 262_144,
176+max_completion_tokens: 262_144,
177+},
178+pricing: { prompt: "0", completion: "0" },
179+},
180+],
181+}),
182+{
183+status: 200,
184+headers: { "content-type": "application/json" },
185+},
186+),
187+);
188+vi.stubGlobal("fetch", fetchSpy);
189+190+const module = await importOpenRouterModelCapabilities("old-context-window-cache");
191+await module.loadOpenRouterModelCapabilities(modelId);
192+193+expect(fetchSpy).toHaveBeenCalledTimes(1);
194+expect(module.getOpenRouterModelCapabilities(modelId)).toMatchObject({
195+contextWindow: 262_144,
196+maxTokens: 262_144,
197+});
198+});
199+});
200+95201it("preserves explicit OpenRouter tool support metadata", async () => {
96202await withOpenRouterStateDir(async () => {
97203vi.stubGlobal(
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。