Skip to content

Commit 4d002c4

Browse files
committed
test(config,webview): cover storage failures and the sibling view's settings on profile deletion
Round 2 of the #1919 review (head c2206c5), tests only. - ProviderSettingsManager.spec: a storage read failure now has a named contract in both methods deleteProviderProfile() branches on. deleteConfig() and getProfile() rethrow a storage outage wrapped ("Failed to delete config: ...", "Failed to get profile: ...") instead of typing it as ProviderSettingsNotFoundError, so an outage cannot be mistaken for a missing profile and cannot prune a list entry whose record is still stored. - ClineProvider.sticky-profile.spec: the mid-deletion case gains the cross-view half it was missing. A second view, sharing the acting view's ContextProxy the way production builds the tab view (activate/registerCommands.ts:449), activates the survivor while the record delete is in flight; the deletion must follow that choice and leave the shared provider keys carrying that survivor's settings rather than its own entry-time pick. Both measure green against c2206c5: nothing is laundered and nothing is stale today, so this round adds coverage rather than changing behaviour. Each assertion was shown to redden under the regression it guards (typing the outage as not-found in either method, dropping the activation's settings write, or pushing the entry-time survivor's settings over the sibling's activation), each on its own.
1 parent c2206c5 commit 4d002c4

2 files changed

Lines changed: 121 additions & 0 deletions

File tree

‎src/core/config/__tests__/ProviderSettingsManager.spec.ts‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,6 +983,20 @@ describe("ProviderSettingsManager", () => {
983983
)
984984
})
985985

