diff --git a/src/core/task/__tests__/Task.dispose.test.ts b/src/core/task/__tests__/Task.dispose.test.ts index 8bc06c9ff5..7a83f16b8d 100644 --- a/src/core/task/__tests__/Task.dispose.test.ts +++ b/src/core/task/__tests__/Task.dispose.test.ts @@ -119,7 +119,7 @@ describe("Task dispose method", () => { expect(disposalComplete).toBe(true) }) - test("owns a per-Task observation registry", () => { + test("owns a per-Task observation registry", async () => { // ReadFileTool and the guarded-write path reach the registry only through the Task, // so a Task that never built one - or shared one across Tasks - would silently drop // read observations. The registry's own tests only exercise standalone instances, and @@ -142,7 +142,7 @@ describe("Task dispose method", () => { expect(task.observationRegistry.has("/workspace/a.ts")).toBe(false) expect(task.observationRegistry.size).toBe(0) } finally { - void other.dispose().catch(() => {}) + await other.dispose() } }) diff --git a/src/core/task/__tests__/Task.spec.ts b/src/core/task/__tests__/Task.spec.ts index 3fea8b61bc..765dd1b2b6 100644 --- a/src/core/task/__tests__/Task.spec.ts +++ b/src/core/task/__tests__/Task.spec.ts @@ -4819,6 +4819,37 @@ describe("Cline", () => { expect(task.abort).toBe(true) expect(task.cancellationGeneration).toBe(1) }) + it("advances the cancellation generation for the disposal an unmocked abort performs", async () => { + // The two rows above mock dispose(), so each proves one increment in isolation. The + // sequence the guarded-write fence actually sees is an abort that tears the task down: + // requestAbort raises the fence, and the dispose() that abortTaskOnce drives raises it + // again. Nothing is mocked here, so if either increment stopped landing - or if disposal + // stopped being part of an abort - this row reads the stale value. + const task = new Task({ + provider: mockProvider, + apiConfiguration: mockApiConfig, + task: "test task", + startTask: false, + }) + + expect(task.cancellationGeneration).toBe(0) + + // Started, not awaited. requestAbort is synchronous and raises the fence before any of the + // abort work runs (Task.abortTask calls it before it hands back abortPromise), so the increment + // has to be visible while the abort promise is still pending. Asserting the generation only + // after the await would still pass if the increment landed at the end of the teardown, which is + // exactly the delay that lets a write parked on its path chain publish after the task is gone. + const aborting = task.abortTask() + expect(task.cancellationGeneration).toBe(1) + + await aborting + + expect(task.abort).toBe(true) + // Disposal never marks a task abandoned; only an explicit abandon does. + expect(task.abandoned).toBe(false) + // One from requestAbort, one from the disposal the abort performed. + expect(task.cancellationGeneration).toBe(2) + }) it("flushes pending state before TaskAborted and disposal while queue state is intact", async () => { const task = new Task({ diff --git a/src/core/task/__tests__/observationRegistry.spec.ts b/src/core/task/__tests__/observationRegistry.spec.ts index a7813fc2bb..7286cc79bb 100644 --- a/src/core/task/__tests__/observationRegistry.spec.ts +++ b/src/core/task/__tests__/observationRegistry.spec.ts @@ -1,8 +1,12 @@ -import { describe, it, expect, vi } from "vitest" +import { afterEach, describe, it, expect, vi } from "vitest" import { ObservationRegistry } from "../observationRegistry" describe("ObservationRegistry", () => { + afterEach(() => { + vi.useRealTimers() + }) + it("observe → get returns the recorded version and observedAt", () => { const reg = new ObservationRegistry() reg.observe("/a/b/c.ts", "1:2:300:4000000000:5000000000") @@ -25,8 +29,6 @@ describe("ObservationRegistry", () => { const second = reg.get("/a/b/c.ts")! expect(second.version).toBe("v2") expect(second.observedAt).toBeGreaterThan(first.observedAt) - - vi.useRealTimers() }) it("has returns true for observed paths, false otherwise", () => {