forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool-registry.test.ts
More file actions
35 lines (31 loc) · 1.07 KB
/
Copy pathtool-registry.test.ts
File metadata and controls
35 lines (31 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { describe, expect, it } from "vitest";
import { RuntimeError, ToolRegistry } from "../src/index.js";
describe("ToolRegistry", () => {
it("prevents duplicate tool names with correct error code and details", () => {
const registry = new ToolRegistry();
const tool = {
name: "echo",
description: "Echo tool",
execute() {
return "ok";
}
};
registry.register(tool);
try {
registry.register(tool);
expect.fail("should have thrown");
} catch (e) {
const err = e as RuntimeError;
expect(err).toBeInstanceOf(RuntimeError);
expect(err.code).toBe("DUPLICATE_TOOL");
expect(err.details?.toolName).toBe("echo");
expect(err.message).toMatch(/already registered/);
}
});
it("allows registering different tools with distinct names", () => {
const registry = new ToolRegistry();
registry.register({ name: "a", description: "A", execute: () => "a" });
registry.register({ name: "b", description: "B", execute: () => "b" });
expect(registry.list()).toHaveLength(2);
});
});