feat(kanban): Interactive Kanban board with real-time task tracking (#83)
* feat(kanban): add Kanban board with task-manager skill, modal UI, and desk clutter Implement a full Kanban board system for tracking agent tasks: - Add task-manager skill with shared JSON task store for persistence - Render board as a floating modal over the live 3D office (not immersive) - Auto-create tasks from actionable user messages with heuristic filtering - Sync task status through OpenClaw agent lifecycle events - Collapse task details panel by default, expand on card click - Add dynamic desk clutter (papers, folders, etc.) reflecting active task count - Exclude done tasks from desk clutter count - Extract KANBAN_CLUTTER_OFFSET for easy positioning adjustment - Add install flow with progress bar for the task-manager skill - Include unit and e2e test coverage Made-with: Cursor * feat(kanban): production-harden task board with AI-free classification, resilient persistence, and modal UX - Harden shared task store with atomic writes, payload size limits, and server-side enum validation - Add client resilience: request timeouts (AbortController), exponential backoff retries, poll deduplication - Implement optimistic UI with rollback on all card mutations (update, move, archive) - Add modal accessibility: focus trap, Escape to close, aria-modal, keyboard card navigation - Trust OpenClaw agent lifecycle phase=start as task classification signal instead of regex heuristics - Keep regex heuristic only as lightweight filter for direct chat events (conversational noise) - Expand verb recognition with typo tolerance and broader action vocabulary - Create tasks from agent runs even when no chat event is received (external channel support) - Merge dual header bars into single bar; reposition close button outside modal corner - Exclude done tasks from desk clutter count; make clutter position configurable via KANBAN_CLUTTER_OFFSET - Update default furniture layout to match user configuration - Ensure kanban_board furniture persists in local storage across sessions - Add comprehensive test coverage for store, API route, and controller logic Made-with: Cursor --------- Co-authored-by: iamlukethedev <lucas.guilherme@smartwayslfl.com>
This commit is contained in:
@@ -6,6 +6,13 @@ export type StudioSettingsFixture = {
|
||||
gateway: { url: string; token: string } | null;
|
||||
focused: Record<string, { mode: "focused"; filter: string; selectedAgentId: string | null }>;
|
||||
avatars: Record<string, Record<string, AgentAvatarProfile>>;
|
||||
taskBoard?: Record<
|
||||
string,
|
||||
{
|
||||
cards: Array<Record<string, unknown>>;
|
||||
selectedCardId: string | null;
|
||||
}
|
||||
>;
|
||||
};
|
||||
|
||||
const DEFAULT_SETTINGS: StudioSettingsFixture = {
|
||||
@@ -13,6 +20,7 @@ const DEFAULT_SETTINGS: StudioSettingsFixture = {
|
||||
gateway: null,
|
||||
focused: {},
|
||||
avatars: {},
|
||||
taskBoard: {},
|
||||
};
|
||||
|
||||
const createStudioRoute = (initial: StudioSettingsFixture = DEFAULT_SETTINGS) => {
|
||||
@@ -21,6 +29,7 @@ const createStudioRoute = (initial: StudioSettingsFixture = DEFAULT_SETTINGS) =>
|
||||
gateway: initial.gateway ?? null,
|
||||
focused: { ...(initial.focused ?? {}) },
|
||||
avatars: { ...(initial.avatars ?? {}) },
|
||||
taskBoard: { ...(initial.taskBoard ?? {}) },
|
||||
};
|
||||
|
||||
return async (route: Route, request: Request) => {
|
||||
@@ -97,6 +106,32 @@ const createStudioRoute = (initial: StudioSettingsFixture = DEFAULT_SETTINGS) =>
|
||||
next.avatars = avatarsNext;
|
||||
}
|
||||
|
||||
if (patch.taskBoard && typeof patch.taskBoard === "object") {
|
||||
const taskBoardPatch = patch.taskBoard as Record<
|
||||
string,
|
||||
{ cards?: Array<Record<string, unknown>>; selectedCardId?: string | null } | null
|
||||
>;
|
||||
const taskBoardNext = { ...(next.taskBoard ?? {}) };
|
||||
for (const [gatewayKey, gatewayValue] of Object.entries(taskBoardPatch)) {
|
||||
if (gatewayValue === null) {
|
||||
delete taskBoardNext[gatewayKey];
|
||||
continue;
|
||||
}
|
||||
const existing = taskBoardNext[gatewayKey] ?? {
|
||||
cards: [],
|
||||
selectedCardId: null,
|
||||
};
|
||||
taskBoardNext[gatewayKey] = {
|
||||
cards: Array.isArray(gatewayValue.cards) ? gatewayValue.cards : existing.cards,
|
||||
selectedCardId:
|
||||
"selectedCardId" in gatewayValue
|
||||
? (gatewayValue.selectedCardId ?? null)
|
||||
: existing.selectedCardId,
|
||||
};
|
||||
}
|
||||
next.taskBoard = taskBoardNext;
|
||||
}
|
||||
|
||||
settings = next;
|
||||
await route.fulfill({
|
||||
status: 200,
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { stubStudioRoute } from "./helpers/studioRoute";
|
||||
|
||||
test.skip(
|
||||
process.env.CLAW3D_E2E_GATEWAY !== "1",
|
||||
"Requires a reachable gateway-backed office shell."
|
||||
);
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await stubStudioRoute(page);
|
||||
});
|
||||
|
||||
test("creates and edits a kanban card from HQ", async ({ page }) => {
|
||||
await page.goto("/");
|
||||
|
||||
await page.getByRole("button", { name: "Open headquarters sidebar" }).click();
|
||||
await page.getByRole("tab", { name: "Kanban" }).click();
|
||||
await page.getByRole("button", { name: "New Task" }).click();
|
||||
|
||||
const titleInput = page.getByLabel("Title");
|
||||
await expect(titleInput).toHaveValue("New task");
|
||||
await titleInput.fill("Create marketing website");
|
||||
await page.getByLabel("Description").fill("Landing page for the spring campaign.");
|
||||
await page.getByLabel("Status").selectOption("in_progress");
|
||||
|
||||
await expect(page.getByText("Create marketing website")).toBeVisible();
|
||||
await expect(titleInput).toHaveValue("Create marketing website");
|
||||
});
|
||||
|
||||
test("persists kanban cards to studio settings", async ({ page }) => {
|
||||
await page.goto("/");
|
||||
|
||||
await page.getByRole("button", { name: "Open headquarters sidebar" }).click();
|
||||
await page.getByRole("tab", { name: "Kanban" }).click();
|
||||
await page.getByRole("button", { name: "New Task" }).click();
|
||||
await page.getByLabel("Title").fill("Persistent task card");
|
||||
|
||||
const request = await page.waitForRequest((req) => {
|
||||
if (!req.url().includes("/api/studio") || req.method() !== "PUT") {
|
||||
return false;
|
||||
}
|
||||
const payload = JSON.parse(req.postData() ?? "{}") as {
|
||||
taskBoard?: Record<string, { cards?: Array<{ title?: string }> }>;
|
||||
};
|
||||
const entries = Object.values(payload.taskBoard ?? {});
|
||||
return entries.some((entry) =>
|
||||
(entry.cards ?? []).some((card) => card.title === "Persistent task card")
|
||||
);
|
||||
});
|
||||
|
||||
const payload = JSON.parse(request.postData() ?? "{}") as {
|
||||
taskBoard?: Record<string, { cards?: Array<{ title?: string }> }>;
|
||||
};
|
||||
expect(
|
||||
Object.values(payload.taskBoard ?? {}).some((entry) =>
|
||||
(entry.cards ?? []).some((card) => card.title === "Persistent task card")
|
||||
)
|
||||
).toBe(true);
|
||||
});
|
||||
@@ -182,6 +182,35 @@ describe("office event triggers", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("does not replay standup commands from old transcript history", () => {
|
||||
const sessionKey = "agent:main:main";
|
||||
const agents = [
|
||||
makeAgent({
|
||||
agentId: "main",
|
||||
name: "Main",
|
||||
sessionKey,
|
||||
lastUserMessage: "Start the standup meeting.",
|
||||
transcriptEntries: [
|
||||
makeTranscriptEntry({
|
||||
line: "Start the standup meeting.",
|
||||
role: "user",
|
||||
sequenceKey: 1,
|
||||
sessionKey,
|
||||
timestampMs: 10_000,
|
||||
}),
|
||||
],
|
||||
}),
|
||||
];
|
||||
|
||||
const state = reconcileOfficeAnimationTriggerState({
|
||||
state: createOfficeAnimationTriggerState(),
|
||||
agents,
|
||||
nowMs: 100_000,
|
||||
});
|
||||
|
||||
expect(state.pendingStandupRequest).toBeNull();
|
||||
});
|
||||
|
||||
it("treats final transport chat messages without an explicit user role as commands", () => {
|
||||
const agents = [
|
||||
makeAgent({
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
archiveSharedTask,
|
||||
listSharedTasks,
|
||||
resolveSharedTaskStorePath,
|
||||
upsertSharedTask,
|
||||
} from "@/lib/tasks/shared-store";
|
||||
|
||||
const makeTempDir = (name: string) => fs.mkdtempSync(path.join(os.tmpdir(), `${name}-`));
|
||||
|
||||
describe("shared task store", () => {
|
||||
const priorStateDir = process.env.OPENCLAW_STATE_DIR;
|
||||
let tempDir: string | null = null;
|
||||
|
||||
afterEach(() => {
|
||||
process.env.OPENCLAW_STATE_DIR = priorStateDir;
|
||||
if (tempDir) {
|
||||
fs.rmSync(tempDir, { recursive: true, force: true });
|
||||
tempDir = null;
|
||||
}
|
||||
});
|
||||
|
||||
it("creates and lists persisted tasks", () => {
|
||||
tempDir = makeTempDir("shared-task-store-create");
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
|
||||
const created = upsertSharedTask({
|
||||
id: "task-1",
|
||||
title: "Research mtulsa.com",
|
||||
description: "Check site positioning.",
|
||||
status: "todo",
|
||||
source: "claw3d_manual",
|
||||
});
|
||||
|
||||
expect(created.history).toHaveLength(1);
|
||||
expect(created.history[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
type: "created",
|
||||
toStatus: "todo",
|
||||
})
|
||||
);
|
||||
|
||||
const stored = listSharedTasks();
|
||||
expect(stored).toHaveLength(1);
|
||||
expect(stored[0]?.title).toBe("Research mtulsa.com");
|
||||
expect(fs.existsSync(resolveSharedTaskStorePath())).toBe(true);
|
||||
});
|
||||
|
||||
it("appends history when task status changes and archives instead of deleting", () => {
|
||||
tempDir = makeTempDir("shared-task-store-history");
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
|
||||
upsertSharedTask({
|
||||
id: "task-1",
|
||||
title: "Research mtulsa.com",
|
||||
status: "todo",
|
||||
source: "claw3d_manual",
|
||||
});
|
||||
const updated = upsertSharedTask({
|
||||
id: "task-1",
|
||||
title: "Research mtulsa.com",
|
||||
status: "in_progress",
|
||||
source: "claw3d_manual",
|
||||
});
|
||||
const archived = archiveSharedTask("task-1");
|
||||
|
||||
expect(updated.history.map((entry) => entry.type)).toContain("status_changed");
|
||||
expect(archived?.isArchived).toBe(true);
|
||||
expect(archived?.history.map((entry) => entry.type)).toContain("archived");
|
||||
});
|
||||
|
||||
it("recovers gracefully from corrupted JSON on disk", () => {
|
||||
tempDir = makeTempDir("shared-task-store-corrupt");
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
|
||||
upsertSharedTask({ id: "t-1", title: "Valid task", status: "todo", source: "claw3d_manual" });
|
||||
const storePath = resolveSharedTaskStorePath();
|
||||
fs.writeFileSync(storePath, "{invalid json!!!", "utf8");
|
||||
|
||||
const tasks = listSharedTasks();
|
||||
expect(tasks).toEqual([]);
|
||||
|
||||
const afterCorrupt = upsertSharedTask({ id: "t-2", title: "After recovery", status: "todo", source: "claw3d_manual" });
|
||||
expect(afterCorrupt.id).toBe("t-2");
|
||||
expect(listSharedTasks()).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("performs atomic writes so partial failures don't corrupt the store", () => {
|
||||
tempDir = makeTempDir("shared-task-store-atomic");
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
|
||||
upsertSharedTask({ id: "t-1", title: "Safe task", status: "todo", source: "claw3d_manual" });
|
||||
const storePath = resolveSharedTaskStorePath();
|
||||
const original = fs.readFileSync(storePath, "utf8");
|
||||
|
||||
expect(JSON.parse(original)).toEqual(
|
||||
expect.objectContaining({ schemaVersion: 1 })
|
||||
);
|
||||
expect(listSharedTasks()).toHaveLength(1);
|
||||
});
|
||||
|
||||
it("coerces invalid status and source to defaults", () => {
|
||||
tempDir = makeTempDir("shared-task-store-coerce");
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
|
||||
const task = upsertSharedTask({
|
||||
id: "t-coerce",
|
||||
title: "Coerce test",
|
||||
status: "banana" as never,
|
||||
source: "alien" as never,
|
||||
});
|
||||
expect(task.status).toBe("todo");
|
||||
expect(task.source).toBe("claw3d_manual");
|
||||
});
|
||||
|
||||
it("truncates oversized title and description", () => {
|
||||
tempDir = makeTempDir("shared-task-store-truncate");
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
|
||||
const longTitle = "A".repeat(1000);
|
||||
const longDesc = "B".repeat(10_000);
|
||||
const task = upsertSharedTask({
|
||||
id: "t-long",
|
||||
title: longTitle,
|
||||
description: longDesc,
|
||||
status: "todo",
|
||||
source: "claw3d_manual",
|
||||
});
|
||||
|
||||
expect(task.title.length).toBeLessThanOrEqual(500);
|
||||
expect(task.description.length).toBeLessThanOrEqual(5000);
|
||||
});
|
||||
|
||||
it("returns null when archiving a non-existent task", () => {
|
||||
tempDir = makeTempDir("shared-task-store-archive-missing");
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
|
||||
const result = archiveSharedTask("does-not-exist");
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it("returns an empty list when store file does not exist", () => {
|
||||
tempDir = makeTempDir("shared-task-store-missing-file");
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
|
||||
expect(listSharedTasks()).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -15,11 +15,17 @@ describe("skill triggers", () => {
|
||||
const todoTrigger = listPackagedSkillTriggerDefinitions().find(
|
||||
(entry) => entry.skillKey === "todo-board",
|
||||
);
|
||||
const taskManagerTrigger = listPackagedSkillTriggerDefinitions().find(
|
||||
(entry) => entry.skillKey === "task-manager",
|
||||
);
|
||||
|
||||
expect(todoTrigger).not.toBeUndefined();
|
||||
expect(todoTrigger?.movementTarget).toBe("desk");
|
||||
expect(todoTrigger?.activationPhrases).toContain("todo");
|
||||
expect(todoTrigger?.activationPhrases).toContain("blocked tasks");
|
||||
expect(taskManagerTrigger).not.toBeUndefined();
|
||||
expect(taskManagerTrigger?.movementTarget).toBe("desk");
|
||||
expect(taskManagerTrigger?.activationPhrases).toContain("add a task");
|
||||
});
|
||||
|
||||
it("matches the running agent's latest request against enabled skill triggers", () => {
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { loadActiveStandupMeeting } from "@/lib/office/standup/store";
|
||||
import type { StandupMeetingStore } from "@/lib/office/standup/types";
|
||||
|
||||
const makeTempDir = (name: string) => fs.mkdtempSync(path.join(os.tmpdir(), `${name}-`));
|
||||
|
||||
const writeStandupStore = (stateDir: string, store: StandupMeetingStore) => {
|
||||
const storeDir = path.join(stateDir, "claw3d");
|
||||
fs.mkdirSync(storeDir, { recursive: true });
|
||||
fs.writeFileSync(
|
||||
path.join(storeDir, "standup-store.json"),
|
||||
JSON.stringify(store, null, 2),
|
||||
"utf8"
|
||||
);
|
||||
};
|
||||
|
||||
describe("standup store", () => {
|
||||
const priorStateDir = process.env.OPENCLAW_STATE_DIR;
|
||||
let tempDir: string | null = null;
|
||||
|
||||
afterEach(() => {
|
||||
process.env.OPENCLAW_STATE_DIR = priorStateDir;
|
||||
if (tempDir) {
|
||||
fs.rmSync(tempDir, { recursive: true, force: true });
|
||||
tempDir = null;
|
||||
}
|
||||
});
|
||||
|
||||
it("drops stale active gathering meetings on load", () => {
|
||||
tempDir = makeTempDir("standup-store-stale");
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
const staleIso = new Date(Date.now() - 60 * 60 * 1000).toISOString();
|
||||
writeStandupStore(tempDir, {
|
||||
activeMeeting: {
|
||||
id: "meeting-stale",
|
||||
trigger: "manual",
|
||||
phase: "gathering",
|
||||
scheduledFor: null,
|
||||
startedAt: staleIso,
|
||||
updatedAt: staleIso,
|
||||
completedAt: null,
|
||||
currentSpeakerAgentId: null,
|
||||
speakerStartedAt: null,
|
||||
speakerDurationMs: 8000,
|
||||
participantOrder: ["main"],
|
||||
arrivedAgentIds: ["main"],
|
||||
cards: [],
|
||||
},
|
||||
lastMeeting: null,
|
||||
});
|
||||
|
||||
expect(loadActiveStandupMeeting()).toBeNull();
|
||||
});
|
||||
|
||||
it("keeps fresh active gatherings on load", () => {
|
||||
tempDir = makeTempDir("standup-store-fresh");
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
const freshIso = new Date().toISOString();
|
||||
writeStandupStore(tempDir, {
|
||||
activeMeeting: {
|
||||
id: "meeting-fresh",
|
||||
trigger: "manual",
|
||||
phase: "gathering",
|
||||
scheduledFor: null,
|
||||
startedAt: freshIso,
|
||||
updatedAt: freshIso,
|
||||
completedAt: null,
|
||||
currentSpeakerAgentId: null,
|
||||
speakerStartedAt: null,
|
||||
speakerDurationMs: 8000,
|
||||
participantOrder: ["main"],
|
||||
arrivedAgentIds: [],
|
||||
cards: [],
|
||||
},
|
||||
lastMeeting: null,
|
||||
});
|
||||
|
||||
expect(loadActiveStandupMeeting()?.id).toBe("meeting-fresh");
|
||||
});
|
||||
|
||||
it("drops stale gathering meetings even if arrivals refreshed updatedAt", () => {
|
||||
tempDir = makeTempDir("standup-store-gathering-updated");
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
const staleStartedIso = new Date(Date.now() - 10 * 60 * 1000).toISOString();
|
||||
const freshUpdatedIso = new Date().toISOString();
|
||||
writeStandupStore(tempDir, {
|
||||
activeMeeting: {
|
||||
id: "meeting-gathering-stale",
|
||||
trigger: "manual",
|
||||
phase: "gathering",
|
||||
scheduledFor: null,
|
||||
startedAt: staleStartedIso,
|
||||
updatedAt: freshUpdatedIso,
|
||||
completedAt: null,
|
||||
currentSpeakerAgentId: null,
|
||||
speakerStartedAt: null,
|
||||
speakerDurationMs: 8000,
|
||||
participantOrder: ["main"],
|
||||
arrivedAgentIds: ["main"],
|
||||
cards: [],
|
||||
},
|
||||
lastMeeting: null,
|
||||
});
|
||||
|
||||
expect(loadActiveStandupMeeting()).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -191,4 +191,113 @@ describe("studio settings normalization", () => {
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("normalizes task board cards per gateway", () => {
|
||||
const normalized = normalizeStudioSettings({
|
||||
taskBoard: {
|
||||
" ws://localhost:18789 ": {
|
||||
cards: [
|
||||
{
|
||||
id: " task-1 ",
|
||||
title: " Review kanban interaction ",
|
||||
status: "review",
|
||||
source: "openclaw_event",
|
||||
assignedAgentId: " agent-1 ",
|
||||
createdAt: "2026-03-29T10:00:00.000Z",
|
||||
updatedAt: "2026-03-29T10:05:00.000Z",
|
||||
notes: [" note one ", " ", "note two"],
|
||||
},
|
||||
],
|
||||
selectedCardId: " task-1 ",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(normalized.taskBoard?.["ws://localhost:18789"]).toEqual(
|
||||
expect.objectContaining({
|
||||
selectedCardId: "task-1",
|
||||
cards: [
|
||||
expect.objectContaining({
|
||||
id: "task-1",
|
||||
title: "Review kanban interaction",
|
||||
assignedAgentId: "agent-1",
|
||||
notes: ["note one", "note two"],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("merges task board patches", () => {
|
||||
const current = normalizeStudioSettings({
|
||||
taskBoard: {
|
||||
"ws://localhost:18789": {
|
||||
cards: [
|
||||
{
|
||||
id: "task-1",
|
||||
title: "Initial task",
|
||||
description: "",
|
||||
status: "todo",
|
||||
source: "claw3d_manual",
|
||||
sourceEventId: null,
|
||||
assignedAgentId: null,
|
||||
createdAt: "2026-03-29T10:00:00.000Z",
|
||||
updatedAt: "2026-03-29T10:00:00.000Z",
|
||||
playbookJobId: null,
|
||||
runId: null,
|
||||
channel: null,
|
||||
externalThreadId: null,
|
||||
lastActivityAt: null,
|
||||
notes: [],
|
||||
isArchived: false,
|
||||
isInferred: false,
|
||||
},
|
||||
],
|
||||
selectedCardId: "task-1",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const merged = mergeStudioSettings(current, {
|
||||
taskBoard: {
|
||||
"ws://localhost:18789": {
|
||||
cards: [
|
||||
{
|
||||
id: "task-2",
|
||||
title: "Replacement task",
|
||||
description: "",
|
||||
status: "in_progress",
|
||||
source: "claw3d_manual",
|
||||
sourceEventId: null,
|
||||
assignedAgentId: null,
|
||||
createdAt: "2026-03-29T10:10:00.000Z",
|
||||
updatedAt: "2026-03-29T10:10:00.000Z",
|
||||
playbookJobId: null,
|
||||
runId: null,
|
||||
channel: null,
|
||||
externalThreadId: null,
|
||||
lastActivityAt: null,
|
||||
notes: [],
|
||||
isArchived: false,
|
||||
isInferred: false,
|
||||
},
|
||||
],
|
||||
selectedCardId: "task-2",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(merged.taskBoard?.["ws://localhost:18789"]).toEqual(
|
||||
expect.objectContaining({
|
||||
selectedCardId: "task-2",
|
||||
cards: [
|
||||
expect.objectContaining({
|
||||
id: "task-2",
|
||||
title: "Replacement task",
|
||||
status: "in_progress",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,244 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import type { AgentState } from "@/features/agents/state/store";
|
||||
import type { RunRecord } from "@/features/office/hooks/useRunLog";
|
||||
import {
|
||||
deriveFallbackChatCard,
|
||||
deriveRecoveredAgentRequestCard,
|
||||
deriveLiveSessionTaskCard,
|
||||
isActionableTaskRequest,
|
||||
parseExplicitTaskEvent,
|
||||
syncCardWithLinkedRun,
|
||||
} from "@/features/office/tasks/useTaskBoardController";
|
||||
|
||||
const makeAgent = (overrides: Partial<AgentState> = {}) =>
|
||||
({
|
||||
agentId: "agent-1",
|
||||
name: "Agent One",
|
||||
sessionKey: "agent:agent-1:main",
|
||||
awaitingUserInput: false,
|
||||
...overrides,
|
||||
}) as AgentState;
|
||||
|
||||
describe("task board controller helpers", () => {
|
||||
it("parses explicit OpenClaw task events", () => {
|
||||
const parsed = parseExplicitTaskEvent({
|
||||
type: "event",
|
||||
event: "task_status_changed",
|
||||
seq: 42,
|
||||
payload: {
|
||||
taskId: "task-42",
|
||||
title: "Ship the kanban board",
|
||||
status: "review",
|
||||
assignedAgentId: "agent-1",
|
||||
runId: "run-1",
|
||||
},
|
||||
});
|
||||
|
||||
expect(parsed).toEqual(
|
||||
expect.objectContaining({
|
||||
taskId: "task-42",
|
||||
title: "Ship the kanban board",
|
||||
status: "review",
|
||||
assignedAgentId: "agent-1",
|
||||
runId: "run-1",
|
||||
sourceEventId: "task_status_changed:42",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("derives fallback cards from user chat requests", () => {
|
||||
const card = deriveFallbackChatCard(
|
||||
{
|
||||
type: "event",
|
||||
event: "chat",
|
||||
payload: {
|
||||
sessionKey: "agent:agent-1:main",
|
||||
seq: 7,
|
||||
channel: "telegram",
|
||||
message: {
|
||||
role: "user",
|
||||
content: [{ type: "text", text: "Create a website for me." }],
|
||||
},
|
||||
},
|
||||
},
|
||||
[makeAgent()],
|
||||
);
|
||||
|
||||
expect(card).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "chat:agent:agent-1:main:7",
|
||||
title: "Create a website for me.",
|
||||
assignedAgentId: "agent-1",
|
||||
channel: "telegram",
|
||||
source: "fallback_inferred",
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("treats plain inbound user asks as live session tasks", () => {
|
||||
const card = deriveLiveSessionTaskCard(
|
||||
{
|
||||
type: "event",
|
||||
event: "chat",
|
||||
payload: {
|
||||
sessionKey: "agent:agent-1:main",
|
||||
seq: 8,
|
||||
channel: "telegram",
|
||||
message: {
|
||||
role: "user",
|
||||
content: [{ type: "text", text: "Can you check the latest news on OpenClaw?" }],
|
||||
},
|
||||
},
|
||||
},
|
||||
[makeAgent()],
|
||||
);
|
||||
|
||||
expect(card).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "chat:agent:agent-1:main:8",
|
||||
title: "Can you check the latest news on OpenClaw?",
|
||||
assignedAgentId: "agent-1",
|
||||
channel: "telegram",
|
||||
externalThreadId: "agent:agent-1:main",
|
||||
source: "openclaw_event",
|
||||
isInferred: false,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("filters conversational messages out of task capture", () => {
|
||||
expect(isActionableTaskRequest("?")).toBe(false);
|
||||
expect(isActionableTaskRequest("are you there")).toBe(false);
|
||||
expect(isActionableTaskRequest("thanks")).toBe(false);
|
||||
expect(isActionableTaskRequest("Can you research about Paul Brady in Tulsa, OK?")).toBe(
|
||||
true
|
||||
);
|
||||
});
|
||||
|
||||
it("accepts messages with common verb typos", () => {
|
||||
expect(isActionableTaskRequest("Rearch who is Luke the dev")).toBe(true);
|
||||
expect(isActionableTaskRequest("Reserch best practices for React")).toBe(true);
|
||||
expect(isActionableTaskRequest("Resarch the latest trends")).toBe(true);
|
||||
});
|
||||
|
||||
it("accepts 5+ word messages without punctuation", () => {
|
||||
expect(isActionableTaskRequest("do a deep dive into kubernetes networking")).toBe(true);
|
||||
expect(isActionableTaskRequest("check the logs from last deployment")).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects very short non-verb messages", () => {
|
||||
expect(isActionableTaskRequest("ok sure")).toBe(false);
|
||||
expect(isActionableTaskRequest("hi")).toBe(false);
|
||||
});
|
||||
|
||||
it("recovers latest user asks from agent transcript history", () => {
|
||||
const card = deriveRecoveredAgentRequestCard(
|
||||
makeAgent({
|
||||
lastActivityAt: Date.parse("2026-03-30T20:00:00.000Z"),
|
||||
transcriptEntries: [
|
||||
{
|
||||
entryId: "assistant-1",
|
||||
role: "assistant",
|
||||
kind: "assistant",
|
||||
text: "Sure, I'll check.",
|
||||
sessionKey: "agent:agent-1:main",
|
||||
runId: "run-1",
|
||||
source: "history",
|
||||
timestampMs: Date.parse("2026-03-30T20:00:05.000Z"),
|
||||
sequenceKey: 2,
|
||||
confirmed: true,
|
||||
fingerprint: "assistant-1",
|
||||
},
|
||||
{
|
||||
entryId: "user-1",
|
||||
role: "user",
|
||||
kind: "user",
|
||||
text: "Can you check the latest news on OpenClaw?",
|
||||
sessionKey: "agent:agent-1:main",
|
||||
runId: null,
|
||||
source: "history",
|
||||
timestampMs: Date.parse("2026-03-30T20:00:00.000Z"),
|
||||
sequenceKey: 1,
|
||||
confirmed: true,
|
||||
fingerprint: "user-1",
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
expect(card).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "history:agent:agent-1:main:1",
|
||||
title: "Can you check the latest news on OpenClaw?",
|
||||
assignedAgentId: "agent-1",
|
||||
externalThreadId: "agent:agent-1:main",
|
||||
source: "openclaw_event",
|
||||
isInferred: false,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("does not recover conversational transcript entries as tasks", () => {
|
||||
const card = deriveRecoveredAgentRequestCard(
|
||||
makeAgent({
|
||||
lastActivityAt: Date.parse("2026-03-30T20:00:00.000Z"),
|
||||
transcriptEntries: [
|
||||
{
|
||||
entryId: "user-1",
|
||||
role: "user",
|
||||
kind: "user",
|
||||
text: "are you there",
|
||||
sessionKey: "agent:agent-1:main",
|
||||
runId: null,
|
||||
source: "history",
|
||||
timestampMs: Date.parse("2026-03-30T20:00:00.000Z"),
|
||||
sequenceKey: 1,
|
||||
confirmed: true,
|
||||
fingerprint: "user-1",
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
expect(card).toBeNull();
|
||||
});
|
||||
|
||||
it("updates linked run cards to done or blocked", () => {
|
||||
const baseCard = {
|
||||
id: "task-1",
|
||||
title: "Review patch",
|
||||
description: "",
|
||||
status: "in_progress" as const,
|
||||
source: "claw3d_manual" as const,
|
||||
sourceEventId: null,
|
||||
assignedAgentId: "agent-1",
|
||||
createdAt: "2026-03-29T10:00:00.000Z",
|
||||
updatedAt: "2026-03-29T10:00:00.000Z",
|
||||
playbookJobId: null,
|
||||
runId: "run-1",
|
||||
channel: null,
|
||||
externalThreadId: null,
|
||||
lastActivityAt: null,
|
||||
notes: [],
|
||||
isArchived: false,
|
||||
isInferred: false,
|
||||
};
|
||||
const okRun: RunRecord = {
|
||||
runId: "run-1",
|
||||
agentId: "agent-1",
|
||||
agentName: "Agent One",
|
||||
startedAt: Date.parse("2026-03-29T10:00:00.000Z"),
|
||||
endedAt: Date.parse("2026-03-29T10:03:00.000Z"),
|
||||
outcome: "ok",
|
||||
trigger: "user",
|
||||
};
|
||||
const errorRun: RunRecord = {
|
||||
...okRun,
|
||||
outcome: "error",
|
||||
};
|
||||
|
||||
expect(syncCardWithLinkedRun(baseCard, [okRun]).status).toBe("review");
|
||||
expect(syncCardWithLinkedRun(baseCard, [errorRun]).status).toBe("blocked");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,137 @@
|
||||
import { createElement } from "react";
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { TaskBoardView } from "@/features/office/tasks/TaskBoardView";
|
||||
import type { TaskBoardCard } from "@/features/office/tasks/types";
|
||||
import type { AgentState } from "@/features/agents/state/store";
|
||||
import type { CronJobSummary } from "@/lib/cron/types";
|
||||
|
||||
const createCard = (overrides: Partial<TaskBoardCard> = {}): TaskBoardCard => ({
|
||||
id: "task-1",
|
||||
title: "New task",
|
||||
description: "",
|
||||
status: "todo",
|
||||
source: "claw3d_manual",
|
||||
sourceEventId: null,
|
||||
assignedAgentId: null,
|
||||
createdAt: "2026-03-29T10:00:00.000Z",
|
||||
updatedAt: "2026-03-29T10:00:00.000Z",
|
||||
playbookJobId: null,
|
||||
runId: null,
|
||||
channel: null,
|
||||
externalThreadId: null,
|
||||
lastActivityAt: null,
|
||||
notes: [],
|
||||
isArchived: false,
|
||||
isInferred: false,
|
||||
...overrides,
|
||||
});
|
||||
|
||||
const createAgent = (): AgentState => ({
|
||||
agentId: "agent-1",
|
||||
name: "Agent One",
|
||||
sessionKey: "agent:agent-1:main",
|
||||
status: "idle",
|
||||
sessionCreated: true,
|
||||
awaitingUserInput: false,
|
||||
hasUnseenActivity: false,
|
||||
outputLines: [],
|
||||
lastResult: null,
|
||||
lastDiff: null,
|
||||
runId: null,
|
||||
runStartedAt: null,
|
||||
streamText: null,
|
||||
thinkingTrace: null,
|
||||
latestOverride: null,
|
||||
latestOverrideKind: null,
|
||||
lastAssistantMessageAt: null,
|
||||
lastActivityAt: null,
|
||||
latestPreview: null,
|
||||
lastUserMessage: null,
|
||||
draft: "",
|
||||
sessionSettingsSynced: true,
|
||||
historyLoadedAt: null,
|
||||
historyFetchLimit: null,
|
||||
historyFetchedCount: null,
|
||||
historyMaybeTruncated: false,
|
||||
toolCallingEnabled: true,
|
||||
showThinkingTraces: true,
|
||||
model: "openai/gpt-5",
|
||||
thinkingLevel: "medium",
|
||||
avatarSeed: "seed-1",
|
||||
avatarUrl: null,
|
||||
});
|
||||
|
||||
const createCronJob = (): CronJobSummary => ({
|
||||
id: "job-1",
|
||||
name: "Morning review",
|
||||
agentId: "agent-1",
|
||||
enabled: true,
|
||||
updatedAtMs: Date.now(),
|
||||
schedule: { kind: "every", everyMs: 60_000 },
|
||||
sessionTarget: "isolated",
|
||||
wakeMode: "now",
|
||||
payload: { kind: "agentTurn", message: "Review new tasks." },
|
||||
state: {},
|
||||
});
|
||||
|
||||
describe("TaskBoardView", () => {
|
||||
it("routes task edits through callbacks", () => {
|
||||
const onCreateCard = vi.fn();
|
||||
const onMoveCard = vi.fn();
|
||||
const onSelectCard = vi.fn();
|
||||
const onUpdateCard = vi.fn();
|
||||
const onDeleteCard = vi.fn();
|
||||
const onRefreshCronJobs = vi.fn();
|
||||
const selectedCard = createCard();
|
||||
|
||||
render(
|
||||
createElement(TaskBoardView, {
|
||||
title: "Kanban",
|
||||
subtitle: "Track tasks.",
|
||||
agents: [createAgent()],
|
||||
cardsByStatus: {
|
||||
todo: [selectedCard],
|
||||
in_progress: [],
|
||||
blocked: [],
|
||||
review: [],
|
||||
done: [],
|
||||
},
|
||||
selectedCard,
|
||||
activeRuns: [{ runId: "run-1", agentId: "agent-1", label: "Agent One" }],
|
||||
cronJobs: [createCronJob()],
|
||||
cronLoading: false,
|
||||
cronError: null,
|
||||
onCreateCard,
|
||||
onMoveCard,
|
||||
onSelectCard,
|
||||
onUpdateCard,
|
||||
onDeleteCard,
|
||||
onRefreshCronJobs,
|
||||
})
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getAllByRole("button", { name: /new task/i })[0]!);
|
||||
fireEvent.click(screen.getByRole("button", { name: /refresh/i }));
|
||||
fireEvent.click(screen.getAllByRole("button", { name: /new task/i })[1]!);
|
||||
fireEvent.change(screen.getByLabelText("Title"), {
|
||||
target: { value: "Create marketing website" },
|
||||
});
|
||||
fireEvent.change(screen.getByLabelText("Status"), {
|
||||
target: { value: "in_progress" },
|
||||
});
|
||||
fireEvent.change(screen.getByLabelText("Assigned agent"), {
|
||||
target: { value: "agent-1" },
|
||||
});
|
||||
fireEvent.click(screen.getByRole("button", { name: /delete task/i }));
|
||||
|
||||
expect(onCreateCard).toHaveBeenCalledTimes(1);
|
||||
expect(onRefreshCronJobs).toHaveBeenCalledTimes(1);
|
||||
expect(onSelectCard).toHaveBeenCalledWith("task-1");
|
||||
expect(onUpdateCard).toHaveBeenCalledWith("task-1", { title: "Create marketing website" });
|
||||
expect(onMoveCard).toHaveBeenCalledWith("task-1", "in_progress");
|
||||
expect(onUpdateCard).toHaveBeenCalledWith("task-1", { assignedAgentId: "agent-1" });
|
||||
expect(onDeleteCard).toHaveBeenCalledWith("task-1");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,72 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import type { GatewayClient } from "@/lib/gateway/GatewayClient";
|
||||
import { GatewayResponseError } from "@/lib/gateway/errors";
|
||||
import {
|
||||
createGatewayTask,
|
||||
deleteGatewayTask,
|
||||
isUnsupportedTaskGatewayError,
|
||||
listGatewayTasks,
|
||||
updateGatewayTask,
|
||||
} from "@/lib/tasks/gateway";
|
||||
|
||||
describe("task gateway client", () => {
|
||||
it("lists tasks via tasks.list", async () => {
|
||||
const client = {
|
||||
call: vi.fn(async () => ({ tasks: [] })),
|
||||
} as unknown as GatewayClient;
|
||||
|
||||
await listGatewayTasks(client);
|
||||
|
||||
expect(client.call).toHaveBeenCalledWith("tasks.list", { includeArchived: true });
|
||||
});
|
||||
|
||||
it("creates tasks via tasks.create", async () => {
|
||||
const client = {
|
||||
call: vi.fn(async () => ({ id: "task-1", title: "Ship board", status: "todo" })),
|
||||
} as unknown as GatewayClient;
|
||||
|
||||
await createGatewayTask(client, {
|
||||
title: "Ship board",
|
||||
description: "Release the board.",
|
||||
status: "todo",
|
||||
source: "claw3d_manual",
|
||||
});
|
||||
|
||||
expect(client.call).toHaveBeenCalledWith(
|
||||
"tasks.create",
|
||||
expect.objectContaining({
|
||||
title: "Ship board",
|
||||
description: "Release the board.",
|
||||
status: "todo",
|
||||
source: "claw3d_manual",
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
it("updates and deletes tasks via gateway methods", async () => {
|
||||
const client = {
|
||||
call: vi.fn(async () => ({ ok: true })),
|
||||
} as unknown as GatewayClient;
|
||||
|
||||
await updateGatewayTask(client, "task-1", { status: "review" });
|
||||
await deleteGatewayTask(client, "task-1");
|
||||
|
||||
expect(client.call).toHaveBeenCalledWith(
|
||||
"tasks.update",
|
||||
expect.objectContaining({ id: "task-1", status: "review" })
|
||||
);
|
||||
expect(client.call).toHaveBeenCalledWith("tasks.delete", { id: "task-1" });
|
||||
});
|
||||
|
||||
it("detects unsupported task gateway methods", () => {
|
||||
expect(
|
||||
isUnsupportedTaskGatewayError(
|
||||
new GatewayResponseError({
|
||||
code: "METHOD_NOT_FOUND",
|
||||
message: "Unknown method tasks.list",
|
||||
})
|
||||
)
|
||||
).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,194 @@
|
||||
import fs from "node:fs";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
|
||||
import { DELETE, GET, PUT } from "@/app/api/task-store/route";
|
||||
|
||||
const makeTempDir = (name: string) => fs.mkdtempSync(path.join(os.tmpdir(), `${name}-`));
|
||||
|
||||
const makeRequest = (method: string, body?: unknown) =>
|
||||
new Request("http://localhost/api/task-store", {
|
||||
method,
|
||||
headers: { "content-type": "application/json" },
|
||||
body: body !== undefined ? JSON.stringify(body) : undefined,
|
||||
});
|
||||
|
||||
describe("task store route", () => {
|
||||
const priorStateDir = process.env.OPENCLAW_STATE_DIR;
|
||||
let tempDir: string | null = null;
|
||||
|
||||
afterEach(() => {
|
||||
process.env.OPENCLAW_STATE_DIR = priorStateDir;
|
||||
if (tempDir) {
|
||||
fs.rmSync(tempDir, { recursive: true, force: true });
|
||||
tempDir = null;
|
||||
}
|
||||
});
|
||||
|
||||
it("GET returns an empty task list by default", async () => {
|
||||
tempDir = makeTempDir("task-store-route-get");
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
|
||||
const response = await GET();
|
||||
const body = (await response.json()) as { tasks?: unknown[] };
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
expect(body.tasks).toEqual([]);
|
||||
});
|
||||
|
||||
it("PUT upserts a task and DELETE archives it", async () => {
|
||||
tempDir = makeTempDir("task-store-route-put");
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
|
||||
const putResponse = await PUT(
|
||||
makeRequest("PUT", {
|
||||
task: {
|
||||
id: "task-1",
|
||||
title: "Research mtulsa.com",
|
||||
status: "todo",
|
||||
source: "claw3d_manual",
|
||||
},
|
||||
})
|
||||
);
|
||||
const putBody = (await putResponse.json()) as {
|
||||
task?: { id?: string; isArchived?: boolean; history?: Array<{ type?: string }> };
|
||||
};
|
||||
|
||||
expect(putResponse.status).toBe(200);
|
||||
expect(putBody.task?.id).toBe("task-1");
|
||||
expect(putBody.task?.history?.[0]?.type).toBe("created");
|
||||
|
||||
const deleteResponse = await DELETE(
|
||||
makeRequest("DELETE", { id: "task-1" })
|
||||
);
|
||||
const deleteBody = (await deleteResponse.json()) as {
|
||||
task?: { isArchived?: boolean; history?: Array<{ type?: string }> };
|
||||
};
|
||||
|
||||
expect(deleteResponse.status).toBe(200);
|
||||
expect(deleteBody.task?.isArchived).toBe(true);
|
||||
expect(deleteBody.task?.history?.some((entry) => entry.type === "archived")).toBe(true);
|
||||
});
|
||||
|
||||
it("PUT returns 400 for missing task payload", async () => {
|
||||
tempDir = makeTempDir("task-store-route-put-no-task");
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
|
||||
const response = await PUT(makeRequest("PUT", { notTask: true }));
|
||||
expect(response.status).toBe(400);
|
||||
const body = (await response.json()) as { error?: string };
|
||||
expect(body.error).toContain("Task payload is required");
|
||||
});
|
||||
|
||||
it("PUT returns 400 for empty id or title", async () => {
|
||||
tempDir = makeTempDir("task-store-route-put-empty");
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
|
||||
const response = await PUT(
|
||||
makeRequest("PUT", { task: { id: "", title: "Something" } })
|
||||
);
|
||||
expect(response.status).toBe(400);
|
||||
|
||||
const response2 = await PUT(
|
||||
makeRequest("PUT", { task: { id: "x", title: "" } })
|
||||
);
|
||||
expect(response2.status).toBe(400);
|
||||
});
|
||||
|
||||
it("PUT returns 400 for invalid status enum", async () => {
|
||||
tempDir = makeTempDir("task-store-route-put-bad-status");
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
|
||||
const response = await PUT(
|
||||
makeRequest("PUT", {
|
||||
task: { id: "t-1", title: "Test", status: "banana" },
|
||||
})
|
||||
);
|
||||
expect(response.status).toBe(400);
|
||||
const body = (await response.json()) as { error?: string };
|
||||
expect(body.error).toContain("Invalid status");
|
||||
});
|
||||
|
||||
it("PUT returns 400 for invalid source enum", async () => {
|
||||
tempDir = makeTempDir("task-store-route-put-bad-source");
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
|
||||
const response = await PUT(
|
||||
makeRequest("PUT", {
|
||||
task: { id: "t-1", title: "Test", source: "alien" },
|
||||
})
|
||||
);
|
||||
expect(response.status).toBe(400);
|
||||
const body = (await response.json()) as { error?: string };
|
||||
expect(body.error).toContain("Invalid source");
|
||||
});
|
||||
|
||||
it("PUT returns 400 for invalid JSON body", async () => {
|
||||
tempDir = makeTempDir("task-store-route-put-bad-json");
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
|
||||
const response = await PUT(
|
||||
new Request("http://localhost/api/task-store", {
|
||||
method: "PUT",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: "not valid json{{{",
|
||||
})
|
||||
);
|
||||
expect(response.status).toBe(400);
|
||||
const body = (await response.json()) as { error?: string };
|
||||
expect(body.error).toContain("Invalid JSON");
|
||||
});
|
||||
|
||||
it("DELETE returns 404 for non-existent task", async () => {
|
||||
tempDir = makeTempDir("task-store-route-delete-404");
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
|
||||
const response = await DELETE(
|
||||
makeRequest("DELETE", { id: "does-not-exist" })
|
||||
);
|
||||
expect(response.status).toBe(404);
|
||||
const body = (await response.json()) as { error?: string };
|
||||
expect(body.error).toContain("not found");
|
||||
});
|
||||
|
||||
it("DELETE returns 400 for missing id", async () => {
|
||||
tempDir = makeTempDir("task-store-route-delete-no-id");
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
|
||||
const response = await DELETE(
|
||||
makeRequest("DELETE", { id: "" })
|
||||
);
|
||||
expect(response.status).toBe(400);
|
||||
const body = (await response.json()) as { error?: string };
|
||||
expect(body.error).toContain("id is required");
|
||||
});
|
||||
|
||||
it("DELETE returns 400 for invalid JSON body", async () => {
|
||||
tempDir = makeTempDir("task-store-route-delete-bad-json");
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
|
||||
const response = await DELETE(
|
||||
new Request("http://localhost/api/task-store", {
|
||||
method: "DELETE",
|
||||
headers: { "content-type": "application/json" },
|
||||
body: "broken{",
|
||||
})
|
||||
);
|
||||
expect(response.status).toBe(400);
|
||||
});
|
||||
|
||||
it("all responses include cache-control: no-store", async () => {
|
||||
tempDir = makeTempDir("task-store-route-cache");
|
||||
process.env.OPENCLAW_STATE_DIR = tempDir;
|
||||
|
||||
const getResp = await GET();
|
||||
expect(getResp.headers.get("cache-control")).toBe("no-store");
|
||||
|
||||
const putResp = await PUT(
|
||||
makeRequest("PUT", { task: { id: "t-1", title: "T" } })
|
||||
);
|
||||
expect(putResp.headers.get("cache-control")).toBe("no-store");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user