Files
archie/ui/test/task-actions.test.ts
archie 9a9629400e
ci/woodpecker/pr/quality Pipeline was successful
Quality / check (pull_request) Successful in 13m0s
Expose all task actions in the task detail header (archie)
2026-11-10 16:54:00 +11:00

161 lines
4.6 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { headerActionIds, shownActionIds } from "../src/tasks/task-actions.ts";
test("task surfaces preserve server-authorized actions and their order", () => {
const cases: Array<[string[] | null | undefined, string[] | undefined, string[]]> = [
[["retry", "abandon", "reject"], undefined, ["retry", "abandon", "reject"]],
[["archive", "open_pr"], ["archive"], ["archive"]],
[["retry", "reject"], ["archive"], []],
[undefined, ["archive"], []],
[null, undefined, []],
[[], ["archive"], []],
[["b", "a"], ["a", "b"], ["b", "a"]],
];
for (const [offered, only, expected] of cases) {
assert.deepEqual(shownActionIds(offered, only), expected, JSON.stringify({ offered, only }));
}
});
test("task detail header exposes all server-authorized actions unless an approval panel owns them", () => {
const activeReviewGate = JSON.stringify({
head_sha: "abc123",
findings: [
{
key: "f1",
finding: {
Title: "Bug",
Body: "Fix it",
File: "a.go",
LineStart: 1,
LineEnd: 2,
Severity: "high",
Score: 90,
Confidence: 90,
},
},
],
});
const emptyReviewGate = JSON.stringify({ head_sha: "abc123", findings: [] });
const resolvedReviewGate = JSON.stringify({
head_sha: "abc123",
outcome: "approved",
findings: JSON.parse(activeReviewGate).findings,
});
const cases: Array<{
name: string;
task: Parameters<typeof headerActionIds>[0];
expected: string[];
}> = [
{
name: "null and undefined tasks",
task: null,
expected: [],
},
{
name: "parked task exposes retry, abandon, reject",
task: {
status: "parked",
actions: ["retry", "abandon", "reject"],
},
expected: ["retry", "abandon", "reject"],
},
{
name: "queued task exposes cancel and reject",
task: {
status: "queued",
actions: ["cancel", "reject"],
},
expected: ["cancel", "reject"],
},
{
name: "running task exposes stop and reject",
task: {
status: "running",
actions: ["stop", "reject"],
},
expected: ["stop", "reject"],
},
{
name: "waiting_approval with budget approval keeps approve, reject, rereview in header",
task: {
status: "waiting_approval",
approval: "budget",
actions: ["approve", "reject", "rereview"],
},
expected: ["approve", "reject", "rereview"],
},
{
name: "waiting_approval with plan approval and non-empty plan omits approve and reject",
task: {
status: "waiting_approval",
approval: "plan",
plan: "# Plan\nDo the work",
actions: ["approve", "reject", "rereview"],
},
expected: ["rereview"],
},
{
name: "waiting_approval with plan approval and missing or blank plan keeps all actions in header",
task: {
status: "waiting_approval",
approval: "plan",
plan: " ",
actions: ["approve", "reject"],
},
expected: ["approve", "reject"],
},
{
name: "waiting_approval with active review gate findings omits approve, rereview, reject",
task: {
status: "waiting_approval",
approval: "review",
review_gate: activeReviewGate,
actions: ["approve", "reject", "rereview"],
},
expected: [],
},
{
name: "waiting_approval with empty review gate findings keeps actions in header",
task: {
status: "waiting_approval",
approval: "review",
review_gate: emptyReviewGate,
actions: ["approve", "reject", "rereview"],
},
expected: ["approve", "reject", "rereview"],
},
{
name: "waiting_approval with already-resolved review gate keeps actions in header",
task: {
status: "waiting_approval",
approval: "review",
review_gate: resolvedReviewGate,
actions: ["approve", "reject", "rereview"],
},
expected: ["approve", "reject", "rereview"],
},
{
name: "pr_open task exposes merge, open_pr, open_issue, reject",
task: {
status: "pr_open",
actions: ["merge", "open_pr", "open_issue", "reject"],
},
expected: ["merge", "open_pr", "open_issue", "reject"],
},
{
name: "terminal task exposes archive",
task: {
status: "merged",
actions: ["archive"],
},
expected: ["archive"],
},
];
for (const { name, task, expected } of cases) {
assert.deepEqual(headerActionIds(task), expected, name);
}
});