|
| 1 | +import { describe, it, expect, vi } from "vitest" |
| 2 | + |
| 3 | +import { webviewMessageHandler } from "../webviewMessageHandler" |
| 4 | + |
| 5 | +vi.mock("../../../i18n", () => ({ |
| 6 | + t: vi.fn((key: string) => key), |
| 7 | + changeLanguage: vi.fn(), |
| 8 | +})) |
| 9 | + |
| 10 | +vi.mock("vscode", () => ({ |
| 11 | + window: { |
| 12 | + showErrorMessage: vi.fn(), |
| 13 | + showWarningMessage: vi.fn(), |
| 14 | + showInformationMessage: vi.fn(), |
| 15 | + }, |
| 16 | + workspace: { |
| 17 | + workspaceFolders: undefined, |
| 18 | + getConfiguration: vi.fn(() => ({ |
| 19 | + get: vi.fn(), |
| 20 | + update: vi.fn(), |
| 21 | + })), |
| 22 | + }, |
| 23 | + ConfigurationTarget: { |
| 24 | + Global: 1, |
| 25 | + Workspace: 2, |
| 26 | + WorkspaceFolder: 3, |
| 27 | + }, |
| 28 | + Uri: { |
| 29 | + parse: vi.fn((str) => ({ toString: () => str })), |
| 30 | + file: vi.fn((path) => ({ fsPath: path })), |
| 31 | + }, |
| 32 | +})) |
| 33 | + |
| 34 | +describe("webviewMessageHandler setTaskThinkingEffort (DTE series 4/5)", () => { |
| 35 | + const makeTask = (supportsReasoningEffort: unknown) => { |
| 36 | + const say = vi.fn(async (_say: string, _text?: string) => {}) |
| 37 | + return { |
| 38 | + taskId: "test-task-id", |
| 39 | + api: { getModel: () => ({ id: "test-model", info: { supportsReasoningEffort } }) }, |
| 40 | + setRuntimeThinkingEffort: vi.fn(), |
| 41 | + say, |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + const makeProvider = (task: unknown) => ({ |
| 46 | + getCurrentTask: vi.fn(() => task), |
| 47 | + postStateToWebviewWithoutTaskHistory: vi.fn(async () => {}), |
| 48 | + }) |
| 49 | + |
| 50 | + const apply = (provider: ReturnType<typeof makeProvider>, message: Record<string, unknown>) => |
| 51 | + webviewMessageHandler(provider as never, message as never) |
| 52 | + |
| 53 | + it("applies a task-local effort for a supported level, records the chat line, and pushes state", async () => { |
| 54 | + const task = makeTask(["low", "medium", "high"]) |
| 55 | + const provider = makeProvider(task) |
| 56 | + |
| 57 | + await apply(provider, { type: "setTaskThinkingEffort", effort: "high" }) |
| 58 | + |
| 59 | + expect(task.setRuntimeThinkingEffort).toHaveBeenCalledWith("high", "you") |
| 60 | + const [say, text] = task.say.mock.calls[0] |
| 61 | + expect(say).toBe("tool") |
| 62 | + expect(text).toBe(JSON.stringify({ tool: "thinkingEffort", effort: "high", source: "you" })) |
| 63 | + expect(provider.postStateToWebviewWithoutTaskHistory).toHaveBeenCalledTimes(1) |
| 64 | + }) |
| 65 | + |
| 66 | + it("accepts boolean/adaptive-class capability", async () => { |
| 67 | + const provider = makeProvider(makeTask(true)) |
| 68 | + |
| 69 | + await apply(provider, { type: "setTaskThinkingEffort", effort: "medium" }) |
| 70 | + |
| 71 | + expect(provider.postStateToWebviewWithoutTaskHistory).toHaveBeenCalledTimes(1) |
| 72 | + }) |
| 73 | + |
| 74 | + it.each([ |
| 75 | + ["an unsupported level", ["low", "medium", "high"], { effort: "max" }], |
| 76 | + ["an effort outside the canonical enum", ["low", "medium", "high"], { effort: "bogus" }], |
| 77 | + ["a missing effort", ["low", "medium", "high"], {}], |
| 78 | + ["a model without effort support", false, { effort: "high" }], |
| 79 | + ])("ignores %s", async (_name, capability, message) => { |
| 80 | + const task = makeTask(capability) |
| 81 | + const provider = makeProvider(task) |
| 82 | + |
| 83 | + await apply(provider, { type: "setTaskThinkingEffort", ...message }) |
| 84 | + |
| 85 | + expect(task.setRuntimeThinkingEffort).not.toHaveBeenCalled() |
| 86 | + expect(task.say).not.toHaveBeenCalled() |
| 87 | + expect(provider.postStateToWebviewWithoutTaskHistory).not.toHaveBeenCalled() |
| 88 | + }) |
| 89 | + |
| 90 | + it("ignores the message when there is no current task", async () => { |
| 91 | + const provider = makeProvider(undefined) |
| 92 | + |
| 93 | + await apply(provider, { type: "setTaskThinkingEffort", effort: "high" }) |
| 94 | + |
| 95 | + expect(provider.postStateToWebviewWithoutTaskHistory).not.toHaveBeenCalled() |
| 96 | + }) |
| 97 | +}) |
0 commit comments