Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(frontend): collapse prompts when switching runs

warren618dac12f500608
diff --git a/frontend/src/pages/RunDetail.tsx b/frontend/src/pages/RunDetail.tsx
index fa05c7ff8..a0fd70092 100644
--- a/frontend/src/pages/RunDetail.tsx
+++ b/frontend/src/pages/RunDetail.tsx
@@ -168,6 +168,7 @@ export function RunDetail() {
cancelBulkChartLoadRef.current = true;
setRun(null);
setCode({});
+ setPromptExpanded(false);
setTab(requestedInitialTab);
setLoading(true);
setSelectedSymbol("");
@@ -375,6 +376,7 @@ export function RunDetail() {
</p>
<button
type="button"
+ aria-expanded={promptExpanded}
onClick={() => setPromptExpanded((v) => !v)}
className="mt-1 text-xs text-primary hover:underline"
>
diff --git a/frontend/src/pages/__tests__/RunDetail.test.tsx b/frontend/src/pages/__tests__/RunDetail.test.tsx
index 4bd4e5e14..68ff1a697 100644
--- a/frontend/src/pages/__tests__/RunDetail.test.tsx
+++ b/frontend/src/pages/__tests__/RunDetail.test.tsx
@@ -142,6 +142,41 @@ describe("RunDetail page", () => {
expect(screen.queryByText("OLD_CODE")).not.toBeInTheDocument();
});
+ it("collapses an expanded prompt when navigating to another run", async () => {
+ const firstPrompt = "First run prompt\n".repeat(8).trim();
+ const secondPrompt = "Second run prompt\n".repeat(8).trim();
+ apiMock.getRun.mockImplementation((runId: string) => Promise.resolve({
+ status: "success",
+ run_id: runId,
+ prompt: runId === "first" ? firstPrompt : secondPrompt,
+ }));
+ apiMock.getRunCode.mockResolvedValue({});
+
+ const router = renderRunDetail("/runs/first");
+ const expandButton = await screen.findByRole("button", { name: "Show full prompt" });
+ const firstPromptElement = expandButton.previousElementSibling;
+ expect(firstPromptElement).toHaveTextContent("First run prompt");
+ expect(firstPromptElement).toHaveClass("line-clamp-3");
+ expect(expandButton).toHaveAttribute("aria-expanded", "false");
+
+ fireEvent.click(expandButton);
+ expect(firstPromptElement).not.toHaveClass("line-clamp-3");
+ expect(screen.getByRole("button", { name: "Show less" })).toHaveAttribute(
+ "aria-expanded",
+ "true",
+ );
+
+ await act(async () => {
+ await router.navigate("/runs/second");
+ });
+
+ const secondExpandButton = await screen.findByRole("button", { name: "Show full prompt" });
+ const secondPromptElement = secondExpandButton.previousElementSibling;
+ expect(secondPromptElement).toHaveTextContent("Second run prompt");
+ expect(secondPromptElement).toHaveClass("line-clamp-3");
+ expect(secondExpandButton).toHaveAttribute("aria-expanded", "false");
+ });
+
it("ignores a chart response that finishes after the route changes", async () => {
const oldChart = deferred<RunData>();
apiMock.getRun.mockImplementation((runId: string, params: Record<string, string>) => {