@@ -2,6 +2,7 @@ import * as gptscript from "../src/gptscript"
22import  { ArgumentSchemaType ,  getEnv ,  PropertyType ,  RunEventType ,  TextType ,  ToolType }  from  "../src/gptscript" 
33import  path  from  "path" 
44import  { fileURLToPath }  from  "url" 
5+ import  *  as  fs  from  "node:fs" 
56
67let  gFirst : gptscript . GPTScript 
78let  g : gptscript . GPTScript 
@@ -286,6 +287,7 @@ describe("gptscript module", () => {
286287            await  g . parse ( path . join ( __dirname ,  "fixtures" ,  "non-existent.gpt" ) ) 
287288        }  catch  ( e )  { 
288289            expect ( e ) . toBeDefined ( ) 
290+             expect ( typeof  e  !==  "string" ) . toBeTruthy ( ) 
289291            return 
290292        } 
291293        expect ( false ) . toBeTruthy ( ) 
@@ -296,6 +298,7 @@ describe("gptscript module", () => {
296298            await  g . parse ( "github.com/thedadams/dne" ) 
297299        }  catch  ( e )  { 
298300            expect ( e ) . toBeDefined ( ) 
301+             expect ( typeof  e  !==  "string" ) . toBeTruthy ( ) 
299302            return 
300303        } 
301304        expect ( false ) . toBeTruthy ( ) 
@@ -408,6 +411,59 @@ describe("gptscript module", () => {
408411        expect ( response ) . toContain ( "Type: Context" ) 
409412    } ) 
410413
414+     test ( "load simple file" ,  async  ( )  =>  { 
415+         const  response  =  await  g . load ( path . join ( __dirname ,  "fixtures" ,  "test.gpt" ) ) 
416+         expect ( response . program ) . toBeDefined ( ) 
417+         expect ( response . program . name ) . toBeTruthy ( ) 
418+         expect ( response . program . entryToolId ) . toBeTruthy ( ) 
419+         expect ( response . program . toolSet ) . toBeDefined ( ) 
420+     } ,  30000 ) 
421+ 
422+     test ( "load remote tool" ,  async  ( )  =>  { 
423+         const  response  =  await  g . load ( "github.com/gptscript-ai/context/workspace" ) 
424+         expect ( response . program ) . toBeDefined ( ) 
425+         expect ( response . program . name ) . toBeTruthy ( ) 
426+         expect ( response . program . entryToolId ) . toBeTruthy ( ) 
427+         expect ( response . program . toolSet ) . toBeDefined ( ) 
428+     } ,  30000 ) 
429+ 
430+     test ( "load content" ,  async  ( )  =>  { 
431+         const  content  =  fs . readFileSync ( path . join ( __dirname ,  "fixtures" ,  "test.gpt" ) ,  { encoding : "utf8" } ) 
432+         const  response  =  await  g . loadContent ( content ) 
433+         expect ( response . program ) . toBeDefined ( ) 
434+         // Name will not be defined in this case. 
435+         expect ( response . program . name ) . toBeFalsy ( ) 
436+         expect ( response . program . entryToolId ) . toBeTruthy ( ) 
437+         expect ( response . program . toolSet ) . toBeDefined ( ) 
438+     } ,  30000 ) 
439+ 
440+     test ( "load tools" ,  async  ( )  =>  { 
441+         const  tools  =  [ { 
442+             tools : [ "ask" ] , 
443+             instructions : "Only use the ask tool to ask who was the president of the united states in 1928?" 
444+         } , 
445+             { 
446+                 name : "other" , 
447+                 instructions : "Who was the president of the united states in 1986?" 
448+             } , 
449+             { 
450+                 name : "ask" , 
451+                 description : "This tool is used to ask a question" , 
452+                 arguments : { 
453+                     type : "object" , 
454+                     question : "The question to ask" 
455+                 } , 
456+                 instructions : "${question}" 
457+             } , 
458+         ]  as  gptscript . ToolDef [ ] 
459+         const  response  =  await  g . loadTools ( tools ) 
460+         expect ( response . program ) . toBeDefined ( ) 
461+         // Name will not be defined in this case. 
462+         expect ( response . program . name ) . toBeFalsy ( ) 
463+         expect ( response . program . entryToolId ) . toBeTruthy ( ) 
464+         expect ( response . program . toolSet ) . toBeDefined ( ) 
465+     } ,  30000 ) 
466+ 
411467    test ( "exec tool with chat" ,  async  ( )  =>  { 
412468        let  err  =  undefined 
413469        const  t  =  { 
0 commit comments