Skip to content

Commit 4bf26f1

Browse files
test(webview): prove the shared-profile rollback from cold state, where there is nothing to restore
CodeRabbit's review of head 0a0e043 (review 5855663461, submitted 2026-11-11T08:07:51Z) posted one actionable row, 4535433710 at src/core/webview/__tests__/ClineProvider.persistedViewState.spec.ts:445, asking for a cold-state case: stored profile unset, first per-view write fails, assert setValues rejects, the shared profile stays unset, and no per-view entry is created. The test already at that line seeds a stored profile (currentApiConfigName is seeded to "test-config" in beforeEach) and asserts the rollback returns to it, so it proves the restore but not the shape where the previous value does not exist. That is this repository's own rule - include the unset case when a default could hide the omission - so it is fixed here rather than argued. The key is unset through provider.contextProxy.setValue rather than by poking the storage double, so the proxy cache and storage agree the key is unset before the call starts, and the unset state is asserted before the failing call instead of assumed. Three outcomes are then asserted: rejection, the shared key still unset, and no entry under this view's id in the durable map, with the tombstone set still empty because nothing was ever cleared from storage. It passes against the shipped code, so no production change is claimed: the rollback path restores an undefined previous value instead of leaving the shared store ahead of the durable record. What this commit does not cover is still the neighbouring case named in the previous commit message - a shared value written by someone else after this view took its snapshot. Legs: focused run pnpm --dir src exec vitest run --config vitest.core.config.ts core/webview/__tests__/ClineProvider.persistedViewState.spec.ts -> 14 passed (14). eslint --prune-suppressions --max-warnings=0 on this file exits 0 and adds no entry to src/eslint-suppressions.json. tsc --noEmit for src exits 0. prettier --check . from the repository root is clean and --write on this file reported it unchanged: CI's compile leg runs pnpm format:check, so a root-directory prettier check is a pre-push leg for a commit that touches a file, which this one is. The core lane was not re-run for a single added test on top of the 199-file run recorded at 0a0e043; this commit touches only this spec. Still 6 of 500 for packages/types and 491 of 500 for src with 0 advisories above merge base 53cb5b5, re-measured rather than assumed: packageForPath excludes *.spec.ts, so a test file costs nothing against the cap, and ClineProvider.ts is untouched here.
1 parent 0a0e043 commit 4bf26f1

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,4 +453,25 @@ describe("ClineProvider - persisted view state write ordering", () => {
453453
expect(provider.contextProxy.getValue("currentApiConfigName")).toBe("profile-a")
454454
expect(viewStates()?.[viewStateId]?.currentApiConfigName).toBe("profile-a")
455455
})
456+
457+
test("leaves the shared profile unset and creates no entry when the first per-view write fails", async () => {
458+
const viewStateId = provider["viewId"]
459+
460+
// Cold state: this profile was never chosen, so there is no earlier value to roll back to.
461+
// Unset through the same store the provider reads, so the proxy cache and storage agree
462+
// that the key is unset before the call starts instead of merely disagreeing about it.
463+
await provider.contextProxy.setValue("currentApiConfigName", undefined)
464+
expect(provider.contextProxy.getValue("currentApiConfigName")).toBeUndefined()
465+
466+
failNextViewStatesWrite = true
467+
468+
await expect(provider.setValues({ currentApiConfigName: "profile-a" })).rejects.toThrow("durable write failed")
469+
470+
// A rollback here has no earlier name to restore: the only correct outcomes are that the
471+
// shared key stays unset, that no per-view entry was created for the write that failed,
472+
// and that the ledger stayed empty because nothing was ever cleared from storage.
473+
expect(provider.contextProxy.getValue("currentApiConfigName")).toBeUndefined()
474+
expect(Object.hasOwn(viewStates() ?? {}, viewStateId)).toBe(false)
475+
expect(tombstones().size).toBe(0)
476+
})
456477
})

0 commit comments

Comments
 (0)