forked from Lilly-Protocol/agentlily-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntime-error-tojson.test.ts
More file actions
42 lines (38 loc) · 1.58 KB
/
Copy pathruntime-error-tojson.test.ts
File metadata and controls
42 lines (38 loc) · 1.58 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
import { describe, it, expect } from "vitest";
import { RuntimeError } from "../../src/errors/runtime-errors.js";
describe("RuntimeError toJSON serialization (Issue #155)", () => {
it("includes code and details in JSON.stringify output", () => {
const err = new RuntimeError("INVALID_TASK", "bad input", {
fieldName: "taskId"
});
const json = JSON.parse(JSON.stringify(err));
expect(json.code).toBe("INVALID_TASK");
expect(json.details).toEqual({ fieldName: "taskId" });
expect(json.message).toBe("bad input");
expect(json.name).toBe("RuntimeError");
});
it("includes stack trace in toJSON output", () => {
const err = new RuntimeError("EXECUTION_FAILED", "oops");
const json = err.toJSON();
expect(json.stack).toBeDefined();
expect(typeof json.stack).toBe("string");
expect((json.stack as string).length).toBeGreaterThan(0);
});
it("serializes undefined details as undefined in toJSON", () => {
const err = new RuntimeError("TOOL_NOT_FOUND", "missing");
const json = err.toJSON();
expect(json.details).toBeUndefined();
expect(json.code).toBe("TOOL_NOT_FOUND");
});
it("preserves all fields through JSON round-trip", () => {
const original = new RuntimeError("DUPLICATE_TOOL", "dup", {
toolName: "echo"
});
const restored = JSON.parse(JSON.stringify(original));
expect(restored.name).toBe("RuntimeError");
expect(restored.code).toBe("DUPLICATE_TOOL");
expect(restored.message).toBe("dup");
expect(restored.details).toEqual({ toolName: "echo" });
expect(restored.stack).toBeDefined();
});
});