feat(ui): cellule agent stoppé — état explicite + reopen from scratch (#197, QA verte)
Surface UI du LayoutGrid pour un agent de cellule stoppé: - Affichage d'un état explicite quand runtimeState vaut « stopped » ou « failedStart », avec actions refresh / reopen from scratch (freshStart) et état restarting pendant la relance. - theme.css: styles .stopped-agent-cell (boutons primary/secondary, états disabled). Consomme le contrat runtime issu de #196 (AgentRuntimeState stopped/failedStart, freshStart) déjà présent dans develop; aucune modification runtime ici. Tests QA verts: LayoutGrid.test.tsx, LayoutGrid.chat.test.tsx (rejoué aussi: agent_lifecycle launch_fresh_start_ignores_existing_conversation_id_and_mints_new_one).
This commit is contained in:
@ -12,7 +12,12 @@ import { describe, it, expect, vi } from "vitest";
|
||||
import { render, screen, waitFor, fireEvent } from "@testing-library/react";
|
||||
|
||||
import type { Gateways } from "@/ports";
|
||||
import { MockLayoutGateway, MockTerminalGateway } from "@/adapters/mock";
|
||||
import {
|
||||
MockAgentGateway,
|
||||
MockLayoutGateway,
|
||||
MockTerminalGateway,
|
||||
MockWorkStateGateway,
|
||||
} from "@/adapters/mock";
|
||||
import { DIProvider } from "@/app/di";
|
||||
import { leaves } from "./layout";
|
||||
import { LayoutGrid } from "./LayoutGrid";
|
||||
@ -181,4 +186,264 @@ describe("LayoutGrid (with MockLayoutGateway)", () => {
|
||||
).not.toThrow();
|
||||
expect(screen.getByTestId("layout-grid")).toBeTruthy();
|
||||
});
|
||||
|
||||
it("renders an explicit stopped-agent cell without showing it as idle", async () => {
|
||||
const layout = new MockLayoutGateway();
|
||||
const agent = new MockAgentGateway();
|
||||
const workState = new MockWorkStateGateway();
|
||||
const created = await agent.createAgent("p1", {
|
||||
name: "StoppedAgent",
|
||||
profileId: "prof-1",
|
||||
});
|
||||
const tree = await layout.loadLayout("p1");
|
||||
const leafId = leaves(tree)[0].id;
|
||||
await layout.mutateLayout("p1", {
|
||||
type: "setCellAgent",
|
||||
target: leafId,
|
||||
agent: created.id,
|
||||
});
|
||||
await layout.mutateLayout("p1", {
|
||||
type: "setSession",
|
||||
target: leafId,
|
||||
session: "dead-session",
|
||||
});
|
||||
workState._setProjectWorkState("p1", {
|
||||
agents: [
|
||||
{
|
||||
agentId: created.id,
|
||||
name: "StoppedAgent",
|
||||
profileId: "prof-1",
|
||||
runtimeState: "stopped",
|
||||
busy: { state: "idle" },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
render(
|
||||
<DIProvider gateways={{ layout, agent, workState } as unknown as Gateways}>
|
||||
<LayoutGrid projectId="p1" cwd="/home/me/proj" />
|
||||
</DIProvider>,
|
||||
);
|
||||
|
||||
expect(await screen.findByLabelText("StoppedAgent arrêté")).toBeTruthy();
|
||||
expect(screen.getByText("Arrêté")).toBeTruthy();
|
||||
expect(screen.getByText("Cette session est terminée.")).toBeTruthy();
|
||||
expect(screen.getByText("Ouvre une nouvelle session pour cet agent.")).toBeTruthy();
|
||||
expect(screen.getByRole("button", { name: "Relancer" })).toBeTruthy();
|
||||
expect(screen.getByRole("button", { name: "Actualiser" })).toBeTruthy();
|
||||
expect(screen.queryByText("Idle")).toBeNull();
|
||||
});
|
||||
|
||||
it("relaunches a stopped agent from scratch in the same cell", async () => {
|
||||
const layout = new MockLayoutGateway();
|
||||
const agent = new MockAgentGateway();
|
||||
const workState = new MockWorkStateGateway();
|
||||
const launchSpy = vi.spyOn(agent, "launchAgent");
|
||||
const created = await agent.createAgent("p1", {
|
||||
name: "StoppedAgent",
|
||||
profileId: "prof-1",
|
||||
});
|
||||
const tree = await layout.loadLayout("p1");
|
||||
const leafId = leaves(tree)[0].id;
|
||||
await layout.mutateLayout("p1", {
|
||||
type: "setCellAgent",
|
||||
target: leafId,
|
||||
agent: created.id,
|
||||
});
|
||||
await layout.mutateLayout("p1", {
|
||||
type: "setSession",
|
||||
target: leafId,
|
||||
session: "dead-session",
|
||||
});
|
||||
await layout.mutateLayout("p1", {
|
||||
type: "setCellConversation",
|
||||
target: leafId,
|
||||
conversationId: "old-conversation",
|
||||
});
|
||||
workState._setProjectWorkState("p1", {
|
||||
agents: [
|
||||
{
|
||||
agentId: created.id,
|
||||
name: "StoppedAgent",
|
||||
profileId: "prof-1",
|
||||
runtimeState: "stopped",
|
||||
busy: { state: "idle" },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
render(
|
||||
<DIProvider gateways={{ layout, agent, workState } as unknown as Gateways}>
|
||||
<LayoutGrid projectId="p1" cwd="/home/me/proj" />
|
||||
</DIProvider>,
|
||||
);
|
||||
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Relancer" }));
|
||||
|
||||
await waitFor(() => expect(launchSpy).toHaveBeenCalledTimes(1));
|
||||
expect(launchSpy.mock.calls[0]?.[0]).toBe("p1");
|
||||
expect(launchSpy.mock.calls[0]?.[1]).toBe(created.id);
|
||||
expect(launchSpy.mock.calls[0]?.[2]).toMatchObject({
|
||||
cwd: "/home/me/proj",
|
||||
nodeId: leafId,
|
||||
freshStart: true,
|
||||
});
|
||||
expect(launchSpy.mock.calls[0]?.[2].conversationId).toBeUndefined();
|
||||
|
||||
await waitFor(async () => {
|
||||
const fresh = await layout.loadLayout("p1");
|
||||
const leaf = leaves(fresh)[0];
|
||||
expect(leaf.agent).toBe(created.id);
|
||||
expect(leaf.session).toMatch(/^mock-agent-session-/);
|
||||
expect(leaf.conversationId).toMatch(/^mock-conversation-/);
|
||||
});
|
||||
});
|
||||
|
||||
it("refreshes a stopped agent state without relaunching", async () => {
|
||||
const layout = new MockLayoutGateway();
|
||||
const agent = new MockAgentGateway();
|
||||
const workState = new MockWorkStateGateway();
|
||||
const refreshSpy = vi.spyOn(workState, "getProjectWorkState");
|
||||
const launchSpy = vi.spyOn(agent, "launchAgent");
|
||||
const created = await agent.createAgent("p1", {
|
||||
name: "StoppedAgent",
|
||||
profileId: "prof-1",
|
||||
});
|
||||
const tree = await layout.loadLayout("p1");
|
||||
const leafId = leaves(tree)[0].id;
|
||||
await layout.mutateLayout("p1", {
|
||||
type: "setCellAgent",
|
||||
target: leafId,
|
||||
agent: created.id,
|
||||
});
|
||||
await layout.mutateLayout("p1", {
|
||||
type: "setSession",
|
||||
target: leafId,
|
||||
session: "dead-session",
|
||||
});
|
||||
workState._setProjectWorkState("p1", {
|
||||
agents: [
|
||||
{
|
||||
agentId: created.id,
|
||||
name: "StoppedAgent",
|
||||
profileId: "prof-1",
|
||||
runtimeState: "stopped",
|
||||
busy: { state: "idle" },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
render(
|
||||
<DIProvider gateways={{ layout, agent, workState } as unknown as Gateways}>
|
||||
<LayoutGrid projectId="p1" cwd="/home/me/proj" />
|
||||
</DIProvider>,
|
||||
);
|
||||
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Actualiser" }));
|
||||
|
||||
await waitFor(() => expect(refreshSpy).toHaveBeenCalledTimes(2));
|
||||
expect(launchSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("shows the transient restart label while relaunching", async () => {
|
||||
const layout = new MockLayoutGateway();
|
||||
const agent = new MockAgentGateway();
|
||||
const workState = new MockWorkStateGateway();
|
||||
let resolveLaunch!: (value: Awaited<ReturnType<MockAgentGateway["launchAgent"]>>) => void;
|
||||
const launchPromise = new Promise<Awaited<ReturnType<MockAgentGateway["launchAgent"]>>>(
|
||||
(resolve) => {
|
||||
resolveLaunch = resolve;
|
||||
},
|
||||
);
|
||||
vi.spyOn(agent, "launchAgent").mockReturnValue(launchPromise);
|
||||
const created = await agent.createAgent("p1", {
|
||||
name: "StoppedAgent",
|
||||
profileId: "prof-1",
|
||||
});
|
||||
const tree = await layout.loadLayout("p1");
|
||||
const leafId = leaves(tree)[0].id;
|
||||
await layout.mutateLayout("p1", {
|
||||
type: "setCellAgent",
|
||||
target: leafId,
|
||||
agent: created.id,
|
||||
});
|
||||
workState._setProjectWorkState("p1", {
|
||||
agents: [
|
||||
{
|
||||
agentId: created.id,
|
||||
name: "StoppedAgent",
|
||||
profileId: "prof-1",
|
||||
runtimeState: "stopped",
|
||||
busy: { state: "idle" },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
render(
|
||||
<DIProvider gateways={{ layout, agent, workState } as unknown as Gateways}>
|
||||
<LayoutGrid projectId="p1" cwd="/home/me/proj" />
|
||||
</DIProvider>,
|
||||
);
|
||||
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Relancer" }));
|
||||
|
||||
await waitFor(() => expect(screen.getAllByText("Relance…")).toHaveLength(2));
|
||||
expect(
|
||||
(screen.getByRole("button", { name: "Relance…" }) as HTMLButtonElement)
|
||||
.disabled,
|
||||
).toBe(true);
|
||||
|
||||
resolveLaunch({
|
||||
sessionId: "mock-agent-session-deferred",
|
||||
assignedConversationId: "mock-conversation-deferred",
|
||||
write: async () => {},
|
||||
resize: async () => {},
|
||||
detach: () => {},
|
||||
close: async () => {},
|
||||
});
|
||||
});
|
||||
|
||||
it("shows the stopped-cell restart error copy when relaunch fails", async () => {
|
||||
const layout = new MockLayoutGateway();
|
||||
const agent = new MockAgentGateway();
|
||||
const workState = new MockWorkStateGateway();
|
||||
const created = await agent.createAgent("p1", {
|
||||
name: "StoppedAgent",
|
||||
profileId: "prof-1",
|
||||
});
|
||||
vi.spyOn(agent, "launchAgent").mockRejectedValue(
|
||||
new Error("launch failed"),
|
||||
);
|
||||
const tree = await layout.loadLayout("p1");
|
||||
const leafId = leaves(tree)[0].id;
|
||||
await layout.mutateLayout("p1", {
|
||||
type: "setCellAgent",
|
||||
target: leafId,
|
||||
agent: created.id,
|
||||
});
|
||||
workState._setProjectWorkState("p1", {
|
||||
agents: [
|
||||
{
|
||||
agentId: created.id,
|
||||
name: "StoppedAgent",
|
||||
profileId: "prof-1",
|
||||
runtimeState: "stopped",
|
||||
busy: { state: "idle" },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
render(
|
||||
<DIProvider gateways={{ layout, agent, workState } as unknown as Gateways}>
|
||||
<LayoutGrid projectId="p1" cwd="/home/me/proj" />
|
||||
</DIProvider>,
|
||||
);
|
||||
|
||||
fireEvent.click(await screen.findByRole("button", { name: "Relancer" }));
|
||||
|
||||
expect(await screen.findByText("Erreur de relance")).toBeTruthy();
|
||||
expect(
|
||||
screen.getByText("Impossible de relancer l’agent. Réessayez."),
|
||||
).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user