


























@@ -4,7 +4,11 @@ import {
44} from "openclaw/plugin-sdk/provider-setup";
55import { afterAll, afterEach, describe, expect, it, vi } from "vitest";
66import { LMSTUDIO_DEFAULT_LOAD_CONTEXT_LENGTH } from "./defaults.js";
7-import { discoverLmstudioModels, ensureLmstudioModelLoaded } from "./models.fetch.js";
7+import {
8+discoverLmstudioModels,
9+ensureLmstudioModelLoaded,
10+fetchLmstudioModels,
11+} from "./models.fetch.js";
812import {
913normalizeLmstudioProviderConfig,
1014resolveLmstudioInferenceBase,
@@ -294,6 +298,24 @@ describe("lmstudio-models", () => {
294298});
295299});
296300301+it("reports malformed model list JSON with an owned error", async () => {
302+const fetchMock = vi.fn(async () => ({
303+ok: true,
304+status: 200,
305+json: async () => {
306+throw new SyntaxError("bad json");
307+},
308+}));
309+310+const result = await fetchLmstudioModels({
311+baseUrl: "http://localhost:1234/v1",
312+fetchImpl: asFetch(fetchMock),
313+});
314+315+expect(result.reachable).toBe(false);
316+expect((result.error as Error).message).toBe("LM Studio model list returned malformed JSON");
317+});
318+297319it("skips model load when already loaded", async () => {
298320const fetchMock = createModelLoadFetchMock({ loadedContextLength: 64000 });
299321vi.stubGlobal("fetch", asFetch(fetchMock));
@@ -329,6 +351,36 @@ describe("lmstudio-models", () => {
329351expectLoadContextLength(fetchMock, 8192);
330352});
331353354+it("reports malformed model load JSON with an owned error", async () => {
355+const fetchMock = vi.fn(async (url: string | URL) => {
356+if (String(url).endsWith("/api/v1/models")) {
357+return {
358+ok: true,
359+json: async () => ({
360+models: [{ type: "llm", key: "qwen3-8b-instruct", loaded_instances: [] }],
361+}),
362+};
363+}
364+if (String(url).endsWith("/api/v1/models/load")) {
365+return {
366+ok: true,
367+json: async () => {
368+throw new SyntaxError("bad json");
369+},
370+};
371+}
372+throw new Error(`Unexpected fetch URL: ${String(url)}`);
373+});
374+vi.stubGlobal("fetch", asFetch(fetchMock));
375+376+await expect(
377+ensureLmstudioModelLoaded({
378+baseUrl: "http://localhost:1234/v1",
379+modelKey: "qwen3-8b-instruct",
380+}),
381+).rejects.toThrow("LM Studio model load returned malformed JSON");
382+});
383+332384it("reloads model to the clamped default target when already loaded below the default window", async () => {
333385const fetchMock = createModelLoadFetchMock({
334386loadedContextLength: 4096,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。