Skip to content

Commit 0df7399

Browse files
committed
fix(webview): leave the surviving pin untouched in deleteProviderProfile
The F1a buffer routing and the new delete-time activation branch interacted in two ways: the unrelated-pin branch re-wrote currentApiConfigName through setValue although the view-local buffer already holds the surviving pin (drop the write: it only triggered a viewStates prune pass and could clobber the pin with the shared slot value), and deleting the current profile now activates the fallback, which reads its settings via providerSettingsManager, so the spec test uses a test double like its siblings in the describe.
1 parent d337499 commit 0df7399

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

‎src/core/webview/ClineProvider.ts‎

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,7 +2431,10 @@ export class ClineProvider
24312431
}
24322432

24332433
// This view pins an unrelated profile, which must survive the deletion: sync the
2434-
// shared profile list and post the updated state only.
2434+
// shared profile list and post the updated state only. The buffer already holds
2435+
// the surviving pin, so the current-profile slot is left untouched here: a
2436+
// setValue would only trigger a viewStates prune write and could clobber the pin
2437+
// with the shared slot's value.
24352438
const entries = this.getProviderProfileEntries().filter(({ name }) => name !== profileToDelete.name)
24362439

24372440
// Write only the profile list back: replaying the full settings snapshot
@@ -2440,9 +2443,9 @@ export class ClineProvider
24402443
// with this view's stale cached copy.
24412444
await this.contextProxy.setValue("listApiConfigMeta", entries)
24422445

2443-
// Resolve the surviving profile's settings so this view and any other
2444-
// live view still pinned to the deleted profile can be re-pinned with
2445-
// a matching configuration.
2446+
// Resolve the surviving profile's settings so the shared provider keys
2447+
// and any other live view still pinned to the deleted profile can be
2448+
// updated with a matching configuration.
24462449
let survivingSettings: ProviderSettings | undefined
24472450
try {
24482451
const { name: _survivingName, ...settings } = await this.providerSettingsManager.getProfile({
@@ -2457,14 +2460,12 @@ export class ClineProvider
24572460
)
24582461
}
24592462

2460-
await this.setValue("currentApiConfigName", profileToActivate)
2461-
24622463
if (profileToDelete.name === globalSettings.currentApiConfigName && survivingSettings) {
2463-
// The deleted profile was the active one, so the shared provider keys
2464-
// and this view's buffer still carry its settings; replace both so
2465-
// getState() reports the surviving profile's configuration.
2464+
// The deleted profile was the shared current, so the shared provider
2465+
// keys still carry its settings; replace the shared slot so views
2466+
// that follow the shared current report the surviving profile's
2467+
// configuration. This view's buffer keeps its surviving pin.
24662468
await this.contextProxy.setProviderSettings(survivingSettings)
2467-
await this._saveViewLocalStateFromMutation(survivingSettings)
24682469
}
24692470

24702471
// Re-pin other live views still buffered on the deleted profile: their

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,6 +1888,14 @@ describe("ClineProvider", () => {
18881888
}
18891889
await provider.contextProxy.setValue("listApiConfigMeta", [oldProfile, keeperProfile])
18901890
await provider.setValue("currentApiConfigName", "old-profile")
1891+
// @ts-ignore - Replace providerSettingsManager with a test double: deleting the
1892+
// current profile now activates the fallback, which reads its settings.
1893+
provider.providerSettingsManager = {
1894+
deleteConfig: vi.fn().mockResolvedValue(undefined),
1895+
activateProfile: vi.fn().mockResolvedValue(keeperProfile),
1896+
listConfig: vi.fn().mockResolvedValue([keeperProfile]),
1897+
setModeConfig: vi.fn(),
1898+
}
18911899
vi.spyOn(provider, "postStateToWebview").mockResolvedValue(undefined)
18921900

18931901
await provider.deleteProviderProfile(oldProfile)

0 commit comments

Comments
 (0)