Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Theme } from "@radix-ui/themes";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { useReviewDraftsStore } from "../reviewDraftsStore";
import { CommentAnnotation } from "./CommentAnnotation";

const { sendPromptToAgent } = vi.hoisted(() => ({
sendPromptToAgent: vi.fn(),
}));

vi.mock("../../sessions/sendPromptToAgent", () => ({ sendPromptToAgent }));

describe("CommentAnnotation", () => {
beforeEach(() => {
vi.clearAllMocks();
useReviewDraftsStore.setState({ drafts: {}, batchEnabled: {} });
});

it("keeps expanded review open when sending an inline comment", async () => {
const user = userEvent.setup();
const onDismiss = vi.fn();

render(
<Theme>
<CommentAnnotation
taskId="task-1"
filePath="src/example.ts"
startLine={8}
endLine={10}
side="additions"
onDismiss={onDismiss}
/>
</Theme>,
);

await user.type(
screen.getByPlaceholderText("Describe the changes you'd like..."),
"Use the shared helper",
);
await user.click(screen.getByRole("button", { name: "Submit" }));

expect(sendPromptToAgent).toHaveBeenCalledWith(
"task-1",
expect.stringContaining("Use the shared helper"),
{ keepReviewExpanded: true },
);
expect(onDismiss).toHaveBeenCalledOnce();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export function CommentAnnotation({
sendPromptToAgent(
taskId,
buildInlineCommentPrompt(filePath, startLine, endLine, side, text),
{ keepReviewExpanded: true },
);
}, [
taskId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Theme } from "@radix-ui/themes";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { useReviewDraftsStore } from "../reviewDraftsStore";
import { PendingReviewBar } from "./PendingReviewBar";

const { sendPromptToAgent } = vi.hoisted(() => ({
sendPromptToAgent: vi.fn(),
}));

vi.mock("../../sessions/sendPromptToAgent", () => ({ sendPromptToAgent }));

describe("PendingReviewBar", () => {
beforeEach(() => {
vi.clearAllMocks();
useReviewDraftsStore.setState({
drafts: {
"task-1": [
{
id: "draft-1",
taskId: "task-1",
filePath: "src/example.ts",
startLine: 8,
endLine: 10,
side: "additions",
text: "Use the shared helper",
createdAt: 1,
},
],
},
batchEnabled: { "task-1": true },
});
});

it("keeps expanded review open when sending batched comments", async () => {
const user = userEvent.setup();

render(
<Theme>
<PendingReviewBar taskId="task-1" />
</Theme>,
);

await user.click(screen.getByRole("button", { name: "Send to agent" }));

expect(sendPromptToAgent).toHaveBeenCalledWith(
"task-1",
expect.stringContaining("Use the shared helper"),
{ keepReviewExpanded: true },
);
expect(useReviewDraftsStore.getState().getDraftCount("task-1")).toBe(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function PendingReviewBar({ taskId }: PendingReviewBarProps) {
const handleSend = () => {
const prompt = buildBatchedInlineCommentsPrompt(drafts);
if (!prompt) return;
sendPromptToAgent(taskId, prompt);
sendPromptToAgent(taskId, prompt, { keepReviewExpanded: true });
clearDrafts(taskId);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ describe("PrCommentThread", () => {
expect(sendPromptToAgent).toHaveBeenCalledWith(
"task-1",
expect.stringContaining("Could this use the shared helper?"),
{ keepReviewExpanded: true },
);
expect(sendPromptToAgent).toHaveBeenCalledWith(
"task-1",
expect.stringContaining("Check whether this helper already exists"),
{ keepReviewExpanded: true },
);
await waitFor(() =>
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ export function PrCommentThread({
const success = await sendPromptToAgent(
taskId,
buildChatAboutPrCommentPrompt(filePath, endLine, side, comments, text),
{ keepReviewExpanded: true },
);
setIsSendingChat(false);
if (success) {
Expand Down
15 changes: 15 additions & 0 deletions packages/ui/src/features/sessions/sendPromptToAgent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,19 @@ describe("sendPromptToAgent", () => {
);
},
);

it("keeps expanded review open when requested", () => {
mockSender.mockResolvedValueOnce(undefined);
reviewState.mode = "expanded";
panelState.taskLayouts = { "task-1": { panelTree: {} } };

sendPromptToAgent("task-1", "hello", { keepReviewExpanded: true });

expect(reviewState.setReviewMode).not.toHaveBeenCalled();
expect(panelState.setActiveTab).toHaveBeenCalledWith(
"task-1",
"panel-logs",
DEFAULT_TAB_IDS.LOGS,
);
});
});
11 changes: 6 additions & 5 deletions packages/ui/src/features/sessions/sendPromptToAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import {
type AgentPromptSender,
} from "./agentPromptSender";

/**
* Sends a prompt to the agent session for a task, collapses the review
* panel to split mode if expanded, and switches to the logs/chat tab.
*/
interface SendPromptToAgentOptions {
keepReviewExpanded?: boolean;
}

export function sendPromptToAgent(
taskId: string,
prompt: string | ContentBlock[],
options: SendPromptToAgentOptions = {},
): Promise<boolean> {
const sendPromise = resolveService<AgentPromptSender>(AGENT_PROMPT_SENDER)(
taskId,
Expand All @@ -33,7 +34,7 @@ export function sendPromptToAgent(
});

const { getReviewMode, setReviewMode } = useReviewNavigationStore.getState();
if (getReviewMode(taskId) === "expanded") {
if (!options.keepReviewExpanded && getReviewMode(taskId) === "expanded") {
setReviewMode(taskId, "split");
}

Expand Down
Loading