@@ -10,6 +10,7 @@ import {
|
10 | 10 | fetchLmstudioModels, |
11 | 11 | } from "./models.fetch.js"; |
12 | 12 | import { |
| 13 | +mapLmstudioWireEntry, |
13 | 14 | normalizeLmstudioConfiguredCatalogEntry, |
14 | 15 | normalizeLmstudioProviderConfig, |
15 | 16 | resolveLmstudioInferenceBase, |
@@ -160,6 +161,23 @@ describe("lmstudio-models", () => {
|
160 | 161 | }); |
161 | 162 | }); |
162 | 163 | |
| 164 | +it("drops malformed discovered context metadata", () => { |
| 165 | +const model = mapLmstudioWireEntry({ |
| 166 | +type: "llm", |
| 167 | +key: "bad-context", |
| 168 | +max_context_length: 32768.5, |
| 169 | +loaded_instances: [{ id: "loaded", config: { context_length: Number.POSITIVE_INFINITY } }], |
| 170 | +}); |
| 171 | + |
| 172 | +expect(model).toMatchObject({ |
| 173 | +id: "bad-context", |
| 174 | +contextWindow: SELF_HOSTED_DEFAULT_CONTEXT_WINDOW, |
| 175 | +contextTokens: LMSTUDIO_DEFAULT_LOAD_CONTEXT_LENGTH, |
| 176 | +maxTokens: SELF_HOSTED_DEFAULT_MAX_TOKENS, |
| 177 | +loaded: false, |
| 178 | +}); |
| 179 | +}); |
| 180 | + |
163 | 181 | it("resolves reasoning capability for supported and unsupported options", () => { |
164 | 182 | expect(resolveLmstudioReasoningCapability({ capabilities: undefined })).toBe(false); |
165 | 183 | expect( |
@@ -499,6 +517,24 @@ describe("lmstudio-models", () => {
|
499 | 517 | expectLoadContextLength(fetchMock, 8192); |
500 | 518 | }); |
501 | 519 | |
| 520 | +it("omits malformed context lengths before loading models", async () => { |
| 521 | +const fetchMock = createModelLoadFetchMock({ |
| 522 | +loadedContextLength: 4096.5, |
| 523 | +maxContextLength: 32768.5, |
| 524 | +}); |
| 525 | +vi.stubGlobal("fetch", asFetch(fetchMock)); |
| 526 | + |
| 527 | +await expect( |
| 528 | +ensureLmstudioModelLoaded({ |
| 529 | +baseUrl: "http://localhost:1234/v1", |
| 530 | +modelKey: "qwen3-8b-instruct", |
| 531 | +requestedContextLength: 8192.5, |
| 532 | +}), |
| 533 | +).resolves.toBeUndefined(); |
| 534 | + |
| 535 | +expectLoadContextLength(fetchMock, LMSTUDIO_DEFAULT_LOAD_CONTEXT_LENGTH); |
| 536 | +}); |
| 537 | + |
502 | 538 | it("throws when model discovery fails", async () => { |
503 | 539 | const fetchMock = vi.fn(async () => ({ |
504 | 540 | ok: false, |
|