Skip to content

Commit 21cc345

Browse files
test(webview): prove the rollback reaches storage and never publishes to the view-local buffer
CodeRabbit's review of head 4bf26f1 (run 130412734156, finished 2026-11-11T08:38:27Z, unprompted: no trigger comment of mine preceded it) posted two actionable rows on the test added by that commit. Row 4535691396, Major, Maintainability & Code Quality, source: path instructions, asked for the shared durable value to be asserted and not only the proxy cache. Row 4535691402, same severity and source, asked for the view-local buffer to be asserted as well. Both are right for this repository: the persisted-setting checklist requires the persistence leg to be tested, and this unit's contract is that the per-view record is persisted before the local buffer is advanced. Neither needed a production change: the assertions pass against the shipped code, which is what makes them worth pinning. Why the durable assertion is not a restatement of the cache assertion: ContextProxy.updateGlobalState sets the cache and then awaits globalState.update, and ClineProvider.setValues awaits that shared write before the per-view write, so storage really did hold "profile-a" when the per-view write rejected. Rather than infer that, the storage double now records the durable profile value at the instant it rejects and the test asserts it was "profile-a", so the rollback below is a rollback of a value that moved and not a no-op over a key that never left the cache. The assertion after the rejection then proves the restore reached storage through contextProxy.setValues, which is the only path that would leave a stale profile behind after a reload. The buffer assertion pins the ordering rather than fixing a live defect: _saveViewLocalStateFromMutation awaits _persistViewLocalStateFromMutation before _updateViewLocalStateFromMutation, so a failed durable write cannot leave viewLocalState holding the profile, and the test now fails if anyone moves that await. It asserts hasOwn rather than the value because the shipped invalidation deletes the key, so a buffer left holding an explicit undefined would also be a divergence. Legs: 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 this file has no entry in src/eslint-suppressions.json before or after the run; the command rewrites that file in place on every run and it was checked out from HEAD again, which also keeps the repository-root format check green (the rewritten JSON is not prettier-clean). tsc --noEmit for src exits 0. prettier --write on this file from the repository directory reports it unchanged and prettier --check . exits 0. Still 6 of 500 for packages/types and 491 of 500 for src with 0 advisories above merge base 53cb5b5, re-measured in worktree mode before this commit and in committed mode after it: packageForPath excludes *.spec.ts, so a test file costs nothing against the cap, and ClineProvider.ts is untouched here.
1 parent 4bf26f1 commit 21cc345

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ describe("ClineProvider - persisted view state write ordering", () => {
141141
let durable: Record<string, unknown>
142142
let failNextViewStatesWrite = false
143143
let mockContext: vscode.ExtensionContext
144+
// The durable profile value the storage double held at the instant the per-view write
145+
// rejected, so a test can tell a shared write that reached storage from one that only
146+
// moved the in-memory cache.
147+
let durableProfileAtViewWriteFailure: unknown
144148
let mockOutputChannel: vscode.OutputChannel
145149

146150
// The tombstone set and the write queue are per-class, so every test starts from an
@@ -155,6 +159,7 @@ describe("ClineProvider - persisted view state write ordering", () => {
155159
beforeEach(() => {
156160
vi.clearAllMocks()
157161
failNextViewStatesWrite = false
162+
durableProfileAtViewWriteFailure = undefined
158163

159164
if (!TelemetryService.hasInstance()) {
160165
TelemetryService.createInstance([])
@@ -171,6 +176,7 @@ describe("ClineProvider - persisted view state write ordering", () => {
171176
const update = vi.fn((key: string, value: unknown) => {
172177
if (key === "viewStates" && failNextViewStatesWrite) {
173178
failNextViewStatesWrite = false
179+
durableProfileAtViewWriteFailure = globalState["currentApiConfigName"]
174180
return Promise.reject(new Error("durable write failed"))
175181
}
176182
globalState[key] = value
@@ -467,11 +473,20 @@ describe("ClineProvider - persisted view state write ordering", () => {
467473

468474
await expect(provider.setValues({ currentApiConfigName: "profile-a" })).rejects.toThrow("durable write failed")
469475

476+
// The shared write landed before the per-view write was attempted: the double held
477+
// "profile-a" in storage at the instant of the failure, so what follows is a rollback of
478+
// a value that really moved, not a no-op over a key that never left the cache.
479+
expect(durableProfileAtViewWriteFailure).toBe("profile-a")
480+
470481
// 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.
482+
// shared key stays unset in storage and not only in the cache this call reads back, that
483+
// no per-view entry was created for the write that failed, that the view-local buffer
484+
// never took the profile because it is advanced only after the durable write lands, and
485+
// that the ledger stayed empty because nothing was ever cleared from storage.
473486
expect(provider.contextProxy.getValue("currentApiConfigName")).toBeUndefined()
487+
expect(durable["currentApiConfigName"]).toBeUndefined()
474488
expect(Object.hasOwn(viewStates() ?? {}, viewStateId)).toBe(false)
489+
expect(Object.hasOwn(provider["viewLocalState"], "currentApiConfigName")).toBe(false)
475490
expect(tombstones().size).toBe(0)
476491
})
477492
})

0 commit comments

Comments
 (0)