Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

10.6 KB
Raw Blame
import { McpServerId, type McpServer } from "@akeru/contracts";
import { describe, expect, it } from "vite-plus/test";
import {
  loadDirectoryCatalog,
  PLUGIN_CATEGORIES,
  type PluginDirectoryDefinition,
} from "../../../../../plugins";
import {
  buildPluginFilters,
  buildPluginSections,
  pluginActiveDependentBotNames,
  pluginBlocker,
  pluginBrokerName,
  pluginConnectionLabel,
  pluginMatchesQuery,
  pluginPrimaryAction,
} from "./pluginPresentation";

const catalog = loadDirectoryCatalog();

const firecrawl = catalog.find((plugin) => plugin.id === "firecrawl");

if (!firecrawl || firecrawl.kind !== "mcp-url") {
  throw new TypeError("Firecrawl is missing from the plugin directory.");
}

const firecrawlUrl = firecrawl.url;

const { kind: _kind, transport: _transport, url: _url, ...pendingBase } = firecrawl;

const pendingPlugin = {
  ...pendingBase,
  id: "pending-vendor",
  name: "Pending Vendor",
  title: "Pending Vendor",
  kind: "mcp-unavailable",
  transport: { type: "unavailable" },
  connection: {
    type: "approval-pending",
    blocker: "The vendor must approve Akeru as an OAuth client.",
  },
  catalogStatus: "approval-pending",
} satisfies PluginDirectoryDefinition;

const verificationPlugin = {
  ...firecrawl,
  id: "verification-vendor",
  name: "Verification Vendor",
  title: "Verification Vendor",
  connection: {
    type: "verification-pending",
    blocker: "The connection lifecycle still needs verification.",
  },
  catalogStatus: "available",
} satisfies PluginDirectoryDefinition;

const apiKeyPlugin = {
  ...firecrawl,
  id: "key-vendor",
  name: "Key Vendor",
  title: "Key Vendor",
  authentication: "api-key",
  connection: { type: "api-key" },
  requiredCredentials: ["key-vendor-api-key"],
} satisfies PluginDirectoryDefinition;

const brokeredPlugin = {
  ...pendingBase,
  id: "gmail",
  name: "Gmail",
  title: "Gmail",
  description: "Read, draft, and send Gmail messages.",
  tags: ["email", "inbox"],
  authentication: "oauth",
  requiredCredentials: [],
  kind: "mcp-unavailable",
  transport: { type: "unavailable" },
  connection: {
    type: "brokered",
    broker: { name: "Composio", url: "https://composio.dev" },
  },
  catalogStatus: "verification-pending",
} satisfies PluginDirectoryDefinition;

function server(enabled: boolean): McpServer {
  return {
    id: McpServerId.make("builtin-firecrawl"),
    name: "Firecrawl",
    transport: "url",
    url: firecrawlUrl,
    enabled,
    createdAt: "2026-08-27T00:00:00.000Z",
    updatedAt: "2026-08-27T00:00:00.000Z",
  };
}

