Add Cloud Console cancel action and cancelled status

- Widen TaskStatus to include "cancelled"; add it to TasksView's
  STATUSES filter dropdown.
- Add TaskCancellationResponse type and cancelTask(taskId) to api.ts.
- Add a Cancel button to TasksView's task detail panel, gated on
  tasks:submit and a non-terminal task status; updates the displayed
  status on success and surfaces errors via the existing error path.
- Extract the cancellability rule into a pure taskCancellation.ts
  module (mirroring taskProgress.ts/plannerHistory.ts) with unit
  tests, since the project has no Vue component-mounting test setup.

Task 6/9 of task-cancellation change.
This commit is contained in:
2026-07-15 18:43:55 +08:00
parent 6776ac2f2d
commit 4d04d7ac83
6 changed files with 94 additions and 5 deletions
@@ -0,0 +1,24 @@
import { describe, expect, it } from "vitest";
import { canCancelTask } from "./taskCancellation";
import type { TaskStatus } from "./types";
describe("canCancelTask", () => {
it.each<TaskStatus>(["queued", "assigned", "dispatched"])(
"allows cancelling a %s task when the caller can submit",
(status) => {
expect(canCancelTask(status, true)).toBe(true);
},
);
it.each<TaskStatus>(["done", "failed", "cancelled"])(
"refuses to cancel a terminal %s task even when the caller can submit",
(status) => {
expect(canCancelTask(status, true)).toBe(false);
},
);
it("refuses to cancel a cancellable task when the caller lacks submit permission", () => {
expect(canCancelTask("assigned", false)).toBe(false);
});
});