feat: add task duration tracking

This commit is contained in:
lesetong
2026-07-28 17:39:45 +08:00
parent 57c3354211
commit 2ff0a314ed
10 changed files with 482 additions and 27 deletions
+39
View File
@@ -113,3 +113,42 @@ test("list is compact and get returns available details for multiple IDs", async
assert.equal(parsed[1].description, undefined);
assert.equal(parsed[1].parentId, 1);
});
test("get_task exposes cumulative timing while list output stays compact", async () => {
const startedAt = Date.UTC(2026, 0, 1);
let now = startedAt;
const harness = registeredTools(new TaskState(() => now));
const added = await execute(harness.tools.get("set_tasks"), {
mode: "append",
tasks: [{ name: "Timed", status: "in-progress" }],
});
assert.equal(added.content[0].text, "Added 1 task: 1. 0/1 done.");
assert.equal(added.details.snapshot.timings[0].activeStartedAt, startedAt);
now += 65_432;
const list = await execute(harness.tools.get("list_task"), {});
assert.equal(list.content[0].text, "1 [in-progress] Timed");
const active = JSON.parse((await execute(harness.tools.get("get_task"), { ids: [1] })).content[0].text);
assert.deepEqual(active[0], {
id: 1,
name: "Timed",
status: "in-progress",
parentId: null,
childrenIds: [],
startedAt: new Date(startedAt).toISOString(),
durationMs: 65_432,
});
now += 568;
const updated = await execute(harness.tools.get("update_task"), {
tasks: [{ id: 1, status: "blocked" }],
});
assert.equal(updated.content[0].text, "Updated 1 task: 1. 0/1 done.");
now += 10_000;
const paused = JSON.parse((await execute(harness.tools.get("get_task"), { ids: [1] })).content[0].text);
assert.equal(paused[0].startedAt, new Date(startedAt).toISOString());
assert.equal(paused[0].stoppedAt, new Date(startedAt + 66_000).toISOString());
assert.equal(paused[0].durationMs, 66_000);
});