Skip to content

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

🧵 ci: Keep a Floor of Two Jest Workers in CI (#15819)

JOJO7fe9a45894f2
diff --git a/api/jest.config.js b/api/jest.config.js
index 4ba0853094..d0cabf39c5 100644
--- a/api/jest.config.js
+++ b/api/jest.config.js
@@ -1,3 +1,5 @@
+const { maxWorkers } = require('../config/jest.workers.cjs');
+
const esModules = [
'openid-client',
'oauth4webapi',
@@ -21,7 +23,7 @@ module.exports = {
clearMocks: true,
roots: ['<rootDir>'],
coverageDirectory: 'coverage',
- maxWorkers: '50%',
+ maxWorkers,
testTimeout: 30000, // 30 seconds timeout for all tests
setupFiles: ['./test/jestSetup.js', './test/__mocks__/logger.js'],
moduleNameMapper: {
diff --git a/client/jest.config.cjs b/client/jest.config.cjs
index 8c01907f40..21a86c4255 100644
--- a/client/jest.config.cjs
+++ b/client/jest.config.cjs
@@ -1,4 +1,6 @@
/** v0.8.8-rc3 */
+const { maxWorkers } = require('../config/jest.workers.cjs');
+
module.exports = {
roots: ['<rootDir>/src'],
testEnvironment: 'jsdom',
@@ -34,7 +36,7 @@ module.exports = {
'^librechat-data-provider/react-query$':
'<rootDir>/../node_modules/librechat-data-provider/src/react-query',
},
- maxWorkers: '50%',
+ maxWorkers,
/** Coverage maps accumulate for the life of a worker, so a long run can push
* a worker past a gigabyte and get it killed by the OS, which fails whatever
* suite it was holding. Recycling bloated workers also avoids swap thrash. */
diff --git a/config/jest.workers.cjs b/config/jest.workers.cjs
new file mode 100644
index 0000000000..7411a4280a
--- /dev/null
+++ b/config/jest.workers.cjs
@@ -0,0 +1,30 @@
+/**
+ * Jest worker count shared by every workspace config.
+ *
+ * Jest runs in band as soon as it resolves to a single worker, and in band a test
+ * file that leaves a server listening or a timer armed keeps the main process alive
+ * after "Ran all test suites" until the CI job hits its timeout. `'50%'` resolves to
+ * exactly one worker on the 2-vCPU GitHub-hosted runners that private repositories
+ * (forks, mirrors) get, so CI keeps a floor of two workers: a leaked handle then
+ * stays inside a worker process, which Jest terminates — the same shape the 4-vCPU
+ * public runners already get from `'50%'`. Local runs keep the percentage so the
+ * pool tracks the machine.
+ */
+const os = require('node:os');
+
+const CI_MIN_WORKERS = 2;
+
+function cpuCount() {
+ return typeof os.availableParallelism === 'function'
+ ? os.availableParallelism()
+ : os.cpus().length;
+}
+
+function resolveMaxWorkers() {
+ if (!process.env.CI) {
+ return '50%';
+ }
+ return Math.max(CI_MIN_WORKERS, Math.floor(cpuCount() / 2));
+}
+
+module.exports = { maxWorkers: resolveMaxWorkers() };
diff --git a/packages/api/jest.config.mjs b/packages/api/jest.config.mjs
index 0aa27c9cf3..5f6e254f2a 100644
--- a/packages/api/jest.config.mjs
+++ b/packages/api/jest.config.mjs
@@ -1,3 +1,5 @@
+import { maxWorkers } from '../../config/jest.workers.cjs';
+
const esModules = [
'@langchain/langgraph',
'@langchain/langgraph-checkpoint',
@@ -52,7 +54,7 @@ export default {
// },
// },
setupFiles: ['<rootDir>/jest.setup.cjs', '<rootDir>/../../config/jest.setup.logging.cjs'],
- maxWorkers: '50%',
+ maxWorkers,
restoreMocks: true,
testTimeout: 15000,
};
diff --git a/packages/client/jest.config.js b/packages/client/jest.config.js
index 3f7fd246c0..b607392a36 100644
--- a/packages/client/jest.config.js
+++ b/packages/client/jest.config.js
@@ -1,3 +1,5 @@
+import { maxWorkers } from '../../config/jest.workers.cjs';
+
export default {
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!<rootDir>/node_modules/'],
coveragePathIgnorePatterns: ['/node_modules/', '/dist/'],
@@ -16,7 +18,7 @@ export default {
// lines: 57,
// },
// },
- maxWorkers: '50%',
+ maxWorkers,
restoreMocks: true,
testTimeout: 15000,
// React component testing requires jsdom environment
diff --git a/packages/data-provider/jest.config.js b/packages/data-provider/jest.config.js
index 70340d36fc..b6b8e90d87 100644
--- a/packages/data-provider/jest.config.js
+++ b/packages/data-provider/jest.config.js
@@ -1,3 +1,5 @@
+const { maxWorkers } = require('../../config/jest.workers.cjs');
+
module.exports = {
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!<rootDir>/node_modules/'],
coveragePathIgnorePatterns: ['/node_modules/', '/dist/'],
@@ -14,6 +16,6 @@ module.exports = {
// lines: 57,
// },
// },
- maxWorkers: '50%',
+ maxWorkers,
restoreMocks: true,
};
diff --git a/packages/data-schemas/jest.config.mjs b/packages/data-schemas/jest.config.mjs
index ff19e63d2f..8f5546fc6f 100644
--- a/packages/data-schemas/jest.config.mjs
+++ b/packages/data-schemas/jest.config.mjs
@@ -1,3 +1,5 @@
+import { maxWorkers } from '../../config/jest.workers.cjs';
+
export default {
collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!<rootDir>/node_modules/'],
coveragePathIgnorePatterns: ['/node_modules/', '/dist/'],
@@ -23,7 +25,7 @@ export default {
// cache the parallel downloads race their final rename and fail whole suites.
globalSetup: '<rootDir>/jest.globalSetup.mjs',
setupFiles: ['<rootDir>/../../config/jest.setup.logging.cjs'],
- maxWorkers: '50%',
+ maxWorkers,
restoreMocks: true,
testTimeout: 15000,
};