Skip to content

Commit d724948

Browse files
committed
fix(provider): sync view-local state when activating provider profile
1 parent 14f65ba commit d724948

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
@@ -1820,6 +1820,8 @@ export class ClineProvider
18201820
this.updateGlobalState("currentApiConfigName", name),
18211821
this.providerSettingsManager.setModeConfig(mode, id),
18221822
this.contextProxy.setProviderSettings(providerSettings),
1823+
this.saveViewState("currentApiConfigName", name),
1824+
this.saveViewState("apiConfiguration", providerSettings),
18231825
])
18241826

18251827
this._updateViewLocalStateFromMutation({
@@ -1922,6 +1924,8 @@ export class ClineProvider
19221924
this.contextProxy.setValue("listApiConfigMeta", listApiConfigMeta),
19231925
this.contextProxy.setValue("currentApiConfigName", name),
19241926
this.contextProxy.setProviderSettings(providerSettings),
1927+
this.saveViewState("currentApiConfigName", name),
1928+
this.saveViewState("apiConfiguration", providerSettings),
19251929
])
19261930

19271931
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)