Files
IdeA/frontend/src/adapters/plugin.test.ts

86 lines
2.9 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from "vitest";
const invoke = vi.fn();
vi.mock("@tauri-apps/api/core", () => ({
invoke: (...args: unknown[]) => invoke(...args),
}));
import { TauriPluginGateway } from "./plugin";
describe("TauriPluginGateway invoke payloads", () => {
beforeEach(() => invoke.mockReset().mockResolvedValue({}));
it("reviewPackage sends the package DTO under the Tauri input arg", async () => {
await new TauriPluginGateway().reviewPackage({
sourceKind: "archive",
path: "/tmp/example.ideaplug",
});
expect(invoke).toHaveBeenCalledWith("plugin_review_package", {
input: {
sourceKind: "archive",
path: "/tmp/example.ideaplug",
},
});
});
it("normalizes backend review DTOs for the Plugins panel view-model", async () => {
invoke.mockResolvedValueOnce({
id: "dev.acme.gitgraph",
displayName: "Git Graph",
publisher: "Acme",
version: "1.2.3",
description: "Graph",
sourceKind: "archive",
sourceLabel: "/tmp/gitgraph.ideaplug",
contentHash: "abc",
trustLevel: "full",
contributionSummary: { topLevelMenus: 1, menuItems: 2, layouts: 3, mcpServers: 4 },
contributes: { menus: [], menuItems: [], layouts: [], mcpServers: [] },
});
const review = await new TauriPluginGateway().reviewPackage({
sourceKind: "archive",
path: "/tmp/gitgraph.ideaplug",
});
expect(review.issues).toEqual([]);
expect(review.installable).toBe(true);
});
it("uses the project-plugin command envelopes", async () => {
const gateway = new TauriPluginGateway();
await gateway.listProjectSettings("project-1");
expect(invoke).toHaveBeenLastCalledWith("plugin_list_project_settings", {
projectId: "project-1",
});
const projectInput = { projectId: "project-1", pluginId: "dev.acme.unity", enabled: true };
await gateway.setProjectEnabled(projectInput);
expect(invoke).toHaveBeenLastCalledWith("plugin_set_project_enabled", { input: projectInput });
const skillInput = {
projectId: "project-1",
agentId: "agent-1",
pluginId: "dev.acme.unity",
skillId: "unity.debug",
};
await gateway.assignAgentSkill(skillInput);
expect(invoke).toHaveBeenLastCalledWith("plugin_assign_agent_skill", { input: skillInput });
await gateway.unassignAgentSkill(skillInput);
expect(invoke).toHaveBeenLastCalledWith("plugin_unassign_agent_skill", { input: skillInput });
const toolInput = {
projectId: "project-1",
agentId: "agent-1",
pluginId: "dev.acme.unity",
serverId: "unity-tools",
toolName: "unity_build",
};
await gateway.assignAgentTool(toolInput);
expect(invoke).toHaveBeenLastCalledWith("plugin_assign_agent_tool", { input: toolInput });
await gateway.unassignAgentTool(toolInput);
expect(invoke).toHaveBeenLastCalledWith("plugin_unassign_agent_tool", { input: toolInput });
});
});