forked from NoeFabris/opencode-antigravity-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.test.ts
More file actions
105 lines (87 loc) · 3.7 KB
/
Copy patherrors.test.ts
File metadata and controls
105 lines (87 loc) · 3.7 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
import { describe, expect, it } from "vitest";
import { EmptyResponseError, ToolIdMismatchError } from "./errors";
// ─── EmptyResponseError ───────────────────────────────────────────────────────
describe("EmptyResponseError", () => {
it("is an instance of Error", () => {
const err = new EmptyResponseError("gemini", "gemini-2.5-flash", 3);
expect(err).toBeInstanceOf(Error);
});
it("has name EmptyResponseError", () => {
const err = new EmptyResponseError("gemini", "gemini-2.5-flash", 3);
expect(err.name).toBe("EmptyResponseError");
});
it("stores provider, model, and attempts on the instance", () => {
const err = new EmptyResponseError("anthropic", "claude-3-5-sonnet", 5);
expect(err.provider).toBe("anthropic");
expect(err.model).toBe("claude-3-5-sonnet");
expect(err.attempts).toBe(5);
});
it("generates a default message that mentions the attempt count", () => {
const err = new EmptyResponseError("gemini", "model-x", 2);
expect(err.message).toContain("2");
expect(err.message).toContain("attempts");
});
it("uses a custom message when provided", () => {
const err = new EmptyResponseError("gemini", "model-x", 1, "custom error msg");
expect(err.message).toBe("custom error msg");
});
it("works with attempts = 1 (singular language check)", () => {
const err = new EmptyResponseError("p", "m", 1);
expect(err.message).toContain("1");
});
it("can be thrown and caught as an Error", () => {
expect(() => {
throw new EmptyResponseError("gemini", "model", 1);
}).toThrow(EmptyResponseError);
});
it("is also catchable as a generic Error", () => {
expect(() => {
throw new EmptyResponseError("gemini", "model", 1);
}).toThrow(Error);
});
});
// ─── ToolIdMismatchError ──────────────────────────────────────────────────────
describe("ToolIdMismatchError", () => {
it("is an instance of Error", () => {
const err = new ToolIdMismatchError(["tool_1"], ["tool_2"]);
expect(err).toBeInstanceOf(Error);
});
it("has name ToolIdMismatchError", () => {
const err = new ToolIdMismatchError(["a"], ["b"]);
expect(err.name).toBe("ToolIdMismatchError");
});
it("stores expectedIds and foundIds on the instance", () => {
const expected = ["tool_a", "tool_b"];
const found = ["tool_c"];
const err = new ToolIdMismatchError(expected, found);
expect(err.expectedIds).toEqual(expected);
expect(err.foundIds).toEqual(found);
});
it("generates a default message mentioning both id lists", () => {
const err = new ToolIdMismatchError(["x", "y"], ["z"]);
expect(err.message).toContain("x");
expect(err.message).toContain("y");
expect(err.message).toContain("z");
});
it("uses a custom message when provided", () => {
const err = new ToolIdMismatchError(["a"], ["b"], "my custom message");
expect(err.message).toBe("my custom message");
});
it("handles empty arrays without throwing", () => {
const err = new ToolIdMismatchError([], []);
expect(err.expectedIds).toEqual([]);
expect(err.foundIds).toEqual([]);
});
it("can be thrown and caught as an Error", () => {
expect(() => {
throw new ToolIdMismatchError(["a"], ["b"]);
}).toThrow(ToolIdMismatchError);
});
it("preserves array references exactly", () => {
const expected = ["id-1"];
const found = ["id-2"];
const err = new ToolIdMismatchError(expected, found);
expect(err.expectedIds).toBe(expected);
expect(err.foundIds).toBe(found);
});
});