feat(plugins): add AI tools and consent-gated data access
This commit is contained in:
71 files changed
+4613
-129
No files matched your search
@@ -0,0 +1,74 @@
|
||||
// @vitest-environment happy-dom
|
||||
|
||||
import { createApp, nextTick } from "vue";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import ConnectionIcon from "./ConnectionIcon.vue";
|
||||
import { clearPluginIconCache } from "@/lib/plugins/pluginIconResolver";
|
||||
import type { ConnectionConfig } from "@/types/database";
|
||||
|
||||
const { listPlugins, readPluginAsset } = vi.hoisted(() => ({ listPlugins: vi.fn(), readPluginAsset: vi.fn() }));
|
||||
vi.mock("@/lib/backend/api", () => ({ listPlugins, readPluginAsset }));
|
||||
|
||||
const cleanups: Array<() => void> = [];
|
||||
const connection: ConnectionConfig = { id: "c1", name: "Connection", db_type: "mysql", host: "localhost", port: 3306, username: "", password: "" };
|
||||
|
||||
async function mountIcon(config?: ConnectionConfig) {
|
||||
const container = document.createElement("div");
|
||||
document.body.append(container);
|
||||
const app = createApp(ConnectionIcon, { connection: config, class: "h-3 w-3" });
|
||||
app.mount(container);
|
||||
cleanups.push(() => {
|
||||
app.unmount();
|
||||
container.remove();
|
||||
});
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
await nextTick();
|
||||
return container;
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
clearPluginIconCache();
|
||||
listPlugins.mockResolvedValue([
|
||||
{
|
||||
manifest: {
|
||||
id: "sample.plugin",
|
||||
icon: "assets/plugin.svg",
|
||||
contributions: [{ type: "connection-provider", id: "sample.connection", icon: "assets/connection.svg" }],
|
||||
},
|
||||
},
|
||||
]);
|
||||
readPluginAsset.mockResolvedValue({ contentType: "image/svg+xml", dataBase64: "PHN2Zy8+" });
|
||||
vi.stubGlobal("URL", { ...URL, createObjectURL: () => "blob:connection-icon", revokeObjectURL: vi.fn() });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
while (cleanups.length) cleanups.pop()?.();
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
describe("ConnectionIcon", () => {
|
||||
it("uses the plugin connection-provider logo and preserves sizing", async () => {
|
||||
const container = await mountIcon({ ...connection, db_type: "plugin", plugin_id: "sample.plugin", plugin_connection_provider: "sample.connection" });
|
||||
expect(readPluginAsset).toHaveBeenCalledWith("sample.plugin", "assets/connection.svg");
|
||||
expect(container.querySelector("img")?.getAttribute("src")).toBe("blob:connection-icon");
|
||||
expect(container.firstElementChild?.classList.contains("h-3")).toBe(true);
|
||||
});
|
||||
|
||||
it("falls back to the plugin logo without a provider logo", async () => {
|
||||
await mountIcon({ ...connection, db_type: "plugin", plugin_id: "sample.plugin" });
|
||||
expect(readPluginAsset).toHaveBeenCalledWith("sample.plugin", "assets/plugin.svg");
|
||||
});
|
||||
|
||||
it("keeps native database logos unchanged", async () => {
|
||||
const container = await mountIcon(connection);
|
||||
expect(container.querySelector("img")?.getAttribute("src")).toBe("/icons/database/mysql.svg");
|
||||
expect(listPlugins).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("renders a safe fallback for missing connection metadata", async () => {
|
||||
const container = await mountIcon();
|
||||
expect(container.querySelector("img")?.getAttribute("src")).toBe("/icons/database/postgres.svg");
|
||||
expect(listPlugins).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
<script setup lang="ts">
|
||||
import DatabaseIcon from "@/components/icons/DatabaseIcon.vue";
|
||||
import PluginIcon from "@/components/plugins/PluginIcon.vue";
|
||||
import { connectionIconType } from "@/lib/connection/connectionPresentation";
|
||||
import type { ConnectionConfig } from "@/types/database";
|
||||
|
||||
defineProps<{ connection?: ConnectionConfig }>();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<PluginIcon v-if="connection?.db_type === 'plugin' && connection.plugin_id" :plugin-id="connection.plugin_id" :contribution-id="connection.plugin_connection_provider" />
|
||||
<DatabaseIcon v-else :db-type="connectionIconType(connection)" />
|
||||
</template>
|
||||
Reference in new issue
Block a user