forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext-fields.test.ts
More file actions
49 lines (43 loc) · 1.59 KB
/
Copy pathcontext-fields.test.ts
File metadata and controls
49 lines (43 loc) · 1.59 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
import { describe, it, expect, vi } from "vitest";
import { AgentRuntime } from "../../src/runtime/agent-runtime.js";
import type { RuntimeOptions } from "../../src/runtime/types.js";
describe("RuntimeContext fields per task (Issue #149)", () => {
it("passes taskId, agent.agentId, runtimeId, and ISO now to tool context", async () => {
let capturedContext: any = null;
const recordingTool = {
name: "recorder",
description: "records invocation context",
inputSchema: {},
execute: async (invocation: { context: any }) => {
capturedContext = invocation.context;
return { output: "ok" };
}
};
const options: RuntimeOptions = {
runtimeId: "ctx-test-runtime",
logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() },
tools: [recordingTool as any],
modelProvider: {
name: "stub",
generate: async () => ({ outputText: "use recorder", metadata: {} })
} as any
};
const runtime = new AgentRuntime(options);
await runtime.start();
await runtime.executeTask({
taskId: "task-149-abc",
agentId: "agent-149",
toolName: "recorder",
input: "run recorder",
payload: {}
});
expect(capturedContext).toBeDefined();
expect(capturedContext.taskId).toBe("task-149-abc");
expect(capturedContext.agent?.agentId).toBe("agent-149");
expect(capturedContext.runtimeId).toBe("ctx-test-runtime");
expect(typeof capturedContext.now).toBe("string");
expect(new Date(capturedContext.now).toISOString()).toBe(
capturedContext.now
);
});
});