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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
import { afterEach, describe, expect, it, vi } from "vitest";
import { prepareDatabaseBackupRestore, previewSqlFile, releaseSqlFilePreview } from "@/lib/backend/http";
afterEach(() => vi.unstubAllGlobals());
describe("Web backup restore transport", () => {
it("returns the server preview from the record-authorized restore endpoint", async () => {
const preview = { fileName: "backup.sql", filePath: "/server/tmp/sql_file/restore-token/backup.sql", preview: "SELECT 1;", cleanupToken: "restore-token" };
const fetchMock = vi.fn().mockResolvedValue({ ok: true, json: async () => preview });
vi.stubGlobal("fetch", fetchMock);
await expect(prepareDatabaseBackupRestore("run/1", 2)).resolves.toEqual(preview);
expect(fetchMock).toHaveBeenCalledWith("/api/database-backups/run%2F1/files/2/restore", expect.objectContaining({ method: "POST", body: "{}" }));
});
it("continues rejecting arbitrary server paths without making a request", async () => {
const fetchMock = vi.fn();
vi.stubGlobal("fetch", fetchMock);
await expect(previewSqlFile("/etc/passwd")).rejects.toThrow("requires a File object");
expect(fetchMock).not.toHaveBeenCalled();
});
it("releases only by the opaque cleanup token", async () => {
const fetchMock = vi.fn().mockResolvedValue({ ok: true, json: async () => null });
vi.stubGlobal("fetch", fetchMock);
await releaseSqlFilePreview("restore-token");
expect(fetchMock).toHaveBeenCalledWith("/api/sql-file/preview/release", expect.objectContaining({ method: "POST", body: '{"cleanupToken":"restore-token"}' }));
});
});