fix(webui): preserve inferred file reference text (#6672)

This commit is contained in:
chengyongru authored and GitHub committed 2026-11-15 20:30:07 +08:00
1 parent 96eb1ace6f
commit 4ebd75623f
7 files changed
+138 -14

No files matched your search

@@ -138,7 +138,7 @@ describe("MarkdownTextRenderer", () => {
});
it.each([
{ kind: "inferred", markdown: "Future file: `notes/missing.md`", path: "notes/missing.md", label: "missing.md" },
{ kind: "inferred", markdown: "Future file: `notes/missing.md`", path: "notes/missing.md", label: "notes/missing.md" },
{ kind: "explicit", markdown: "[Future report](notes/missing.md)", path: "notes/missing.md", label: "Future report" },
{ kind: "malformed explicit", markdown: "[Python code](/home/example/workspace/model_check.py)", path: "/home/example/workspace/model_check.py", label: "Python code" },
])("keeps unavailable $kind file references non-interactive", async ({ markdown, path, label }) => {
@@ -188,6 +188,7 @@ describe("MarkdownTextRenderer", () => {
expect(reference).not.toHaveAttribute("role");
expect(reference).not.toHaveAttribute("tabindex");
expect(reference.textContent).toBe(kind === "inferred" ? "notes/locked.md" : "Unreadable report");
fireEvent.click(reference);
expect(onOpenFilePreview).not.toHaveBeenCalled();
});
@@ -209,16 +210,31 @@ describe("MarkdownTextRenderer", () => {
const reference = screen.getByTestId("inline-file-path");
expect(reference).not.toHaveAttribute("role");
expect(reference).toHaveClass("text-muted-foreground");
const label = kind === "inferred" ? "notes/ready.md" : "Existing report";
expect(reference.textContent).toBe(label);
await waitFor(() => expect(resolve).toHaveBeenCalledWith("notes/ready.md"));
await act(async () => resolveAvailability(true));
await waitFor(() => expect(reference).toHaveAttribute("role", "button"));
expect(reference).toHaveAttribute("tabindex", "0");
expect(reference.textContent).toBe(label);
fireEvent.click(reference);
expect(onOpenFilePreview).toHaveBeenCalledWith("notes/ready.md");
});
it.each([
"pytest tests/test_agent.py",
"这是一段说明文字,最后引用 /tmp/sample.txt",
String.raw`C:\Users\reader\My Docs\report.md`,
"cat \t~/My Docs/report.md",
])("preserves complete inferred file text: %s", (text) => {
const { container } = render(<MarkdownTextRenderer>{`Before \`${text}\` after.`}</MarkdownTextRenderer>);
expect(screen.getByTestId("inline-file-path").textContent).toBe(text);
expect(container.querySelector("p")?.textContent).toBe(`Before ${text} after.`);
});
it("does not treat non-file hrefs as previews just because the label looks like a file", () => {
const onOpenFilePreview = vi.fn();
render(
@@ -290,7 +306,7 @@ describe("MarkdownTextRenderer", () => {
render(<MarkdownTextRenderer onOpenFilePreview={onOpenFilePreview}>{`Open \`${path}\`.`}</MarkdownTextRenderer>);
const reference = screen.getByTestId("inline-file-path");
expect(reference).toHaveTextContent("report.md");
expect(reference.textContent).toBe(path);
expect(reference).toHaveAttribute("aria-label", path);
fireEvent.click(reference);
expect(onOpenFilePreview).toHaveBeenCalledWith(path);
+3 -5
View File
@@ -1295,7 +1295,7 @@ describe("MessageBubble", () => {
expect(container.querySelector("h3")).not.toBeInTheDocument();
});
it("renders inline file paths as compact file references", async () => {
it("keeps complete inline file paths and their preview hints", async () => {
await import("@/components/MarkdownTextRenderer");
const message: UIMessage = {
id: "a-file-path",
@@ -1314,10 +1314,8 @@ describe("MessageBubble", () => {
expect(references[0].parentElement).toHaveClass("align-baseline");
expect(references[0].parentElement).toHaveClass("leading-[inherit]");
expect(references[0]).toHaveClass("items-baseline");
expect(references[0]).toHaveTextContent("MarkdownTextRenderer.tsx");
expect(references[0]).not.toHaveTextContent("webui/src/components");
expect(screen.getByText("index.html")).toBeInTheDocument();
expect(references[1]).not.toHaveTextContent("/Users/renxubin");
expect(references[0].textContent).toBe("webui/src/components/MarkdownTextRenderer.tsx");
expect(references[1].textContent).toBe("/Users/renxubin/.nanobot/workspace/minecraft-fps/index.html");
expect(references[1]).not.toHaveAttribute("title");
expect(references[1]).toHaveAttribute(
"aria-label",