Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/core/task/__tests__/Task.dispose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
})

Expand Down
31 changes: 31 additions & 0 deletions src/core/task/__tests__/Task.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
8 changes: 5 additions & 3 deletions src/core/task/__tests__/observationRegistry.spec.ts
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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", () => {
Expand Down
Loading