Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

1.8 KB
Raw Blame
import { describe, expect, it } from "vitest";
import { pluginFilesystemParentUri, pluginFilesystemRootUri, sortPluginFilesystemEntries, uniquePluginFilesystemEntries } from "./pluginFilesystem";

describe("plugin filesystem navigation", () => {
  it("derives a default root from the first declared scheme", () => {
    expect(pluginFilesystemRootUri({ schemes: ["sftp"] })).toBe("sftp:/");
    expect(pluginFilesystemRootUri({ schemes: ["s3"], root_uri: "s3://bucket/" })).toBe("s3://bucket/");
  });

  it("keeps parent navigation inside the declared root", () => {
    expect(pluginFilesystemParentUri("sftp:/home/user/files/", "sftp:/")).toBe("sftp:/home/user/");
    expect(pluginFilesystemParentUri("s3://bucket/reports/2026/", "s3://bucket/")).toBe("s3://bucket/reports/");
    expect(pluginFilesystemParentUri("s3://bucket/reports/", "s3://bucket/reports/")).toBeUndefined();
  });

  it("sorts directories before naturally ordered files", () => {
    const sorted = sortPluginFilesystemEntries([
      { name: "file10.txt", uri: "sample:/file10.txt", kind: "file" },
      { name: "folder", uri: "sample:/folder/", kind: "directory" },
      { name: "file2.txt", uri: "sample:/file2.txt", kind: "file" },
    ]);
    expect(sorted.map((entry) => entry.name)).toEqual(["folder", "file2.txt", "file10.txt"]);
  });

  it("removes duplicate entries by URI while preserving the latest metadata", () => {
    expect(
      uniquePluginFilesystemEntries([
        { name: "object.txt", uri: "s3:/object.txt", kind: "file", size: 1 },
        { name: "object.txt", uri: "s3:/object.txt", kind: "file", size: 2 },
        { name: "other.txt", uri: "s3:/other.txt", kind: "file" },
      ]),
    ).toEqual([
      { name: "object.txt", uri: "s3:/object.txt", kind: "file", size: 2 },
      { name: "other.txt", uri: "s3:/other.txt", kind: "file" },
    ]);
  });
});