Skip to content

Commit a0405d2

Browse files
committed
fix(provider): sync view-local state when activating provider profile
1 parent 0d2321a commit a0405d2

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

src/core/webview/ClineProvider.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,6 +1825,8 @@ export class ClineProvider
18251825
this.updateGlobalState("currentApiConfigName", name),
18261826
this.providerSettingsManager.setModeConfig(mode, id),
18271827
this.contextProxy.setProviderSettings(providerSettings),
1828+
this.saveViewState("currentApiConfigName", name),
1829+
this.saveViewState("apiConfiguration", providerSettings),
18281830
])
18291831

18301832
this._updateViewLocalStateFromMutation({
@@ -1927,6 +1929,8 @@ export class ClineProvider
19271929
this.contextProxy.setValue("listApiConfigMeta", listApiConfigMeta),
19281930
this.contextProxy.setValue("currentApiConfigName", name),
19291931
this.contextProxy.setProviderSettings(providerSettings),
1932+
this.saveViewState("currentApiConfigName", name),
1933+
this.saveViewState("apiConfiguration", providerSettings),
19301934
])
19311935

19321936
this._updateViewLocalStateFromMutation({

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,37 @@ describe("ClineProvider - Parallel Mode Support", () => {
11951195
})
11961196
})
11971197

1198+
describe("provider profile activation", () => {
1199+
it("should sync view-local apiConfiguration when activating an upserted profile", async () => {
1200+
const provider = new ClineProvider(mockContext, mockOutputChannel, "sidebar", new ContextProxy(mockContext))
1201+
await (provider as any).saveViewState("apiConfiguration", {
1202+
apiProvider: "openrouter",
1203+
openRouterModelId: "openai/gpt-4.1",
1204+
})
1205+
1206+
const providerSettings = {
1207+
apiProvider: "zai" as const,
1208+
zaiApiKey: "mock-key",
1209+
zaiApiLine: "international_api" as const,
1210+
apiModelId: "glm-5.1",
1211+
}
1212+
vi.spyOn(provider.providerSettingsManager, "saveConfig").mockResolvedValue("zai-profile-id")
1213+
vi.spyOn(provider.providerSettingsManager, "listConfig").mockResolvedValue([
1214+
{ name: "default", id: "zai-profile-id", apiProvider: "zai" },
1215+
])
1216+
1217+
await provider.upsertProviderProfile("default", providerSettings, true)
1218+
1219+
const state = await provider.getState()
1220+
expect(state.currentApiConfigName).toBe("default")
1221+
expect(state.apiConfiguration).toMatchObject(providerSettings)
1222+
expect(state.apiConfiguration.apiProvider).toBe("zai")
1223+
expect((provider as any).viewLocalState.apiConfiguration).toMatchObject(providerSettings)
1224+
1225+
await provider.dispose()
1226+
})
1227+
})
1228+
11981229
describe("handleModeSwitch integration", () => {
11991230
it("should update viewLocalState.mode when handleModeSwitch is called", async () => {
12001231
const postMessage = vi.fn()

0 commit comments

Comments
 (0)