Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

test(preview): reveal a linked file by its real path from the pane beside the chat

laijsg17345468b12eb
diff --git a/src/components/FilePreviewPanel.dom.test.ts b/src/components/FilePreviewPanel.dom.test.ts
index 53a3d87254..1deaec20ff 100644
--- a/src/components/FilePreviewPanel.dom.test.ts
+++ b/src/components/FilePreviewPanel.dom.test.ts
@@ -15,6 +15,7 @@ const { closeFilePreview } = await import("@/lib/file-preview");
const { openAppPreview, closeAppPreview } = await import("@/lib/app-preview");
const { AttachedFileChip } = await import("./AttachmentPreview");
const { FilePreviewPanel } = await import("./FilePreviewPanel");
+const { ChatMarkdown } = await import("./ChatMarkdown");
// The preview loads this lazily; loaded once here, the tests wait only on the file.
await import("./MarkdownFilePreview");
@@ -35,6 +36,7 @@ afterEach(async () => {
await act(async () => { closeFilePreview(); closeAppPreview(); root.unmount(); });
host.remove();
vi.unstubAllGlobals();
+ Reflect.deleteProperty(window, "ogb");
});
/** A conversation with one Markdown file in a reply, and the shell's pane beside it; `inPanel` draws the chip in a
@@ -97,6 +99,26 @@ describe("a file opened from the chat on a wide window", () => {
expect(pane()).toBeNull();
});
+ it("shows a linked file outside the chat in its folder by its real path, asking for it by the link as written", async () => {
+ const fetch = vi.fn(async (_url: string, _init?: RequestInit) => new Response(JSON.stringify({ error: "the linked file is outside this conversation's workspace", code: "outside_workspace" }), { status: 403, headers: { "content-type": "application/json" } }));
+ const revealInFolder = vi.fn(async () => "shown");
+ vi.stubGlobal("fetch", fetch);
+ Object.assign(window, { ogb: { revealInFolder } });
+ await act(async () => root.render(createElement(Fragment, null,
+ createElement("main", { "data-look": "chat" }, createElement(ChatMarkdown, { text: "Report: [Q3 report.md](/workspace/finance/Q3%20report.md)", message })),
+ createElement(FilePreviewPanel, { threadId: "t1" }),
+ )));
+ await act(async () => host.querySelector<HTMLButtonElement>("main button[title='Preview: Q3 report.md']")!.click());
+ const show = await vi.waitFor(() => {
+ const button = [...(pane()?.querySelectorAll("button") ?? [])].find((candidate) => candidate.textContent === "Show in folder");
+ expect(button).toBeDefined();
+ return button!;
+ });
+ await act(async () => show.click());
+ expect(JSON.parse(String(fetch.mock.calls[0]![1]!.body))).toEqual({ path: "/workspace/finance/Q3%20report.md" });
+ expect(revealInFolder).toHaveBeenCalledWith("/workspace/finance/Q3 report.md");
+ });
+
it("gives way to another panel on that side", async () => {
await render();
await openFile();