Download files from unavailable previews (#9640)

* feat(app): download files from unavailable previews

* fix(app): download files outside the workspace
This commit is contained in:
Mohamed Boudra authored and GitHub committed 2026-11-14 13:06:42 +07:00
1 parent 02d3a05d2b
commit 6213df73dc
5 files changed
+76 -2

No files matched your search

@@ -3,6 +3,7 @@ import path from "node:path";
import type { Locator } from "@playwright/test";
import { expect, test, type Page } from "../support/fixtures";
import {
downloadFileFromPreview,
expandFolder,
openFileExplorer,
openFileFromExplorer,
@@ -141,6 +142,29 @@ async function seedAgentWithFileLink(input: LinkedFile) {
}
test.describe("CodeMirror workspace file editing", () => {
test("downloads an assistant-linked binary outside the workspace", async ({ page }, testInfo) => {
const filePath = testInfo.outputPath("outside.bin");
const source = Buffer.from([0, 1, 128, 255]);
await writeFile(filePath, source);
const session = await seedMockAgentWorkspace({
repoPrefix: "outside-binary-",
title: "Outside binary",
initialPrompt: "Show the file",
featureValues: { mockAssistantResponse: `[Open binary](${filePath})` },
});
try {
await openAgentRoute(page, session);
await openAssistantMarkdownLink(page, "Open binary");
const downloaded = await downloadFileFromPreview(page);
expect(downloaded.suggestedFilename()).toBe("outside.bin");
const savedFile = testInfo.outputPath("downloaded.bin");
await downloaded.saveAs(savedFile);
expect(await readFile(savedFile)).toEqual(source);
} finally {
await session.cleanup();
}
});
test("opens explicit screenshot links and explains missing files", async ({ page }) => {
const session = await seedMockAgentWorkspace({
repoPrefix: "screenshot-markdown-link-",
@@ -2,7 +2,12 @@ import { mkdir, readFile, rm, writeFile } from "node:fs/promises";
import path from "node:path";
import { expect, type Page } from "@playwright/test";
import { test } from "../support/fixtures";
import { downloadFileFromExplorer, openFileExplorer } from "../support/helpers/file-explorer";
import {
downloadFileFromExplorer,
downloadFileFromPreview,
openFileFromExplorer,
openFileExplorer,
} from "../support/helpers/file-explorer";
import { openChangesPanel } from "../support/helpers/workspace-tabs";
import { gotoWorkspace } from "../support/helpers/launcher";
import { daemonWsRoutePattern, getE2EDaemonPort } from "../support/helpers/daemon-port";
@@ -473,3 +478,21 @@ test("downloads a file over direct TCP with its original filename and bytes", as
expect(await downloaded.failure()).toBeNull();
expect(await readFile(savedFile)).toEqual(source);
});
test("downloads an unsupported binary from its preview with original filename and bytes", async ({
page,
}, testInfo) => {
const fileName = "rapport données.bin";
const source = Buffer.from([0, 1, 2, 127, 128, 255, 10]);
await writeFile(path.join(workspace.workspaceDirectory, fileName), source);
await gotoWorkspace(page, workspace.workspaceId);
await openFileExplorer(page);
await openFileFromExplorer(page, fileName);
const downloaded = await downloadFileFromPreview(page);
expect(downloaded.suggestedFilename()).toBe(fileName);
const savedFile = testInfo.outputPath(fileName);
await downloaded.saveAs(savedFile);
expect(await downloaded.failure()).toBeNull();
expect(await readFile(savedFile)).toEqual(source);
});
@@ -46,3 +46,12 @@ export async function downloadFileFromExplorer(page: Page, fileName: string): Pr
await page.getByRole("menuitem", { name: "Download", exact: true }).click();
return downloaded;
}
export async function downloadFileFromPreview(page: Page): Promise<Download> {
await expect(page.getByText("Binary preview unavailable", { exact: true })).toBeVisible();
const button = page.getByRole("button", { name: "Download", exact: true });
await expect(button).toBeVisible();
const downloaded = page.waitForEvent("download");
await button.click();
return downloaded;
}
+18 -1
View File
@@ -1,7 +1,8 @@
import { usePaneContext } from "@/panels/pane-context";
import { useEffect, useMemo, useState } from "react";
import { useCallback, useEffect, useMemo, useState } from "react";
import type { PluginFile, PluginTab } from "@getpaseo/plugin/client";
import { Text, View } from "react-native";
import { Download } from "lucide-react-native";
import { StyleSheet } from "react-native-unistyles";
import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button";
@@ -10,6 +11,7 @@ import { useFileHandle, useFileHandleSnapshot } from "@/file-panels/file";
import { FilePanelLoading } from "@/file-panels/loading";
import { FilePanelPicker, FilePanelView, useFilePanelChoice, type FilePanel } from "@/file-panels";
import { resolveFilePreviewReadTarget } from "@/file-explorer/preview-target";
import { useFileDownload } from "@/hooks/use-file-download";
import { useAppActivelyVisible } from "@/hooks/use-app-visible";
import { usePublishPanelInstanceAttributes } from "@/panels/panel-instance-attributes";
import { useSessionStore } from "@/stores/session-store";
@@ -24,11 +26,13 @@ import type { WorkspaceFileLocation } from "@/workspace/file-open";
*/
export function FilePane({
serverId,
workspaceId,
workspaceRoot,
location,
navigationRevision,
}: {
serverId: string;
workspaceId?: string | null;
workspaceRoot: string;
location: WorkspaceFileLocation;
navigationRevision: number;
@@ -41,6 +45,16 @@ export function FilePane({
() => (path ? resolveFilePreviewReadTarget({ path, workspaceRoot: root }) : null),
[path, root],
);
const downloadFile = useFileDownload({
serverId,
workspaceId,
workspaceRoot: target?.cwd ?? root,
});
const handleDownload = useCallback(() => {
if (target) {
downloadFile({ fileName: path.split(/[\\/]/).pop() ?? path, path: target.path });
}
}, [downloadFile, path, target]);
const absolutePath = useMemo(
() => buildAbsoluteExplorerPath({ workspaceRoot: root, entryPath: path }),
[path, root],
@@ -100,6 +114,9 @@ export function FilePane({
<>
<Text style={styles.mutedText}>{t("panels.file.binaryPreviewUnavailable")}</Text>
<Text style={styles.mutedText}>{formatFileSize(snapshot.size)}</Text>
<Button variant="outline" leftIcon={Download} onPress={handleDownload}>
{t("workspace.fileActions.download")}
</Button>
</>
);
} else {
+1
View File
@@ -43,6 +43,7 @@ function FilePanel() {
return (
<FilePane
serverId={serverId}
workspaceId={workspaceId}
workspaceRoot={workspaceDirectory}
location={target}
navigationRevision={panelRevision ?? 0}