|
| 1 | +import { describe, expect, it, vi } from "vitest" |
| 2 | + |
| 3 | +import { API } from "../api" |
| 4 | + |
| 5 | +vi.mock("@roo-code/ipc", () => ({ |
| 6 | + IpcServer: class {}, |
| 7 | +})) |
| 8 | + |
| 9 | +vi.mock("../../integrations/terminal/Terminal", () => ({ |
| 10 | + Terminal: { |
| 11 | + getTerminalProfile: vi.fn(), |
| 12 | + setTerminalProfile: vi.fn(), |
| 13 | + }, |
| 14 | +})) |
| 15 | + |
| 16 | +vi.mock("../../integrations/terminal/TerminalRegistry", () => ({ |
| 17 | + TerminalRegistry: { |
| 18 | + closeIdleTerminals: vi.fn(), |
| 19 | + }, |
| 20 | +})) |
| 21 | + |
| 22 | +describe("API.setConfiguration", () => { |
| 23 | + it("routes configuration through ClineProvider.setValues so view-local state stays in sync", async () => { |
| 24 | + const provider = { |
| 25 | + context: {}, |
| 26 | + on: vi.fn(), |
| 27 | + setValues: vi.fn().mockResolvedValue(undefined), |
| 28 | + contextProxy: { |
| 29 | + setValues: vi.fn().mockResolvedValue(undefined), |
| 30 | + }, |
| 31 | + providerSettingsManager: { |
| 32 | + saveConfig: vi.fn().mockResolvedValue("default-id"), |
| 33 | + }, |
| 34 | + postStateToWebview: vi.fn().mockResolvedValue(undefined), |
| 35 | + } as any |
| 36 | + const api = new API({ appendLine: vi.fn() } as any, provider) |
| 37 | + const configuration = { |
| 38 | + apiProvider: "bedrock" as const, |
| 39 | + currentApiConfigName: "default", |
| 40 | + awsRegion: "us-east-1", |
| 41 | + apiModelId: "us.anthropic.claude-haiku-4-5-20251001-v1:0", |
| 42 | + } |
| 43 | + |
| 44 | + await api.setConfiguration(configuration) |
| 45 | + |
| 46 | + expect(provider.setValues).toHaveBeenCalledWith(configuration) |
| 47 | + expect(provider.contextProxy.setValues).not.toHaveBeenCalled() |
| 48 | + expect(provider.providerSettingsManager.saveConfig).toHaveBeenCalledWith("default", configuration) |
| 49 | + expect(provider.postStateToWebview).toHaveBeenCalled() |
| 50 | + }) |
| 51 | +}) |
0 commit comments