mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-20 23:13:35 +00:00
fix: defer logger serialization to sanitized transports (#17169)
Some checks are pending
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Votes / vote (full suite) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Some checks are pending
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Votes / vote (full suite) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
This commit is contained in:
parent
d4e52acdfb
commit
e01b570779
2 changed files with 53 additions and 0 deletions
50
packages/data-schemas/src/config/loggerSerialization.spec.ts
Normal file
50
packages/data-schemas/src/config/loggerSerialization.spec.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import type winston from 'winston';
|
||||
|
||||
/** Check the real logger configuration: transport-only formatter tests miss
|
||||
* Winston's implicit JSON serialization before any transport receives a record. */
|
||||
describe('logger serialization boundary', () => {
|
||||
let logger: winston.Logger;
|
||||
const originalLogToFile = process.env.LOG_TO_FILE;
|
||||
|
||||
beforeAll(() => {
|
||||
process.env.LOG_TO_FILE = 'false';
|
||||
jest.isolateModules(() => {
|
||||
logger = jest.requireActual<typeof import('./winston')>('./winston').default;
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
logger.close();
|
||||
if (originalLogToFile === undefined) {
|
||||
delete process.env.LOG_TO_FILE;
|
||||
} else {
|
||||
process.env.LOG_TO_FILE = originalLogToFile;
|
||||
}
|
||||
});
|
||||
|
||||
it('does not serialize a raw HTTP agent graph before transport sanitization', () => {
|
||||
const serializeAgent = jest.fn(() => ({ sockets: 'raw socket graph' }));
|
||||
const error = Object.assign(new Error('Request failed with status code 403'), {
|
||||
isAxiosError: true,
|
||||
config: {
|
||||
method: 'delete',
|
||||
url: 'https://example.test/files/1',
|
||||
httpAgent: { toJSON: serializeAgent },
|
||||
},
|
||||
});
|
||||
// Winston merges enumerable error metadata into the top-level info before
|
||||
// running the logger-level format, including config and request objects.
|
||||
const info: winston.Logform.TransformableInfo = {
|
||||
...error,
|
||||
level: 'error',
|
||||
message: 'Error deleting file',
|
||||
[Symbol.for('level')]: 'error',
|
||||
[Symbol.for('splat')]: [error],
|
||||
};
|
||||
|
||||
const result = logger.format.transform(info, logger.format.options);
|
||||
|
||||
expect(serializeAgent).not.toHaveBeenCalled();
|
||||
expect(Object.getOwnPropertySymbols(result || {})).not.toContain(Symbol.for('message'));
|
||||
});
|
||||
});
|
||||
|
|
@ -132,6 +132,9 @@ if (useDebugConsole) {
|
|||
// Create logger
|
||||
const logger: winston.Logger = winston.createLogger({
|
||||
level: level(),
|
||||
// Transports sanitize and serialize. Winston otherwise JSON-serializes raw
|
||||
// errors here, walking the shared HTTP agent graph before those guards run.
|
||||
format: winston.format((info) => info)(),
|
||||
levels: logLevels,
|
||||
transports,
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue