27 lines
1.6 KiB
TypeScript
27 lines
1.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { TaskStateMachine } from "@/runtime/coordination/task-state";
|
|
|
|
const TIME = "2026-08-03T09:00:00.000Z";
|
|
|
|
describe("TaskStateMachine", () => {
|
|
it("projects repeated progress updates into one task record", () => {
|
|
const tasks = new TaskStateMachine();
|
|
tasks.receive({ operation_id: "task_001", title: "Generate report", percent: 20, status: "running", cancellable: true }, "conversation_001", TIME);
|
|
tasks.receive({ operation_id: "task_001", title: "Generate report", percent: 80, status: "running", cancellable: true }, "conversation_001", "2026-08-03T09:01:00.000Z");
|
|
|
|
expect(tasks.snapshot()).toEqual([expect.objectContaining({ operation_id: "task_001", percent: 80, status: "running" })]);
|
|
});
|
|
|
|
it("records one local cancellation request and lets the Agent close it as cancelled", () => {
|
|
const tasks = new TaskStateMachine();
|
|
tasks.receive({ operation_id: "task_002", title: "Export", percent: 40, status: "running", cancellable: true }, "conversation_001", TIME);
|
|
|
|
expect(tasks.requestCancel("task_002", "2026-08-03T09:01:00.000Z")).toMatchObject({ disposition: "accepted", record: { cancel_requested_at: "2026-08-03T09:01:00.000Z" } });
|
|
expect(tasks.requestCancel("task_002", "2026-08-03T09:02:00.000Z").disposition).toBe("invalid_transition");
|
|
tasks.receive({ operation_id: "task_002", title: "Export", percent: 40, status: "cancelled", cancellable: false }, "conversation_001", "2026-08-03T09:03:00.000Z");
|
|
|
|
expect(tasks.get("task_002")).toMatchObject({ status: "cancelled" });
|
|
expect(tasks.get("task_002")).not.toHaveProperty("cancel_requested_at");
|
|
});
|
|
});
|