mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-07-02 04:12:36 +00:00
Replace the Rollup + `rollup-plugin-typescript2` build with a split pipeline: tsdown (rolldown) bundles the JS in ~0.2s, and plain `tsc` emits the declarations to `dist/types` (~2s). Full cold build drops from ~9.2s to ~2.5s (~3.6x) with zero source changes. Unlike data-schemas, the fast oxc/isolated-declarations dts path isn't viable here: the package's 78 exported zod schemas produce 374 `isolatedDeclarations` errors (TS9013/TS9038) and a `z.ZodType<T>` annotation would break the 76 downstream `.extend`/`.shape`/`.pick` usages. Plain `tsc` keeps the rich zod types intact, and since dts was never the bottleneck (rollup-plugin-typescript2 was), the win stands. - dts stays unbundled in `dist/types/` — identical to the prior output, so the existing deep `dist/types` imports and the exports `types` paths are unchanged. - ESM output renamed `index.es.js` -> `index.mjs` (via the exports map; no consumer hardcodes the old path). cjs/types paths unchanged. - `./react-query` now emits a real cjs build + types — the exports map already promised them, but Rollup only ever built the esm file. - Kept `rollup` + the plugins used by `server-rollup.config.js` (the `rollup:api` server-bundle smoke test in backend-review.yml); removed only the deps used solely by the deleted `rollup.config.js`. - Repointed CI build-cache keys from `rollup.config.js` to `tsdown.config.mjs`.
426 lines
13 KiB
YAML
426 lines
13 KiB
YAML
name: Backend Unit Tests
|
|
on:
|
|
pull_request:
|
|
paths:
|
|
- 'api/**'
|
|
- 'packages/**'
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
env:
|
|
NODE_ENV: CI
|
|
NODE_OPTIONS: '--max-old-space-size=${{ secrets.NODE_MAX_OLD_SPACE_SIZE || 6144 }}'
|
|
|
|
jobs:
|
|
build:
|
|
name: Build packages
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 15
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Use Node.js 24.16.0
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '24.16.0'
|
|
|
|
- name: Restore node_modules cache
|
|
id: cache-node-modules
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
node_modules
|
|
api/node_modules
|
|
packages/api/node_modules
|
|
packages/data-provider/node_modules
|
|
packages/data-schemas/node_modules
|
|
key: node-modules-backend-${{ runner.os }}-24.16.0-${{ hashFiles('package-lock.json') }}
|
|
|
|
- name: Install dependencies
|
|
if: steps.cache-node-modules.outputs.cache-hit != 'true'
|
|
run: npm ci
|
|
|
|
- name: Restore data-provider build cache
|
|
id: cache-data-provider
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: packages/data-provider/dist
|
|
key: build-data-provider-${{ runner.os }}-${{ hashFiles('packages/data-provider/src/**', 'packages/data-provider/tsconfig*.json', 'packages/data-provider/tsdown.config.mjs', 'packages/data-provider/package.json') }}
|
|
|
|
- name: Build data-provider
|
|
if: steps.cache-data-provider.outputs.cache-hit != 'true'
|
|
run: npm run build:data-provider
|
|
|
|
- name: Restore data-schemas build cache
|
|
id: cache-data-schemas
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: packages/data-schemas/dist
|
|
key: build-data-schemas-${{ runner.os }}-${{ hashFiles('packages/data-schemas/src/**', 'packages/data-schemas/tsconfig*.json', 'packages/data-schemas/tsdown.config.mjs', 'packages/data-schemas/package.json', 'packages/data-provider/src/**', 'packages/data-provider/tsconfig*.json', 'packages/data-provider/tsdown.config.mjs', 'packages/data-provider/package.json') }}
|
|
|
|
- name: Build data-schemas
|
|
if: steps.cache-data-schemas.outputs.cache-hit != 'true'
|
|
run: npm run build:data-schemas
|
|
|
|
- name: Restore api build cache
|
|
id: cache-api
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: packages/api/dist
|
|
key: build-api-${{ runner.os }}-${{ hashFiles('packages/api/src/**', 'packages/api/tsconfig*.json', 'packages/api/tsdown.config.mjs', 'packages/api/package.json', 'packages/data-provider/src/**', 'packages/data-provider/tsconfig*.json', 'packages/data-provider/tsdown.config.mjs', 'packages/data-provider/package.json', 'packages/data-schemas/src/**', 'packages/data-schemas/tsconfig*.json', 'packages/data-schemas/tsdown.config.mjs', 'packages/data-schemas/package.json') }}
|
|
|
|
- name: Build api
|
|
if: steps.cache-api.outputs.cache-hit != 'true'
|
|
run: npm run build:api
|
|
|
|
- name: Upload data-provider build
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: build-data-provider
|
|
path: packages/data-provider/dist
|
|
retention-days: 2
|
|
|
|
- name: Upload data-schemas build
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: build-data-schemas
|
|
path: packages/data-schemas/dist
|
|
retention-days: 2
|
|
|
|
- name: Upload api build
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: build-api
|
|
path: packages/api/dist
|
|
retention-days: 2
|
|
|
|
typecheck:
|
|
name: TypeScript type checks
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 10
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Use Node.js 24.16.0
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '24.16.0'
|
|
|
|
- name: Restore node_modules cache
|
|
id: cache-node-modules
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
node_modules
|
|
api/node_modules
|
|
packages/api/node_modules
|
|
packages/data-provider/node_modules
|
|
packages/data-schemas/node_modules
|
|
key: node-modules-backend-${{ runner.os }}-24.16.0-${{ hashFiles('package-lock.json') }}
|
|
|
|
- name: Install dependencies
|
|
if: steps.cache-node-modules.outputs.cache-hit != 'true'
|
|
run: npm ci
|
|
|
|
- name: Download data-provider build
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: build-data-provider
|
|
path: packages/data-provider/dist
|
|
|
|
- name: Download data-schemas build
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: build-data-schemas
|
|
path: packages/data-schemas/dist
|
|
|
|
- name: Download api build
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: build-api
|
|
path: packages/api/dist
|
|
|
|
- name: Type check data-provider
|
|
run: npx tsc --noEmit -p packages/data-provider/tsconfig.json
|
|
|
|
- name: Type check data-schemas
|
|
run: npx tsc --noEmit -p packages/data-schemas/tsconfig.json
|
|
|
|
- name: Type check @librechat/api
|
|
run: npx tsc --noEmit -p packages/api/tsconfig.json
|
|
|
|
- name: Type check @librechat/client
|
|
run: npx tsc --noEmit -p packages/client/tsconfig.json
|
|
|
|
circular-deps:
|
|
name: Circular dependency checks
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 10
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Use Node.js 24.16.0
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '24.16.0'
|
|
|
|
- name: Restore node_modules cache
|
|
id: cache-node-modules
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
node_modules
|
|
api/node_modules
|
|
packages/api/node_modules
|
|
packages/data-provider/node_modules
|
|
packages/data-schemas/node_modules
|
|
key: node-modules-backend-${{ runner.os }}-24.16.0-${{ hashFiles('package-lock.json') }}
|
|
|
|
- name: Install dependencies
|
|
if: steps.cache-node-modules.outputs.cache-hit != 'true'
|
|
run: npm ci
|
|
|
|
- name: Download data-provider build
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: build-data-provider
|
|
path: packages/data-provider/dist
|
|
|
|
- name: Download data-schemas build
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: build-data-schemas
|
|
path: packages/data-schemas/dist
|
|
|
|
- name: Rebuild @librechat/api and check for circular dependencies
|
|
run: |
|
|
output=$(npm run build:api 2>&1)
|
|
echo "$output"
|
|
if echo "$output" | grep -q "Circular depend"; then
|
|
echo "Error: Circular dependency detected in @librechat/api!"
|
|
exit 1
|
|
fi
|
|
|
|
- name: Detect circular dependencies in rollup
|
|
working-directory: ./packages/data-provider
|
|
run: |
|
|
output=$(npm run rollup:api)
|
|
echo "$output"
|
|
if echo "$output" | grep -q "Circular dependency"; then
|
|
echo "Error: Circular dependency detected!"
|
|
exit 1
|
|
fi
|
|
|
|
test-api:
|
|
name: 'Tests: api (shard ${{ matrix.shard }}/3)'
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 15
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
shard: [1, 2, 3]
|
|
env:
|
|
MONGO_URI: ${{ secrets.MONGO_URI }}
|
|
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
|
JWT_SECRET: ${{ secrets.JWT_SECRET }}
|
|
CREDS_KEY: ${{ secrets.CREDS_KEY }}
|
|
CREDS_IV: ${{ secrets.CREDS_IV }}
|
|
BAN_VIOLATIONS: ${{ secrets.BAN_VIOLATIONS }}
|
|
BAN_DURATION: ${{ secrets.BAN_DURATION }}
|
|
BAN_INTERVAL: ${{ secrets.BAN_INTERVAL }}
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Use Node.js 24.16.0
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '24.16.0'
|
|
|
|
- name: Restore node_modules cache
|
|
id: cache-node-modules
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
node_modules
|
|
api/node_modules
|
|
packages/api/node_modules
|
|
packages/data-provider/node_modules
|
|
packages/data-schemas/node_modules
|
|
key: node-modules-backend-${{ runner.os }}-24.16.0-${{ hashFiles('package-lock.json') }}
|
|
|
|
- name: Install dependencies
|
|
if: steps.cache-node-modules.outputs.cache-hit != 'true'
|
|
run: npm ci
|
|
|
|
- name: Download data-provider build
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: build-data-provider
|
|
path: packages/data-provider/dist
|
|
|
|
- name: Download data-schemas build
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: build-data-schemas
|
|
path: packages/data-schemas/dist
|
|
|
|
- name: Download api build
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: build-api
|
|
path: packages/api/dist
|
|
|
|
- name: Create empty auth.json file
|
|
run: |
|
|
mkdir -p api/data
|
|
echo '{}' > api/data/auth.json
|
|
|
|
- name: Prepare .env.test file
|
|
run: cp api/test/.env.test.example api/test/.env.test
|
|
|
|
- name: Run unit tests (shard ${{ matrix.shard }}/3)
|
|
run: cd api && npm run test:ci -- --shard=${{ matrix.shard }}/3
|
|
|
|
test-data-provider:
|
|
name: 'Tests: data-provider'
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 10
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Use Node.js 24.16.0
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '24.16.0'
|
|
|
|
- name: Restore node_modules cache
|
|
id: cache-node-modules
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
node_modules
|
|
api/node_modules
|
|
packages/api/node_modules
|
|
packages/data-provider/node_modules
|
|
packages/data-schemas/node_modules
|
|
key: node-modules-backend-${{ runner.os }}-24.16.0-${{ hashFiles('package-lock.json') }}
|
|
|
|
- name: Install dependencies
|
|
if: steps.cache-node-modules.outputs.cache-hit != 'true'
|
|
run: npm ci
|
|
|
|
- name: Download data-provider build
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: build-data-provider
|
|
path: packages/data-provider/dist
|
|
|
|
- name: Run unit tests
|
|
run: cd packages/data-provider && npm run test:ci
|
|
|
|
test-data-schemas:
|
|
name: 'Tests: data-schemas'
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 10
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Use Node.js 24.16.0
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '24.16.0'
|
|
|
|
- name: Restore node_modules cache
|
|
id: cache-node-modules
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
node_modules
|
|
api/node_modules
|
|
packages/api/node_modules
|
|
packages/data-provider/node_modules
|
|
packages/data-schemas/node_modules
|
|
key: node-modules-backend-${{ runner.os }}-24.16.0-${{ hashFiles('package-lock.json') }}
|
|
|
|
- name: Install dependencies
|
|
if: steps.cache-node-modules.outputs.cache-hit != 'true'
|
|
run: npm ci
|
|
|
|
- name: Download data-provider build
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: build-data-provider
|
|
path: packages/data-provider/dist
|
|
|
|
- name: Download data-schemas build
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: build-data-schemas
|
|
path: packages/data-schemas/dist
|
|
|
|
- name: Run unit tests
|
|
run: cd packages/data-schemas && npm run test:ci
|
|
|
|
test-packages-api:
|
|
name: 'Tests: @librechat/api (shard ${{ matrix.shard }}/4)'
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
# Suite typically completes in ~5 min on a warm runner, but tail-latency
|
|
# cancellations have started showing up: tests are actively passing right
|
|
# up to the timeout, then the job is killed mid-suite. Sharding splits the
|
|
# suite across runners; per-shard headroom still absorbs runner variance.
|
|
timeout-minutes: 20
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
shard: [1, 2, 3, 4]
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Use Node.js 24.16.0
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '24.16.0'
|
|
|
|
- name: Restore node_modules cache
|
|
id: cache-node-modules
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
node_modules
|
|
api/node_modules
|
|
packages/api/node_modules
|
|
packages/data-provider/node_modules
|
|
packages/data-schemas/node_modules
|
|
key: node-modules-backend-${{ runner.os }}-24.16.0-${{ hashFiles('package-lock.json') }}
|
|
|
|
- name: Install dependencies
|
|
if: steps.cache-node-modules.outputs.cache-hit != 'true'
|
|
run: npm ci
|
|
|
|
- name: Download data-provider build
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: build-data-provider
|
|
path: packages/data-provider/dist
|
|
|
|
- name: Download data-schemas build
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: build-data-schemas
|
|
path: packages/data-schemas/dist
|
|
|
|
- name: Download api build
|
|
uses: actions/download-artifact@v4
|
|
with:
|
|
name: build-api
|
|
path: packages/api/dist
|
|
|
|
- name: Run unit tests (shard ${{ matrix.shard }}/4)
|
|
run: cd packages/api && npm run test:ci -- --shard=${{ matrix.shard }}/4
|