986+
it("should not surface a storage read failure as ProviderSettingsNotFoundError", async () => {
987+
// deleteProviderProfile() branches on the not-found type to prune a stale list entry as an
988+
// idempotent success, so a storage outage must stay distinguishable from a missing profile:
989+
// typed as not-found it would prune the entry while the stored record is still there.
990+
mockSecrets.get.mockRejectedValue(new Error("Storage failed"))
991+
992+
const error = await providerSettingsManager.deleteConfig("nonexistent").catch((caught: unknown) => caught)
993+
994+
expect(error).not.toBeInstanceOf(ProviderSettingsNotFoundError)
995+
expect(error).toMatchObject({ message: expect.stringContaining("Failed to delete config:") })
996+
// Nothing was rewritten: the outage refused before the profile list was touched.
997+
expect(mockSecrets.store).not.toHaveBeenCalled()
998+
})
999+
9861000
it("should throw error when trying to delete last remaining config", async () => {
9871001
mockSecrets.get.mockResolvedValue(
9881002
JSON.stringify({
@@ -1122,6 +1136,20 @@ describe("ProviderSettingsManager", () => {
11221136
})
11231137
})
11241138

1139+
it("should not surface a storage read failure as ProviderSettingsNotFoundError", async () => {
1140+
// getProfile() is the entry point deleteProviderProfile() and the mode mapping use to treat an
1141+
// already-deleted profile as an idempotent no-op, so an outage must not arrive as not-found:
1142+
// that would read as "the profile is gone" when the record could not be read at all.
1143+
mockSecrets.get.mockRejectedValue(new Error("Storage failed"))
1144+
1145+
const error = await providerSettingsManager
1146+
.getProfile({ name: "nonexistent" })
1147+
.catch((caught: unknown) => caught)
1148+
1149+
expect(error).not.toBeInstanceOf(ProviderSettingsNotFoundError)
1150+
expect(error).toMatchObject({ message: expect.stringContaining("Failed to get profile:") })
1151+
})
1152+
11251153
it("should throw error if secrets storage fails", async () => {
11261154
mockSecrets.get.mockResolvedValue(
11271155
JSON.stringify({

‎src/core/webview/__tests__/ClineProvider.sticky-profile.spec.ts‎

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,5 +1342,98 @@ describe("ClineProvider - Sticky Provider Profile", () => {
13421342
expect(values.currentApiConfigName).toBe("other-survivor")
13431343
expect(values.listApiConfigMeta?.map((entry) => entry.name)).toEqual(["default", "other-survivor"])
13441344
})
1345+
1346+
it("leaves a sibling view's shared settings on the survivor it activated mid-deletion", async () => {
1347+
const defaultId = await provider.providerSettingsManager.saveConfig("default", {
1348+
apiProvider: providerIdentifiers.openrouter,
1349+
openRouterApiKey: "mock-key",
1350+
openRouterModelId: "openai/gpt-4.1",
1351+
})
1352+
const otherId = await provider.providerSettingsManager.saveConfig("other-survivor", {
1353+
apiProvider: providerIdentifiers.openrouter,
1354+
openRouterApiKey: "mock-key",
1355+
openRouterModelId: "openai/gpt-4o",
1356+
})
1357+
const childId = await provider.providerSettingsManager.saveConfig("subtask-child-profile", {
1358+
apiProvider: providerIdentifiers.openrouter,
1359+
openRouterApiKey: "mock-key",
1360+
openRouterModelId: "openai/gpt-4.1-mini",
1361+
})
1362+
await provider.contextProxy.setValues({
1363+
listApiConfigMeta: [
1364+
{ name: "default", id: defaultId, apiProvider: providerIdentifiers.openrouter },
1365+
{ name: "other-survivor", id: otherId, apiProvider: providerIdentifiers.openrouter },
1366+
{ name: "subtask-child-profile", id: childId, apiProvider: providerIdentifiers.openrouter },
1367+
],
1368+
currentApiConfigName: "subtask-child-profile",
1369+
})
1370+
await provider.resolveWebviewView(mockWebviewView)
1371+
1372+
// The cross-view half of this deletion is only observable from another view: the deletion names
1373+
// the survivor in the shared store, but whether the survivor's settings actually land in a second
1374+
// view's provider keys is a property of that view. Production builds the tab view on the same
1375+
// ContextProxy as the sidebar view (activate/registerCommands.ts:449 passes the sidebar's
1376+
// contextProxy; ClineProvider.ts:3634 documents that the two views share it while their queues
1377+
// and settings-manager locks stay per instance), so the sibling here shares provider.contextProxy
1378+
// and keeps its own settings-manager, which is exactly the shape that lets it move the selection
1379+
// mid-deletion.
1380+
// resolved webview.
1381+
const siblingView = {
1382+
webview: {
1383+
postMessage: vi.fn(),
1384+
html: "",
1385+
options: {},
1386+
onDidReceiveMessage: vi.fn(),
1387+
asWebviewUri: vi.fn(),
1388+
cspSource: "vscode-webview://sibling-csp-source",
1389+
},
1390+
visible: true,
1391+
onDidDispose: vi.fn().mockImplementation(() => {
1392+
return { dispose: vi.fn() }
1393+
}),
1394+
onDidChangeVisibility: vi.fn().mockImplementation(() => {
1395+
return { dispose: vi.fn() }
1396+
}),
1397+
} as unknown as vscode.WebviewView
1398+
const sibling = new ClineProvider(
1399+
mockContext,
1400+
mockOutputChannel,
1401+
"sidebar",
1402+
provider.contextProxy,
1403+
new WebviewFocusTracker(),
1404+
)
1405+
await new Promise((resolve) => setTimeout(resolve, 10))
1406+
sibling.getMcpHub = vi.fn().mockReturnValue({
1407+
listTools: vi.fn().mockResolvedValue([]),
1408+
callTool: vi.fn().mockResolvedValue({ content: [] }),
1409+
listResources: vi.fn().mockResolvedValue([]),
1410+
readResource: vi.fn().mockResolvedValue({ contents: [] }),
1411+
getAllServers: vi.fn().mockReturnValue([]),
1412+
})
1413+
await sibling.resolveWebviewView(siblingView)
1414+
1415+
const manager = provider.providerSettingsManager
1416+
const deleteStoredConfig = manager.deleteConfig.bind(manager)
1417+
manager.deleteConfig = async (name: string) => {
1418+
// A sibling view moves the shared selection onto another survivor and activates it there while
1419+
// the record delete is in flight; the deletion must follow that choice instead of pushing its
1420+
// own entry-time pick back onto the sibling's provider keys.
1421+
await provider.contextProxy.setValue("currentApiConfigName", "other-survivor")
1422+
await sibling.activateProviderProfile({ name: "other-survivor" })
1423+
return deleteStoredConfig(name)
1424+
}
1425+
1426+
await provider.deleteProviderProfile({
1427+
name: "subtask-child-profile",
1428+
id: childId,
1429+
apiProvider: providerIdentifiers.openrouter,
1430+
})
1431+
1432+
expect(sibling.contextProxy.getValues().currentApiConfigName).toBe("other-survivor")
1433+
expect(sibling.contextProxy.getProviderSettings().openRouterModelId).toBe("openai/gpt-4o")
1434+
// The same shared store is what the acting view reads: if the deletion pushed its own entry-time
1435+
// survivor's settings over the sibling's activation, this is where it shows up.
1436+
expect(provider.contextProxy.getProviderSettings().openRouterModelId).toBe("openai/gpt-4o")
1437+
})
13451438
})
13461439
})

0 commit comments

Comments
 (0)