Skip to content

Commit 9347e16

Browse files
docs(webview): name what the deleted-profile check covers
deleteProviderProfile keys its activation branch on viewPinsDeletedProfile, whose first leg is "no pin of its own". A view with no pin does not resolve to the deleted profile: it follows the shared selection. Measured both deletions on this head with the view unpinned - - shared selection on a survivor, delete an unrelated profile: activation ran for the survivor, the view ended pinned to it, shared selection and served provider unchanged. - shared selection on the deleted profile, delete it: activation ran for the replacement, same observable outcome. - with the condition narrowed to the name the view actually resolves to, the first run stops activating (pin unset, no activation call, same served provider) and the second is unchanged, and three cases in ClineProvider.parallelMode.spec.ts go red: the leg is specified behaviour, including the manager-gate hand-off that only the activation path performs. So the leg is narrower than it reads rather than wrong. Rename the local to viewFollowsDeletedProfile, record the measurement beside it, and add the paired coverage the row was missing: the unrelated deletion and the shared-selection deletion for an unpinned view, asserted apart. No behaviour change - ClineProvider.spec 480 passed, ClineProvider.parallelMode.spec 55 passed, tsc, eslint and prettier clean. Review thread 8-G- of Zoo-Code-Org#1565.
1 parent 3ec9a48 commit 9347e16

2 files changed

Lines changed: 151 additions & 2 deletions

File tree

‎src/core/webview/ClineProvider.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3670,11 +3670,21 @@ export class ClineProvider
36703670
// do not rehydrate a missing profile name after a reload.
36713671
await this.repointPersistedViewStates(profileToDelete.name, profileToActivate)
36723672

3673-
const viewPinsDeletedProfile =
3673+
// Whether this deletion has to re-anchor this view onto the replacement. The second leg
3674+
// is a view whose own pin names the deleted profile. The first leg is narrower than it
3675+
// reads: a view with no pin of its own does not resolve to the deleted profile, it
3676+
// follows the shared selection, and the deletion hands that selection to it through
3677+
// activation regardless of which profile was removed - the same hand-off the manager
3678+
// gate and the current task handler depend on. Measured both deletions: with the shared
3679+
// selection pointing at a survivor, deleting an unrelated profile still activates the
3680+
// selection for this view and leaves it pinned to it; deleting the profile the selection
3681+
// names activates the replacement. Either way what the view serves afterwards is the
3682+
// profile the shared store holds.
3683+
const viewFollowsDeletedProfile =
36743684
this.viewLocalState.currentApiConfigName === undefined ||
36753685
this.viewLocalState.currentApiConfigName === profileToDelete.name
36763686

3677-
if (viewPinsDeletedProfile) {
3687+
if (viewFollowsDeletedProfile) {
36783688
// Apply the replacement through the activation path so this view's
36793689
// viewLocalState.apiConfiguration and the current task's api handler are
36803690
// refreshed; a name-only update would leave the deleted profile's settings

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

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6759,6 +6759,145 @@ describe("ClineProvider", () => {
67596759
})
67606760
})
67616761

