LibreChat/api
JorgeCosta87 5b11a5a076
🪵 chore: Restore Winston Format Factory Shape In Test Mocks (#13139)
Four jest mocks for `winston` in the test suite return the wrong shape:

  api/test/__mocks__/logger.js                                   (returns inner fn directly)
  packages/api/src/agents/__tests__/memory.test.ts               (`format` is a plain object)
  packages/api/src/agents/__tests__/run-summarization.test.ts    (same)
  packages/api/src/agents/__tests__/initialize.test.ts           (same)

Real `winston.format(fn)` returns a Format constructor whose instances
expose a `.transform(info, opts)` method that winston's pipeline calls
with the log info object. The current mocks collapse this:

- `(fn) => fn` returns the inner transform fn directly. When module-load
  code in `@librechat/data-schemas/dist/config/parsers.cjs:52` does
  `const redactFormat = winston.format((info) => ...)`, `redactFormat`
  becomes the inner fn. The next line in `winston.cjs` calls
  `parsers.redactFormat()` which invokes the inner fn with no `info`,
  throwing `TypeError: Cannot read properties of undefined (reading 'level')`.

- `format: { combine, colorize, simple }` makes `winston.format` not
  callable at all — `winston.format((info) => ...)` throws
  `TypeError: winston.format is not a function`.

These currently pass in CI on GitHub Actions Ubuntu / Node 20.19, but
fail reproducibly on Node 24.x and on some Linux distros (verified on
WSL Ubuntu with Node 24.9.0). The CI passes appears to be environmental
luck around jest's mock-hoisting interaction with the workspace symlink
chain — the mocks are genuinely wrong against the data-schemas contract.

The fix: return a thunk that yields `{ transform: fn }` — matches real
winston's shape just enough that module-load completes; the inner fn is
only ever invoked by winston's pipeline (never at load time). Also adds
the full `winston.format.*` method surface (printf, timestamp, errors,
splat, json) plus `addColors` and the `DailyRotateFile`/`File` transports
that data-schemas's dist code references at module-load.

Verification (Node 24.9.0):
  npm run build:data-provider && npm run build:data-schemas && npm run build:api
  cd packages/api && npx jest src/agents/__tests__/{memory,run-summarization,initialize}.test.ts
  → 3 suites, 106 tests, all pass

No production code or behavior changes — test-only patch.

Co-authored-by: Jorge Costa <8352477+JorgeCosta87@users.noreply.github.com>
2026-05-15 14:51:53 -04:00
..
app 🔐 feat: Mint Code API Auth Tokens (#13028) 2026-05-09 16:09:10 -04:00
cache 🚦 fix: ERR_ERL_INVALID_IP_ADDRESS and IPv6 Key Collisions in IP Rate Limiters (#12319) 2026-03-19 21:48:03 -04:00
config 🧾 feat: Add Structured Logging Context (#13110) 2026-05-13 19:17:39 -04:00
db 🐛 fix: Resolve MeiliSearch Startup Sync Failure from Model Loading Order (#12397) 2026-03-25 14:02:44 -04:00
models 🗑️ chore: Remove Action Test Suite and Update Mock Implementations (#12268) 2026-03-21 14:28:55 -04:00
server 🗝️ fix: Protect Model Spec Instructions (#13125) 2026-05-14 10:07:23 -04:00
strategies 🛂 fix: Restrict OpenID JWT Bearer Reuse (#13052) 2026-05-11 02:00:38 -04:00
test 🪵 chore: Restore Winston Format Factory Shape In Test Mocks (#13139) 2026-05-15 14:51:53 -04:00
utils 🧮 feat: Add GPT-5.5 Token Definitions (#12973) 2026-05-06 10:50:16 -04:00
jest.config.js 📏 refactor: Add File Size Limits to Conversation Imports (#12221) 2026-03-14 03:06:29 -04:00
jsconfig.json
package.json 📡 feat: Add Backend OpenTelemetry Tracing (#12909) 2026-05-14 09:08:55 -04:00
typedefs.js 🧬 chore: Align LibreChat With Agents LangChain Upgrade (#12922) 2026-05-03 12:46:01 -04:00