Skip to content

Commit 1b04a75

Browse files
test(webview): pin that the rename target read follows the save, not just the other lookup
The rename case asserted which name each getProfile call used, which is not the same as asserting when the target read happened. A read that ran before saveConfig would still be the second call with the second name, while the real manager rejects a lookup of a profile that has not been written yet. Control on pinned node v22.23.4 (.tmp-node22): moving the target read above the save in webviewMessageHandler.ts (line-level swap of :2632 and :2644, blob 80e1da20ec8d) fails the new line with "expected 739 to be greater than 740" at the toBeGreaterThan; the same mutant also breaks eight sibling rename cases because the swap changes which call's result is used, so it is a coarse mutant, not a minimal one - the ordering line is the one that names the defect. With the handler blob restored to df7f0c0 (verified by git hash-object) the file is 180/180. Gates: focused spec 180/180, vitest.core.config.ts 4482 passed and vitest.misc.config.ts 2113 passed on pinned v22.23.4; tsc --noEmit and knip --treat-config-hints-as-errors clean on box node v25.9.0; eslint --max-warnings=0 clean with .eslintcache deleted after the last prettier write; prettier --check clean before and after --write; src/eslint-suppressions.json left at the parent blob 57dbc2b. The handler is unchanged (blob df7f0c0 before and after), so this is test-only and does not move any behaviour. Co-Authored-By: Claude <[email protected]>
1 parent 21741e5 commit 1b04a75

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3206,12 +3206,13 @@ describe("webviewMessageHandler - renameApiConfiguration", () => {
32063206
// an existing source, and the guard aimed at the target.
32073207
const hasConfig = vi.fn(async (name: string) => name === "old-profile")
32083208
const getProfile = vi.fn().mockResolvedValue({ id: "profile-id", apiProvider: providerIdentifiers.anthropic })
3209+
const saveConfig = vi.fn().mockResolvedValue(undefined)
32093210
const repoint = vi.fn().mockResolvedValue(undefined)
32103211
provider.providerSettingsManager = {
32113212
runExclusiveAcrossInstances,
32123213
hasConfig,
32133214
getProfile,
3214-
saveConfig: vi.fn().mockResolvedValue(undefined),
3215+
saveConfig,
32153216
deleteConfig: vi.fn().mockResolvedValue(undefined),
32163217
}
32173218
provider.repointViewLocalStateAfterProfileRename = repoint
@@ -3233,6 +3234,14 @@ describe("webviewMessageHandler - renameApiConfiguration", () => {
32333234
// lines existed (measured by mutating the source lookup in the handler).
32343235
expect(getProfile).toHaveBeenNthCalledWith(1, { name: "old-profile" })
32353236
expect(getProfile).toHaveBeenNthCalledWith(2, { name: "new-profile" })
3237+
// Order by name is not order in time: a target read that happened before the save
3238+
// would still be the second call with the second name, and the real manager rejects
3239+
// a lookup of a profile that has not been written yet. Pin the position against the
3240+
// save itself, not only against the other lookup.
3241+
expect(getProfile).toHaveBeenCalledTimes(2)
3242+
const saveAt = vi.mocked(provider.providerSettingsManager.saveConfig).mock.invocationCallOrder[0]
3243+
const targetReadAt = getProfile.mock.invocationCallOrder[1]
3244+
expect(targetReadAt).toBeGreaterThan(saveAt)
32363245
expect(provider.providerSettingsManager.saveConfig).toHaveBeenCalledWith("new-profile", {
32373246
apiProvider: providerIdentifiers.anthropic,
32383247
id: "profile-id",

0 commit comments

Comments
 (0)