Skip to content

Commit 3b0ed89

Browse files
test(webview): pin the name the rename guard asks about, and the steps a rejected rename skips
The collision case stubbed hasConfig to answer true for every name, so a guard aimed at oldName satisfied it, and nothing in it said whether a rejected rename still moved user-visible state. The case now asserts the argument the existence check was called with, and that neither the view re-point nor the profile activation ran. Measured by mutating the handler rather than by asserting intent: pointing the guard at oldName leaves every pre-existing assertion in the case green and fails only the new argument assertion (expected "vi.fn()" to be called with arguments: [ 'foo' ], received [ 'Foo' ]); re-pointing live views before the rejection fails only the new re-point assertion. Both mutants were reverted and the handler blob verifies back to df7f0c0. Test-only change: no behaviour in the handler or the provider moved. webviewMessageHandler spec: 179 passed (179). Counts from git diff --cached --numstat in this same run: 15 added, 3 deleted in 1 file (core/webview/__tests__/webviewMessageHandler.spec.ts).
1 parent 628b913 commit 3b0ed89

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3162,15 +3162,18 @@ describe("webviewMessageHandler - renameApiConfiguration", () => {
31623162
})
31633163

31643164
it("rejects a rename onto an existing profile without saving", async () => {
3165+
const hasConfig = vi.fn().mockResolvedValue(true)
3166+
const repoint = vi.fn().mockResolvedValue(undefined)
3167+
const activate = vi.fn().mockResolvedValue(undefined)
31653168
provider.providerSettingsManager = {
31663169
runExclusiveAcrossInstances,
3167-
hasConfig: vi.fn().mockResolvedValue(true),
3170+
hasConfig,
31683171
getProfile: vi.fn().mockResolvedValue({ id: "profile-id" }),
31693172
saveConfig: vi.fn().mockResolvedValue(undefined),
31703173
deleteConfig: vi.fn().mockResolvedValue(undefined),
31713174
}
3172-
provider.repointViewLocalStateAfterProfileRename = vi.fn().mockResolvedValue(undefined)
3173-
provider.activateProviderProfile = vi.fn().mockResolvedValue(undefined)
3175+
provider.repointViewLocalStateAfterProfileRename = repoint
3176+
provider.activateProviderProfile = activate
31743177

31753178
await webviewMessageHandler(mockClineProvider, {
31763179
type: "renameApiConfiguration",
@@ -3182,8 +3185,17 @@ describe("webviewMessageHandler - renameApiConfiguration", () => {
31823185
// current profile as the current profile, so a case-only collision would
31833186
// otherwise overwrite the existing record - and the delete-failure rollback
31843187
// would then delete a profile the rename never owned.
3188+
// hasConfig answers true for every name here on purpose: an always-true
3189+
// manager cannot show *which* name the guard asked about, so the only thing
3190+
// that can catch a check aimed at oldName is the argument it was called with.
3191+
expect(hasConfig).toHaveBeenCalledWith("foo")
31853192
expect(provider.providerSettingsManager.saveConfig).not.toHaveBeenCalled()
31863193
expect(provider.providerSettingsManager.deleteConfig).not.toHaveBeenCalled()
3194+
// Rejecting the save is only half the contract. A rename that reports the
3195+
// collision but still re-points live views or activates the colliding profile
3196+
// has already moved user-visible state before the rejection is even shown.
3197+
expect(repoint).not.toHaveBeenCalled()
3198+
expect(activate).not.toHaveBeenCalled()
31873199
expect(mockClineProvider.log).toHaveBeenCalledWith(expect.stringContaining("Error rename api configuration"))
31883200
})
31893201

0 commit comments

Comments
 (0)