illuma-agents 1.0.23 → 1.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,235 +0,0 @@
1
- /**
2
- * Tests for Browser Interrupt Tools
3
- *
4
- * These tests verify:
5
- * 1. Tool creation and schema validation
6
- * 2. Interrupt type exports and guards
7
- * 3. Tool naming consistency
8
- */
9
-
10
- import { z } from 'zod';
11
- import {
12
- createBrowserInterruptTools,
13
- createBrowserNavigateInterruptTool,
14
- createBrowserClickInterruptTool,
15
- createBrowserTypeInterruptTool,
16
- createBrowserGetPageStateInterruptTool,
17
- createBrowserScrollInterruptTool,
18
- createBrowserExtractInterruptTool,
19
- createBrowserHoverInterruptTool,
20
- createBrowserWaitInterruptTool,
21
- createBrowserGoBackInterruptTool,
22
- createBrowserScreenshotInterruptTool,
23
- isBrowserInterrupt,
24
- isBrowserInterruptToolCall,
25
- BROWSER_INTERRUPT_TOOL_NAMES,
26
- EBrowserInterruptTools,
27
- type BrowserInterrupt,
28
- type BrowserActionResult,
29
- } from '../tools/BrowserInterruptTools';
30
-
31
- describe('BrowserInterruptTools', () => {
32
- describe('createBrowserInterruptTools', () => {
33
- it('should create all 10 browser tools', () => {
34
- const tools = createBrowserInterruptTools();
35
- expect(tools).toHaveLength(10);
36
- });
37
-
38
- it('should have unique tool names', () => {
39
- const tools = createBrowserInterruptTools();
40
- const names = tools.map(t => t.name);
41
- const uniqueNames = new Set(names);
42
- expect(uniqueNames.size).toBe(names.length);
43
- });
44
-
45
- it('should match BROWSER_INTERRUPT_TOOL_NAMES', () => {
46
- const tools = createBrowserInterruptTools();
47
- const names = tools.map(t => t.name);
48
- expect(names.sort()).toEqual([...BROWSER_INTERRUPT_TOOL_NAMES].sort());
49
- });
50
- });
51
-
52
- describe('individual tool creation', () => {
53
- it('should create navigate tool with correct schema', () => {
54
- const tool = createBrowserNavigateInterruptTool();
55
- expect(tool.name).toBe('browser_navigate');
56
- expect(tool.schema).toBeDefined();
57
-
58
- // Verify schema accepts valid input
59
- const schema = tool.schema as z.ZodObject<any>;
60
- const result = schema.safeParse({ url: 'https://example.com' });
61
- expect(result.success).toBe(true);
62
- });
63
-
64
- it('should create click tool with correct schema', () => {
65
- const tool = createBrowserClickInterruptTool();
66
- expect(tool.name).toBe('browser_click');
67
-
68
- const schema = tool.schema as z.ZodObject<any>;
69
- // Click by index
70
- expect(schema.safeParse({ index: 5 }).success).toBe(true);
71
- // Click by coordinates
72
- expect(schema.safeParse({ coordinates: { x: 100, y: 200 } }).success).toBe(true);
73
- });
74
-
75
- it('should create type tool with correct schema', () => {
76
- const tool = createBrowserTypeInterruptTool();
77
- expect(tool.name).toBe('browser_type');
78
-
79
- const schema = tool.schema as z.ZodObject<any>;
80
- expect(schema.safeParse({ index: 3, text: 'hello world' }).success).toBe(true);
81
- expect(schema.safeParse({ index: 3, text: 'search', pressEnter: true }).success).toBe(true);
82
- });
83
-
84
- it('should create get_page_state tool with correct schema', () => {
85
- const tool = createBrowserGetPageStateInterruptTool();
86
- expect(tool.name).toBe('browser_get_page_state');
87
-
88
- const schema = tool.schema as z.ZodObject<any>;
89
- expect(schema.safeParse({}).success).toBe(true);
90
- expect(schema.safeParse({ reason: 'checking elements' }).success).toBe(true);
91
- });
92
-
93
- it('should create scroll tool with correct schema', () => {
94
- const tool = createBrowserScrollInterruptTool();
95
- expect(tool.name).toBe('browser_scroll');
96
-
97
- const schema = tool.schema as z.ZodObject<any>;
98
- expect(schema.safeParse({ direction: 'down' }).success).toBe(true);
99
- expect(schema.safeParse({ direction: 'up', amount: 500 }).success).toBe(true);
100
- expect(schema.safeParse({ direction: 'invalid' }).success).toBe(false);
101
- });
102
-
103
- it('should create extract tool with correct schema', () => {
104
- const tool = createBrowserExtractInterruptTool();
105
- expect(tool.name).toBe('browser_extract');
106
-
107
- const schema = tool.schema as z.ZodObject<any>;
108
- expect(schema.safeParse({}).success).toBe(true);
109
- expect(schema.safeParse({ query: 'product prices' }).success).toBe(true);
110
- });
111
-
112
- it('should create hover tool with correct schema', () => {
113
- const tool = createBrowserHoverInterruptTool();
114
- expect(tool.name).toBe('browser_hover');
115
-
116
- const schema = tool.schema as z.ZodObject<any>;
117
- expect(schema.safeParse({ index: 5 }).success).toBe(true);
118
- expect(schema.safeParse({}).success).toBe(false); // index is required
119
- });
120
-
121
- it('should create wait tool with correct schema', () => {
122
- const tool = createBrowserWaitInterruptTool();
123
- expect(tool.name).toBe('browser_wait');
124
-
125
- const schema = tool.schema as z.ZodObject<any>;
126
- expect(schema.safeParse({}).success).toBe(true);
127
- expect(schema.safeParse({ duration: 2000 }).success).toBe(true);
128
- });
129
-
130
- it('should create back tool with correct schema', () => {
131
- const tool = createBrowserGoBackInterruptTool();
132
- expect(tool.name).toBe('browser_back');
133
-
134
- const schema = tool.schema as z.ZodObject<any>;
135
- expect(schema.safeParse({}).success).toBe(true);
136
- });
137
-
138
- it('should create screenshot tool with correct schema', () => {
139
- const tool = createBrowserScreenshotInterruptTool();
140
- expect(tool.name).toBe('browser_screenshot');
141
-
142
- const schema = tool.schema as z.ZodObject<any>;
143
- expect(schema.safeParse({}).success).toBe(true);
144
- expect(schema.safeParse({ fullPage: true }).success).toBe(true);
145
- });
146
- });
147
-
148
- describe('isBrowserInterrupt', () => {
149
- it('should return true for valid browser interrupt', () => {
150
- const interrupt: BrowserInterrupt = {
151
- type: 'browser_interrupt',
152
- action: { type: 'navigate', url: 'https://example.com' },
153
- interruptId: 'test_123',
154
- };
155
- expect(isBrowserInterrupt(interrupt)).toBe(true);
156
- });
157
-
158
- it('should return false for null/undefined', () => {
159
- expect(isBrowserInterrupt(null)).toBe(false);
160
- expect(isBrowserInterrupt(undefined)).toBe(false);
161
- });
162
-
163
- it('should return false for non-object', () => {
164
- expect(isBrowserInterrupt('string')).toBe(false);
165
- expect(isBrowserInterrupt(123)).toBe(false);
166
- });
167
-
168
- it('should return false for wrong type field', () => {
169
- expect(isBrowserInterrupt({ type: 'other_type' })).toBe(false);
170
- });
171
- });
172
-
173
- describe('isBrowserInterruptToolCall', () => {
174
- it('should return true for valid tool names', () => {
175
- expect(isBrowserInterruptToolCall('browser_navigate')).toBe(true);
176
- expect(isBrowserInterruptToolCall('browser_click')).toBe(true);
177
- expect(isBrowserInterruptToolCall('browser_type')).toBe(true);
178
- expect(isBrowserInterruptToolCall('browser_get_page_state')).toBe(true);
179
- });
180
-
181
- it('should return false for invalid tool names', () => {
182
- expect(isBrowserInterruptToolCall('invalid_tool')).toBe(false);
183
- expect(isBrowserInterruptToolCall('browser_invalid')).toBe(false);
184
- expect(isBrowserInterruptToolCall('')).toBe(false);
185
- });
186
- });
187
-
188
- describe('EBrowserInterruptTools enum', () => {
189
- it('should have all expected tool names', () => {
190
- expect(EBrowserInterruptTools.CLICK).toBe('browser_click');
191
- expect(EBrowserInterruptTools.TYPE).toBe('browser_type');
192
- expect(EBrowserInterruptTools.NAVIGATE).toBe('browser_navigate');
193
- expect(EBrowserInterruptTools.SCROLL).toBe('browser_scroll');
194
- expect(EBrowserInterruptTools.EXTRACT).toBe('browser_extract');
195
- expect(EBrowserInterruptTools.HOVER).toBe('browser_hover');
196
- expect(EBrowserInterruptTools.WAIT).toBe('browser_wait');
197
- expect(EBrowserInterruptTools.BACK).toBe('browser_back');
198
- expect(EBrowserInterruptTools.SCREENSHOT).toBe('browser_screenshot');
199
- expect(EBrowserInterruptTools.GET_PAGE_STATE).toBe('browser_get_page_state');
200
- });
201
- });
202
-
203
- describe('BrowserActionResult type', () => {
204
- it('should accept success result', () => {
205
- const result: BrowserActionResult = {
206
- success: true,
207
- };
208
- expect(result.success).toBe(true);
209
- });
210
-
211
- it('should accept result with page state', () => {
212
- const result: BrowserActionResult = {
213
- success: true,
214
- pageState: {
215
- url: 'https://example.com',
216
- title: 'Example',
217
- elementList: '[0] <button>Click me</button>',
218
- elementCount: 1,
219
- scrollPosition: 0,
220
- scrollHeight: 1000,
221
- viewportHeight: 800,
222
- },
223
- };
224
- expect(result.pageState?.elementCount).toBe(1);
225
- });
226
-
227
- it('should accept error result', () => {
228
- const result: BrowserActionResult = {
229
- success: false,
230
- error: 'Element not found',
231
- };
232
- expect(result.error).toBe('Element not found');
233
- });
234
- });
235
- });