forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog-tool-duration.test.ts
More file actions
62 lines (53 loc) · 2.1 KB
/
Copy pathlog-tool-duration.test.ts
File metadata and controls
62 lines (53 loc) · 2.1 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { describe, it, expect, vi } from "vitest";
import { ActionExecutor } from "../../src/actions/action-executor.js";
import { ToolRegistry } from "../../src/tools/tool-registry.js";
import type { RuntimeContext } from "../../src/runtime/context.js";
describe("ActionExecutor tool invocation duration logging", () => {
it("logs toolName and durationMs after tool execution", async () => {
const logger = {
info: vi.fn(),
error: vi.fn(),
warn: vi.fn(),
debug: vi.fn()
};
const registry = new ToolRegistry();
registry.register({
name: "slow-tool",
description: "A tool that takes some time",
inputSchema: { type: "object", properties: {} },
execute: vi.fn(async () => {
await new Promise((resolve) => setTimeout(resolve, 30));
return { done: true };
})
});
const executor = new ActionExecutor(registry, logger as any);
const context = {} as RuntimeContext;
const result = await executor.execute("slow-tool", {}, context);
expect(result).toEqual({ done: true });
// Verify logger was called with toolName and durationMs
const logCall = logger.info.mock.calls.find(
(call: any[]) =>
typeof call[0] === "string" &&
call[0].includes("Tool invocation completed")
);
expect(logCall).toBeDefined();
expect(logCall![1]).toHaveProperty("toolName", "slow-tool");
expect(logCall![1]).toHaveProperty("durationMs");
expect(logCall![1].durationMs).toBeGreaterThanOrEqual(20);
expect(logCall![1].durationMs).toBeLessThan(500);
});
it("works without logger (optional dependency)", async () => {
const registry = new ToolRegistry();
registry.register({
name: "quick-tool",
description: "A fast tool",
inputSchema: { type: "object", properties: {} },
execute: vi.fn(async () => ({ ok: true }))
});
// No logger passed - should not throw
const executor = new ActionExecutor(registry);
const context = {} as RuntimeContext;
const result = await executor.execute("quick-tool", {}, context);
expect(result).toEqual({ ok: true });
});
});