Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

5.4 KB
Raw Blame
import { describe, expect, it, vi } from "vitest";
vi.mock("server-only", () => ({}));

const { dispatch } = await import("./dispatch");
const { CHATGPT_APP_ONLY_TOOL_NAMES } = await import("./tool-contract");
const { TOOLS } = await import("./tools");
const { MSO_NATIVE_UI_PROBE_URI } = await import("./ui-native-probe");

const context = { principal: "mcp-client:chatgpt-test", sessionId: "session-profile", toolProfile: "chatgpt" as const };

describe("ChatGPT full generic MCP profile", () => {
  it("advertises every MSO-owned generic model tool with complete OpenAI metadata and bounded scanner size", async () => {
    const response = await dispatch({ id: 1, method: "tools/list" }, "exec", "test", context);
    const tools = (response.result as { tools: Array<Record<string, unknown>> }).tools;
    const expected = TOOLS.map((tool) => tool.name).sort();
    expect(tools.map((tool) => tool.name).sort()).toEqual(expected);
    expect(tools).toHaveLength(expected.length);

    for (const tool of tools) {
      expect(typeof tool.title, String(tool.name)).toBe("string");
      expect(String(tool.title).trim().length, String(tool.name)).toBeGreaterThan(0);
      const annotations = tool.annotations as Record<string, unknown>;
      for (const key of ["readOnlyHint", "destructiveHint", "openWorldHint"]) {
        expect(typeof annotations?.[key], `${String(tool.name)}.${key}`).toBe("boolean");
      }
      const schemes = tool.securitySchemes as Array<Record<string, unknown>>;
      expect(schemes?.[0]?.type, String(tool.name)).toBe("oauth2");
      expect(Array.isArray(schemes?.[0]?.scopes), String(tool.name)).toBe(true);
      expect((tool._meta as { securitySchemes?: unknown })?.securitySchemes, String(tool.name)).toEqual(schemes);
      expect(tool.outputSchema, `${String(tool.name)}.outputSchema`).toBeDefined();
      expect(Buffer.byteLength(JSON.stringify(tool)), String(tool.name)).toBeLessThan(8 * 1024);
    }

    const bytes = Buffer.byteLength(JSON.stringify(tools));
    if (process.env.MSO_PROFILE_METRICS === "1") console.info(`CHATGPT_PROFILE_METRICS tools=${tools.length} bytes=${bytes} roughTokens4=${Math.ceil(bytes/4)} maxToolBytes=${Math.max(...tools.map((tool)=>Buffer.byteLength(JSON.stringify(tool))))}`);
    // Ceiling raised 92 -> 100 KiB when four coding tools landed (fs_edit, fs_grep,
    // fs_glob, todo_write). The alternative was to stop advertising tools to ChatGPT,
    // which silently removes capability. The largest single descriptor is 2.8 KiB, so
    // there is no fat left to trim: 125 tools at ~770 B average is the actual shape.
    expect(bytes).toBeLessThan(100 * 1024);
    const start = tools.find((tool) => tool.name === "workflow_start") as { description?: string };
    expect(String(start?.description)).toMatch(/First call.*multi-step/i);
    const search = tools.find((tool) => tool.name === "skills_search") as { description?: string };
    expect(String(search?.description)).toContain("mso-agent-bootstrap");
    expect(tools.some((tool) => tool.name === "local_agent_inbox")).toBe(true);
    expect(tools.some((tool) => tool.name === "project_candidate_search")).toBe(true);
    expect(tools.some((tool) => tool.name === "project_mcp_tools")).toBe(true);
    expect(tools.some((tool) => tool.name === "project_mcp_call")).toBe(true);
    expect(tools.some((tool) => tool.name === "tool_forge_promote")).toBe(true);
    expect(tools.some((tool) => tool.name === "a2a_handoff")).toBe(true);
    expect(tools.some((tool) => tool.name === "project_memory_upsert")).toBe(true);
    const nativeProbe = tools.find((tool) => tool.name === "mso_native_ui_probe") as {
      _meta?: { ui?: { resourceUri?: string; visibility?: string[] }; "ui/resourceUri"?: string };
    } | undefined;
    expect(nativeProbe?._meta?.ui).toEqual({ resourceUri: MSO_NATIVE_UI_PROBE_URI, visibility: ["model", "app"] });
    expect(nativeProbe?._meta?.["ui/resourceUri"]).toBe(MSO_NATIVE_UI_PROBE_URI);
    const probeCall = await dispatch({ id: 3, method: "tools/call", params: { name: "mso_native_ui_probe", arguments: {} } }, "read", "mcp:native-ui-probe", context);
    expect(probeCall.error).toBeUndefined();
    expect(JSON.stringify(probeCall.result)).toContain("MSO NATIVE UI WORKS");
    for (const name of CHATGPT_APP_ONLY_TOOL_NAMES) {
      const tool = tools.find((entry) => entry.name === name) as { _meta?: { ui?: { visibility?: string[] } } } | undefined;
      expect(tool?._meta?.ui?.visibility, name).toEqual(["app"]);
    }
    const pipeline = tools.find((tool) => tool.name === "read_pipeline") as { inputSchema?: { properties?: { calls?: { items?: { properties?: { transform?: { properties?: { where?: { items?: { properties?: { value?: unknown } } } } } } } } } } } | undefined;
    expect(pipeline?.inputSchema?.properties?.calls?.items?.properties?.transform?.properties?.where?.items?.properties?.value).toEqual({
      anyOf: [{ type: "string", maxLength: 2048 }, { type: "number" }, { type: "boolean" }, { type: "null" }],
    });
    expect(tools.some((tool) => String(tool.name) === "private_echo" || String(tool.name).startsWith("project_fixture_"))).toBe(false);
  });

  it("keeps unknown/project-owned global names out while app-only bridges remain callable by the app", async () => {
    for (const name of ["private_echo", "project_fixture_secret_tool"]) {
      const result = await dispatch({ id: 2, method: "tools/call", params: { name, arguments: {} } }, "exec", "test", context);
      expect(result.error, name).toMatchObject({ code: -32602 });
    }
  });
});