Skip to content

Commit f742cfe

Browse files
fatihozdilclaude
andcommitted
fix(web): do not show a starting code block run as Terminal closed
A terminal session that has not attached yet reports closed at version 0. The run output showed that as Terminal closed until the first update, which the real-environment recording of the run flow caught. Treat closed as a real close only once the session version is above 0, matching watchChatShellRun. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
1 parent 68acb81 commit f742cfe

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

‎apps/web/src/components/ChatMarkdown.browser.test.tsx‎

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ vi.mock(import("../remoteOpen"), async (original) => ({
6868
useRemoteOpenResolution: () => ({ state: { mode: "local-exec" }, isResolved: true }) as never,
6969
}));
7070
const terminalOutput = vi.hoisted(() => ({ text: "" }));
71+
const terminalState = vi.hoisted(() => ({ status: "running" as string, version: 1 }));
7172
const sessionAtoms = vi.hoisted(() => new Map<string, unknown>());
7273
vi.mock(import("../state/terminalSessions"), async (original) => {
7374
const { Atom } = await import("effect/reactivity");
@@ -77,7 +78,8 @@ vi.mock(import("../state/terminalSessions"), async (original) => {
7778
const atom = Atom.make({
7879
output: { chunks: [{ data: terminalOutput.text }] },
7980
error: null,
80-
status: "running",
81+
status: terminalState.status,
82+
version: terminalState.version,
8183
});
8284
sessionAtoms.set(input.terminalId, atom);
8385
return atom;
@@ -159,6 +161,8 @@ function setup() {
159161
parsedSources.length = 0;
160162
sessionAtoms.clear();
161163
terminalOutput.text = "";
164+
terminalState.status = "running";
165+
terminalState.version = 1;
162166
settingsOverrides.mathRenderingEnabled = false;
163167
renderDiagram.mockReset();
164168
workspaceSearch.mockReset().mockResolvedValue(AsyncResult.success({ entries: [] }));
@@ -307,6 +311,37 @@ describe("ChatMarkdown inline run output", () => {
307311
await runAndWait(screen.container);
308312
await expect.element(screen.getByText("Running…")).toBeVisible();
309313
});
314+
315+
it("shows a terminal that has not attached yet as running, not closed", async () => {
316+
setup();
317+
terminalState.status = "closed";
318+
terminalState.version = 0;
319+
await using screen = await render(
320+
<ChatMarkdown
321+
cwd="/tmp/project"
322+
text={"```bash\nnpm run dev\n```"}
323+
onRunShellCommand={(_command, onStarted) => onStarted(run)}
324+
/>,
325+
);
326+
await runAndWait(screen.container);
327+
await expect.element(screen.getByText("Running…")).toBeVisible();
328+
expect(screen.container.textContent).not.toContain("Terminal closed");
329+
});
330+
331+
it("shows a terminal that closed before the run finished", async () => {
332+
setup();
333+
terminalState.status = "closed";
334+
terminalState.version = 2;
335+
await using screen = await render(
336+
<ChatMarkdown
337+
cwd="/tmp/project"
338+
text={"```bash\nnpm run dev\n```"}
339+
onRunShellCommand={(_command, onStarted) => onStarted(run)}
340+
/>,
341+
);
342+
await runAndWait(screen.container);
343+
await expect.element(screen.getByText("Terminal closed")).toBeVisible();
344+
});
310345
});
311346

312347
describe("ChatMarkdown favicon privacy", () => {

‎apps/web/src/components/chat/ChatCodeBlockRunOutput.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export function ChatCodeBlockRunOutput({ run }: { readonly run: ChatShellRun })
2323
? `Exited with code ${exitCode}`
2424
: session.status === "exited"
2525
? "Ended without an exit status"
26-
: session.status === "closed"
26+
: // A session that has not attached yet also reports "closed", at version 0.
27+
session.status === "closed" && session.version > 0
2728
? "Terminal closed"
2829
: "Running…";
2930

0 commit comments

Comments
 (0)