🧵 ci: Keep a Floor of Two Jest Workers in CI (#15819)
Some checks are pending
Docker Dev Images Build / publish (push) Waiting to run
Sync Helm Chart Tags / Ignore non-main push (push) Waiting to run
Sync Helm Chart Tags / Sync chart tags (push) Waiting to run

`maxWorkers: '50%'` resolves to a single worker on the 2-vCPU GitHub-hosted
runners that private repositories get, and Jest then runs in band. Any test
file that leaves a handle open (a listening `http.Server`, a timer, a DB
connection) keeps the main process alive after "Ran all test suites" until the
job's `timeout-minutes` cancels it, so a run with every test passing still
fails. Public runners have 4 vCPUs, where `'50%'` is already two workers and
the leaked handle dies with the worker process.

Move the worker count into `config/jest.workers.cjs`, shared by all six
workspace configs: local runs keep `'50%'`, CI uses `max(2, floor(cpus / 2))`.
On 4-vCPU runners the value is unchanged; on 2-vCPU runners Jest now uses
worker processes the same way it does upstream.

Co-authored-by: Danny Avila <danny@librechat.ai>
This commit is contained in:
JOJO 2026-09-14 13:32:20 +09:00 • committed by GitHub
parent fa3dff1cff
commit 7fe9a45894
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 48 additions and 6 deletions

View file

@ -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: {

View file

@ -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. */

30
config/jest.workers.cjs Normal file
View file

@ -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() };

View file

@ -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,
};

View file

@ -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

View file

@ -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,
};

View file

@ -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,
};