Files
kandev/apps/web/lib/api/domains/kanban-api.test.ts
T
Carlos Florêncio bc218dfbbe feat: add workspace sources from files panel (#1900)
* feat: add workspace sources from files panel

* fix: preserve worktree identity during recovery

* feat: unify workspace source actions

* fix: validate recovered workspace repositories

* fix: harden workspace source filesystem boundaries

* test: split workspace repository chip coverage

* fix: restrict repository rescan recovery paths

* fix: stabilize workspace source CI checks

* test: canonicalize workspace source paths

* test: align workspace source container paths

* fix: populate direct workspace repository names

* test: preserve git fixture rewrites across restarts

* test: isolate backend git fixture config

* fix: resume remote workspace executions before creation

* fix: preserve ssh agent identity during resume

* fix: preserve SSH workspace across backend restart

* fix: simplify workspace actions trigger

* fix: refine add workspace repositories UX

* docs: narrow workspace source UX updates

* fix: avoid phantom turn on session resume

* test(web): normalize workspace source request headers

* feat(web): streamline workspace source picker

* docs: remove trailing spaces from workspace source plan

* fix: prevent resume status from creating phantom turns

* fix(web): stabilize workspace source attachment

* refactor(web): extract workspace source store contract

* fix: avoid phantom turns on idle agent resume

* fix: address backend static analysis findings

* fix: preserve agentctl readiness status value

* fix: preserve resume messages without active turns

* fix: resume agents from promoted workspace root

* chore: merge origin/main into feature/add-new-repo-folder-d97

* feat(web): explain workspace source consequences

* test(websocket): count session activity subscription
2026-07-25 21:29:53 +01:00

82 lines
2.7 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { attachTaskWorkspaceSources, detachTask } from "./kanban-api";
const fetchSpy = vi.fn<typeof fetch>();
beforeEach(() => {
fetchSpy.mockReset();
vi.stubGlobal("fetch", fetchSpy);
});
afterEach(() => vi.unstubAllGlobals());
describe("detachTask", () => {
it("posts without a body to the canonical detach endpoint", async () => {
fetchSpy.mockResolvedValueOnce(
new Response(JSON.stringify({ id: "child-1", parent_id: "" }), {
status: 200,
headers: { "Content-Type": "application/json" },
}),
);
await detachTask("child-1", { baseUrl: "http://api.test" });
expect(fetchSpy).toHaveBeenCalledOnce();
const [url, init] = fetchSpy.mock.calls[0];
expect(url).toBe("http://api.test/api/v1/tasks/child-1/detach");
expect(init?.method).toBe("POST");
expect(init?.body).toBeUndefined();
});
});
describe("attachTaskWorkspaceSources", () => {
it("posts the exact mixed-source payload and returns the persisted projection", async () => {
fetchSpy.mockResolvedValueOnce(
new Response(
JSON.stringify({
task_id: "task-1",
repositories: [],
workspace_folders: [
{ id: "folder-1", local_path: "/docs", display_name: "docs", position: 0 },
],
workspace_path: "/workspace/task-1",
session_ids: ["session-1"],
}),
{ status: 200, headers: { "Content-Type": "application/json" } },
),
);
await expect(
attachTaskWorkspaceSources(
"task-1",
{ sources: [{ kind: "folder", local_path: "/docs", display_name: "docs" }] },
{ baseUrl: "http://api.test" },
),
).resolves.toMatchObject({ task_id: "task-1", workspace_path: "/workspace/task-1" });
expect(fetchSpy).toHaveBeenCalledOnce();
const [url, init] = fetchSpy.mock.calls[0];
expect(url).toBe("http://api.test/api/v1/tasks/task-1/workspace-sources");
expect(init).toMatchObject({
method: "POST",
body: JSON.stringify({
sources: [{ kind: "folder", local_path: "/docs", display_name: "docs" }],
}),
});
expect(new Headers(init?.headers).get("Content-Type")).toBe("application/json");
});
it("preserves normalized API errors for retry UI", async () => {
fetchSpy.mockResolvedValueOnce(
new Response(JSON.stringify({ error: "task has an active turn" }), {
status: 409,
headers: { "Content-Type": "application/json" },
}),
);
await expect(
attachTaskWorkspaceSources("task-1", { sources: [] }, { baseUrl: "http://api.test" }),
).rejects.toMatchObject({ name: "ApiError", status: 409, message: "task has an active turn" });
});
});