feat(ui): édition templates — nom d'agent par défaut, permissions système et MCP outils — #242

TemplateEditor/TemplatesPanel étendus aux nouveaux champs, projection
useTemplates/adapters/ports, panneau Agents aligné, templatePresentation.ts
extrait. Tests frontend étendus (templates, agents, routage chat WS).
This commit is contained in:
2026-08-23 11:00:04 +02:00
parent d6c80be56d
commit f952807882
13 changed files with 551 additions and 174 deletions

View File

@ -152,6 +152,45 @@ describe("TemplatesPanel (with MockTemplateGateway)", () => {
expect(screen.getByText("v1")).toBeTruthy();
});
it("creates a template with default agent name, model and permissions summaries", async () => {
const agent = new MockAgentGateway();
const tmpl = new MockTemplateGateway(agent);
renderTemplatesPanel({ agent, template: tmpl });
await waitForTemplatesIdle();
fireEvent.click(screen.getByRole("button", { name: "create template" }));
await waitFor(() => expect(screen.getByLabelText("template name")).toBeTruthy());
fireEvent.change(screen.getByLabelText("template name"), {
target: { value: "Main template" },
});
fireEvent.change(screen.getByLabelText("template content"), {
target: { value: "# Main instructions" },
});
fireEvent.change(screen.getByLabelText("template default agent name"), {
target: { value: "Main" },
});
fireEvent.change(screen.getByLabelText("template default profile"), {
target: { value: "profile-main" },
});
chooseDropdownOption("template system network permission", "Réseau autorisé");
fireEvent.click(screen.getByLabelText("template MCP tool idea_ticket_read"));
fireEvent.click(screen.getByRole("button", { name: "Save template" }));
await screen.findByText("Main template");
expect(screen.getByText("agent initial: Main")).toBeTruthy();
expect(screen.getByText("modèle: Profil profile-main")).toBeTruthy();
expect(screen.getByText(/Système: réseau autorisé/)).toBeTruthy();
expect(screen.getByText(/MCP: Lire un ticket/)).toBeTruthy();
const templates = await tmpl.listTemplates();
expect(templates[0]).toMatchObject({
defaultAgentName: "Main",
defaultProfileId: "profile-main",
systemPermissions: { network: "allow" },
mcpToolPermissions: { allowedTools: ["idea_ticket_read"] },
});
});
it("the Create button is disabled when the name is empty", async () => {
renderTemplatesPanel();
await waitForTemplatesIdle();
@ -234,6 +273,32 @@ describe("TemplatesPanel (with MockTemplateGateway)", () => {
});
});
it("creating an agent from a template applies the displayed default name and profile", async () => {
const agent = new MockAgentGateway();
const tmpl = new MockTemplateGateway(agent);
await tmpl.createTemplate({
name: "Worker template",
content: "## ctx",
defaultProfileId: "profile-worker",
defaultAgentName: "Worker",
});
renderTemplatesPanel({ agent, template: tmpl });
await screen.findByText("Worker template");
expect(screen.getByText("agent initial: Worker")).toBeTruthy();
expect(screen.getByText("modèle: Profil profile-worker")).toBeTruthy();
fireEvent.click(
screen.getByRole("button", { name: "create agent from Worker template" }),
);
await waitFor(async () => {
const agents = await agent.listAgents(PROJECT_ID);
expect(agents).toHaveLength(1);
expect(agents[0].name).toBe("Worker");
expect(agents[0].profileId).toBe("profile-worker");
});
});
it("TemplateEditor: can switch Edit/Preview tabs and Save persists the template", async () => {
const agent = new MockAgentGateway();
const tmpl = new MockTemplateGateway(agent);