appendProgress déduplique par entité (tool/mcp/delegation) + bucket de stage sur l'ensemble du tour, évitant le doublon entre tap live et flux autoritatif. idea_ask_agent/idea_ask_agents rendus comme Délégation. completeRunningProgress marque les entités complétées (settled) pour stopper l'animation. 2 nouveaux tests: ordre pre-MCP avant la première carte MCP, et dédup -> exactement 2 cartes Délégation pour 2 délégations.
This commit is contained in:
@ -335,6 +335,209 @@ describe("CustomAgentChatView", () => {
|
||||
await screen.findByText("done");
|
||||
});
|
||||
|
||||
it("renders available pre-MCP progress before the first MCP card", async () => {
|
||||
let emitChunk: ((chunk: unknown) => void) | null = null;
|
||||
const agent = {
|
||||
launchAgentChat: vi.fn(),
|
||||
reattachAgentChat: vi.fn(async (sessionId: string) => ({
|
||||
sessionId,
|
||||
scrollback: [],
|
||||
})),
|
||||
sendAgentChat: vi.fn(
|
||||
(_sessionId: string, _prompt: string, onChunk: (chunk: unknown) => void) =>
|
||||
new Promise<void>((resolve) => {
|
||||
emitChunk = (chunk: unknown) => {
|
||||
onChunk(chunk);
|
||||
if ((chunk as { kind?: string }).kind === "final") resolve();
|
||||
};
|
||||
}),
|
||||
),
|
||||
cancelAgentChat: vi.fn(async () => {}),
|
||||
closeAgentChat: vi.fn(async () => {}),
|
||||
};
|
||||
|
||||
const { container } = 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: "delegate after intent" },
|
||||
});
|
||||
fireEvent.click(screen.getByRole("button", { name: "Envoyer" }));
|
||||
await waitFor(() => expect(emitChunk).not.toBeNull());
|
||||
|
||||
act(() => {
|
||||
emitChunk?.({
|
||||
kind: "progress",
|
||||
progress: {
|
||||
source: "providerNative",
|
||||
kind: "message",
|
||||
stage: "delta",
|
||||
label: "Intention",
|
||||
text: "Je vais d'abord regarder les outils MCP disponibles.",
|
||||
provider: "codex",
|
||||
nativeEvent: "agent.message.delta",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
expect(
|
||||
screen.getByText("Je vais d'abord regarder les outils MCP disponibles."),
|
||||
).toBeTruthy();
|
||||
expect(screen.queryByText("idea_ask_agent")).toBeNull();
|
||||
|
||||
act(() => {
|
||||
emitChunk?.({
|
||||
kind: "progress",
|
||||
progress: {
|
||||
source: "ideaLocal",
|
||||
kind: "mcp",
|
||||
stage: "started",
|
||||
label: "idea_ask_agent",
|
||||
toolName: "idea_ask_agent",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
const intent = screen.getByText(
|
||||
"Je vais d'abord regarder les outils MCP disponibles.",
|
||||
);
|
||||
const delegation = screen.getByText("idea_ask_agent");
|
||||
expect(
|
||||
Boolean(intent.compareDocumentPosition(delegation) & Node.DOCUMENT_POSITION_FOLLOWING),
|
||||
).toBe(true);
|
||||
|
||||
act(() => {
|
||||
emitChunk?.({ kind: "final", content: "done" });
|
||||
});
|
||||
await screen.findByText("done");
|
||||
expect(container.textContent).toContain("Je vais d'abord regarder");
|
||||
});
|
||||
|
||||
it("deduplicates delegated tool progress from tap and authoritative stream", async () => {
|
||||
let emitChunk: ((chunk: unknown) => void) | null = null;
|
||||
const agent = {
|
||||
launchAgentChat: vi.fn(),
|
||||
reattachAgentChat: vi.fn(async (sessionId: string) => ({
|
||||
sessionId,
|
||||
scrollback: [],
|
||||
})),
|
||||
sendAgentChat: vi.fn(
|
||||
(_sessionId: string, _prompt: string, onChunk: (chunk: unknown) => void) =>
|
||||
new Promise<void>((resolve) => {
|
||||
emitChunk = (chunk: unknown) => {
|
||||
onChunk(chunk);
|
||||
if ((chunk as { kind?: string }).kind === "final") resolve();
|
||||
};
|
||||
}),
|
||||
),
|
||||
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: "delegate once" },
|
||||
});
|
||||
fireEvent.click(screen.getByRole("button", { name: "Envoyer" }));
|
||||
await waitFor(() => expect(emitChunk).not.toBeNull());
|
||||
|
||||
const progress = (source: "providerNative" | "ideaLocal", stage: "started" | "completed") => ({
|
||||
kind: "progress" as const,
|
||||
progress: {
|
||||
source,
|
||||
kind: source === "ideaLocal" ? ("mcp" as const) : ("tool" as const),
|
||||
stage,
|
||||
label: "idea_ask_agent",
|
||||
text: stage === "started" ? "target=QA task=validate" : "reply delivered",
|
||||
provider: source === "providerNative" ? "opencode" : undefined,
|
||||
nativeEvent:
|
||||
source === "providerNative"
|
||||
? stage === "started"
|
||||
? "tool_use"
|
||||
: "tool_done"
|
||||
: stage === "started"
|
||||
? "conversation.item.added"
|
||||
: "conversation.item.done",
|
||||
toolName: "idea_ask_agent",
|
||||
},
|
||||
});
|
||||
|
||||
act(() => {
|
||||
emitChunk?.(progress("providerNative", "started"));
|
||||
emitChunk?.(progress("ideaLocal", "started"));
|
||||
emitChunk?.(progress("providerNative", "completed"));
|
||||
emitChunk?.(progress("ideaLocal", "completed"));
|
||||
emitChunk?.(progress("providerNative", "started"));
|
||||
emitChunk?.(progress("ideaLocal", "started"));
|
||||
emitChunk?.(progress("providerNative", "completed"));
|
||||
emitChunk?.(progress("ideaLocal", "completed"));
|
||||
emitChunk?.({ kind: "final", content: "done" });
|
||||
});
|
||||
|
||||
await screen.findByText("done");
|
||||
expect(screen.getAllByText("Délégation")).toHaveLength(2);
|
||||
expect(screen.getByText("target=QA task=validate")).toBeTruthy();
|
||||
expect(screen.getByText("reply delivered")).toBeTruthy();
|
||||
expect(screen.queryByText("Tool")).toBeNull();
|
||||
await waitFor(() =>
|
||||
expect(screen.queryByRole("status", { name: "Loading" })).toBeNull(),
|
||||
);
|
||||
});
|
||||
|
||||
it("stops animating running progress rows once the turn reaches a final chunk", async () => {
|
||||
let emitChunk: ((chunk: unknown) => void) | null = null;
|
||||
const agent = {
|
||||
|
||||
Reference in New Issue
Block a user