@@ -16,33 +16,57 @@ describe.skipIf(!OPENROUTER_API_KEY)('OpenRouter GPTAdapter (live)', () => {
1616 baseUrl : 'https://openrouter.ai/api' ,
1717 } ) ;
1818
19- it ( 'should complete a prompt and return text content' , async ( ) => {
20- const result = await adapter . complete (
21- [ { role : 'user' , content : 'Reply with exactly: hello world' } ] ,
22- { model : MODEL , maxTokens : 64 , temperature : 0 }
23- ) ;
24-
25- const text = result . content
26- . filter ( ( c ) => c . type === 'text' )
27- . map ( ( c ) => ( c as { type : 'text' ; text : string } ) . text )
28- . join ( '' ) ;
29-
30- expect ( text . length ) . toBeGreaterThan ( 0 ) ;
31- expect ( result . stopReason ) . toBeDefined ( ) ;
19+ it ( 'should complete a prompt and return text content' , async ( ctx ) => {
20+ try {
21+ const result = await adapter . complete (
22+ [ { role : 'user' , content : 'Reply with exactly: hello world' } ] ,
23+ { model : MODEL , maxTokens : 64 , temperature : 0 }
24+ ) ;
25+
26+ const text = result . content
27+ . filter ( ( c ) => c . type === 'text' )
28+ . map ( ( c ) => ( c as { type : 'text' ; text : string } ) . text )
29+ . join ( '' ) ;
30+
31+ expect ( text . length ) . toBeGreaterThan ( 0 ) ;
32+ expect ( result . stopReason ) . toBeDefined ( ) ;
33+ } catch ( e ) {
34+ if ( e instanceof Error && / \b 4 0 [ 1 3 ] \b / . test ( e . message ) ) {
35+ ctx . skip ( ) ;
36+ return ;
37+ }
38+ throw e ;
39+ }
3240 } , 30_000 ) ;
3341
34- it ( 'should return usage with inputTokens > 0' , async ( ) => {
35- const result = await adapter . complete (
36- [ { role : 'user' , content : 'Say hi' } ] ,
37- { model : MODEL , maxTokens : 16 , temperature : 0 }
38- ) ;
42+ it ( 'should return usage with inputTokens > 0' , async ( ctx ) => {
43+ try {
44+ const result = await adapter . complete (
45+ [ { role : 'user' , content : 'Say hi' } ] ,
46+ { model : MODEL , maxTokens : 16 , temperature : 0 }
47+ ) ;
3948
40- expect ( result . usage . inputTokens ) . toBeGreaterThan ( 0 ) ;
41- expect ( result . usage . outputTokens ) . toBeGreaterThan ( 0 ) ;
49+ expect ( result . usage . inputTokens ) . toBeGreaterThan ( 0 ) ;
50+ expect ( result . usage . outputTokens ) . toBeGreaterThan ( 0 ) ;
51+ } catch ( e ) {
52+ if ( e instanceof Error && / \b 4 0 [ 1 3 ] \b / . test ( e . message ) ) {
53+ ctx . skip ( ) ;
54+ return ;
55+ }
56+ throw e ;
57+ }
4258 } , 30_000 ) ;
4359
44- it ( 'should validate connection successfully' , async ( ) => {
45- const ok = await adapter . validateConnection ( ) ;
46- expect ( ok ) . toBe ( true ) ;
60+ it ( 'should validate connection successfully' , async ( ctx ) => {
61+ try {
62+ const ok = await adapter . validateConnection ( ) ;
63+ expect ( ok ) . toBe ( true ) ;
64+ } catch ( e ) {
65+ if ( e instanceof Error && / \b 4 0 [ 1 3 ] \b / . test ( e . message ) ) {
66+ ctx . skip ( ) ;
67+ return ;
68+ }
69+ throw e ;
70+ }
4771 } , 30_000 ) ;
4872} ) ;
0 commit comments