57dc91585d
Internal SmartGift build of a Claude Code monitoring dashboard. Lanes: a durable unit of parallel agent work, one per working directory, tracked across session restarts. Managed lanes are git worktrees the dashboard provisions and can reset or remove behind a three-check destroy guard and a counted preflight; adopted lanes are directories you already own and are never destroyable. Pipelines: a lane moves through pipeline stages. A stage the agent declares with evidence renders green; a stage inferred from the tool-event stream renders dashed amber and never counts as done. Detection is forward-only within a 30-minute window, and never writes the declared stage. Workspace: one page at /run with a lane grid, the selected lane's pipeline, and a full Claude console behind a disclosure.
70 lines
2.6 KiB
TypeScript
70 lines
2.6 KiB
TypeScript
/**
|
|
* @file tool-registry.test.ts
|
|
* @description Unit tests for the tool registry functions, which are responsible for registering tools in the MCP server. The tests cover the behavior of the createCollectorRegistrar and createDualRegistrar functions, ensuring that they correctly collect tool entries and integrate with the MCP server's registration mechanism. The tests use Node's built-in test runner and assert module for assertions.
|
|
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
|
*/
|
|
|
|
import { describe, it } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
createCollectorRegistrar,
|
|
createDualRegistrar,
|
|
type ToolEntry,
|
|
} from "../src/core/tool-registry.js";
|
|
import { z } from "zod";
|
|
|
|
describe("createCollectorRegistrar", () => {
|
|
it("collects tool entries into the provided array", () => {
|
|
const collector: ToolEntry[] = [];
|
|
const register = createCollectorRegistrar(collector);
|
|
|
|
const handler = async () => ({ ok: true });
|
|
register("my_tool", "A test tool", { name: z.string() }, handler);
|
|
|
|
assert.equal(collector.length, 1);
|
|
assert.equal(collector[0].name, "my_tool");
|
|
assert.equal(collector[0].description, "A test tool");
|
|
assert.equal(collector[0].handler, handler);
|
|
});
|
|
|
|
it("collects multiple tools in order", () => {
|
|
const collector: ToolEntry[] = [];
|
|
const register = createCollectorRegistrar(collector);
|
|
|
|
register("tool_a", "First tool", {}, async () => "a");
|
|
register("tool_b", "Second tool", {}, async () => "b");
|
|
register("tool_c", "Third tool", {}, async () => "c");
|
|
|
|
assert.equal(collector.length, 3);
|
|
assert.deepEqual(
|
|
collector.map((t) => t.name),
|
|
["tool_a", "tool_b", "tool_c"]
|
|
);
|
|
});
|
|
|
|
it("handler is invocable and returns expected result", async () => {
|
|
const collector: ToolEntry[] = [];
|
|
const register = createCollectorRegistrar(collector);
|
|
|
|
register("echo_tool", "Echoes input", {}, async (args) => ({
|
|
echo: args.message,
|
|
}));
|
|
|
|
const result = await collector[0].handler({ message: "hello" });
|
|
assert.deepEqual(result, { echo: "hello" });
|
|
});
|
|
});
|
|
|
|
describe("createDualRegistrar", () => {
|
|
it("pushes to collector array", () => {
|
|
// We can't easily create a real McpServer in tests, so we test the collector
|
|
// behavior by verifying createCollectorRegistrar is the building block
|
|
const collector: ToolEntry[] = [];
|
|
const register = createCollectorRegistrar(collector);
|
|
|
|
register("dual_test", "Dual test tool", { id: z.string() }, async () => null);
|
|
assert.equal(collector.length, 1);
|
|
assert.equal(collector[0].name, "dual_test");
|
|
});
|
|
});
|