mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-17 13:01:24 +00:00
238 lines
9.8 KiB
JavaScript
238 lines
9.8 KiB
JavaScript
"use strict";
|
|
|
|
const test = require("node:test");
|
|
const assert = require("node:assert/strict");
|
|
const { CAPABILITY_STATUS } = require("../constants.cjs");
|
|
const { ALL_CAPABILITIES } = require("../catalog/index.cjs");
|
|
const { TOOL_INPUT_FIELDS } = require("../schemas/toolInputs.cjs");
|
|
const {
|
|
listMcpTools,
|
|
listCattyToolSpecs,
|
|
CATTY_CAPABILITY_DENYLIST,
|
|
isCattyEligible,
|
|
} = require("./toolSurfaces.cjs");
|
|
const { registerMcpTools, buildZodShapeObject } = require("./mcpToolRegistry.cjs");
|
|
|
|
test("listCattyToolSpecs includes terminal long-running tools", () => {
|
|
const specs = listCattyToolSpecs();
|
|
const names = specs.map((spec) => spec.toolName);
|
|
assert.ok(names.includes("terminal_execute"));
|
|
assert.ok(names.includes("terminal_start"));
|
|
assert.ok(names.includes("terminal_poll"));
|
|
assert.ok(names.includes("terminal_stop"));
|
|
});
|
|
|
|
test("listCattyToolSpecs includes SFTP write tools and attachments", () => {
|
|
const capabilityIds = listCattyToolSpecs().map((spec) => spec.capabilityId);
|
|
assert.ok(capabilityIds.includes("attachment.list"));
|
|
assert.ok(capabilityIds.includes("attachment.read"));
|
|
assert.ok(capabilityIds.includes("sftp.write"));
|
|
assert.ok(capabilityIds.includes("sftp.mkdir"));
|
|
assert.ok(capabilityIds.includes("sftp.delete"));
|
|
assert.ok(capabilityIds.includes("sftp.rename"));
|
|
assert.ok(capabilityIds.includes("sftp.chmod"));
|
|
assert.ok(!capabilityIds.includes("meta.status"));
|
|
assert.ok(!capabilityIds.includes("session.cancel"));
|
|
});
|
|
|
|
test("listCattyToolSpecs includes vault host tools and SFTP transfer", () => {
|
|
const capabilityIds = listCattyToolSpecs().map((spec) => spec.capabilityId);
|
|
assert.ok(capabilityIds.includes("vault.host.get"));
|
|
assert.ok(capabilityIds.includes("vault.host.list"));
|
|
assert.ok(capabilityIds.includes("vault.host.open"));
|
|
assert.ok(capabilityIds.includes("vault.hosts.create"));
|
|
assert.ok(capabilityIds.includes("vault.host.update"));
|
|
assert.ok(capabilityIds.includes("vault.host.delete"));
|
|
assert.ok(capabilityIds.includes("vault.host.import"));
|
|
assert.ok(capabilityIds.includes("vault.note.create"));
|
|
assert.ok(capabilityIds.includes("vault.note.list"));
|
|
assert.ok(capabilityIds.includes("sftp.download"));
|
|
assert.ok(capabilityIds.includes("sftp.upload"));
|
|
});
|
|
|
|
test("listMcpTools includes vault host update and delete for external MCP clients", () => {
|
|
const tools = listMcpTools();
|
|
const create = tools.find((tool) => tool.mcpTool === "vault_hosts_create");
|
|
const update = tools.find((tool) => tool.mcpTool === "vault_hosts_update");
|
|
const remove = tools.find((tool) => tool.mcpTool === "vault_hosts_delete");
|
|
assert.match(create?.inputShape.hosts?.description ?? "", /passphrase/i);
|
|
assert.equal(update?.capabilityId, "vault.host.update");
|
|
assert.equal(update?.publicRpcMethod, "public/vault/hosts/update");
|
|
assert.ok(update?.inputShape.keyPath);
|
|
assert.ok(update?.inputShape.keypath);
|
|
assert.ok(update?.inputShape.savePassword);
|
|
assert.ok(update?.inputShape.passphrase);
|
|
assert.equal(remove?.capabilityId, "vault.host.delete");
|
|
assert.equal(remove?.publicRpcMethod, "public/vault/hosts/delete");
|
|
});
|
|
|
|
test("listMcpTools includes host_open for external MCP clients", () => {
|
|
const tools = listMcpTools();
|
|
const hostOpen = tools.find((tool) => tool.mcpTool === "host_open");
|
|
assert.ok(hostOpen);
|
|
assert.equal(hostOpen.capabilityId, "vault.host.open");
|
|
assert.equal(hostOpen.publicRpcMethod, "public/vault/hosts/open");
|
|
});
|
|
|
|
test("session_close is exposed to agents and external MCP clients", () => {
|
|
const mcpTool = listMcpTools().find((tool) => tool.mcpTool === "session_close");
|
|
assert.ok(mcpTool);
|
|
assert.equal(mcpTool.capabilityId, "session.close");
|
|
assert.equal(mcpTool.publicRpcMethod, "public/session/close");
|
|
|
|
const cattyTool = listCattyToolSpecs().find((tool) => tool.toolName === "session_close");
|
|
assert.ok(cattyTool);
|
|
assert.equal(cattyTool.rpcMethod, "session/close");
|
|
});
|
|
|
|
test("host_open tells agents to close sessions after use", () => {
|
|
const hostOpen = listMcpTools().find((tool) => tool.mcpTool === "host_open");
|
|
assert.match(hostOpen?.description || "", /session_close/i);
|
|
});
|
|
|
|
test("vault host import tool description routes unknown attached host text to host creation", () => {
|
|
const importSpec = listCattyToolSpecs().find((spec) => spec.capabilityId === "vault.host.import");
|
|
assert.ok(importSpec);
|
|
assert.match(importSpec.description, /known export formats/i);
|
|
assert.match(importSpec.description, /unknown/i);
|
|
assert.match(importSpec.description, /read_attachment/i);
|
|
assert.match(importSpec.description, /vault_hosts_create/i);
|
|
});
|
|
|
|
test("listCattyToolSpecs binds vault note tools to global RPC methods", () => {
|
|
const specs = listCattyToolSpecs();
|
|
const noteCreate = specs.find((spec) => spec.capabilityId === "vault.note.create");
|
|
assert.equal(noteCreate?.rpcMethod, "vault/notes/create");
|
|
const noteList = specs.find((spec) => spec.capabilityId === "vault.note.list");
|
|
assert.equal(noteList?.rpcMethod, "vault/notes/list");
|
|
});
|
|
|
|
test("listCattyToolSpecs binds vault and portforward tools to global RPC methods", () => {
|
|
const specs = listCattyToolSpecs();
|
|
const hostNotesSet = specs.find((spec) => spec.capabilityId === "vault.host.notes.set");
|
|
assert.equal(hostNotesSet?.rpcMethod, "vault/host/notes/set");
|
|
const portforwardStart = specs.find((spec) => spec.capabilityId === "portforward.start");
|
|
assert.equal(portforwardStart?.rpcMethod, "portforward/start");
|
|
});
|
|
|
|
test("listAgentToolSpecs splits sidebar harness tools from shared RPC tools", () => {
|
|
const { AGENT_KINDS, listAgentToolSpecs } = require("./toolSurfaces.cjs");
|
|
const sidebarIds = listAgentToolSpecs(AGENT_KINDS.SIDEBAR).map((spec) => spec.capabilityId);
|
|
const globalIds = listAgentToolSpecs(AGENT_KINDS.GLOBAL).map((spec) => spec.capabilityId);
|
|
|
|
assert.ok(sidebarIds.includes("harness.workspace.get_info"));
|
|
assert.ok(!globalIds.includes("harness.workspace.get_info"));
|
|
|
|
assert.ok(sidebarIds.includes("terminal.execute"));
|
|
assert.ok(globalIds.includes("terminal.execute"));
|
|
assert.ok(globalIds.includes("vault.note.create"));
|
|
|
|
assert.ok(globalIds.every((id) => sidebarIds.includes(id) || id.startsWith("harness.") === false));
|
|
});
|
|
|
|
test("listCattyToolSpecs includes harness catty-only tools with local execution", () => {
|
|
const specs = listCattyToolSpecs();
|
|
assert.ok(specs.length >= 40);
|
|
const harness = specs.filter((spec) => spec.capabilityId.startsWith("harness."));
|
|
assert.equal(harness.length, 6);
|
|
for (const spec of harness) {
|
|
assert.equal(spec.localExecution, true);
|
|
assert.equal(spec.rpcMethod, null);
|
|
}
|
|
const harnessIds = harness.map((spec) => spec.capabilityId);
|
|
assert.ok(harnessIds.includes("harness.tool_output.read"));
|
|
assert.ok(harnessIds.includes("harness.workspace.get_info"));
|
|
assert.ok(harnessIds.includes("harness.terminal.read_context"));
|
|
});
|
|
|
|
test("harness capabilities are not exposed on MCP", () => {
|
|
const mcpCapabilityIds = listMcpTools().map((tool) => tool.capabilityId);
|
|
for (const capabilityId of mcpCapabilityIds) {
|
|
assert.ok(!capabilityId.startsWith("harness."));
|
|
}
|
|
});
|
|
|
|
test("listMcpTools descriptions stay aligned with catalog capability ids", () => {
|
|
const mcpTools = listMcpTools();
|
|
assert.ok(mcpTools.length >= 35);
|
|
for (const tool of mcpTools) {
|
|
assert.ok(tool.capabilityId);
|
|
assert.ok(tool.mcpTool);
|
|
assert.ok(tool.description.length > 0);
|
|
assert.ok(tool.rpcMethod);
|
|
}
|
|
});
|
|
|
|
test("catty and mcp terminal tools share capability ids", () => {
|
|
const catty = listCattyToolSpecs().find((spec) => spec.toolName === "terminal_execute");
|
|
const mcp = listMcpTools().find((tool) => tool.mcpTool === "terminal_execute");
|
|
assert.equal(catty?.capabilityId, "terminal.execute");
|
|
assert.equal(mcp?.capabilityId, "terminal.execute");
|
|
});
|
|
|
|
test("implemented catalog tools with inputs are catty-eligible unless denylisted", () => {
|
|
const implemented = ALL_CAPABILITIES.filter((cap) => cap.status === CAPABILITY_STATUS.IMPLEMENTED);
|
|
for (const capability of implemented) {
|
|
const hasInputs = Object.prototype.hasOwnProperty.call(TOOL_INPUT_FIELDS, capability.id);
|
|
if (!hasInputs) continue;
|
|
if (CATTY_CAPABILITY_DENYLIST.has(capability.id)) {
|
|
assert.equal(isCattyEligible(capability), false);
|
|
continue;
|
|
}
|
|
const hasRpc = Boolean(
|
|
capability.surfaces?.builtin?.rpcMethod
|
|
|| capability.surfaces?.public?.mcpTool,
|
|
);
|
|
if (hasRpc) {
|
|
assert.equal(isCattyEligible(capability), true);
|
|
}
|
|
}
|
|
});
|
|
|
|
test("mcp registry builds zod shapes for every MCP tool", () => {
|
|
for (const tool of listMcpTools()) {
|
|
const shape = buildZodShapeObject(tool.inputShape);
|
|
assert.equal(typeof shape, "object");
|
|
}
|
|
});
|
|
|
|
test("registerMcpTools registers one handler per catalog MCP tool", () => {
|
|
const registered = [];
|
|
const fakeServer = {
|
|
tool(name, _description, _shape, handler) {
|
|
registered.push({ name, handler: typeof handler });
|
|
},
|
|
};
|
|
const count = registerMcpTools(fakeServer, {
|
|
rpcCall: async () => ({ ok: true }),
|
|
scopeParams: {},
|
|
guardWriteOperation: () => null,
|
|
catalogDescription: (_name, fallback) => fallback,
|
|
});
|
|
assert.equal(count, listMcpTools().length);
|
|
assert.equal(registered.length, listMcpTools().length);
|
|
});
|
|
|
|
test("session_close remains available as a cleanup action in observer mode", async () => {
|
|
let handler = null;
|
|
let guardCalls = 0;
|
|
const fakeServer = {
|
|
tool(name, _description, _shape, candidate) {
|
|
if (name === "session_close") handler = candidate;
|
|
},
|
|
};
|
|
registerMcpTools(fakeServer, {
|
|
rpcCall: async (_method, params) => ({ ok: true, sessionId: params.sessionId, status: "closed" }),
|
|
scopeParams: { chatSessionId: "chat-1" },
|
|
guardWriteOperation: () => {
|
|
guardCalls += 1;
|
|
return "Observer mode";
|
|
},
|
|
catalogDescription: (_name, fallback) => fallback,
|
|
});
|
|
|
|
const result = await handler({ sessionId: "session-1" });
|
|
assert.equal(result.isError, undefined);
|
|
assert.equal(guardCalls, 0);
|
|
});
|