Files
Void-Homelab/tests/ai/agent/registry.test.js
2026-06-01 18:10:11 +10:00

33 lines
1022 B
JavaScript

import { describe, it, expect } from 'vitest';
import { createRegistry } from '../../../lib/ai/agent/registry.js';
describe('tool registry', () => {
const def = {
name: 'echo',
description: 'echo back',
input_schema: { type: 'object', properties: { x: { type: 'string' } }, required: ['x'] },
handler: async ({ x }) => ({ ok: true, x })
};
it('registers and retrieves a tool', () => {
const r = createRegistry();
r.registerTool(def);
expect(r.getTool('echo')).toBe(def);
expect(r.listTools().map(t => t.name)).toEqual(['echo']);
});
it('rejects duplicate names', () => {
const r = createRegistry();
r.registerTool(def);
expect(() => r.registerTool(def)).toThrow(/already registered/);
});
it('serialises to the Anthropic tools shape (no handler leak)', () => {
const r = createRegistry();
r.registerTool(def);
expect(r.toAnthropicTools()).toEqual([
{ name: 'echo', description: 'echo back', input_schema: def.input_schema }
]);
});
});