Skip to content

Commit 8360f85

Browse files
committed
update based on feedback
1 parent f3d6855 commit 8360f85

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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']) {

tests/index.test.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff 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
});

0 commit comments

Comments
 (0)