forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreproduce-issue-252.test.ts
More file actions
142 lines (128 loc) · 3.65 KB
/
Copy pathreproduce-issue-252.test.ts
File metadata and controls
142 lines (128 loc) · 3.65 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import { describe, expect, it } from "vitest";
import {
ActionExecutor,
AgentInstanceManager,
InMemoryMemoryStore,
InMemoryRuntimeStateStore,
RuntimeError,
TaskRunner,
ToolRegistry,
UnconfiguredModelProvider,
type RuntimeContext
} from "../../src/index.js";
describe("Reproduce Issue #252: Tool execution error propagation contract", () => {
const createMockContext = (taskId: string): RuntimeContext => ({
runtimeId: "rt-test-252",
taskId,
agent: new AgentInstanceManager().getOrCreate("agent-252"),
memory: new InMemoryMemoryStore(),
modelProvider: new UnconfiguredModelProvider(),
state: new InMemoryRuntimeStateStore(),
now: new Date().toISOString()
});
it("propagates a plain Error thrown by a tool untouched without RuntimeError wrapper", async () => {
const registry = new ToolRegistry();
registry.register({
name: "plainExplode",
description: "Throws plain error",
execute() {
throw new Error("tool exploded");
}
});
const runner = new TaskRunner(
new ActionExecutor(registry),
new InMemoryMemoryStore()
);
let caught: unknown;
try {
await runner.run(
{
taskId: "task-1",
agentId: "agent-252",
toolName: "plainExplode",
input: "run",
payload: {}
},
createMockContext("task-1")
);
} catch (err) {
caught = err;
}
expect(caught).toBeInstanceOf(Error);
expect(caught).not.toBeInstanceOf(RuntimeError);
expect((caught as Error).message).toBe("tool exploded");
});
it("propagates RuntimeError thrown by tool preserving original code and error", async () => {
const registry = new ToolRegistry();
registry.register({
name: "runtimeExplode",
description: "Throws RuntimeError",
execute() {
throw new RuntimeError("TOOL_NOT_FOUND", "tool exploded with runtime error");
}
});
const runner = new TaskRunner(
new ActionExecutor(registry),
new InMemoryMemoryStore()
);
let caught: unknown;
try {
await runner.run(
{
taskId: "task-2",
agentId: "agent-252",
toolName: "runtimeExplode",
input: "run",
payload: {}
},
createMockContext("task-2")
);
} catch (err) {
caught = err;
}
expect(caught).toBeInstanceOf(RuntimeError);
const runtimeErr = caught as RuntimeError;
expect(runtimeErr.code).toBe("TOOL_NOT_FOUND");
expect(runtimeErr.message).toBe("tool exploded with runtime error");
});
it("wraps memoryStore.append rejection in RuntimeError(EXECUTION_FAILED, cause)", async () => {
const registry = new ToolRegistry();
registry.register({
name: "okTool",
description: "Successful tool",
execute() {
return { success: true };
}
});
const failingStore = {
append: async () => {
throw new Error("disk full");
},
listByAgent: async () => []
};
const runner = new TaskRunner(
new ActionExecutor(registry),
failingStore as any
);
let caught: unknown;
try {
await runner.run(
{
taskId: "task-3",
agentId: "agent-252",
toolName: "okTool",
input: "run",
payload: {}
},
createMockContext("task-3")
);
} catch (err) {
caught = err;
}
expect(caught).toBeInstanceOf(RuntimeError);
const runtimeErr = caught as RuntimeError;
expect(runtimeErr.code).toBe("EXECUTION_FAILED");
expect(runtimeErr.message).toBe("disk full");
expect(runtimeErr.details?.cause).toBe("disk full");
});
});