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.

3.4 KB
Raw Blame
import { describe, expect, it, vi } from "vitest";

vi.mock("@/lib/a2a/local-session", () => ({
  handoffOwnerLocalSession: vi.fn(async () => ({ session: { id: "target" }, task: { state: "completed" } })),
}));

const { LOCAL_AGENT_TOOLS } = await import("./tools-local-agents");
const local = new Map(LOCAL_AGENT_TOOLS.map((tool) => [tool.name, tool]));

describe("native local session agent MCP tools", () => {
  it("uses the Organization storage alias while retaining the web authority", async () => {
    const { handoffOwnerLocalSession } = await import("@/lib/a2a/local-session");
    const context = { principal: "web:device", sessionId: "parent", scope: "exec" as const, capabilities: { list: () => [], invoke: vi.fn() } };
    await local.get("local_agent_request")!.run({ target: "target", objective: "inspect" }, context);
    expect(handoffOwnerLocalSession).toHaveBeenCalledWith("cli:device", "target", "inspect", context.capabilities, "parent", { authority: context });
  });
  it("carries the initiating grant and restrictions into on-demand workers", async () => {
    const { handoffOwnerLocalSession } = await import("@/lib/a2a/local-session");
    const context = { principal: "mcp-client:fixture", sessionId: "parent", scope: "exec" as const, authorizationGrant: { kind: "mcp" as const, id: "a".repeat(64), resource: "https://fixture.invalid/mcp", fingerprint: "fixture" }, allowedTools: ["local_agent_request", "project_get"], toolArgumentConstraints: { project_get: { project: ["reviewed"] } }, capabilities: { list: () => [], invoke: vi.fn() } };
    await local.get("local_agent_request")!.run({ target: "target", objective: "inspect" }, context);
    expect(handoffOwnerLocalSession).toHaveBeenCalledWith(context.principal, "target", "inspect", context.capabilities, "parent", { authority: context });
  });
  it("keeps discovery/wait/inbox read-only, mailbox delivery below exec, and fresh-worker request explicit exec", () => {
    expect(local.get("local_agents_list")?.scope).toBe("read");
    expect(local.get("local_agent_inbox")?.scope).toBe("read");
    expect(local.get("local_agent_request_wait")?.scope).toBe("read");
    expect(local.get("local_agent_message_send")?.scope).toBe("write");
    expect(local.get("local_agent_reply")?.scope).toBe("write");
    expect(local.get("local_agent_request")?.scope).toBe("exec");
    expect(local.get("local_agent_standby")?.scope).toBe("exec");
  });

  it("describes local collaboration without Agent Card registration", () => {
    const description = local.get("local_agent_message_send")?.description || "";
    expect(description).toMatch(/same-owner MSO session agent/i);
    expect(description).toMatch(/no hidden transcript/i);
    expect(description).not.toMatch(/Agent Card URL/i);
    expect(local.get("local_agent_reply")?.description).toMatch(/correlation/i);
    expect(local.get("local_agent_request_wait")?.description).toMatch(/bounded foreground/i);
    expect(local.get("local_agent_request")?.description).toMatch(/fresh bounded worker/i);
    expect(local.get("local_agent_inbox")?.description).toMatch(/bounded interval/i);
    expect(local.get("local_agent_standby")?.description).toMatch(/returns immediately/i);
    expect(local.get("local_agent_standby")?.description).toMatch(/consumerConnected/i);
    const inboxSchema = JSON.stringify(local.get("local_agent_inbox")?.inputSchema ?? {});
    expect(inboxSchema).toContain('"wait_ms"');
    expect(inboxSchema).toContain('"maximum":20000');
  });
});