describe("plugin presentation", () => {
  it("shows only populated directory categories and keeps pending categories discoverable", () => {
    expect(buildPluginFilters(catalog)).toEqual([
      "All",
      "Featured",
      "Installed",
      "Work",
      "Web",
      "Marketing",
      "Build",
      "Design",
      "Sales",
      "Support",
      "Commerce",
    ]);
    expect(
      buildPluginFilters([
        ...catalog.filter((plugin) => ["Work", "Web"].includes(plugin.primaryCategory)),
        { ...pendingPlugin, primaryCategory: "Marketing", category: "Marketing" },
      ]),
    ).toEqual(["All", "Featured", "Installed", "Work", "Web", "Marketing", "Support"]);
    expect(
      buildPluginSections({ plugins: catalog, query: "", filter: "All" }).flatMap((section) =>
        section.plugins.map((plugin) => plugin.id),
      ),
    ).toHaveLength(54);
    expect(
      buildPluginSections({
        plugins: catalog,
        query: "",
        filter: "Installed",
        installedPluginIds: new Set(["firecrawl"]),
      })[0]?.plugins.map((plugin) => plugin.id),
    ).toEqual(["firecrawl"]);
    expect(
      buildPluginSections({ plugins: catalog, query: "", filter: "Featured" })[0]?.plugins.map(
        (plugin) => plugin.id,
      ),
    ).toEqual(["context", "gmail", "zernio", "hoplite"]);
    expect(
      buildPluginSections({ plugins: catalog, query: "", filter: "Web" })[0]?.plugins.map(
        (plugin) => plugin.id,
      ),
    ).toEqual(["context", "apify", "exa", "firecrawl", "parallel-search", "tavily"]);
    expect(
      buildPluginSections({ plugins: catalog, query: "", filter: "Sales" })[0]?.plugins,
    ).toEqual(expect.arrayContaining([expect.objectContaining({ id: "hubspot" })]));
    expect(
      buildPluginSections({ plugins: catalog, query: "", filter: "Support" })[0]?.plugins,
    ).toEqual(
      expect.arrayContaining([
        expect.objectContaining({ id: "customer-io" }),
        expect.objectContaining({ id: "linear" }),
      ]),
    );
  });

  it("groups the unfiltered directory into populated category sections", () => {
    const sections = buildPluginSections({ plugins: catalog, query: "", filter: "All" });
    expect(sections.map((section) => section.title)).toEqual([
      "Featured",
      ...PLUGIN_CATEGORIES.filter((category) =>
        catalog.some((plugin) => !plugin.featured && plugin.category === category),
      ),
    ]);
    expect(sections.every((section) => section.plugins.length > 0)).toBe(true);
    expect(sections[0]?.plugins.map((plugin) => plugin.id)).toEqual([
      "context",
      "gmail",
      "zernio",
      "hoplite",
    ]);

    for (const section of sections.slice(1)) {
      expect(
        section.plugins.every((plugin) => !plugin.featured && plugin.category === section.title),
      ).toBe(true);
    }

    expect(
      buildPluginSections({ plugins: catalog, query: "firecrawl", filter: "All" }).map(
        (section) => section.title,
      ),
    ).toEqual(["Search results"]);
  });

  it("searches only the directory discovery fields", () => {
    const executor = catalog.find((plugin) => plugin.id === "executor");

    if (!executor) throw new TypeError("Executor is missing from the plugin directory.");

    const searchPlugin = {
      ...firecrawl,
      name: "Manifest name token",
      title: "Display title token",
      description: "Description token",
      tags: ["tag token"],
      capabilities: ["capability token"],
      publisher: { ...firecrawl.publisher, name: "Publisher token" },
    } satisfies PluginDirectoryDefinition;

    for (const query of [
      "Manifest name token",
      "Display title token",
      "Description token",
      "Web",
      "tag token",
      "capability token",
      "Publisher token",
    ]) {
      expect(pluginMatchesQuery(searchPlugin, query)).toBe(true);
    }

    for (const query of [searchPlugin.url, "available", "mobile", "oauth"]) {
      expect(pluginMatchesQuery(searchPlugin, query)).toBe(false);
    }

    expect(pluginMatchesQuery(executor, "bunx")).toBe(false);
  });

  it("shows active bot dependents only for an enabled installation", () => {
    const enabledServer = server(true);

    const bots = [
      { name: "Research", archivedAt: null, disabledMcpServerIds: [] },
      { name: "Writer", archivedAt: null, disabledMcpServerIds: [enabledServer.id] },
      {
        name: "Archived",
        archivedAt: "2026-08-01T00:00:00.000Z",
        disabledMcpServerIds: [],
      },
    ];

    expect(pluginActiveDependentBotNames(enabledServer, bots)).toEqual(["Research"]);
    expect(pluginActiveDependentBotNames(server(false), bots)).toEqual([]);
    expect(pluginActiveDependentBotNames(undefined, bots)).toEqual([]);
  });

  it("uses state-correct actions without claiming a successful connection", () => {
    expect(pluginPrimaryAction(firecrawl, undefined)).toEqual({
      label: "Connect",
      enable: null,
      blocker:
        firecrawl.connection.type === "verification-pending"
          ? firecrawl.connection.blocker
          : undefined,
    });
    expect(pluginPrimaryAction(apiKeyPlugin, undefined)).toEqual({
      label: "Add key",
      enable: true,
    });
    expect(pluginPrimaryAction(firecrawl, server(true)).label).toBe("Disable");
    // A pending entry keeps Disable for installed servers, even when their
    // access needs reconnecting, but never reconnects into a connection
    // recipe that has not passed the lifecycle.
    expect(
      pluginPrimaryAction(firecrawl, server(true), {
        id: "mcp-builtin-firecrawl",
        label: "Firecrawl",
        accessMethod: "mcp",
        health: "failed-first-request",
        apiAccess: "not-applicable",
        nextAction: "Reconnect Firecrawl.",
        pluginId: "firecrawl",
        dependentBots: [],
        dependentRoutines: [],
      }),
    ).toEqual({ label: "Disable", enable: false });
    expect(pluginPrimaryAction(firecrawl, server(false))).toEqual({
      label: "Connect",
      enable: null,
      blocker:
        firecrawl.connection.type === "verification-pending"
          ? firecrawl.connection.blocker
          : undefined,
    });
    expect(pluginConnectionLabel(firecrawl)).toBe("Verification pending");
  });

  it("blocks unavailable plugins and names the approval blocker", () => {
    expect(pluginPrimaryAction(pendingPlugin, undefined)).toEqual({
      label: "Connect",
      enable: null,
      blocker: "The vendor must approve Akeru as an OAuth client.",
    });
    expect(pluginPrimaryAction(pendingPlugin, server(true)).label).toBe("Disable");
    expect(pluginConnectionLabel(pendingPlugin)).toBe("Approval pending");
    expect(pluginPrimaryAction(verificationPlugin, undefined)).toEqual({
      label: "Connect",
      enable: null,
      blocker: "The connection lifecycle still needs verification.",
    });
    expect(pluginConnectionLabel(verificationPlugin)).toBe("Verification pending");
  });

  it("names the broker without hiding the app it stands for", () => {
    expect(pluginBrokerName(brokeredPlugin)).toBe("Composio");
    expect(pluginBrokerName(firecrawl)).toBeNull();

    for (const query of ["Gmail", "email", "inbox", "Composio"]) {
      expect(pluginMatchesQuery(brokeredPlugin, query)).toBe(true);
    }

    expect(pluginMatchesQuery(firecrawl, "Composio")).toBe(false);
    expect(pluginPrimaryAction(brokeredPlugin, undefined)).toEqual({
      label: "Connect",
      enable: true,
    });
    expect(pluginConnectionLabel(brokeredPlugin)).toBe("OAuth");

    const pendingBrokered = {
      ...brokeredPlugin,
      connection: {
        ...brokeredPlugin.connection,
        pendingBlocker: "The brokered lifecycle still needs verification.",
      },
    } satisfies PluginDirectoryDefinition;

    expect(pluginPrimaryAction(pendingBrokered, undefined)).toEqual({
      label: "Connect",
      enable: null,
      blocker: "The brokered lifecycle still needs verification.",
    });
    expect(pluginBlocker(pendingBrokered)).toBe("The brokered lifecycle still needs verification.");
    expect(pluginConnectionLabel(pendingBrokered)).toBe("Verification pending");
    expect(pluginPrimaryAction(pendingBrokered, server(true)).label).toBe("Disable");
  });
});