diff --git a/api/test/__mocks__/logger.js b/api/test/__mocks__/logger.js index 62f9bee93a..94dd08bb1c 100644 --- a/api/test/__mocks__/logger.js +++ b/api/test/__mocks__/logger.js @@ -1,5 +1,13 @@ jest.mock('winston', () => { - const mockFormatFunction = jest.fn((fn) => fn); + // Real `winston.format(fn)` returns a Format constructor whose instances + // expose a `.transform(info, opts)` method that winston's pipeline calls. + // The previous mock `(fn) => fn` collapsed this — `parsers.redactFormat()` + // (called at @librechat/data-schemas dist module-load) ended up invoking + // the inner transform fn with no `info` argument, throwing on `info.level`. + // Returning a thunk that yields `{ transform: fn }` matches real winston's + // shape just enough that module-load completes cleanly; the inner fn is + // only ever invoked by winston's pipeline (never at load time). + const mockFormatFunction = jest.fn((fn) => () => ({ transform: fn })); mockFormatFunction.colorize = jest.fn(); mockFormatFunction.combine = jest.fn(); diff --git a/packages/api/src/agents/__tests__/initialize.test.ts b/packages/api/src/agents/__tests__/initialize.test.ts index b98af340aa..6636c13af6 100644 --- a/packages/api/src/agents/__tests__/initialize.test.ts +++ b/packages/api/src/agents/__tests__/initialize.test.ts @@ -39,20 +39,34 @@ import type { ServerRequest, InitializeResultBase, EndpointTokenConfig } from '~ import type { InitializeAgentDbMethods } from '../initialize'; import { DEFAULT_MAX_CONTEXT_TOKENS } from '../initialize'; -// Mock logger +// Mock logger — `format` must be a callable factory so @librechat/data-schemas +// dist module-load completes cleanly; see api/test/__mocks__/logger.js. jest.mock('winston', () => ({ createLogger: jest.fn(() => ({ debug: jest.fn(), warn: jest.fn(), error: jest.fn(), + info: jest.fn(), })), - format: { - combine: jest.fn(), - colorize: jest.fn(), - simple: jest.fn(), - }, + format: Object.assign( + jest.fn((fn) => () => ({ transform: fn })), + { + combine: jest.fn(), + colorize: jest.fn(), + simple: jest.fn(), + label: jest.fn(), + timestamp: jest.fn(), + printf: jest.fn(), + errors: jest.fn(), + splat: jest.fn(), + json: jest.fn(), + }, + ), + addColors: jest.fn(), transports: { Console: jest.fn(), + DailyRotateFile: jest.fn(), + File: jest.fn(), }, })); diff --git a/packages/api/src/agents/__tests__/memory.test.ts b/packages/api/src/agents/__tests__/memory.test.ts index dabe6de629..d23a07aa7d 100644 --- a/packages/api/src/agents/__tests__/memory.test.ts +++ b/packages/api/src/agents/__tests__/memory.test.ts @@ -5,19 +5,35 @@ import type { MemoryArtifact } from 'librechat-data-provider'; import { createMemoryTool, processMemory } from '../memory'; // Mock the logger +// `winston.format` must be a callable factory (real winston returns a Format +// constructor) so that `@librechat/data-schemas` dist code can complete its +// module-load — see api/test/__mocks__/logger.js for the canonical shape. jest.mock('winston', () => ({ createLogger: jest.fn(() => ({ debug: jest.fn(), warn: jest.fn(), error: jest.fn(), + info: jest.fn(), })), - format: { - combine: jest.fn(), - colorize: jest.fn(), - simple: jest.fn(), - }, + format: Object.assign( + jest.fn((fn) => () => ({ transform: fn })), + { + combine: jest.fn(), + colorize: jest.fn(), + simple: jest.fn(), + label: jest.fn(), + timestamp: jest.fn(), + printf: jest.fn(), + errors: jest.fn(), + splat: jest.fn(), + json: jest.fn(), + }, + ), + addColors: jest.fn(), transports: { Console: jest.fn(), + DailyRotateFile: jest.fn(), + File: jest.fn(), }, })); diff --git a/packages/api/src/agents/__tests__/run-summarization.test.ts b/packages/api/src/agents/__tests__/run-summarization.test.ts index 1aa8e0d58d..7d22511c21 100644 --- a/packages/api/src/agents/__tests__/run-summarization.test.ts +++ b/packages/api/src/agents/__tests__/run-summarization.test.ts @@ -9,7 +9,8 @@ import { } from 'librechat-data-provider'; import { createRun } from '~/agents/run'; -// Mock winston logger +// Mock winston logger — `format` must be callable so @librechat/data-schemas +// dist module-load completes cleanly; see api/test/__mocks__/logger.js. jest.mock('winston', () => ({ createLogger: jest.fn(() => ({ debug: jest.fn(), @@ -17,8 +18,26 @@ jest.mock('winston', () => ({ error: jest.fn(), info: jest.fn(), })), - format: { combine: jest.fn(), colorize: jest.fn(), simple: jest.fn() }, - transports: { Console: jest.fn() }, + format: Object.assign( + jest.fn((fn) => () => ({ transform: fn })), + { + combine: jest.fn(), + colorize: jest.fn(), + simple: jest.fn(), + label: jest.fn(), + timestamp: jest.fn(), + printf: jest.fn(), + errors: jest.fn(), + splat: jest.fn(), + json: jest.fn(), + }, + ), + addColors: jest.fn(), + transports: { + Console: jest.fn(), + DailyRotateFile: jest.fn(), + File: jest.fn(), + }, })); // Mock env utilities so header resolution doesn't fail