- Set task status to 'failed' on execution failure in engine executor - Add failed indicator styling on TaskCard component - Add POST /tasks/:id/retry API endpoint and client function - Add retry button in TaskDetailModal for failed tasks - Add tests for failed indicator, retry endpoint, and modal behavior
176 lines
6.8 KiB
TypeScript
176 lines
6.8 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import type { Column } from "@hai/core";
|
|
|
|
/**
|
|
* Tests for the agent-active class logic in TaskCard.
|
|
*
|
|
* Since no DOM environment (jsdom/happy-dom) or @testing-library/react is available,
|
|
* we extract and test the class computation logic directly.
|
|
*/
|
|
|
|
const ACTIVE_STATUSES = new Set(["planning", "researching", "executing", "finalizing", "merging", "specifying"]);
|
|
|
|
/** Mirrors the cardClass computation from TaskCard.tsx */
|
|
function computeCardClass(opts: { dragging?: boolean; queued?: boolean; status?: string; column?: Column }): string {
|
|
const { dragging = false, queued = false, status, column = "todo" } = opts;
|
|
const isFailed = status === "failed";
|
|
const isAgentActive = !queued && !isFailed && (column === "in-progress" || ACTIVE_STATUSES.has(status as string));
|
|
return `card${dragging ? " dragging" : ""}${queued ? " queued" : ""}${isAgentActive ? " agent-active" : ""}${isFailed ? " failed" : ""}`;
|
|
}
|
|
|
|
describe("TaskCard agent-active class", () => {
|
|
it("applies agent-active for an active status (executing)", () => {
|
|
const cls = computeCardClass({ status: "executing" });
|
|
expect(cls).toContain("agent-active");
|
|
});
|
|
|
|
it("applies agent-active for all active statuses", () => {
|
|
for (const status of ["planning", "researching", "executing", "finalizing", "merging", "specifying"]) {
|
|
const cls = computeCardClass({ status });
|
|
expect(cls).toContain("agent-active");
|
|
}
|
|
});
|
|
|
|
it("does NOT apply agent-active when status is undefined and column is not in-progress", () => {
|
|
const cls = computeCardClass({});
|
|
expect(cls).not.toContain("agent-active");
|
|
});
|
|
|
|
it("does NOT apply agent-active for non-active status (idle) outside in-progress", () => {
|
|
const cls = computeCardClass({ status: "idle" });
|
|
expect(cls).not.toContain("agent-active");
|
|
});
|
|
|
|
it("does NOT apply agent-active for queued card even with active status", () => {
|
|
const cls = computeCardClass({ status: "executing", queued: true });
|
|
expect(cls).not.toContain("agent-active");
|
|
expect(cls).toContain("queued");
|
|
});
|
|
|
|
it("does NOT apply agent-active for queued card with no status", () => {
|
|
const cls = computeCardClass({ queued: true });
|
|
expect(cls).not.toContain("agent-active");
|
|
});
|
|
|
|
it("combines dragging and agent-active correctly", () => {
|
|
const cls = computeCardClass({ status: "executing", dragging: true });
|
|
expect(cls).toContain("agent-active");
|
|
expect(cls).toContain("dragging");
|
|
});
|
|
|
|
it("base card class is always present", () => {
|
|
expect(computeCardClass({})).toBe("card");
|
|
expect(computeCardClass({ status: "executing" })).toMatch(/^card /);
|
|
});
|
|
|
|
// Column-based agent-active tests
|
|
|
|
it("applies agent-active for in-progress column with no status", () => {
|
|
const cls = computeCardClass({ column: "in-progress" });
|
|
expect(cls).toContain("agent-active");
|
|
});
|
|
|
|
it("applies agent-active for in-progress column with an active status", () => {
|
|
const cls = computeCardClass({ column: "in-progress", status: "executing" });
|
|
expect(cls).toContain("agent-active");
|
|
});
|
|
|
|
it("does NOT apply agent-active for todo column with no status", () => {
|
|
const cls = computeCardClass({ column: "todo" });
|
|
expect(cls).not.toContain("agent-active");
|
|
});
|
|
|
|
it("applies agent-active for in-review column with active status (merging)", () => {
|
|
const cls = computeCardClass({ column: "in-review", status: "merging" });
|
|
expect(cls).toContain("agent-active");
|
|
});
|
|
|
|
it("does NOT apply agent-active for queued card in in-progress column", () => {
|
|
const cls = computeCardClass({ column: "in-progress", queued: true });
|
|
expect(cls).not.toContain("agent-active");
|
|
expect(cls).toContain("queued");
|
|
});
|
|
|
|
it("does NOT apply agent-active when status is 'failed' even in in-progress column", () => {
|
|
const cls = computeCardClass({ column: "in-progress", status: "failed" });
|
|
expect(cls).not.toContain("agent-active");
|
|
expect(cls).toContain("failed");
|
|
});
|
|
});
|
|
|
|
describe("TaskCard failed status", () => {
|
|
it("applies 'failed' class to card when status is 'failed'", () => {
|
|
const cls = computeCardClass({ status: "failed", column: "in-progress" });
|
|
expect(cls).toContain("failed");
|
|
expect(cls).not.toContain("agent-active");
|
|
});
|
|
|
|
it("does NOT apply 'failed' class for non-failed statuses", () => {
|
|
const cls = computeCardClass({ status: "executing", column: "in-progress" });
|
|
expect(cls).not.toContain("failed");
|
|
});
|
|
|
|
it("does NOT apply 'failed' class when status is undefined", () => {
|
|
const cls = computeCardClass({ column: "in-progress" });
|
|
expect(cls).not.toContain("failed");
|
|
});
|
|
|
|
/** Mirrors the badge style condition from TaskCard.tsx */
|
|
function shouldShowFailedBadge(status?: string | null): boolean {
|
|
return status === "failed";
|
|
}
|
|
|
|
it("shows failed badge when status is 'failed'", () => {
|
|
expect(shouldShowFailedBadge("failed")).toBe(true);
|
|
});
|
|
|
|
it("does NOT show failed badge for other statuses", () => {
|
|
expect(shouldShowFailedBadge("executing")).toBe(false);
|
|
expect(shouldShowFailedBadge(undefined)).toBe(false);
|
|
expect(shouldShowFailedBadge(null)).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("TaskCard queued badge logic", () => {
|
|
/** Mirrors the card-status-badge visibility condition from TaskCard.tsx */
|
|
function shouldShowStatusBadge(status?: string | null): boolean {
|
|
return !!status && status !== "queued";
|
|
}
|
|
|
|
/** Mirrors the queued-badge visibility condition from TaskCard.tsx */
|
|
function shouldShowQueuedBadge(opts: { queued?: boolean; status?: string | null }): boolean {
|
|
return !!(opts.queued || opts.status === "queued");
|
|
}
|
|
|
|
it("shows queued-badge when queued prop is true", () => {
|
|
expect(shouldShowQueuedBadge({ queued: true })).toBe(true);
|
|
});
|
|
|
|
it("shows queued-badge when task.status is 'queued'", () => {
|
|
expect(shouldShowQueuedBadge({ status: "queued" })).toBe(true);
|
|
});
|
|
|
|
it("shows queued-badge when both queued prop and status are set", () => {
|
|
expect(shouldShowQueuedBadge({ queued: true, status: "queued" })).toBe(true);
|
|
});
|
|
|
|
it("does NOT show queued-badge when neither queued prop nor status is 'queued'", () => {
|
|
expect(shouldShowQueuedBadge({ queued: false, status: "executing" })).toBe(false);
|
|
expect(shouldShowQueuedBadge({})).toBe(false);
|
|
});
|
|
|
|
it("does NOT show card-status-badge when status is 'queued'", () => {
|
|
expect(shouldShowStatusBadge("queued")).toBe(false);
|
|
});
|
|
|
|
it("shows card-status-badge for non-queued statuses", () => {
|
|
expect(shouldShowStatusBadge("executing")).toBe(true);
|
|
expect(shouldShowStatusBadge("planning")).toBe(true);
|
|
});
|
|
|
|
it("does NOT show card-status-badge when status is null/undefined", () => {
|
|
expect(shouldShowStatusBadge(null)).toBe(false);
|
|
expect(shouldShowStatusBadge(undefined)).toBe(false);
|
|
});
|
|
});
|