diff --git a/apps/smart-ssh-community/frontend/e2e/tests/file-browser.spec.ts b/apps/smart-ssh-community/frontend/e2e/tests/file-browser.spec.ts index 23ced05e8..42d0bc15a 100644 --- a/apps/smart-ssh-community/frontend/e2e/tests/file-browser.spec.ts +++ b/apps/smart-ssh-community/frontend/e2e/tests/file-browser.spec.ts @@ -24,7 +24,7 @@ function entry(name: string, isDir = false): RemoteEntryDto { uid: 1000, gid: 1000, owner: "deploy", - group: "deploy", + group: "deploy", isSymlink: false, linkTarget: null, linkKind: null, }; } diff --git a/apps/smart-ssh-community/frontend/e2e/tests/narrow-dialogs.spec.ts b/apps/smart-ssh-community/frontend/e2e/tests/narrow-dialogs.spec.ts index 7f2e93eeb..84228cae5 100644 --- a/apps/smart-ssh-community/frontend/e2e/tests/narrow-dialogs.spec.ts +++ b/apps/smart-ssh-community/frontend/e2e/tests/narrow-dialogs.spec.ts @@ -80,7 +80,7 @@ const entry = (name: string): RemoteEntryDto => ({ uid: 1000, gid: 1000, owner: "deploy", - group: "deploy", + group: "deploy", isSymlink: false, linkTarget: null, linkKind: null, }); async function openEntryMenuItem(app: import("../support/app").AppDriver, item: RegExp | string) { @@ -145,7 +145,7 @@ test("xl: ssh_config import dialog is a full-screen sheet @phone", async ({ app entries: Array.from({ length: 6 }, (_, index) => ({ index, name: `host-${index}`, - group: 0, + group: 0, isSymlink: false, linkTarget: null, linkKind: null, host: { value: `host-${index}.example.test`, origin: null }, port: { value: 22, origin: null }, username: { value: "deploy", origin: null }, diff --git a/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.android.test.tsx b/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.android.test.tsx index 60551f6bd..02ed66ec9 100644 --- a/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.android.test.tsx +++ b/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.android.test.tsx @@ -104,7 +104,7 @@ const fileEntry: RemoteEntryDto = { uid: 1000, gid: 1000, owner: null, - group: null, + group: null, isSymlink: false, linkTarget: null, linkKind: null, }; async function openActions() { diff --git a/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.elevationAllowed.test.tsx b/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.elevationAllowed.test.tsx index 8d2d5f774..50016c3a2 100644 --- a/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.elevationAllowed.test.tsx +++ b/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.elevationAllowed.test.tsx @@ -92,7 +92,7 @@ const fileEntry: RemoteEntryDto = { uid: 1000, gid: 1000, owner: null, - group: null, + group: null, isSymlink: false, linkTarget: null, linkKind: null, }; async function renderPanel() { diff --git a/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.links.test.tsx b/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.links.test.tsx new file mode 100644 index 000000000..ff6073a3e --- /dev/null +++ b/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.links.test.tsx @@ -0,0 +1,196 @@ +// Issue #1291: symbolic links in the file browser — rendering, sorting, +// navigation and the properties dialog for links to folders, links to files +// and broken links. +import { fireEvent, render, screen, waitFor } from "@testing-library/react"; +import { I18nextProvider } from "react-i18next"; +import { beforeEach, describe, expect, it, vi } from "vitest"; + +import { sftpList } from "../api/api"; +import { loadFileManagerColumnWidths, loadFileManagerSort } from "../settings/layoutSettings"; +import { testI18n } from "../testI18n"; +import type { RemoteEntryDto } from "../api/types"; +import { FileBrowserPanel } from "./FileBrowserPanel"; + +if (!Element.prototype.setPointerCapture) { + Element.prototype.setPointerCapture = () => {}; + Element.prototype.releasePointerCapture = () => {}; +} + +vi.mock("../api/api", async () => + (await import("../test/apiMock")).createApiMock({ + sessionIsRoot: vi.fn(() => Promise.resolve(false)), + sftpElevationDisable: vi.fn(() => Promise.resolve({ disabled: true, runningOperations: [] })), + claimDroppedPaths: vi.fn(() => Promise.resolve([])), + sftpElevationStatus: vi.fn(() => Promise.resolve(null)), + clipboardHasFiles: vi.fn(() => Promise.resolve(false)), + }), +); + +vi.mock("../api/events", () => ({ + onConnectionStatusChanged: vi.fn(() => Promise.resolve(() => {})), + onSftpTransferStarted: vi.fn(() => Promise.resolve(() => {})), + onElevationAutoDisabled: vi.fn(() => Promise.resolve(() => {})), + onElevationRevokedByProfile: vi.fn(() => Promise.resolve(() => {})), + onSftpTransferFinished: vi.fn(() => Promise.resolve(() => {})), + onSftpTransferProgress: vi.fn(() => Promise.resolve(() => {})), +})); + +vi.mock("@tauri-apps/api/webview", () => ({ + getCurrentWebview: () => ({ onDragDropEvent: vi.fn(() => Promise.resolve(() => {})) }), +})); + +vi.mock("@tauri-apps/plugin-dialog", () => ({ open: vi.fn() })); +vi.mock("@tauri-apps/plugin-opener", () => ({ + openPath: vi.fn(), + revealItemInDir: vi.fn(() => Promise.resolve()), +})); +vi.mock("../buses/toastBus", () => ({ showToast: vi.fn() })); +vi.mock("../settings/fileTypeSettings", () => ({ + loadFileTypeApps: vi.fn(() => Promise.resolve({})), + appForFileName: () => null, +})); +vi.mock("../settings/layoutSettings", () => ({ + loadFileManagerColumnWidths: vi.fn(() => Promise.resolve({})), + saveFileManagerColumnWidths: vi.fn(() => Promise.resolve()), + loadHiddenFileColumns: vi.fn(() => Promise.resolve([])), + saveHiddenFileColumns: vi.fn(() => Promise.resolve()), + loadFileManagerSort: vi.fn(() => Promise.resolve(null)), + saveFileManagerSort: vi.fn(() => Promise.resolve()), +})); + +import { NarrowEntryList } from "./fileBrowser/NarrowEntryList"; +import { isRealDir } from "../lib/remotePath"; + +const base: RemoteEntryDto = { + name: "", + path: "", + isDir: false, + size: 0, + permissions: "rw-r--r--", + modified: null, + permissionsOctal: 0o644, + uid: 1000, + gid: 1000, + owner: null, + group: null, + isSymlink: false, + linkTarget: null, + linkKind: null, +}; +const MARKER = testI18n.t("fileBrowser.linkMarker"); +const folder = { ...base, name: "zfolder", path: "/h/zfolder", isDir: true }; +const file = { ...base, name: "afile", path: "/h/afile" }; +const linkDir: RemoteEntryDto = { + ...base, + name: "link-dir", + path: "/h/link-dir", + isDir: true, + isSymlink: true, + linkTarget: "/srv/releases/42", + linkKind: "dir", +}; +const linkFile: RemoteEntryDto = { + ...base, + name: "link-file", + path: "/h/link-file", + isSymlink: true, + linkTarget: "afile", + linkKind: "file", +}; +const dangling: RemoteEntryDto = { + ...base, + name: "dangling", + path: "/h/dangling", + isSymlink: true, + linkTarget: null, + linkKind: "broken", +}; + +describe("symbolic links in the file browser (#1291)", () => { + beforeEach(() => { + vi.clearAllMocks(); + vi.mocked(loadFileManagerColumnWidths).mockResolvedValue({}); + vi.mocked(loadFileManagerSort).mockResolvedValue(null); + vi.mocked(sftpList).mockResolvedValue([file, linkFile, dangling, linkDir, folder]); + }); + + it("wide table: a link to a folder sorts with the folders and opens like one; the other links are not navigable", async () => { + render( + + + , + ); + const rows = await screen.findAllByRole("row"); + expect(rows.length).toBeGreaterThan(5); + const names = Array.from(document.querySelectorAll("tbody tr td:first-child")).map((td) => + td.textContent?.replace(/\s+/g, " ").trim(), + ); + // Folders first (link-dir < zfolder), then files by name. + expect(names.map((n) => n?.split(" ")[1])).toEqual(["link-dir", "zfolder", "afile", "dangling", "link-file"]); + expect(names[0]).toContain("📁"); + expect(names[2]).not.toContain("↪"); + expect(names[4]).toContain("📄"); + // Every link has the accessible marker; ordinary entries have none. + expect(screen.getAllByText(MARKER)).toHaveLength(3); + // Hover shows the target; an unreadable target is omitted. + expect(screen.getAllByTitle("link-dir -> /srv/releases/42").length).toBeGreaterThan(0); + expect(screen.getAllByTitle("link-file -> afile").length).toBeGreaterThan(0); + expect(screen.getAllByTitle("dangling").length).toBeGreaterThan(0); + // Only folder-like entries are buttons. + expect(screen.getByRole("button", { name: /^📁 link-dir/ })).toBeInTheDocument(); + expect(screen.queryByRole("button", { name: /^📄 link-file/ })).toBeNull(); + expect(screen.queryByRole("button", { name: /^⚠️ dangling/ })).toBeNull(); + // The broken link is de-emphasised. + expect(screen.getAllByTitle("dangling")[0].closest("span.opacity-50")).not.toBeNull(); + + vi.mocked(sftpList).mockClear(); + fireEvent.click(screen.getByRole("button", { name: /^📁 link-dir/ })); + await waitFor(() => expect(sftpList).toHaveBeenCalledWith("s1", "/h/link-dir", null)); + }); + + it("narrow list: same three kinds, navigation uses the link path", () => { + const load = vi.fn(); + render( + + {}} + setDirMenu={() => {}} + load={load} + renderEntryMenu={() => null} + /> + , + ); + expect(screen.getAllByText(MARKER)).toHaveLength(3); + expect(screen.getAllByTitle("link-dir -> /srv/releases/42").length).toBeGreaterThan(0); + expect(screen.queryByRole("button", { name: /^📄 link-file/ })).toBeNull(); + expect(screen.queryByRole("button", { name: /^⚠️ dangling/ })).toBeNull(); + fireEvent.click(screen.getByRole("button", { name: /^📁 link-dir/ })); + expect(load).toHaveBeenCalledWith("/h/link-dir"); + }); + + it("truncates a very long target in the tooltip", () => { + const long = { ...linkFile, linkTarget: "x".repeat(500) }; + render( + + {}} + setDirMenu={() => {}} + load={() => {}} + renderEntryMenu={() => null} + /> + , + ); + const title = screen.getByText(MARKER).closest("[data-link-marker]")?.getAttribute("title") ?? ""; + expect(title.length).toBeLessThan(260); + }); + + it("a link to a folder is not a real folder for recursive operations", () => { + expect(isRealDir(linkDir)).toBe(false); + expect(isRealDir(folder)).toBe(true); + expect(isRealDir(linkFile)).toBe(false); + }); +}); diff --git a/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.sort.test.tsx b/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.sort.test.tsx index bfe6ef71d..446a105e8 100644 --- a/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.sort.test.tsx +++ b/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.sort.test.tsx @@ -68,7 +68,7 @@ const base: RemoteEntryDto = { uid: 1000, gid: 1000, owner: null, - group: null, + group: null, isSymlink: false, linkTarget: null, linkKind: null, }; const small = { ...base, name: "a.txt", path: "a.txt", size: 1 }; const big = { ...base, name: "b.txt", path: "b.txt", size: 999 }; diff --git a/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.startDirectory.test.tsx b/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.startDirectory.test.tsx index 97d460968..230dc4175 100644 --- a/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.startDirectory.test.tsx +++ b/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.startDirectory.test.tsx @@ -94,7 +94,7 @@ function dirEntry(path: string): RemoteEntryDto { uid: 1000, gid: 1000, owner: null, - group: null, + group: null, isSymlink: false, linkTarget: null, linkKind: null, }; } diff --git a/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.test.tsx b/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.test.tsx index a212d51f3..f16ff587e 100644 --- a/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.test.tsx +++ b/apps/smart-ssh-community/frontend/src/components/FileBrowserPanel.test.tsx @@ -190,7 +190,7 @@ const entry: RemoteEntryDto = { uid: 1000, gid: 1000, owner: null, - group: null, + group: null, isSymlink: false, linkTarget: null, linkKind: null, }; function renderPanel() { diff --git a/apps/smart-ssh-community/frontend/src/components/fileBrowser/ChmodDialog.tsx b/apps/smart-ssh-community/frontend/src/components/fileBrowser/ChmodDialog.tsx index a2deb2780..d4a567521 100644 --- a/apps/smart-ssh-community/frontend/src/components/fileBrowser/ChmodDialog.tsx +++ b/apps/smart-ssh-community/frontend/src/components/fileBrowser/ChmodDialog.tsx @@ -1,3 +1,4 @@ +import { isRealDir } from "../../lib/remotePath"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { type RemoteEntryDto } from "../../api/types"; @@ -169,7 +170,7 @@ export function ChmodDialog({ )} - {entry.isDir && ( + {isRealDir(entry) && ( )} - {entry.isDir && recursive && ( + {isRealDir(entry) && recursive && (

{t("fileBrowser.chmod.recursiveSummary", { folders: folderBits.toString(8).padStart(3, "0"), diff --git a/apps/smart-ssh-community/frontend/src/components/fileBrowser/ChownDialog.tsx b/apps/smart-ssh-community/frontend/src/components/fileBrowser/ChownDialog.tsx index e95fdb668..d470868d5 100644 --- a/apps/smart-ssh-community/frontend/src/components/fileBrowser/ChownDialog.tsx +++ b/apps/smart-ssh-community/frontend/src/components/fileBrowser/ChownDialog.tsx @@ -1,3 +1,4 @@ +import { isRealDir } from "../../lib/remotePath"; import { useRef, useState } from "react"; import { useTranslation } from "react-i18next"; import { type RemoteEntryDto } from "../../api/types"; @@ -43,7 +44,7 @@ export function ChownDialog({ onSubmit={(e) => { e.preventDefault(); if (nothingToChange) return; - onConfirm(ownerChange, groupChange, recursive && entry.isDir); + onConfirm(ownerChange, groupChange, recursive && isRealDir(entry)); }} actions={ <> @@ -84,7 +85,7 @@ export function ChownDialog({ )}

{t("fileBrowser.chown.hint")}

- {entry.isDir && ( + {isRealDir(entry) && (