Files
AgentCompany/tests/unit/task-helpers.test.ts
T
2026-10-08 08:19:41 -04:00

24 lines
1.5 KiB
TypeScript

import { describe, expect, test } from "vitest";
import { descendantIds, runBlocker } from "../../src/renderer/src/pages/work/task-helpers";
import type { ProviderRecord, TaskRecord, TaskRunRecord } from "../../src/shared/domain";
const provider = { enabled: true, authState: "configured" } as ProviderRecord;
const task = (status: TaskRecord["status"]) => ({ id: "tsk_1", status }) as TaskRecord;
const run = (state: string, taskId = "tsk_1") => ({ taskId, state }) as TaskRunRecord;
describe("work task helpers", () => {
test("a manual run needs a provider, an open task and no session in flight", () => {
expect(runBlocker(task("in_progress"), provider, [run("completed"), run("running", "tsk_other")])).toBeNull();
expect(runBlocker(task("in_progress"), null, [])).toBe("Connect a provider to run");
expect(runBlocker(task("done"), provider, [])).toBe("Done tasks do not run");
expect(runBlocker(task("backlog"), provider, [run("queued")])).toBe("A session is already queued or running");
expect(runBlocker(task("review"), provider, [run("running")])).toBe("A session is already queued or running");
});
test("descendants are found through every level, so the parent picker can leave them out", () => {
const tree = [["b", "a"], ["c", "b"], ["d", null], ["e", "c"]].map(([id, parentTaskId]) => ({ id, parentTaskId }) as TaskRecord);
expect([...descendantIds("a", tree)].sort()).toEqual(["b", "c", "e"]);
expect([...descendantIds("d", tree)]).toEqual([]);
});
});