@@ -4,7 +4,7 @@ import adapter from './index.js';
44
55smokeTest ( adapter , { idPrefix : 'ai' } ) ;
66
7- const ctx = ( secrets : Record < string , string > = { DEEPINFRA_API_KEY : 'test-key' } , dryRun = false ) => ( {
7+ const ctx = ( secrets : Record < string , string > = { DEEPINFRA_API_KEY : 'test-deepinfra- key' } , dryRun = false ) => ( {
88 secret : ( key : string ) => secrets [ key ] ,
99 log : ( ) => { } ,
1010 dryRun,
@@ -19,7 +19,7 @@ describe('DeepInfra OpenAI-compatible generation', () => {
1919 const fetchMock = vi . fn ( ) ;
2020 vi . stubGlobal ( 'fetch' , fetchMock ) ;
2121
22- const result = await adapter . generate ( ctx ( { DEEPINFRA_API_KEY : 'test-key' } , true ) , 'hello' , { } , { } ) ;
22+ const result = await adapter . generate ( ctx ( { DEEPINFRA_API_KEY : 'test-deepinfra- key' } , true ) , 'hello' , { } , { } ) ;
2323
2424 expect ( result ) . toEqual ( { text : '[dry-run]' , model : 'deepseek-ai/DeepSeek-V3' } ) ;
2525 expect ( fetchMock ) . not . toHaveBeenCalled ( ) ;
@@ -42,14 +42,15 @@ describe('DeepInfra OpenAI-compatible generation', () => {
4242 maxTokens : 20 ,
4343 temperature : 0.2 ,
4444 extra : { reasoning_effort : 'low' } ,
45- } , { } ) ;
45+ } , { baseUrl : 'https://deepinfra.test/v1/openai/' } ) ;
4646
4747 expect ( fetchMock ) . toHaveBeenCalledOnce ( ) ;
4848 const call = fetchMock . mock . calls [ 0 ] ;
4949 expect ( call ) . toBeDefined ( ) ;
5050 const [ url , request ] = call ! ;
51- expect ( url ) . toBe ( 'https://api.deepinfra.com/v1/openai/chat/completions' ) ;
52- expect ( request . headers . authorization ) . toBe ( 'Bearer test-key' ) ;
51+ expect ( url ) . toBe ( 'https://deepinfra.test/v1/openai/chat/completions' ) ;
52+ expect ( request . headers . authorization ) . toBe ( [ 'Bearer' , 'test-deepinfra-key' ] . join ( ' ' ) ) ;
53+ expect ( request . headers [ 'content-type' ] ) . toBe ( 'application/json' ) ;
5354 expect ( JSON . parse ( request . body ) ) . toEqual ( {
5455 model : 'deepseek-ai/DeepSeek-R1' ,
5556 messages : [
@@ -68,13 +69,15 @@ describe('DeepInfra OpenAI-compatible generation', () => {
6869 } ) ;
6970 } ) ;
7071
71- it ( 'includes status and response body excerpt on errors ' , async ( ) => {
72+ it ( 'redacts DeepInfra keys from provider error excerpts ' , async ( ) => {
7273 vi . stubGlobal ( 'fetch' , vi . fn ( ) . mockResolvedValue ( {
7374 ok : false ,
7475 status : 429 ,
75- text : async ( ) => 'rate limited' . repeat ( 30 ) ,
76+ text : async ( ) => 'rate limited for test-deepinfra-key' ,
7677 } ) ) ;
7778
78- await expect ( adapter . generate ( ctx ( ) , 'hello' , { } , { } ) ) . rejects . toThrow ( / D e e p I n f r a 4 2 9 : r a t e l i m i t e d / ) ;
79+ await expect ( adapter . generate ( ctx ( ) , 'hello' , { } , { } ) ) . rejects . toThrow (
80+ 'DeepInfra 429: rate limited for [redacted]' ,
81+ ) ;
7982 } ) ;
8083} ) ;
0 commit comments