Skip to content

Commit 3a0747d

Browse files
committed
test(core): cover fail-fast ordering when profile config purge rejects
What: add a negative spec to the deleteProviderProfile suite that makes the mocked providerSettingsManager.deleteConfig reject with the manager's not-found error and asserts the error propagates out of deleteProviderProfile while no ContextProxy write occurs (contextProxy.setValues never called, globalState.update call count unchanged). Why: the PR body claims the manager's not-found/last-config guards fail fast before any ContextProxy state is written, but no test pinned that ordering, so a future refactor that moved the purge after the ContextProxy write or swallowed the manager error would pass the whole suite. Verified the new spec fails under an ordering mutation (setValues before deleteConfig) and passes at head.
1 parent eb5e65b commit 3a0747d

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2996,6 +2996,26 @@ describe("ClineProvider", () => {
29962996
expect(provider.getProviderProfileEntries()).toEqual([otherProfile])
29972997
expect(mockContext.globalState.update).toHaveBeenCalledWith("currentApiConfigName", "other-config")
29982998
})
2999+
3000+
test("fails fast without writing ContextProxy state when the config purge rejects", async () => {
3001+
Object.assign(provider, {
3002+
providerSettingsManager: {
3003+
deleteConfig: vi.fn().mockRejectedValue(new Error("Config 'other-config' not found")),
3004+
listConfig: vi.fn().mockResolvedValue([currentProfile, otherProfile]),
3005+
},
3006+
})
3007+
3008+
const setValuesSpy = vi.spyOn(provider.contextProxy, "setValues")
3009+
const updateCallsBefore = vi.mocked(mockContext.globalState.update).mock.calls.length
3010+
3011+
await expect(provider.deleteProviderProfile(otherProfile)).rejects.toThrow(
3012+
"Config 'other-config' not found",
3013+
)
3014+
3015+
expect(provider.providerSettingsManager.deleteConfig).toHaveBeenCalledWith("other-config")
3016+
expect(setValuesSpy).not.toHaveBeenCalled()
3017+
expect(vi.mocked(mockContext.globalState.update).mock.calls.length).toBe(updateCallsBefore)
3018+
})
29993019
})
30003020
})
30013021

0 commit comments

Comments
 (0)