121 lines
4.7 KiB
TypeScript
121 lines
4.7 KiB
TypeScript
import { test, expect } from "../../fixtures/test-base";
|
|
import { SessionPage } from "../../pages/session-page";
|
|
|
|
test.describe("MCP-created task agent profile default", () => {
|
|
test("workspace-default mode routes an omitted-profile subtask to the workspace profile", async ({
|
|
testPage,
|
|
apiClient,
|
|
seedData,
|
|
}) => {
|
|
test.setTimeout(180_000);
|
|
|
|
const workflow = (await apiClient.listWorkflows(seedData.workspaceId)).workflows.find(
|
|
(candidate) => candidate.id === seedData.workflowId,
|
|
);
|
|
const startStep = seedData.steps.find((step) => step.id === seedData.startStepId);
|
|
expect(workflow?.agent_profile_id).toBeFalsy();
|
|
expect(startStep?.agent_profile_id).toBeFalsy();
|
|
|
|
const { agents } = await apiClient.listAgents();
|
|
const workspaceProfile = await apiClient.createAgentProfile(
|
|
agents[0].id,
|
|
"MCP Workspace Default E2E",
|
|
{ model: "mock-slow" },
|
|
);
|
|
expect(workspaceProfile.id).not.toBe(seedData.agentProfileId);
|
|
await apiClient.updateWorkspace(seedData.workspaceId, {
|
|
default_agent_profile_id: workspaceProfile.id,
|
|
});
|
|
|
|
await testPage.goto("/settings/preferences/task-behavior");
|
|
await expect(testPage.getByText("create_task_kandev", { exact: true })).toBeVisible();
|
|
await expect(testPage.getByText("spawn_session_kandev", { exact: true })).toBeVisible();
|
|
const mcpToolHelp = testPage.getByRole("button", {
|
|
name: "About affected Kandev MCP tools",
|
|
});
|
|
await mcpToolHelp.hover();
|
|
await expect(testPage.getByRole("tooltip")).toContainText(
|
|
"spawn_session_kandev adds a session to the current task",
|
|
);
|
|
const workspaceDefault = testPage.getByRole("radio", {
|
|
name: "Workspace default profile",
|
|
});
|
|
await expect(workspaceDefault).not.toBeChecked();
|
|
await workspaceDefault.click();
|
|
await expect(workspaceDefault).toBeChecked();
|
|
await expect
|
|
.poll(async () => (await apiClient.getUserSettings()).settings.mcp_task_agent_profile_default)
|
|
.toBe("current_task");
|
|
await testPage
|
|
.getByTestId("settings-floating-save")
|
|
.getByRole("button", { name: "Save changes" })
|
|
.click();
|
|
await expect
|
|
.poll(async () => (await apiClient.getUserSettings()).settings.mcp_task_agent_profile_default)
|
|
.toBe("workspace_default");
|
|
|
|
await testPage.reload();
|
|
await expect(workspaceDefault).toBeChecked();
|
|
|
|
const subtaskTitle = "Workspace Default MCP Subtask E2E";
|
|
const script = [
|
|
'e2e:thinking("Creating workspace-default subtask...")',
|
|
"e2e:delay(100)",
|
|
`e2e:mcp:kandev:create_task_kandev({"parent_id":"self","title":"${subtaskTitle}","description":"E2E omitted-profile workspace-default subtask"})`,
|
|
"e2e:delay(100)",
|
|
'e2e:message("Done.")',
|
|
].join("\n");
|
|
|
|
const parent = await apiClient.createTaskWithAgent(
|
|
seedData.workspaceId,
|
|
"Workspace Default MCP Parent E2E",
|
|
seedData.agentProfileId,
|
|
{
|
|
description: script,
|
|
workflow_id: seedData.workflowId,
|
|
workflow_step_id: seedData.startStepId,
|
|
repository_ids: [seedData.repositoryId],
|
|
},
|
|
);
|
|
|
|
await testPage.goto(`/t/${parent.id}`);
|
|
const parentSession = new SessionPage(testPage);
|
|
await parentSession.waitForLoad();
|
|
// The MCP call is part of the parent agent turn. Wait for the scripted
|
|
// turn to finish before polling the task list, otherwise a busy CI worker
|
|
// can spend the whole assertion window before the call is dispatched.
|
|
await parentSession.waitForChatIdle({ timeout: 120_000 });
|
|
|
|
const parentSessions = await apiClient.listTaskSessions(parent.id);
|
|
expect(parentSessions.sessions[0]?.agent_profile_id).toBe(seedData.agentProfileId);
|
|
|
|
let subtaskId: string | undefined;
|
|
await expect
|
|
.poll(
|
|
async () => {
|
|
const { tasks } = await apiClient.listTasks(seedData.workspaceId);
|
|
subtaskId = tasks.find((task) => task.title === subtaskTitle)?.id;
|
|
return subtaskId;
|
|
},
|
|
{ timeout: 30_000, message: "Omitted-profile MCP subtask should be created" },
|
|
)
|
|
.toBeTruthy();
|
|
|
|
await expect
|
|
.poll(
|
|
async () => {
|
|
const { sessions } = await apiClient.listTaskSessions(subtaskId!);
|
|
return sessions[0]?.agent_profile_id;
|
|
},
|
|
{ timeout: 60_000, message: "MCP subtask should start with the workspace profile" },
|
|
)
|
|
.toBe(workspaceProfile.id);
|
|
|
|
const { sessions: subtaskSessions } = await apiClient.listTaskSessions(subtaskId!);
|
|
const subtaskRuntime = subtaskSessions[0]?.metadata?.runtime_config_overrides as
|
|
| { model?: string; mode?: string; config_options?: Record<string, string> }
|
|
| undefined;
|
|
expect(subtaskRuntime).toBeUndefined();
|
|
});
|
|
});
|