fix(custom-cli): affichage conversation stable au second tour — dédup du prompt et scope de progression par tour, sans reliquats du tour précédent — #251 (QA verte)

This commit is contained in:
2026-08-23 17:51:50 +02:00
parent d5fea391b2
commit 7b7ab5b95a
2 changed files with 151 additions and 35 deletions

View File

@ -1176,6 +1176,119 @@ describe("CustomAgentChatView", () => {
expect(screen.getByText("Terminé").closest(".justify-end")).toBeTruthy();
});
it("keeps successive turns isolated when backend userPrompt echoes arrive after progress (#251)", async () => {
const agent = {
launchAgentChat: vi.fn(),
reattachAgentChat: vi.fn(async (sessionId: string) => ({
sessionId,
scrollback: [],
})),
sendAgentChat: vi.fn(
async (_sessionId: string, prompt: string, onChunk: (chunk: ReplyChunk) => void) => {
onChunk({
kind: "progress",
progress: {
source: "providerNative",
kind: "tool",
stage: "started",
label: "shell",
toolName: "shell",
text: `Running ${prompt}`,
},
});
onChunk({ kind: "userPrompt", text: prompt });
onChunk({
kind: "progress",
progress: {
source: "providerNative",
kind: "tool",
stage: "completed",
label: "shell",
toolName: "shell",
text: `Done ${prompt}`,
},
});
onChunk({ kind: "final", content: `final ${prompt}` });
},
),
cancelAgentChat: vi.fn(async () => {}),
closeAgentChat: vi.fn(async () => {}),
};
render(
<DIProvider
gateways={{
agent,
system: { pickFile: vi.fn(async () => null) },
} as unknown as Gateways}
>
<CustomAgentChatView
projectId="project-1"
agentId="agent-1"
agentName="Worker"
profile={profile}
cwd="/repo"
nodeId="node-1"
sessionId="chat-session-1"
conversationId="conversation-1"
onSessionId={vi.fn()}
onConversationId={vi.fn()}
/>
</DIProvider>,
);
await waitFor(() =>
expect(agent.reattachAgentChat).toHaveBeenCalledWith(
"chat-session-1",
expect.any(Function),
),
);
fireEvent.change(screen.getByLabelText(/message CLI custom/), {
target: { value: "first request" },
});
fireEvent.click(screen.getByRole("button", { name: "Envoyer" }));
await screen.findByText("final first request");
fireEvent.change(screen.getByLabelText(/message CLI custom/), {
target: { value: "second request" },
});
fireEvent.click(screen.getByRole("button", { name: "Envoyer" }));
await screen.findByText("final second request");
expect(screen.getAllByText("first request")).toHaveLength(1);
expect(screen.getAllByText("second request")).toHaveLength(1);
expect(screen.getAllByTestId("chat-tool-progress")).toHaveLength(2);
expect(screen.queryByText("Running first request")).toBeNull();
expect(screen.queryByText("Running second request")).toBeNull();
expect(screen.getByText("Done first request")).toBeTruthy();
expect(screen.getByText("Done second request")).toBeTruthy();
expect(screen.getAllByText("Terminé")).toHaveLength(2);
const firstPrompt = screen.getByText("first request");
const firstProgress = screen.getByText("Done first request");
const firstFinal = screen.getByText("final first request");
const secondPrompt = screen.getByText("second request");
const secondProgress = screen.getByText("Done second request");
const secondFinal = screen.getByText("final second request");
expect(
Boolean(firstPrompt.compareDocumentPosition(firstProgress) & Node.DOCUMENT_POSITION_FOLLOWING),
).toBe(true);
expect(
Boolean(firstProgress.compareDocumentPosition(firstFinal) & Node.DOCUMENT_POSITION_FOLLOWING),
).toBe(true);
expect(
Boolean(firstFinal.compareDocumentPosition(secondPrompt) & Node.DOCUMENT_POSITION_FOLLOWING),
).toBe(true);
expect(
Boolean(secondPrompt.compareDocumentPosition(secondProgress) & Node.DOCUMENT_POSITION_FOLLOWING),
).toBe(true);
expect(
Boolean(secondProgress.compareDocumentPosition(secondFinal) & Node.DOCUMENT_POSITION_FOLLOWING),
).toBe(true);
});
it("renders canonical progress chunks as live agent, MCP, and delegation activity", async () => {
const agent = {
launchAgentChat: vi.fn(),
@ -2293,7 +2406,7 @@ describe("CustomAgentChatView", () => {
expect(screen.getByText("Progress").parentElement?.textContent).toContain("Terminé");
});
it("renders late progress chunks after the final answer without reopening the turn", async () => {
it("ignores late progress chunks after the final answer without reopening the turn", async () => {
let emitChunk: ((chunk: unknown) => void) | null = null;
const agent = {
launchAgentChat: vi.fn(),
@ -2368,7 +2481,7 @@ describe("CustomAgentChatView", () => {
});
expect(screen.getByText("done")).toBeTruthy();
expect(screen.getByText("idea_ticket_read")).toBeTruthy();
expect(screen.queryByText("idea_ticket_read")).toBeNull();
expect(screen.getByRole("button", { name: "Envoyer" })).toBeTruthy();
expect(screen.queryByRole("button", { name: "Stop" })).toBeNull();
});