|
16 | 16 |
|
17 | 17 | import { z as zod3 } from 'zod/v3'; |
18 | 18 | import * as zod4 from 'zod'; |
| 19 | +import fs from 'fs'; |
19 | 20 |
|
20 | 21 | import { browserTest as test, expect } from '../config/browserTest'; |
21 | | -import { run, generateAgent, cacheObject, runAgent, setCacheObject } from './agent-helpers'; |
| 22 | +import { run, generateAgent, cacheObject, runAgent, setCacheObject, cacheFile } from './agent-helpers'; |
22 | 23 |
|
23 | 24 | // LOWIRE_NO_CACHE=1 to generate api caches |
24 | 25 | // LOWIRE_FORCE_CACHE=1 to force api caches |
@@ -191,6 +192,33 @@ Failed to parse cache file ${test.info().outputPath('agent-cache.json')}: |
191 | 192 | `.trim()); |
192 | 193 | }); |
193 | 194 |
|
| 195 | +test('non-json cache file throws a nice error', async ({ context }) => { |
| 196 | + await fs.promises.writeFile(cacheFile(), 'bogus', 'utf8'); |
| 197 | + const { agent } = await runAgent(context); |
| 198 | + const error = await agent.perform('click the Test button').catch(e => e); |
| 199 | + expect(error.message).toContain(`Failed to parse cache file ${test.info().outputPath('agent-cache.json')}:`); |
| 200 | + expect(error.message.toLowerCase()).toContain(`valid json`); |
| 201 | +}); |
| 202 | + |
| 203 | +test('empty cache file works', async ({ context }) => { |
| 204 | + await fs.promises.writeFile(cacheFile(), '', 'utf8'); |
| 205 | + const { page, agent } = await generateAgent(context); |
| 206 | + await page.setContent(`<button>Test</button>`); |
| 207 | + await agent.perform('click the Test button'); |
| 208 | +}); |
| 209 | + |
| 210 | +test('missing apiKey throws a nice error', async ({ page }) => { |
| 211 | + const agent = await page.agent({ provider: { api: 'anthropic', model: 'some model' } as any }); |
| 212 | + const error = await agent.perform('click the Test button').catch(e => e); |
| 213 | + expect(error.message).toContain(`This action requires API key to be set on the page agent`); |
| 214 | +}); |
| 215 | + |
| 216 | +test('malformed apiEndpoint throws a nice error', async ({ page }) => { |
| 217 | + const agent = await page.agent({ provider: { api: 'anthropic', model: 'some model', apiKey: 'some key', apiEndpoint: 'foobar' } }); |
| 218 | + const error = await agent.perform('click the Test button').catch(e => e); |
| 219 | + expect(error.message).toContain(`Agent API endpoint "foobar" is not a valid URL`); |
| 220 | +}); |
| 221 | + |
194 | 222 | test('perform reports error', async ({ context }) => { |
195 | 223 | const { page, agent } = await generateAgent(context); |
196 | 224 | await page.setContent(` |
|
0 commit comments