forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog-task-duration.test.ts
More file actions
65 lines (57 loc) · 1.92 KB
/
Copy pathlog-task-duration.test.ts
File metadata and controls
65 lines (57 loc) · 1.92 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
63
64
65
import { describe, it, expect, vi } from "vitest";
import { AgentRuntime } from "../../src/runtime/agent-runtime.js";
describe("Task execution duration logging", () => {
it("includes durationMs in completion log and event", async () => {
const logger = {
info: vi.fn(),
error: vi.fn(),
warn: vi.fn(),
debug: vi.fn()
};
const events: any[] = [];
const eventBus = {
emit: vi.fn((e: any) => events.push(e)),
on: vi.fn(),
off: vi.fn()
};
const runtime = new AgentRuntime({
runtimeId: "test-log-duration",
logger: logger as any,
eventBus: eventBus as any,
tools: [],
modelProvider: { generate: vi.fn() } as any
});
runtime.registerTool({
name: "echo",
description: "Echo tool",
inputSchema: { type: "object", properties: {} },
execute: vi.fn(async () => ({ echoed: true }))
});
await runtime.start();
const result = await runtime.executeTask({
taskId: "task-log-1",
agentId: "agent-1",
toolName: "echo",
input: "test",
payload: {}
});
// Verify result has durationMs (from #136)
expect(result.durationMs).toBeDefined();
expect(result.durationMs).toBeGreaterThanOrEqual(0);
// Verify completion log includes durationMs
const completionLog = logger.info.mock.calls.find(
(call: any[]) =>
typeof call[0] === "string" && call[0].includes("completed")
);
expect(completionLog).toBeDefined();
expect(completionLog![1]).toHaveProperty("durationMs");
expect(completionLog![1].durationMs).toBe(result.durationMs);
// Verify completion event includes durationMs
const completedEvent = events.find(
(e) => e.name === "runtime.task.completed"
);
expect(completedEvent).toBeDefined();
expect(completedEvent.payload).toHaveProperty("durationMs");
expect(completedEvent.payload.durationMs).toBe(result.durationMs);
});
});