File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -1147,7 +1147,7 @@ export function debug(action: string, ...args: any[]) {
11471147 return arg ;
11481148 }
11491149
1150- const modifiedArg = { ... arg } ;
1150+ const modifiedArg = JSON . parse ( JSON . stringify ( arg ) ) ;
11511151 // Check for sensitive headers in request body 'headers' object
11521152 if ( modifiedArg [ 'headers' ] ) {
11531153 for ( const header in modifiedArg [ 'headers' ] ) {
Original file line number Diff line number Diff line change @@ -412,7 +412,7 @@ describe('retries', () => {
412412 } ) ;
413413} ) ;
414414
415- describe ( 'Debug ' , ( ) => {
415+ describe ( 'debug() ' , ( ) => {
416416 const env = process . env ;
417417 const spy = jest . spyOn ( console , 'log' ) ;
418418
@@ -466,4 +466,22 @@ describe('Debug', () => {
466466 authorization : 'REDACTED' ,
467467 } ) ;
468468 } ) ;
469+
470+ test ( 'input are not mutated' , function ( ) {
471+ const authorizationTest = {
472+ authorization : 'fakeValue' ,
473+ } ;
474+ const client = new OpenAI ( {
475+ baseURL : 'http://localhost:5000/' ,
476+ defaultHeaders : authorizationTest ,
477+ apiKey : 'api-key' ,
478+ } ) ;
479+
480+ const { req } = client . buildRequest ( { path : '/foo' , method : 'post' } ) ;
481+ debug ( 'request' , authorizationTest ) ;
482+ expect ( ( req . headers as Headers ) [ 'authorization' ] ) . toEqual ( 'fakeValue' ) ;
483+ expect ( spy ) . toHaveBeenCalledWith ( 'OpenAI:DEBUG:request' , {
484+ authorization : 'REDACTED' ,
485+ } ) ;
486+ } ) ;
469487} ) ;
You can’t perform that action at this time.
0 commit comments