Skip to content

Commit ca2dc28

Browse files
unit 3a: assert the detach loop's splice branch in dispose
The detach loop added to dispose() carries five mutants the digest at this head lists as Survived: four on the splice guard (ConditionalExpression on both arms, the EqualityOperator on the index test, and the UnaryOperator on the delete count) and one CallExpression that removes the splice itself. Two rows discriminate them: one where the entry has already left the shared queue, so the guard must not splice and a foreign entry sitting on the queue is still there afterwards, and one where the entry is still queued, so the splice runs, the entry is gone, and the entry behind it is untouched. Both rows assert that the scheduled entry's provider field is cleared, which is what releases the provider. The not-found shape is the one the queue step itself produces: it removes the entry from the shared list at its own turn before it asks whether the owner's generation is still live, so a write whose owner went stale stays on that provider's schedule while it is gone from the list. Verification: eslint on the file exits 0 with --max-warnings=0 and the file's suppression entry stays at 195 no-explicit-any; the focused spec runs 349 tests with 349 passing, up from 347.
1 parent 735dc22 commit ca2dc28

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

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

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2835,6 +2835,98 @@ describe("ClineProvider", () => {
28352835
void queued
28362836
})
28372837

2838+
test("leaves the shared queue untouched when dispose finds the entry already drained", async () => {
2839+
await provider.resolveWebviewView(mockWebviewPanel)
2840+
const drained: {
2841+
provider: ClineProvider | null
2842+
generation: number
2843+
run: (owner: ClineProvider) => Promise<void>
2844+
} = {
2845+
provider,
2846+
generation: provider["viewStateGeneration"],
2847+
run: async () => {},
2848+
}
2849+
const queuedDrained = ClineProvider["enqueuePersistedViewStateWrite"](drained)
2850+
// The queue step drops the entry from the shared list at its own turn before it asks
2851+
// whether the owner's generation is still live, so a write whose owner went stale
2852+
// stays on this provider's schedule while it is already gone from the shared list.
2853+
// That is the state below, built the way the queue step builds it.
2854+
const drainedIndex = ClineProvider["pendingViewStateWrites"].indexOf(drained)
2855+
ClineProvider["pendingViewStateWrites"].splice(drainedIndex, 1)
2856+
// A write belonging to somebody else, left on the shared queue so that a splice
2857+
// run without a match would remove it.
2858+
const neighbour: {
2859+
provider: ClineProvider | null
2860+
generation: number
2861+
run: (owner: ClineProvider) => Promise<void>
2862+
} = {
2863+
provider: null,
2864+
generation: 0,
2865+
run: async () => {},
2866+
}
2867+
ClineProvider["pendingViewStateWrites"].push(neighbour)
2868+
const sharedBefore = ClineProvider["pendingViewStateWrites"].slice()
2869+
2870+
await provider.dispose()
2871+
2872+
expect(ClineProvider["pendingViewStateWrites"]).toEqual(sharedBefore)
2873+
expect(ClineProvider["pendingViewStateWrites"]).toContain(neighbour)
2874+
expect(provider["scheduledViewStateWrites"]).toEqual([])
2875+
expect(drained.provider).toBeNull()
2876+
expect(ClineProvider["pendingViewStateWrites"]).toHaveLength(sharedBefore.length)
2877+
2878+
// The neighbour belongs to no provider, so this dispose leaves it on the shared
2879+
// queue; take it back out rather than hand it to the next test.
2880+
const neighbourIndex = ClineProvider["pendingViewStateWrites"].indexOf(neighbour)
2881+
if (neighbourIndex !== -1) {
2882+
ClineProvider["pendingViewStateWrites"].splice(neighbourIndex, 1)
2883+
}
2884+
2885+
void queuedDrained
2886+
})
2887+
2888+
test("splices the provider entry out of the shared queue without touching the entry behind it", async () => {
2889+
await provider.resolveWebviewView(mockWebviewPanel)
2890+
const entry: {
2891+
provider: ClineProvider | null
2892+
generation: number
2893+
run: (owner: ClineProvider) => Promise<void>
2894+
} = {
2895+
provider,
2896+
generation: provider["viewStateGeneration"],
2897+
run: async () => {},
2898+
}
2899+
const queued = ClineProvider["enqueuePersistedViewStateWrite"](entry)
2900+
// A write from another provider that is already waiting behind this one.
2901+
const behind: {
2902+
provider: ClineProvider | null
2903+
generation: number
2904+
run: (owner: ClineProvider) => Promise<void>
2905+
} = {
2906+
provider: null,
2907+
generation: 0,
2908+
run: async () => {},
2909+
}
2910+
ClineProvider["pendingViewStateWrites"].push(behind)
2911+
2912+
const entryIndex = ClineProvider["pendingViewStateWrites"].indexOf(entry)
2913+
expect(ClineProvider["pendingViewStateWrites"].indexOf(behind)).toBe(entryIndex + 1)
2914+
2915+
await provider.dispose()
2916+
2917+
expect(ClineProvider["pendingViewStateWrites"]).not.toContain(entry)
2918+
expect(ClineProvider["pendingViewStateWrites"]).toContain(behind)
2919+
expect(provider["scheduledViewStateWrites"]).toEqual([])
2920+
expect(entry.provider).toBeNull()
2921+
2922+
const behindIndex = ClineProvider["pendingViewStateWrites"].indexOf(behind)
2923+
if (behindIndex !== -1) {
2924+
ClineProvider["pendingViewStateWrites"].splice(behindIndex, 1)
2925+
}
2926+
2927+
void queued
2928+
})
2929+
28382930
test("numbers this provider's view id from the shared counter", () => {
28392931
const suffix = Number(String(provider["viewId"]).split("-").pop())
28402932

0 commit comments

Comments
 (0)