From 8de03ac0a2814f60e8aa969a09f2837a45f7e053 Mon Sep 17 00:00:00 2001 From: chengyongru Date: Fri, 16 Oct 2026 18:50:23 +0800 Subject: [PATCH] fix(webui): use file-type icons in file change activity --- webui/src/components/FileReferenceChip.tsx | 8 ++- .../thread/activity/ActivityStep.tsx | 51 +++++++++++-------- .../thread/activity/FileEditRow.tsx | 35 +++++-------- webui/src/dev/gallery/shared-views.tsx | 13 +++-- webui/src/tests/activity-step.test.tsx | 36 +++++++++++-- .../src/tests/agent-activity-cluster.test.tsx | 42 ++++++++------- webui/src/tests/file-reference-icon.test.tsx | 13 +++++ webui/src/tests/thread-messages.test.tsx | 2 +- 8 files changed, 132 insertions(+), 68 deletions(-) diff --git a/webui/src/components/FileReferenceChip.tsx b/webui/src/components/FileReferenceChip.tsx index ff4539ae3..cbf1a8e20 100644 --- a/webui/src/components/FileReferenceChip.tsx +++ b/webui/src/components/FileReferenceChip.tsx @@ -31,6 +31,7 @@ interface FileReferenceChipProps { path: string; tooltipPath?: string; display?: "name" | "path"; + showIcon?: boolean; active?: boolean; className?: string; textClassName?: string; @@ -43,6 +44,7 @@ export function FileReferenceChip({ path, tooltipPath, display = "name", + showIcon = true, active = false, className, textClassName, @@ -97,7 +99,7 @@ export function FileReferenceChip({ ], )} > - + {showIcon ? : null} ; +export function fileIconForPath(path: string): LucideIcon { + return FILE_ICONS[fileKindForPath(path)]; +} + /** The same file silhouette and stroke in replies, tabs, and attachment tiles. */ export function FileReferenceIcon({ kind, className }: { kind: FileReferenceKind; className?: string }) { const Icon = FILE_ICONS[kind]; diff --git a/webui/src/components/thread/activity/ActivityStep.tsx b/webui/src/components/thread/activity/ActivityStep.tsx index 8933cfa6b..12cdf690a 100644 --- a/webui/src/components/thread/activity/ActivityStep.tsx +++ b/webui/src/components/thread/activity/ActivityStep.tsx @@ -3,7 +3,7 @@ import type { LucideIcon } from "lucide-react"; import { StreamingLabelSheen } from "@/components/ui/streaming-label-sheen"; import { formControlFocusClassName } from "@/components/ui/form-control"; -import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; +import { HoverHint, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; import { cn } from "@/lib/utils"; export type ActivityStepTone = "neutral" | "active" | "success" | "error"; @@ -11,6 +11,7 @@ export type ActivityStepTone = "neutral" | "active" | "success" | "error"; export interface ActivityStepProps { icon?: LucideIcon; marker?: ReactNode; + markerLabel?: string; showMarker?: boolean; label: ReactNode; detail?: string; @@ -30,6 +31,7 @@ export interface ActivityStepProps { export function ActivityStep({ icon: Icon, marker, + markerLabel, showMarker = true, label, detail, @@ -48,6 +50,30 @@ export function ActivityStep({ const lineRef = useRef(null); const [hintOpen, setHintOpen] = useState(false); const textLabel = typeof label === "string" ? [label, detail].filter(Boolean).join("\n") : undefined; + const activityMarker = ( + + {marker ?? ( + + {Icon ? : null} + + )} + + ); const line = (
- {showMarker ? ( - - {marker ?? ( - - {Icon ? : null} - - )} - - ) : null} + {showMarker ? markerLabel ? ( + {activityMarker} + ) : activityMarker : null}
{typeof label === "string" ? ( diff --git a/webui/src/components/thread/activity/FileEditRow.tsx b/webui/src/components/thread/activity/FileEditRow.tsx index 1b4ed83ff..49e19325d 100644 --- a/webui/src/components/thread/activity/FileEditRow.tsx +++ b/webui/src/components/thread/activity/FileEditRow.tsx @@ -6,9 +6,9 @@ import { ChevronUp, ExternalLink, } from "lucide-react"; -import { Trans, useTranslation } from "react-i18next"; +import { useTranslation } from "react-i18next"; -import { FileReferenceChip } from "@/components/FileReferenceChip"; +import { FileReferenceChip, fileIconForPath } from "@/components/FileReferenceChip"; import { codeLanguageFromPath } from "@/lib/code-language"; import { hasRenderableFileDiff, @@ -98,7 +98,8 @@ function FileEditRow({ return (
- , - target: ( - - ), - }} + {hasCountedDiff ? : null} diff --git a/webui/src/dev/gallery/shared-views.tsx b/webui/src/dev/gallery/shared-views.tsx index 7502b5563..c3285edbc 100644 --- a/webui/src/dev/gallery/shared-views.tsx +++ b/webui/src/dev/gallery/shared-views.tsx @@ -73,14 +73,21 @@ function ActivityPreview() { function FilesPreview() { const [state, setState] = useState<"done" | "editing" | "error">("done"); + const [operation, setOperation] = useState<"create" | "edit" | "delete">("edit"); const [display, setDisplay] = useState<"summary" | "diff" | "collapsed_diff">("diff"); const [opened, setOpened] = useState(""); + const diffs = { + create: '@@ -0,0 +1 @@\n+export const greeting = "Hello, Nanobot";\n', + edit: '@@ -1,2 +1,2 @@\n-export const greeting = "Hello";\n+export const greeting = "Hello, Nanobot";\n export const ready = true;\n', + delete: '@@ -1 +0,0 @@\n-export const greeting = "Hello";\n', + }; const edit: FileEditSummary = { - key: "example-edit", path: "src/greeting.ts", added: 1, deleted: 1, approximate: false, binary: false, - status: state, pending: state === "editing", operation: "edit", error: state === "error" ? "Example edit could not be applied." : undefined, - diff: { format: "unified", text: '@@ -1,2 +1,2 @@\n-export const greeting = "Hello";\n+export const greeting = "Hello, Nanobot";\n export const ready = true;\n' }, + key: "example-edit", path: "src/greeting.ts", added: operation === "delete" ? 0 : 1, deleted: operation === "create" ? 0 : 1, approximate: false, binary: false, + status: state, pending: state === "editing", operation, error: state === "error" ? "Example edit could not be applied." : undefined, + diff: { format: "unified", text: diffs[operation] }, }; return <> +

{opened ? `Selected file: ${opened}` : "Select a file reference to exercise its callback."}

; diff --git a/webui/src/tests/activity-step.test.tsx b/webui/src/tests/activity-step.test.tsx index 930d27cc6..604a94453 100644 --- a/webui/src/tests/activity-step.test.tsx +++ b/webui/src/tests/activity-step.test.tsx @@ -1,10 +1,14 @@ -import { cleanup, render, screen, within } from "@testing-library/react"; +import { act, cleanup, fireEvent, render, screen, within } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; -import { afterEach, expect, it } from "vitest"; +import { FileCode2 } from "lucide-react"; +import { afterEach, expect, it, vi } from "vitest"; import { ActivityStep } from "@/components/thread/activity/ActivityStep"; -afterEach(cleanup); +afterEach(() => { + cleanup(); + vi.useRealTimers(); +}); it("animates a running label with details and keeps the completed activity readable", () => { const { rerender } = render(); @@ -32,3 +36,29 @@ it("keeps truncated activity details available on keyboard focus", async () => { const tooltip = await screen.findByRole("tooltip"); expect(within(tooltip).getByText(/Used Blender/)).toHaveTextContent("--json project new"); }); + +it("describes a named operation marker on keyboard focus before the file action", async () => { + render(src/app.tsx} />); + + await userEvent.tab(); + + const marker = screen.getByRole("img", { name: "Created" }); + expect(marker).toHaveFocus(); + expect(marker.closest('[aria-hidden="true"]')).toBeNull(); + expect(screen.getByRole("tooltip")).toHaveTextContent("Created"); + + await userEvent.tab(); + expect(screen.getByRole("button", { name: "src/app.tsx" })).toHaveFocus(); +}); + +it("uses the shared hover delay for a named operation marker", () => { + vi.useFakeTimers(); + render(src/app.tsx} />); + const marker = screen.getByRole("img", { name: "Created" }); + + fireEvent.pointerMove(marker, { pointerType: "mouse" }); + act(() => vi.advanceTimersByTime(499)); + expect(screen.queryByRole("tooltip")).not.toBeInTheDocument(); + act(() => vi.advanceTimersByTime(1)); + expect(screen.getByRole("tooltip")).toHaveTextContent("Created"); +}); diff --git a/webui/src/tests/agent-activity-cluster.test.tsx b/webui/src/tests/agent-activity-cluster.test.tsx index 7c2e952cd..440ca8e20 100644 --- a/webui/src/tests/agent-activity-cluster.test.tsx +++ b/webui/src/tests/agent-activity-cluster.test.tsx @@ -162,7 +162,7 @@ describe("AgentActivityCluster", () => { expect(screen.getByText(`Reading file ${path}`)).toBeInTheDocument(); expect(screen.getByLabelText("Using Blender, --json --background scene.blend")).toBeInTheDocument(); expect(screen.getByLabelText("Opening example.com, Browserbase")).toBeInTheDocument(); - expect(screen.getByText("Edited")).toBeInTheDocument(); + expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument(); expect(screen.getByTestId("activity-file-reference")).toHaveTextContent(path); await act(async () => setAppLanguage("zh-CN")); @@ -171,7 +171,7 @@ describe("AgentActivityCluster", () => { expect(screen.getByText(`正在读取文件 ${path}`)).toBeInTheDocument(); expect(screen.getByLabelText("正在使用 Blender, --json --background scene.blend")).toBeInTheDocument(); expect(screen.getByLabelText("正在打开 example.com, Browserbase")).toBeInTheDocument(); - expect(screen.getByText("编辑")).toBeInTheDocument(); + expect(screen.getByRole("img", { name: "编辑", exact: true })).toBeInTheDocument(); expect(screen.getByTestId("activity-file-reference")).toHaveTextContent(path); await act(async () => setAppLanguage("ja")); @@ -180,8 +180,9 @@ describe("AgentActivityCluster", () => { expect(screen.getByText(`${path} ファイルを読み取り中`)).toBeInTheDocument(); expect(screen.getByLabelText("Blender を使用中, --json --background scene.blend")).toBeInTheDocument(); expect(screen.getByLabelText("example.com 開いています, Browserbase")).toBeInTheDocument(); + expect(screen.getByRole("img", { name: "編集", exact: true })).toBeInTheDocument(); expect(screen.getByTestId("activity-file-reference").closest('[data-testid="activity-step"]')) - .toHaveTextContent(`${path} 編集`); + .toHaveAttribute("aria-label", `${path} 編集`); }); it("loads deferred trace details only after completed activity is expanded", async () => { @@ -535,7 +536,7 @@ describe("AgentActivityCluster", () => { />, ); - assertBetween(screen.getByText("Editing")); + assertBetween(screen.getByRole("img", { name: "Editing", exact: true })); rerender( { />, ); - assertBetween(screen.getByText("Edited")); + assertBetween(screen.getByRole("img", { name: "Edited", exact: true })); }); it.each(["diff", "collapsed_diff"] as const)( @@ -676,7 +677,7 @@ describe("AgentActivityCluster", () => { expect(screen.getByTestId("file-edit-diff")).toBeInTheDocument(); expect(screen.getByText("return ;")).toBeInTheDocument(); expect(screen.getByText("return ;")).toBeInTheDocument(); - expect(screen.getByText("Edited")).toBeInTheDocument(); + expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument(); expect(screen.getByTestId("activity-file-reference")).toHaveTextContent("src/app.tsx"); expect(screen.getAllByTestId("activity-diff-pair")).toHaveLength(1); @@ -684,7 +685,7 @@ describe("AgentActivityCluster", () => { writeLocalPreferences({ ...DEFAULT_LOCAL_PREFS, fileEditDisplayMode: "summary" }); }); expect(screen.queryByTestId("file-edit-diff")).not.toBeInTheDocument(); - expect(screen.getByText("Edited")).toBeInTheDocument(); + expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument(); act(() => { writeLocalPreferences({ ...DEFAULT_LOCAL_PREFS, fileEditDisplayMode: "diff" }); @@ -977,9 +978,10 @@ describe("AgentActivityCluster", () => { hasBodyBelow={false} />, ); - expect(screen.getByText("Created")).toBeInTheDocument(); + expect(screen.getByRole("img", { name: "Created", exact: true }).querySelector("svg")) + .toHaveClass("lucide-file-text"); expect(screen.getByLabelText("Created tmp.txt")).toBeInTheDocument(); - expect(screen.queryByText("Edited")).not.toBeInTheDocument(); + expect(screen.queryByRole("img", { name: "Edited", exact: true })).not.toBeInTheDocument(); expect(screen.getByTestId("activity-file-reference")).toHaveTextContent("tmp.txt"); expect(!!screen.queryByTestId("file-edit-diff")).toBe(hasDiff); } finally { @@ -1015,8 +1017,9 @@ describe("AgentActivityCluster", () => { ); fireEvent.click(screen.getByRole("button", { name: /^Worked/ })); - expect(screen.getByText("Deleted")).toBeInTheDocument(); - expect(screen.queryByText("Edited")).not.toBeInTheDocument(); + expect(screen.getByRole("img", { name: "Deleted", exact: true }).querySelector("svg")) + .toHaveClass("lucide-file-code2"); + expect(screen.queryByRole("img", { name: "Edited", exact: true })).not.toBeInTheDocument(); }); it("renders file-only edits without a redundant disclosure", () => { @@ -1048,8 +1051,11 @@ describe("AgentActivityCluster", () => { expect(screen.queryByRole("button", { name: /edited app\.tsx/i })).not.toBeInTheDocument(); expect(screen.queryByTestId("agent-activity-content")).not.toBeInTheDocument(); - expect(screen.getByText("Edited")).toBeInTheDocument(); + expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument(); expect(screen.queryByTestId("activity-header-file-reference")).not.toBeInTheDocument(); + const marker = screen.getByRole("img", { name: "Edited", exact: true }); + expect(marker.querySelector("svg")).toHaveClass("lucide-file-code2"); + expect(marker.closest('[data-testid="activity-step"]')?.querySelectorAll("svg")).toHaveLength(1); expect(screen.getByTestId("activity-file-reference")).toHaveTextContent("src/app.tsx"); expect(screen.getByText("+12")).toBeInTheDocument(); expect(screen.getByText("-3")).toBeInTheDocument(); @@ -1798,7 +1804,7 @@ describe("AgentActivityCluster", () => { ); fireEvent.click(screen.getByRole("button", { name: /^Worked/ })); - expect(screen.getByText("Edited")).toBeInTheDocument(); + expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument(); expect(screen.queryByText("+0")).not.toBeInTheDocument(); expect(screen.queryByText("-0")).not.toBeInTheDocument(); }); @@ -1893,7 +1899,7 @@ describe("AgentActivityCluster", () => { ); fireEvent.click(screen.getByRole("button", { name: /^Worked/ })); - const row = screen.getByText("Could not edit").closest('[data-testid="activity-step"]'); + const row = screen.getByRole("img", { name: "Could not edit", exact: true }).closest('[data-testid="activity-step"]'); expect(row).toBeInTheDocument(); expect(row).not.toHaveAttribute("title"); expect(screen.queryByText("Target text was not found in angry-birds.html.")).not.toBeInTheDocument(); @@ -1927,7 +1933,7 @@ describe("AgentActivityCluster", () => { ); fireEvent.click(screen.getByRole("button", { name: /^Worked/ })); - const row = screen.getByText("Could not edit").closest('[data-testid="activity-step"]'); + const row = screen.getByRole("img", { name: "Could not edit", exact: true }).closest('[data-testid="activity-step"]'); expect(row).toBeInTheDocument(); expect(row).not.toHaveAttribute("title"); expect(screen.queryByText("No permission to change this location.")).not.toBeInTheDocument(); @@ -2008,7 +2014,7 @@ describe("AgentActivityCluster", () => { const fileRefs = screen.getAllByTestId("activity-file-reference"); expect(fileRefs).toHaveLength(3); expect(fileRefs.every((ref) => ref.textContent?.includes("minecraft-fps/index.html"))).toBe(true); - const failedRow = screen.getByText("Could not edit").closest( + const failedRow = screen.getByRole("img", { name: "Could not edit", exact: true }).closest( '[data-testid="activity-step"]', ); expect(failedRow).toBeInTheDocument(); @@ -2066,8 +2072,8 @@ describe("AgentActivityCluster", () => { ); fireEvent.click(screen.getByRole("button", { name: /^Worked/ })); - expect(screen.getByText("Edited")).toBeInTheDocument(); - expect(screen.getByText("Could not edit")).toBeInTheDocument(); + expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument(); + expect(screen.getByRole("img", { name: "Could not edit", exact: true })).toBeInTheDocument(); expect(screen.getAllByTestId("activity-file-reference")).toHaveLength(2); }); diff --git a/webui/src/tests/file-reference-icon.test.tsx b/webui/src/tests/file-reference-icon.test.tsx index ae2f4e0ff..c3fde7d40 100644 --- a/webui/src/tests/file-reference-icon.test.tsx +++ b/webui/src/tests/file-reference-icon.test.tsx @@ -63,6 +63,19 @@ describe("shared file icons", () => { }, ); + it("keeps iconless activity references named and keyboard-operable", () => { + const open = vi.fn(); + render(); + + const reference = screen.getByRole("button", { name: "src/app.tsx" }); + expect(reference).toHaveTextContent("src/app.tsx"); + expect(reference.querySelector("svg")).toBeNull(); + expect(reference).toHaveAttribute("tabindex", "0"); + fireEvent.keyDown(reference, { key: "Enter" }); + expect(open).toHaveBeenCalledWith("/repo/src/app.tsx"); + }); + it.each(["image", "video"] as const)("retains %s identity when its attachment is unavailable", (kind) => { const { container } = render(); expect(container.querySelector("svg")).toHaveClass(kind === "image" ? "lucide-file-image" : "lucide-file-video2"); diff --git a/webui/src/tests/thread-messages.test.tsx b/webui/src/tests/thread-messages.test.tsx index 4d5ea23c5..87deb5983 100644 --- a/webui/src/tests/thread-messages.test.tsx +++ b/webui/src/tests/thread-messages.test.tsx @@ -86,7 +86,7 @@ describe("ThreadMessages", () => { const assertIndependentDiff = () => { const diff = screen.getByTestId("file-edit-diff"); expect(diff).toBeVisible(); - expect(screen.getByText("Edited")).toBeInTheDocument(); + expect(screen.getByRole("img", { name: "Edited", exact: true })).toBeInTheDocument(); expect(diff.closest('[aria-hidden="true"], [inert], [data-testid="agent-activity-content"]')) .toBeNull(); expect(screen.getByText("File updated")).toBeVisible();