fix(chat): ignore self-emitted custom session echoes
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
|
||||
import { useState } from "react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { DIProvider } from "@/app/di";
|
||||
@ -151,6 +152,63 @@ describe("CustomAgentChatView", () => {
|
||||
expect(screen.queryByText(/structured session gone/)).toBeNull();
|
||||
});
|
||||
|
||||
it("does not reopen when the parent echoes a launched session id", async () => {
|
||||
const agent = {
|
||||
launchAgentChat: vi.fn(async () => ({
|
||||
sessionId: "chat-session-echo",
|
||||
assignedConversationId: "conversation-2",
|
||||
})),
|
||||
reattachAgentChat: vi.fn(async (sessionId: string) => ({
|
||||
sessionId,
|
||||
scrollback: [],
|
||||
})),
|
||||
sendAgentChat: vi.fn(() => new Promise<void>(() => {})),
|
||||
cancelAgentChat: vi.fn(async () => {}),
|
||||
closeAgentChat: vi.fn(async () => {}),
|
||||
};
|
||||
const onSessionId = vi.fn();
|
||||
|
||||
function EchoingParent() {
|
||||
const [echoedSessionId, setEchoedSessionId] = useState<string | null>(null);
|
||||
return (
|
||||
<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={echoedSessionId}
|
||||
conversationId="conversation-1"
|
||||
onSessionId={(nextSessionId) => {
|
||||
onSessionId(nextSessionId);
|
||||
setEchoedSessionId(nextSessionId);
|
||||
}}
|
||||
onConversationId={vi.fn()}
|
||||
/>
|
||||
</DIProvider>
|
||||
);
|
||||
}
|
||||
|
||||
render(<EchoingParent />);
|
||||
|
||||
await waitFor(() =>
|
||||
expect(onSessionId).toHaveBeenCalledWith("chat-session-echo"),
|
||||
);
|
||||
await waitFor(() => expect(agent.launchAgentChat).toHaveBeenCalledTimes(1));
|
||||
await waitFor(() => expect(agent.reattachAgentChat).toHaveBeenCalledTimes(1));
|
||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
|
||||
expect(agent.launchAgentChat).toHaveBeenCalledTimes(1);
|
||||
expect(agent.reattachAgentChat).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("recovers and retries the prompt when send reports NOT_FOUND", async () => {
|
||||
const agent = {
|
||||
launchAgentChat: vi.fn(async () => ({
|
||||
|
||||
Reference in New Issue
Block a user