@@ -12,6 +12,7 @@ import {
1212} from '@codebuff/common/testing/impl/agent-runtime'
1313import { getToolCallString } from '@codebuff/common/tools/utils'
1414import { getInitialSessionState } from '@codebuff/common/types/session-state'
15+ import { success } from '@codebuff/common/util/error'
1516import {
1617 afterEach ,
1718 beforeAll ,
@@ -33,7 +34,7 @@ import type {
3334 AgentRuntimeScopedDeps ,
3435} from '@codebuff/common/types/contracts/agent-runtime'
3536
36- let agentRuntimeImpl : AgentRuntimeDeps = { ... TEST_AGENT_RUNTIME_IMPL }
37+ let agentRuntimeImpl : AgentRuntimeDeps
3738function mockAgentStream ( content : string | string [ ] ) {
3839 agentRuntimeImpl . promptAiSdkStream = async function * ( { } ) {
3940 if ( typeof content === 'string' ) {
@@ -54,6 +55,14 @@ describe('web_search tool with researcher agent', () => {
5455 } )
5556
5657 beforeEach ( ( ) => {
58+ agentRuntimeImpl = {
59+ ...TEST_AGENT_RUNTIME_IMPL ,
60+ consumeCreditsWithFallback : async ( ) => {
61+ return success ( {
62+ chargedToOrganization : false ,
63+ } )
64+ } ,
65+ }
5766 agentRuntimeScopedImpl = { ...TEST_AGENT_RUNTIME_SCOPED_IMPL }
5867
5968 // Mock analytics and tracing
@@ -139,11 +148,12 @@ describe('web_search tool with researcher agent', () => {
139148 } )
140149
141150 // Just verify that searchWeb was called
142- expect ( linkupApi . searchWeb ) . toHaveBeenCalledWith ( {
143- query : 'test query' ,
144- depth : 'standard' ,
145- logger : expect . anything ( ) ,
146- } )
151+ expect ( linkupApi . searchWeb ) . toHaveBeenCalledWith (
152+ expect . objectContaining ( {
153+ query : 'test query' ,
154+ depth : 'standard' ,
155+ } ) ,
156+ )
147157 } )
148158
149159 test ( 'should successfully perform web search with basic query' , async ( ) => {
@@ -190,11 +200,12 @@ describe('web_search tool with researcher agent', () => {
190200 spawnParams : undefined ,
191201 } )
192202
193- expect ( linkupApi . searchWeb ) . toHaveBeenCalledWith ( {
194- query : 'Next.js 15 new features' ,
195- depth : 'standard' ,
196- logger : expect . anything ( ) ,
197- } )
203+ expect ( linkupApi . searchWeb ) . toHaveBeenCalledWith (
204+ expect . objectContaining ( {
205+ query : 'Next.js 15 new features' ,
206+ depth : 'standard' ,
207+ } ) ,
208+ )
198209
199210 // Check that the search results were added to the message history
200211 const toolResultMessages = newAgentState . messageHistory . filter (
@@ -251,11 +262,12 @@ describe('web_search tool with researcher agent', () => {
251262 spawnParams : undefined ,
252263 } )
253264
254- expect ( linkupApi . searchWeb ) . toHaveBeenCalledWith ( {
255- query : 'React Server Components tutorial' ,
256- depth : 'deep' ,
257- logger : expect . anything ( ) ,
258- } )
265+ expect ( linkupApi . searchWeb ) . toHaveBeenCalledWith (
266+ expect . objectContaining ( {
267+ query : 'React Server Components tutorial' ,
268+ depth : 'deep' ,
269+ } ) ,
270+ )
259271 } )
260272
261273 test ( 'should handle case when no search results are found' , async ( ) => {
@@ -298,11 +310,12 @@ describe('web_search tool with researcher agent', () => {
298310 } )
299311
300312 // Verify that searchWeb was called
301- expect ( linkupApi . searchWeb ) . toHaveBeenCalledWith ( {
302- query : 'very obscure search query that returns nothing' ,
303- depth : 'standard' ,
304- logger : expect . anything ( ) ,
305- } )
313+ expect ( linkupApi . searchWeb ) . toHaveBeenCalledWith (
314+ expect . objectContaining ( {
315+ query : 'very obscure search query that returns nothing' ,
316+ depth : 'standard' ,
317+ } ) ,
318+ )
306319
307320 // Check that the "no results found" message was added
308321 const toolResultMessages = newAgentState . messageHistory . filter (
@@ -358,11 +371,12 @@ describe('web_search tool with researcher agent', () => {
358371 } )
359372
360373 // Verify that searchWeb was called
361- expect ( linkupApi . searchWeb ) . toHaveBeenCalledWith ( {
362- query : 'test query' ,
363- depth : 'standard' ,
364- logger : expect . anything ( ) ,
365- } )
374+ expect ( linkupApi . searchWeb ) . toHaveBeenCalledWith (
375+ expect . objectContaining ( {
376+ query : 'test query' ,
377+ depth : 'standard' ,
378+ } ) ,
379+ )
366380
367381 // Check that the error message was added
368382 const toolResultMessages = newAgentState . messageHistory . filter (
@@ -417,11 +431,12 @@ describe('web_search tool with researcher agent', () => {
417431 } )
418432
419433 // Verify that searchWeb was called
420- expect ( linkupApi . searchWeb ) . toHaveBeenCalledWith ( {
421- query : 'test query' ,
422- depth : 'standard' ,
423- logger : expect . anything ( ) ,
424- } )
434+ expect ( linkupApi . searchWeb ) . toHaveBeenCalledWith (
435+ expect . objectContaining ( {
436+ query : 'test query' ,
437+ depth : 'standard' ,
438+ } ) ,
439+ )
425440 } )
426441
427442 test ( 'should handle non-Error exceptions' , async ( ) => {
@@ -466,11 +481,12 @@ describe('web_search tool with researcher agent', () => {
466481 } )
467482
468483 // Verify that searchWeb was called
469- expect ( linkupApi . searchWeb ) . toHaveBeenCalledWith ( {
470- query : 'test query' ,
471- depth : 'standard' ,
472- logger : expect . anything ( ) ,
473- } )
484+ expect ( linkupApi . searchWeb ) . toHaveBeenCalledWith (
485+ expect . objectContaining ( {
486+ query : 'test query' ,
487+ depth : 'standard' ,
488+ } ) ,
489+ )
474490
475491 // Check that the error message was added
476492 const toolResultMessages = newAgentState . messageHistory . filter (
@@ -527,11 +543,12 @@ describe('web_search tool with researcher agent', () => {
527543 } )
528544
529545 // Verify that searchWeb was called
530- expect ( linkupApi . searchWeb ) . toHaveBeenCalledWith ( {
531- query : 'test formatting' ,
532- depth : 'standard' ,
533- logger : expect . anything ( ) ,
534- } )
546+ expect ( linkupApi . searchWeb ) . toHaveBeenCalledWith (
547+ expect . objectContaining ( {
548+ query : 'test formatting' ,
549+ depth : 'standard' ,
550+ } ) ,
551+ )
535552
536553 // Check that the search results were formatted correctly
537554 const toolResultMessages = newAgentState . messageHistory . filter (
0 commit comments