tool-registry-alias.test.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { describe, expect, it } from "vitest";
  2. import { createToolRegistry } from "../src/tool/registry.js";
  3. import type { ToolEntry } from "../src/tool/types.js";
  4. describe("ToolRegistry aliases", () => {
  5. it("does not let a newly registered alias shadow an existing canonical tool", () => {
  6. const registry = createToolRegistry();
  7. const existingCanonical = createEntry("mcp__computer_use__open_application");
  8. const officialTool = createEntry("mcp__computer-use__open_application", [
  9. "mcp__computer_use__open_application",
  10. ]);
  11. registry.register(existingCanonical);
  12. registry.register(officialTool);
  13. expect(registry.get("mcp__computer_use__open_application")).toBe(existingCanonical);
  14. expect(registry.get("mcp__computer-use__open_application")).toBe(officialTool);
  15. });
  16. it("lets a later canonical registration displace an older alias with the same name", () => {
  17. const registry = createToolRegistry();
  18. const officialTool = createEntry("mcp__computer-use__open_application", [
  19. "mcp__computer_use__open_application",
  20. ]);
  21. const laterCanonical = createEntry("mcp__computer_use__open_application");
  22. registry.register(officialTool);
  23. registry.register(laterCanonical);
  24. expect(registry.get("mcp__computer_use__open_application")).toBe(laterCanonical);
  25. expect(registry.get("mcp__computer-use__open_application")).toBe(officialTool);
  26. });
  27. });
  28. function createEntry(name: string, aliases?: readonly string[]): ToolEntry {
  29. return {
  30. aliases,
  31. capability: `test capability for ${name}`,
  32. handler: async () => ({ ok: true }),
  33. inputSchema: {
  34. type: "object",
  35. properties: {},
  36. additionalProperties: false,
  37. },
  38. metadata: {
  39. concurrentSafe: true,
  40. destructive: false,
  41. name,
  42. needsApproval: false,
  43. readOnly: true,
  44. riskLevel: "low",
  45. sideEffectScope: "none",
  46. },
  47. };
  48. }