@@ -202,4 +202,73 @@ describe('run', () => {
202202 expect ( error . errorCode ) . toBeFalsy ( ) ;
203203 }
204204 } ) ;
205+
206+ it ( 'correctly handles useFallback when passed to the run function' , async ( ) => {
207+ const run1Fixture = await readFile ( fixturePath ( 'run1.json' ) , 'utf-8' ) ;
208+ mockFetch . mockResponseOnce ( run1Fixture ) ;
209+
210+ const result = await run ( { animal : 'platypus' } , { useFallback : 'never' } ) ;
211+ expect ( result . output ) . toEqual ( {
212+ is_cute : true ,
213+ is_dangerous : true ,
214+ explanation_of_reasoning : 'Plat plat' ,
215+ } ) ;
216+
217+ expect ( mockFetch . mock . calls . length ) . toEqual ( 1 ) ;
218+ const req = mockFetch . mock . calls [ 0 ] [ 0 ] as Request ;
219+ expect ( req . url ) . toEqual (
220+ 'https://run.workflowai.com/v1/_/agents/animal-classification/schemas/4/run'
221+ ) ;
222+ expect ( req . method ) . toEqual ( 'POST' ) ;
223+ expect ( req . headers . get ( 'Authorization' ) ) . toEqual ( 'Bearer hello' ) ;
224+ const body = await req . json ( ) ;
225+ expect ( body ) . toEqual ( {
226+ version : 'production' ,
227+ stream : false ,
228+ task_input : {
229+ animal : 'platypus' ,
230+ } ,
231+ use_cache : 'auto' ,
232+ use_fallback : 'never' ,
233+ } ) ;
234+ } ) ;
235+
236+ it ( 'correctly handles useFallback when passed to the agent' , async ( ) => {
237+ const run2 = workflowAI . agent <
238+ AnimalClassificationInput ,
239+ AnimalClassificationOutput
240+ > ( {
241+ id : 'animal-classification' ,
242+ schemaId : 4 ,
243+ version : 'production' ,
244+ useFallback : [ 'gpt-4o-mini' , 'gpt-4o' ] ,
245+ } ) ;
246+ const run1Fixture = await readFile ( fixturePath ( 'run1.json' ) , 'utf-8' ) ;
247+ mockFetch . mockResponseOnce ( run1Fixture ) ;
248+
249+ const result = await run2 ( { animal : 'platypus' } ) ;
250+ expect ( result . output ) . toEqual ( {
251+ is_cute : true ,
252+ is_dangerous : true ,
253+ explanation_of_reasoning : 'Plat plat' ,
254+ } ) ;
255+
256+ expect ( mockFetch . mock . calls . length ) . toEqual ( 1 ) ;
257+ const req = mockFetch . mock . calls [ 0 ] [ 0 ] as Request ;
258+ expect ( req . url ) . toEqual (
259+ 'https://run.workflowai.com/v1/_/agents/animal-classification/schemas/4/run'
260+ ) ;
261+ expect ( req . method ) . toEqual ( 'POST' ) ;
262+ expect ( req . headers . get ( 'Authorization' ) ) . toEqual ( 'Bearer hello' ) ;
263+ const body = await req . json ( ) ;
264+ expect ( body ) . toEqual ( {
265+ version : 'production' ,
266+ stream : false ,
267+ task_input : {
268+ animal : 'platypus' ,
269+ } ,
270+ use_cache : 'auto' ,
271+ use_fallback : [ 'gpt-4o-mini' , 'gpt-4o' ] ,
272+ } ) ;
273+ } ) ;
205274} ) ;
0 commit comments