Skip to content

Commit e6afc8d

Browse files
committed
test(webview): pin viewStates pruning edge cases and dispose retention
1 parent 0a8ffc9 commit e6afc8d

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,48 @@ describe("ClineProvider", () => {
12251225

12261226
await provider.dispose()
12271227
})
1228+
1229+
it("should drop the entry without updatedAt first when the cap is exceeded", async () => {
1230+
const provider = new ClineProvider(mockContext, mockOutputChannel, "sidebar", new ContextProxy(mockContext))
1231+
// An entry written before updatedAt existed ranks below every timestamped entry
1232+
// (updatedAt ?? 0) and is the first to fall off the cap.
1233+
const states = {
1234+
...Object.fromEntries(
1235+
Array.from({ length: 50 }, (_, index) => [
1236+
`view-${index}`,
1237+
{ mode: `mode-${index}`, updatedAt: index + 1 },
1238+
]),
1239+
),
1240+
"view-missing": { mode: "mode-legacy" },
1241+
}
1242+
1243+
const pruned = provider["prunePersistedViewStates"](states)
1244+
1245+
expect(Object.keys(pruned)).toHaveLength(50)
1246+
expect(pruned["view-missing"]).toBeUndefined()
1247+
expect(pruned["view-0"]).toBeDefined()
1248+
expect(pruned["view-49"]).toBeDefined()
1249+
1250+
await provider.dispose()
1251+
})
1252+
1253+
it("should keep the earliest inserted entries when updatedAt values tie", async () => {
1254+
const provider = new ClineProvider(mockContext, mockOutputChannel, "sidebar", new ContextProxy(mockContext))
1255+
// Equal timestamps preserve insertion order (stable sort), so the first 50
1256+
// registered views survive and the last 5 fall off the cap.
1257+
const states = Object.fromEntries(
1258+
Array.from({ length: 55 }, (_, index) => [`view-${index}`, { mode: `mode-${index}`, updatedAt: 1 }]),
1259+
)
1260+
1261+
const pruned = provider["prunePersistedViewStates"](states)
1262+
1263+
expect(Object.keys(pruned)).toHaveLength(50)
1264+
expect(pruned["view-0"]).toBeDefined()
1265+
expect(pruned["view-49"]).toBeDefined()
1266+
expect(pruned["view-50"]).toBeUndefined()
1267+
1268+
await provider.dispose()
1269+
})
12281270
})
12291271

12301272
describe("setViewStateId", () => {
@@ -1336,6 +1378,20 @@ describe("ClineProvider", () => {
13361378
await provider.dispose()
13371379
})
13381380

1381+
it("should preserve the persisted viewStates entry when the provider is disposed", async () => {
1382+
// #1065: disposal is retention-only for durable per-view state — the entry must
1383+
// survive teardown so an editor tab reopens with its saved selections.
1384+
const provider = new ClineProvider(mockContext, mockOutputChannel, "editor", new ContextProxy(mockContext))
1385+
1386+
await provider["setViewStateId"]("tab-to-preserve")
1387+
await provider.saveViewState("mode", "architect")
1388+
expect(provider.contextProxy.getValue("viewStates")).toHaveProperty("tab-to-preserve")
1389+
1390+
await provider.dispose()
1391+
1392+
expect(provider.contextProxy.getValue("viewStates")).toHaveProperty("tab-to-preserve")
1393+
})
1394+
13391395
it("should prune by updatedAt regardless of insertion order", async () => {
13401396
const provider = new ClineProvider(mockContext, mockOutputChannel, "sidebar", new ContextProxy(mockContext))
13411397
const states = Object.fromEntries(

0 commit comments

Comments
 (0)