6b938b61cb
Co-authored-by: Carlos Florencio <carlosmflorencio@gmail.com>
83 lines
3.0 KiB
TypeScript
83 lines
3.0 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { renderHook } from "@testing-library/react";
|
|
import type { Executor } from "@/lib/types/http";
|
|
import type { AgentProfileOption } from "@/lib/state/slices/settings/types";
|
|
import { computeExecutorHint, useAgentProfileOptions } from "./task-create-dialog-options";
|
|
|
|
function profileOption(id: string, enabled?: boolean): AgentProfileOption {
|
|
return {
|
|
id,
|
|
label: `Agent • ${id}`,
|
|
agent_id: "a1",
|
|
agent_name: "agent",
|
|
cli_passthrough: false,
|
|
enabled,
|
|
};
|
|
}
|
|
|
|
function exec(id: string, type: Executor["type"]): Executor {
|
|
return { id, type, name: id } as Executor;
|
|
}
|
|
|
|
const WORKTREE_SINGLE = "A git worktree will be created from the base branch.";
|
|
const WORKTREE_MULTI =
|
|
"A git worktree will be created for each repository in a parent folder. The agent runs in that parent folder so it can see every worktree side by side.";
|
|
const DOCKER =
|
|
"A Docker container will be created from the selected base branch and checked out on a task branch.";
|
|
const LOCAL = "The agent will run directly on the repository.";
|
|
|
|
describe("computeExecutorHint", () => {
|
|
const executors = [
|
|
exec("wt", "worktree"),
|
|
exec("loc", "local"),
|
|
exec("docker", "local_docker"),
|
|
exec("remote-docker", "remote_docker"),
|
|
];
|
|
|
|
it("returns the multi-repo worktree hint when more than one repo is selected", () => {
|
|
expect(computeExecutorHint(executors, "wt", 2)).toBe(WORKTREE_MULTI);
|
|
});
|
|
|
|
it("returns the single-repo worktree hint when exactly one repo is selected", () => {
|
|
expect(computeExecutorHint(executors, "wt", 1)).toBe(WORKTREE_SINGLE);
|
|
});
|
|
|
|
it("explains that Docker profiles create an isolated task branch", () => {
|
|
expect(computeExecutorHint(executors, "docker", 1)).toBe(DOCKER);
|
|
expect(computeExecutorHint(executors, "remote-docker", 1)).toBe(DOCKER);
|
|
});
|
|
|
|
it("returns the local hint regardless of repoCount", () => {
|
|
expect(computeExecutorHint(executors, "loc", 1)).toBe(LOCAL);
|
|
expect(computeExecutorHint(executors, "loc", 5)).toBe(LOCAL);
|
|
});
|
|
|
|
it("returns null for an unknown executor id", () => {
|
|
expect(computeExecutorHint(executors, "nope", 1)).toBeNull();
|
|
});
|
|
|
|
it("returns null for an unrecognised executor type", () => {
|
|
const odd = [exec("x", "remote" as Executor["type"])];
|
|
expect(computeExecutorHint(odd, "x", 1)).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe("useAgentProfileOptions", () => {
|
|
it("omits disabled profiles from the selectable options", () => {
|
|
const { result } = renderHook(() =>
|
|
useAgentProfileOptions([
|
|
profileOption("p-enabled"),
|
|
profileOption("p-disabled", false),
|
|
profileOption("p-legacy"),
|
|
]),
|
|
);
|
|
const ids = result.current.map((o) => o.value);
|
|
expect(ids).toEqual(["p-enabled", "p-legacy"]);
|
|
});
|
|
|
|
it("keeps profiles whose enabled flag is absent (legacy options)", () => {
|
|
const { result } = renderHook(() => useAgentProfileOptions([profileOption("p-legacy")]));
|
|
expect(result.current.map((o) => o.value)).toEqual(["p-legacy"]);
|
|
});
|
|
});
|