Skip to content

Commit a0326ab

Browse files
committed
fix(web): keep background details bound to the command item
1 parent fadc8b4 commit a0326ab

2 files changed

Lines changed: 51 additions & 26 deletions

File tree

‎apps/web/src/components/chat/BackgroundWorkDetails.browser.test.tsx‎

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import "~/index.css";
2-
import { EnvironmentId, ThreadId, TurnItemId } from "@t3tools/contracts";
2+
import { EnvironmentId, ProviderDriverKind, ThreadId, TurnItemId } from "@t3tools/contracts";
33
import * as DateTime from "effect/DateTime";
44
import { expect, it, vi } from "vite-plus/test";
55
import { page } from "vite-plus/test/browser";
@@ -14,34 +14,58 @@ import { ThreadNow } from "./ThreadNow";
1414

1515
it("opens full command details for short labels and keeps pending tasks current", async () => {
1616
const command = "python3 audit.py -j 6\n> scratch/audit.log 2>&1";
17-
const view = (description?: string, status: "running" | "completed" = "completed") => (
17+
const commandItem = (status: "running" | "completed") => ({
18+
id: TurnItemId.make("bash-1"),
19+
threadId: ThreadId.make("thread"),
20+
runId: null,
21+
nodeId: null,
22+
providerThreadId: null,
23+
providerTurnId: null,
24+
nativeItemRef: null,
25+
parentItemId: null,
26+
ordinal: 1,
27+
status,
28+
title: null,
29+
startedAt: null,
30+
completedAt: null,
31+
updatedAt: DateTime.makeUnsafe("2026-11-09T00:00:00Z"),
32+
type: "command_execution" as const,
33+
input: command,
34+
output: "Command running in background with ID: native-task",
35+
});
36+
const view = (
37+
description?: string,
38+
status: "running" | "completed" = "completed",
39+
explicitItem = true,
40+
) => (
1841
<ThreadNow
1942
attention={null}
2043
syncPhase={null}
2144
goal={null}
2245
work={backgroundWorkNowItem({
2346
environmentId: EnvironmentId.make("test"),
2447
threadId: ThreadId.make("thread"),
25-
tasks: [{ taskId: "bash-1", kind: "command", description, command, awaited: true }],
48+
tasks: [
49+
{
50+
taskId: "native-task",
51+
itemId: explicitItem ? TurnItemId.make("bash-1") : undefined,
52+
kind: "command",
53+
description,
54+
command,
55+
awaited: true,
56+
},
57+
],
2658
turnItems: [
59+
commandItem(status),
2760
{
28-
id: TurnItemId.make("bash-1"),
29-
threadId: ThreadId.make("thread"),
30-
runId: null,
31-
nodeId: null,
32-
providerThreadId: null,
33-
providerTurnId: null,
34-
nativeItemRef: null,
35-
parentItemId: null,
36-
ordinal: 1,
37-
status,
38-
title: null,
39-
startedAt: null,
40-
completedAt: null,
41-
updatedAt: DateTime.makeUnsafe("2026-11-09T00:00:00Z"),
42-
type: "command_execution",
43-
input: command,
44-
output: "Command running in background with ID: bash-1",
61+
...commandItem("running"),
62+
id: TurnItemId.make("native-match"),
63+
nativeItemRef: {
64+
driver: ProviderDriverKind.make("codex"),
65+
nativeId: "native-task",
66+
strength: "strong",
67+
},
68+
ordinal: 2,
4569
},
4670
],
4771
stopDisabled: false,
@@ -66,6 +90,8 @@ it("opens full command details for short labels and keeps pending tasks current"
6690
.element(page.getByRole("heading", { name: "Check remaining modules" }))
6791
.toBeVisible();
6892
await expect.element(page.getByText("Command output stream")).toBeVisible();
93+
await screen.rerender(view("Native fallback", "completed", false));
94+
await expect.element(page.getByText("Command output stream")).toBeVisible();
6995
await page.getByRole("button", { name: "Close", exact: true }).click();
7096
await expect.element(page.getByRole("dialog")).not.toBeInTheDocument();
7197
});

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ export function BackgroundWorkDetails(props: {
3737
<DialogPanel>
3838
<div className="space-y-5">
3939
{props.tasks.map((task) => {
40-
const item = props.turnItems.findLast(
41-
(candidate) =>
42-
candidate.id === task.itemId ||
43-
(candidate.nativeItemRef?.nativeId || candidate.id) === task.taskId,
40+
const item = props.turnItems.findLast((candidate) =>
41+
task.itemId === undefined
42+
? (candidate.nativeItemRef?.nativeId || candidate.id) === task.taskId
43+
: candidate.id === task.itemId,
4444
);
4545
const command =
4646
task.command ?? (item?.type === "command_execution" ? item.input : undefined);
@@ -68,8 +68,7 @@ export function BackgroundWorkDetails(props: {
6868
</div>
6969
) : null}
7070
{itemId && streamsOutput && item?.status === "running" ? (
71-
<div className="space-y-1 font-mono text-xs whitespace-pre-wrap break-words">
72-
<p className="font-sans text-muted-foreground">Captured output</p>
71+
<div className="font-mono text-xs whitespace-pre-wrap break-words">
7372
<CommandOutputPanel
7473
environmentId={props.environmentId}
7574
threadId={task.sourceThreadId ?? item?.threadId ?? props.threadId}

0 commit comments

Comments
 (0)