Skip to content

Commit bb3a988

Browse files
committed
test: strengthen view-state storage assertions and rename the state-payload test
Series-wide test hygiene (same round as the sibling units): the pruning test compares the full kept entries instead of toBeDefined(); the two re-key storage tests seed viewStates through the durable write path so their assertions can actually fail; the webview state-payload test is renamed to describe what it asserts (a later payload overwriting locally edited values).
1 parent 78c21d1 commit bb3a988

3 files changed

Lines changed: 11 additions & 11 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,8 +2071,8 @@ describe("ClineProvider", () => {
20712071
const pruned = provider["prunePersistedViewStates"](states)
20722072

20732073
expect(Object.keys(pruned)).toHaveLength(50)
2074-
expect(pruned["view-54"]).toBeDefined()
2075-
expect(pruned["view-5"]).toBeDefined()
2074+
expect(pruned["view-54"]).toEqual({ mode: "mode-54", updatedAt: 54 })
2075+
expect(pruned["view-5"]).toEqual({ mode: "mode-5", updatedAt: 5 })
20762076
expect(pruned["view-4"]).toBeUndefined()
20772077

20782078
await provider.dispose()

‎src/core/webview/__tests__/ClineProvider.sticky-mode.spec.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,10 +1693,10 @@ describe("ClineProvider - Sticky Mode", () => {
16931693
it("does not resolve a view id that names an Object.prototype key through the chain", async () => {
16941694
await provider.resolveWebviewView(mockWebviewView)
16951695

1696-
mockContext.globalState.get = vi.fn().mockImplementation((key: string) => {
1697-
if (key === "viewStates") return { "stable-test-view": { mode: "architect" } }
1698-
return undefined
1699-
})
1696+
// Seed through the durable write path so later writes land in the same
1697+
// backing map the assertions read: a frozen get() literal would make every
1698+
// post-write assertion read the seed no matter what the provider wrote.
1699+
await provider.contextProxy.setValue("viewStates", { "stable-test-view": { mode: "architect" } })
17001700

17011701
const states = provider["getPersistedViewStates"]({ fresh: true })
17021702
expect(Object.getPrototypeOf(states)).toBeNull()
@@ -1811,10 +1811,10 @@ describe("ClineProvider - Sticky Mode", () => {
18111811
// Temporary ids restart from 0 on every host start, so the same name can
18121812
// belong to a different session. An entry this instance never wrote must not
18131813
// be adopted as this view's state.
1814-
mockContext.globalState.get = vi.fn().mockImplementation((key: string) => {
1815-
if (key === "viewStates") return { [provider.viewId]: { mode: "architect" } }
1816-
return undefined
1817-
})
1814+
// Seed through the durable write path so the assertions below read the
1815+
// same backing map a re-key adoption would write to: a frozen get()
1816+
// literal made the negative assertion unable to fail.
1817+
await provider.contextProxy.setValue("viewStates", { [provider.viewId]: { mode: "architect" } })
18181818

18191819
await provider["setViewStateId"]("stable-test-view")
18201820

‎webview-ui/src/context/__tests__/ExtensionStateContext.spec.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ describe("ExtensionStateContext", () => {
179179
}
180180
})
181181

182-
it("reseeds view-local mode and API profile from a new state payload after local edits", () => {
182+
it("applies mode and profile from a later state payload after local edits", () => {
183183
render(
184184
<ExtensionStateContextProvider>
185185
<ViewLocalStateTestComponent />

0 commit comments

Comments
 (0)