6762+
// The two deletions an unpinned view can meet, measured separately rather than averaged.
6763+
// This one removes a profile the shared selection does not name, so nothing this view
6764+
// resolves through disappears; the deletion still hands the view the selection through
6765+
// activation, and the durable record gains a pin the view never authored.
6766+
it("anchors a view with no pin of its own on the shared selection when an unrelated profile is deleted", async () => {
6767+
const provider = new ClineProvider(
6768+
mockContext,
6769+
mockOutputChannel,
6770+
"sidebar",
6771+
new ContextProxy(mockContext),
6772+
new WebviewFocusTracker(),
6773+
)
6774+
const oldProfile: ProviderSettingsEntry = {
6775+
name: "old-profile",
6776+
id: "old-id",
6777+
apiProvider: providerIdentifiers.openrouter,
6778+
}
6779+
const keeperProfile: ProviderSettingsEntry = {
6780+
name: "keeper-profile",
6781+
id: "keeper-id",
6782+
apiProvider: providerIdentifiers.anthropic,
6783+
}
6784+
await provider.contextProxy.setValue("listApiConfigMeta", [oldProfile, keeperProfile])
6785+
await provider.contextProxy.setValue("currentApiConfigName", "keeper-profile")
6786+
await provider.contextProxy.setProviderSettings({
6787+
apiProvider: providerIdentifiers.anthropic,
6788+
apiKey: "keeper-shared",
6789+
})
6790+
vi.spyOn(provider, "postStateToWebview").mockResolvedValue(undefined)
6791+
const keeperSettings = {
6792+
name: "keeper-profile",
6793+
id: "keeper-id",
6794+
apiProvider: providerIdentifiers.anthropic,
6795+
}
6796+
const activateProfile = vi.fn().mockResolvedValue(keeperSettings)
6797+
// @ts-ignore - Replace the manager with a structural double for this deletion.
6798+
provider.providerSettingsManager = {
6799+
runExclusiveAcrossInstances: runManagerSectionInline,
6800+
activateProfile,
6801+
listConfig: vi.fn().mockResolvedValue([keeperProfile]),
6802+
setModeConfig: vi.fn(),
6803+
deleteConfig: vi.fn().mockResolvedValue(undefined),
6804+
getProfile: vi
6805+
.fn()
6806+
.mockImplementation(async ({ name }: { name: string }) =>
6807+
name === "keeper-profile"
6808+
? keeperSettings
6809+
: { name: "old-profile", id: "old-id", apiProvider: providerIdentifiers.openrouter },
6810+
),
6811+
hasConfig: vi.fn().mockResolvedValue(false),
6812+
getSelectionAndModeConfigs: vi.fn().mockResolvedValue({
6813+
currentApiConfigName: "keeper-profile",
6814+
modeApiConfigs: {},
6815+
}),
6816+
}
6817+
6818+
await provider.deleteProviderProfile(oldProfile)
6819+
6820+
const served = await provider.getState({ includeTaskHistory: false })
6821+
6822+
// Measured on the current head: the deletion still takes the activation path here, so the
6823+
// view comes back anchored to the selection it was following. What it serves is unchanged -
6824+
// the shared store already held that profile's settings - but the pin is new. The case
6825+
// below isolates the deletion the activation path is actually for.
6826+
expect(activateProfile).toHaveBeenCalledWith({ name: "keeper-profile" })
6827+
expect(provider.pinnedProfileName).toBe("keeper-profile")
6828+
expect(provider.contextProxy.getValue("currentApiConfigName")).toBe("keeper-profile")
6829+
expect(served.apiConfiguration.apiProvider).toBe(providerIdentifiers.anthropic)
6830+
expect(served.currentApiConfigName).toBe("keeper-profile")
6831+
await provider.dispose()
6832+
})
6833+
6834+
// The matching leg for the same unpinned view: when the deleted profile is the shared
6835+
// selection this view resolves through, the replacement must be activated for it - the
6836+
// shared store still carries the deleted profile's settings until this path replaces
6837+
// them. Measured identical before and after the tightened condition below.
6838+
it("activates the replacement for a view with no pin when the deleted profile is the shared selection", async () => {
6839+
const provider = new ClineProvider(
6840+
mockContext,
6841+
mockOutputChannel,
6842+
"sidebar",
6843+
new ContextProxy(mockContext),
6844+
new WebviewFocusTracker(),
6845+
)
6846+
const oldProfile: ProviderSettingsEntry = {
6847+
name: "old-profile",
6848+
id: "old-id",
6849+
apiProvider: providerIdentifiers.openrouter,
6850+
}
6851+
const keeperProfile: ProviderSettingsEntry = {
6852+
name: "keeper-profile",
6853+
id: "keeper-id",
6854+
apiProvider: providerIdentifiers.anthropic,
6855+
}
6856+
await provider.contextProxy.setValue("listApiConfigMeta", [oldProfile, keeperProfile])
6857+
await provider.contextProxy.setValue("currentApiConfigName", "old-profile")
6858+
await provider.contextProxy.setProviderSettings({
6859+
apiProvider: providerIdentifiers.openrouter,
6860+
apiKey: "old-shared",
6861+
})
6862+
vi.spyOn(provider, "postStateToWebview").mockResolvedValue(undefined)
6863+
const keeperSettings = {
6864+
name: "keeper-profile",
6865+
id: "keeper-id",
6866+
apiProvider: providerIdentifiers.anthropic,
6867+
}
6868+
const activateProfile = vi.fn().mockResolvedValue(keeperSettings)
6869+
// @ts-ignore - Replace the manager with a structural double for this deletion.
6870+
provider.providerSettingsManager = {
6871+
runExclusiveAcrossInstances: runManagerSectionInline,
6872+
activateProfile,
6873+
listConfig: vi.fn().mockResolvedValue([keeperProfile]),
6874+
setModeConfig: vi.fn(),
6875+
deleteConfig: vi.fn().mockResolvedValue(undefined),
6876+
getProfile: vi
6877+
.fn()
6878+
.mockImplementation(async ({ name }: { name: string }) =>
6879+
name === "keeper-profile"
6880+
? keeperSettings
6881+
: { name: "old-profile", id: "old-id", apiProvider: providerIdentifiers.openrouter },
6882+
),
6883+
hasConfig: vi.fn().mockResolvedValue(false),
6884+
getSelectionAndModeConfigs: vi.fn().mockResolvedValue({
6885+
currentApiConfigName: "keeper-profile",
6886+
modeApiConfigs: {},
6887+
}),
6888+
}
6889+
6890+
await provider.deleteProviderProfile(oldProfile)
6891+
6892+
const served = await provider.getState({ includeTaskHistory: false })
6893+
6894+
expect(activateProfile).toHaveBeenCalledWith({ name: "keeper-profile" })
6895+
expect(provider.pinnedProfileName).toBe("keeper-profile")
6896+
expect(provider.contextProxy.getValue("currentApiConfigName")).toBe("keeper-profile")
6897+
expect(served.apiConfiguration.apiProvider).toBe(providerIdentifiers.anthropic)
6898+
await provider.dispose()
6899+
})
6900+
67626901
describe("local state isolation", () => {
67636902
it("should isolate mode state between instances", async () => {
67646903
const provider1 = new ClineProvider(

0 commit comments

Comments
 (0)