Skip to content

Commit 22b95b2

Browse files
PierrunoYTclaude
andcommitted
test(webview): tighten upsertProviderProfile rollback assertions
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent 604d28c commit 22b95b2

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎src/core/webview/__tests__/ClineProvider.apiHandlerRebuild.spec.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,9 @@ describe("ClineProvider - API Handler Rebuild Guard", () => {
396396
vi.mocked(manager.getProfile).mockResolvedValue({ name: "test-config", ...previousProfile })
397397
vi.mocked(manager.getModeConfigId).mockResolvedValue("previous-mode-id")
398398
const previousSettings = provider.contextProxy.getProviderSettings()
399+
const { mode } = await provider.getState()
400+
const mockTask = new Task({ ...defaultTaskOptions, apiConfiguration: previousSettings })
401+
await provider.addClineToStack(mockTask)
399402
const setProviderSettings = vi
400403
.spyOn(provider.contextProxy, "setProviderSettings")
401404
.mockRejectedValueOnce(new Error("context write failed"))
@@ -412,8 +415,10 @@ describe("ClineProvider - API Handler Rebuild Guard", () => {
412415
openRouterModelId: "anthropic/claude",
413416
})
414417
expect(manager.saveConfig).toHaveBeenLastCalledWith("test-config", previousProfile)
415-
expect(manager.setModeConfig).toHaveBeenLastCalledWith(expect.any(String), "previous-mode-id")
418+
expect(manager.setModeConfig).toHaveBeenLastCalledWith(mode, "previous-mode-id")
416419
expect(setProviderSettings).toHaveBeenLastCalledWith(previousSettings)
420+
// The task's API handler is rebuilt from the prior settings.
421+
expect(mockTask.updateApiConfiguration).toHaveBeenLastCalledWith(previousSettings)
417422
expect(vscode.window.showErrorMessage).toHaveBeenCalledWith("errors.create_api_config")
418423
})
419424

‎src/core/webview/__tests__/ClineProvider.spec.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3498,6 +3498,9 @@ describe("ClineProvider", () => {
34983498

34993499
test("handles buildApiHandler error in updateApiConfiguration", async () => {
35003500
await provider.resolveWebviewView(mockWebviewView)
3501+
// Seed the active profile so the rollback has a known name to put back.
3502+
await provider.setValue("currentApiConfigName", "current-config")
3503+
vi.mocked(mockContext.globalState.update).mockClear()
35013504
const messageHandler = (mockWebviewView.webview.onDidReceiveMessage as any).mock.calls[0][0]
35023505

35033506
// Mock buildApiHandler to throw an error
@@ -3554,7 +3557,7 @@ describe("ClineProvider", () => {
35543557
.mocked(mockContext.globalState.update)
35553558
.mock.calls.filter(([key]) => key === "currentApiConfigName")
35563559
expect(nameWrites.at(0)?.[1]).toBe("test-config")
3557-
expect(nameWrites.at(-1)?.[1]).not.toBe("test-config")
3560+
expect(nameWrites.at(-1)?.[1]).toBe("current-config")
35583561
})
35593562

35603563
test("handles successful saveApiConfiguration", async () => {

0 commit comments

Comments
 (0)