|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { describe, it, expect } from 'vitest'; |
|
|
import { TestRig, printDebugInfo, validateModelOutput } from './test-helper.js'; |
|
|
|
|
|
describe('google_web_search', () => { |
|
|
it('should be able to search the web', async () => { |
|
|
const rig = new TestRig(); |
|
|
await rig.setup('should be able to search the web'); |
|
|
|
|
|
let result; |
|
|
try { |
|
|
result = await rig.run(`what is the weather in London`); |
|
|
} catch (error) { |
|
|
|
|
|
if ( |
|
|
error instanceof Error && |
|
|
(error.message.includes('network') || error.message.includes('timeout')) |
|
|
) { |
|
|
console.warn( |
|
|
'Skipping test due to network error:', |
|
|
(error as Error).message, |
|
|
); |
|
|
return; |
|
|
} |
|
|
throw error; |
|
|
} |
|
|
|
|
|
const foundToolCall = await rig.waitForToolCall('google_web_search'); |
|
|
|
|
|
|
|
|
if (!foundToolCall) { |
|
|
const allTools = printDebugInfo(rig, result); |
|
|
|
|
|
|
|
|
const failedSearchCalls = allTools.filter( |
|
|
(t) => |
|
|
t.toolRequest.name === 'google_web_search' && !t.toolRequest.success, |
|
|
); |
|
|
if (failedSearchCalls.length > 0) { |
|
|
console.warn( |
|
|
'google_web_search tool was called but failed, possibly due to network issues', |
|
|
); |
|
|
console.warn( |
|
|
'Failed calls:', |
|
|
failedSearchCalls.map((t) => t.toolRequest.args), |
|
|
); |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
expect( |
|
|
foundToolCall, |
|
|
'Expected to find a call to google_web_search', |
|
|
).toBeTruthy(); |
|
|
|
|
|
|
|
|
const hasExpectedContent = validateModelOutput( |
|
|
result, |
|
|
['weather', 'london'], |
|
|
'Google web search test', |
|
|
); |
|
|
|
|
|
|
|
|
if (!hasExpectedContent) { |
|
|
const searchCalls = rig |
|
|
.readToolLogs() |
|
|
.filter((t) => t.toolRequest.name === 'google_web_search'); |
|
|
if (searchCalls.length > 0) { |
|
|
console.warn( |
|
|
'Search queries used:', |
|
|
searchCalls.map((t) => t.toolRequest.args), |
|
|
); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|