Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
🪵 chore: Restore Winston Format Factory Shape In Test Mocks (#13139)
JorgeCosta875b11a5a0760e
diff --git a/api/test/__mocks__/logger.js b/api/test/__mocks__/logger.jsindex 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.tsindex 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.tsindex 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.tsindex 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