Skip to content

Commit cdc086a

Browse files
committed
team-mode: auto-claim pending tasks on start
1 parent b007b18 commit cdc086a

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/features/team-mode/team-tasklist/update.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,29 @@ test("updateTaskStatus supports the one-way claim to complete flow", async () =>
2929
}
3030
})
3131

32+
test("updateTaskStatus auto-claims when a member starts a pending task directly", async () => {
33+
// given
34+
const fixture = await createTasklistFixture()
35+
36+
try {
37+
const task = await createTask(fixture.teamRunId, createTaskInput(), fixture.config)
38+
39+
// when
40+
const inProgressTask = await updateTaskStatus(fixture.teamRunId, task.id, "in_progress", "member-a", fixture.config)
41+
const loadedTask = await getTask(fixture.teamRunId, task.id, fixture.config)
42+
43+
// then
44+
expect(inProgressTask.status).toBe("in_progress")
45+
expect(inProgressTask.owner).toBe("member-a")
46+
expect(typeof inProgressTask.claimedAt).toBe("number")
47+
expect(loadedTask.status).toBe("in_progress")
48+
expect(loadedTask.owner).toBe("member-a")
49+
expect(typeof loadedTask.claimedAt).toBe("number")
50+
} finally {
51+
await fixture.cleanup()
52+
}
53+
})
54+
3255
test("updateTaskStatus rejects reverse transitions", async () => {
3356
// given
3457
const fixture = await createTasklistFixture()

src/features/team-mode/team-tasklist/update.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getTasksDir, resolveBaseDir } from "../team-registry"
55
import { atomicWrite } from "../team-state-store/locks"
66
import { TaskSchema } from "../types"
77
import type { Task } from "../types"
8+
import { claimTask } from "./claim"
89
import { getTask } from "./get"
910

1011
const ALLOWED_TRANSITIONS: Readonly<Record<Task["status"], ReadonlyArray<Task["status"]>>> = {
@@ -45,6 +46,11 @@ export async function updateTaskStatus(
4546

4647
if (task.status === newStatus) return task
4748

49+
if (task.status === "pending" && newStatus === "in_progress") {
50+
await claimTask(teamRunId, taskId, memberName, config)
51+
return updateTaskStatus(teamRunId, taskId, newStatus, memberName, config)
52+
}
53+
4854
if (!isValidTransition(task.status, newStatus)) {
4955
throw new InvalidTaskTransitionError(task.status, newStatus)
5056
}

0 commit comments

Comments
 (0)