Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

3.2 KB
Raw Blame
import { describe, expect, it } from "vitest";
import { extractMcpImages, isOwnScreenTool, isOwnScreenToolName, ownScreenMounts } from "./mcp-tool-images.ts";

describe("extractMcpImages", () => {
  it("pulls image blocks out of a raw content array, ignoring text", () => {
    const content = [
      { type: "text", text: "ok" },
      { type: "image", data: "abc123", mimeType: "image/png" },
    ];
    expect(extractMcpImages(content)).toEqual([{ type: "image", data: "abc123", mimeType: "image/png" }]);
  });

  it("pulls image blocks out of a { content: [...] } wrapper", () => {
    const result = { content: [{ type: "image", data: "xyz", mimeType: "image/jpeg" }], isError: false };
    expect(extractMcpImages(result)).toEqual([{ type: "image", data: "xyz", mimeType: "image/jpeg" }]);
  });

  it("returns [] for text-only, missing, or malformed input", () => {
    expect(extractMcpImages([{ type: "text", text: "ok" }])).toEqual([]);
    expect(extractMcpImages(undefined)).toEqual([]);
    expect(extractMcpImages({ content: [{ type: "image", data: 5, mimeType: "image/png" }] })).toEqual([]);
  });

  it("normalizes Anthropic API image blocks (Claude CLI's tool_result shape)", () => {
    const content = [
      { type: "text", text: "ok" },
      { type: "image", source: { type: "base64", media_type: "image/jpeg", data: "def456" } },
    ];
    expect(extractMcpImages(content)).toEqual([{ data: "def456", mimeType: "image/jpeg" }]);
  });
});

describe("isOwnScreenTool", () => {
  const own = ownScreenMounts(["computer", "browser", "agents", "omarchy-bridge", "data"]);

  it("names OpenMausBot's own computer and browser tools, and the lent computer's", () => {
    expect(isOwnScreenTool("computer", "screenshot", own)).toBe(true);
    expect(isOwnScreenTool("browser", "agent_browser_screenshot", own)).toBe(true);
    expect(isOwnScreenTool("agents", "shared_computer", own)).toBe(true);
    expect(isOwnScreenToolName("mcp__computer__screenshot", own)).toBe(true);
    expect(isOwnScreenToolName("mcp__browser__agent_browser_click", own)).toBe(true);
    expect(isOwnScreenToolName("mcp__agents__shared_computer", own)).toBe(true);
  });

  it("leaves custom tools and the app's other tools out", () => {
    expect(isOwnScreenTool("omarchy-bridge", "screenshot", own)).toBe(false);
    expect(isOwnScreenTool(undefined, "screenshot", own)).toBe(false);
    expect(isOwnScreenTool("agents", "attach_file", own)).toBe(false);
    expect(isOwnScreenToolName("mcp__omarchy-bridge__screenshot", own)).toBe(false);
    expect(isOwnScreenToolName("mcp__mcp-computer__screenshot", own)).toBe(false);
    expect(isOwnScreenToolName("screenshot", own)).toBe(false);
    expect(isOwnScreenToolName("Read", own)).toBe(false);
    expect(isOwnScreenToolName(undefined, own)).toBe(false);
  });

  it("leaves a same-named server OpenMausBot did not mount this turn out (native config or project folder)", () => {
    expect(ownScreenMounts(["omarchy-bridge", "data", "computer"])).toEqual(new Set(["computer"]));
    expect(isOwnScreenTool("computer", "screenshot", new Set())).toBe(false);
    expect(isOwnScreenToolName("mcp__browser__agent_browser_screenshot", new Set(["computer"]))).toBe(false);
  });
});