feat(agent): UI hot-swap de profil (A2) — commande Tauri + sélecteur + dialog
- Tauri : commande change_agent_profile + ChangeAgentProfileRequestDto/Dto (camelCase, relaunchedSession omis si None), câblage state.rs par composition. - Front : gateway changeAgentProfile (adapters Tauri+mock), sélecteur de profil par agent, dialog de confirmation FR (« Changer le moteur abandonne l'historique de conversation… »), refresh sur event agentProfileChanged. Tests : app-tauri dto 5/5 ; vitest 314/314 (mapping, payload, dialog gating, libellé FR, refresh). 0 régression. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -390,6 +390,125 @@ describe("MockAgentGateway (unit)", () => {
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// A2 — profile hot-swap selector + confirmation dialog
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
/** Seeds two profiles so an agent's engine can be swapped to a different one. */
|
||||
async function seededProfiles(): Promise<MockProfileGateway> {
|
||||
const profile = new MockProfileGateway();
|
||||
await profile.configureProfiles([
|
||||
{
|
||||
id: "prof-1",
|
||||
name: "Claude Code",
|
||||
command: "claude",
|
||||
args: [],
|
||||
contextInjection: { strategy: "conventionFile", target: "CLAUDE.md" },
|
||||
detect: null,
|
||||
cwdTemplate: "{projectRoot}",
|
||||
},
|
||||
{
|
||||
id: "prof-2",
|
||||
name: "Codex CLI",
|
||||
command: "codex",
|
||||
args: [],
|
||||
contextInjection: { strategy: "conventionFile", target: "AGENTS.md" },
|
||||
detect: null,
|
||||
cwdTemplate: "{projectRoot}",
|
||||
},
|
||||
]);
|
||||
return profile;
|
||||
}
|
||||
|
||||
describe("AgentsPanel profile hot-swap (A2)", () => {
|
||||
it("changing the profile select does NOT call changeAgentProfile immediately — it opens a confirmation dialog", async () => {
|
||||
const agent = new MockAgentGateway();
|
||||
await agent.createAgent(PROJECT_ID, { name: "Swap", profileId: "prof-1" });
|
||||
const swapSpy = vi.spyOn(agent, "changeAgentProfile");
|
||||
|
||||
renderPanel(agent, await seededProfiles());
|
||||
await waitForIdle();
|
||||
await screen.findByText("Swap");
|
||||
|
||||
const select = screen.getByLabelText("profile for Swap") as HTMLSelectElement;
|
||||
fireEvent.change(select, { target: { value: "prof-2" } });
|
||||
|
||||
// No gateway call yet — only the dialog appears.
|
||||
expect(swapSpy).not.toHaveBeenCalled();
|
||||
expect(screen.getByRole("dialog")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("Cancel closes the dialog without calling changeAgentProfile", async () => {
|
||||
const agent = new MockAgentGateway();
|
||||
await agent.createAgent(PROJECT_ID, { name: "Swap", profileId: "prof-1" });
|
||||
const swapSpy = vi.spyOn(agent, "changeAgentProfile");
|
||||
|
||||
renderPanel(agent, await seededProfiles());
|
||||
await waitForIdle();
|
||||
await screen.findByText("Swap");
|
||||
|
||||
fireEvent.change(screen.getByLabelText("profile for Swap"), {
|
||||
target: { value: "prof-2" },
|
||||
});
|
||||
fireEvent.click(
|
||||
screen.getByRole("button", { name: "cancel profile change" }),
|
||||
);
|
||||
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).toBeNull());
|
||||
expect(swapSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("Continue confirms and calls changeAgentProfile with the chosen profile", async () => {
|
||||
const agent = new MockAgentGateway();
|
||||
const created = await agent.createAgent(PROJECT_ID, {
|
||||
name: "Swap",
|
||||
profileId: "prof-1",
|
||||
});
|
||||
const swapSpy = vi.spyOn(agent, "changeAgentProfile");
|
||||
|
||||
renderPanel(agent, await seededProfiles());
|
||||
await waitForIdle();
|
||||
await screen.findByText("Swap");
|
||||
|
||||
fireEvent.change(screen.getByLabelText("profile for Swap"), {
|
||||
target: { value: "prof-2" },
|
||||
});
|
||||
fireEvent.click(
|
||||
screen.getByRole("button", { name: "confirm profile change" }),
|
||||
);
|
||||
|
||||
await waitFor(() => {
|
||||
expect(swapSpy).toHaveBeenCalled();
|
||||
expect(swapSpy.mock.calls[0][0]).toBe(PROJECT_ID);
|
||||
expect(swapSpy.mock.calls[0][1]).toBe(created.id);
|
||||
expect(swapSpy.mock.calls[0][2]).toBe("prof-2");
|
||||
});
|
||||
// Dialog closes after confirmation.
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).toBeNull());
|
||||
});
|
||||
|
||||
it("the confirmation dialog message is in FRENCH and conveys the spec §15.1 wording", async () => {
|
||||
const agent = new MockAgentGateway();
|
||||
await agent.createAgent(PROJECT_ID, { name: "Swap", profileId: "prof-1" });
|
||||
|
||||
renderPanel(agent, await seededProfiles());
|
||||
await waitForIdle();
|
||||
await screen.findByText("Swap");
|
||||
|
||||
fireEvent.change(screen.getByLabelText("profile for Swap"), {
|
||||
target: { value: "prof-2" },
|
||||
});
|
||||
|
||||
const dialog = screen.getByRole("dialog");
|
||||
const text = dialog.textContent ?? "";
|
||||
// Spec §15.1: « Changer le moteur abandonne l'historique de conversation
|
||||
// (le contexte et la mémoire sont conservés). Continuer ? » — must be FRENCH.
|
||||
expect(text).toMatch(/abandonne l'historique de conversation/i);
|
||||
expect(text).toMatch(/contexte et la mémoire sont conservés/i);
|
||||
expect(text).toMatch(/Continuer\s*\?/);
|
||||
});
|
||||
});
|
||||
|
||||
describe("AgentsPanel live refresh on domain events", () => {
|
||||
it("refreshes the list when an `agentLaunched` event fires (out-of-band creation)", async () => {
|
||||
const agent = new MockAgentGateway();
|
||||
@ -423,6 +542,38 @@ describe("AgentsPanel live refresh on domain events", () => {
|
||||
expect(await screen.findByText("Orchestrated")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("refreshes the list when an `agentProfileChanged` event fires (A2 hot-swap)", async () => {
|
||||
const agent = new MockAgentGateway();
|
||||
const profile = new MockProfileGateway();
|
||||
const system = new MockSystemGateway();
|
||||
const template = new MockTemplateGateway(agent);
|
||||
const gateways = { agent, profile, system, template } as unknown as Gateways;
|
||||
|
||||
const created = await agent.createAgent(PROJECT_ID, {
|
||||
name: "Swapper",
|
||||
profileId: "p1",
|
||||
});
|
||||
|
||||
render(
|
||||
<DIProvider gateways={gateways}>
|
||||
<AgentsPanel projectId={PROJECT_ID} projectRoot="/home/me/proj" />
|
||||
</DIProvider>,
|
||||
);
|
||||
await waitFor(() => expect(screen.getByText("Swapper")).toBeTruthy());
|
||||
|
||||
// Mutate the profile out of band, then emit the event the backend relays.
|
||||
await agent.changeAgentProfile(PROJECT_ID, created.id, "p2", 24, 80);
|
||||
const refreshSpy = vi.spyOn(agent, "listAgents");
|
||||
system.emit({
|
||||
type: "agentProfileChanged",
|
||||
agentId: created.id,
|
||||
profileId: "p2",
|
||||
});
|
||||
|
||||
// The hook re-fetches the list on the event.
|
||||
await waitFor(() => expect(refreshSpy).toHaveBeenCalled());
|
||||
});
|
||||
|
||||
it("does not crash when the system gateway is absent", async () => {
|
||||
// The existing renderPanel helper injects no `system` gateway; the
|
||||
// subscription effect must no-op rather than throw.
|
||||
|
||||
Reference in New Issue
Block a user