mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-04-03 22:37:20 +02:00
* fix(data-schemas): resolve TypeScript strict type check errors in source files - Constrain ConfigSection to string keys via `string & keyof TCustomConfig` - Replace broken `z` import from data-provider with TCustomConfig derivation - Add `_id: Types.ObjectId` to IUser matching other Document interfaces - Add `federatedTokens` and `openidTokens` optional fields to IUser - Type mongoose model accessors as `Model<IRole>` and `Model<IUser>` - Widen `getPremiumRate` param to accept `number | null` - Widen `bulkWriteAclEntries` ops to untyped `AnyBulkWriteOperation[]` - Fix `getUserPrincipals` return type to use `PrincipalType` enum - Add non-null assertions for `connection.db` in migration files - Import DailyRotateFile constructor directly instead of relying on broken module augmentation across mismatched node_modules trees - Add winston-daily-rotate-file as devDependency for type resolution * fix(data-schemas): resolve TypeScript type errors in test files - Replace arbitrary test keys with valid TCustomConfig properties in config.spec - Use non-null assertions for permission objects in role.methods.spec - Replace `.SHARED_GLOBAL` access with `.not.toHaveProperty()` for legacy field - Add non-null assertions for balance, writeRate, readRate in spendTokens.spec - Update mock user _id to use ObjectId in user.test - Remove unused Schema import in tenantIndexes.spec * fix(api): resolve TypeScript strict type check errors across source and test files - Widen getUserPrincipals dep type in capabilities middleware - Fix federatedTokens type in createSafeUser return - Use proper mock req type for read-only properties in preAuthTenant.spec - Replace `as IUser` casts with ObjectId-typed mocks in openid/oidc specs - Use TokenExchangeMethodEnum values instead of string literals in MCP specs - Fix SessionStore type compatibility in sessionCache specs - Replace `catch (error: any)` with `(error as Error)` in redis specs - Remove invalid properties from test data in initialize and MCP specs - Add String.prototype.isWellFormed declaration for sanitizeTitle spec * fix(client): resolve TypeScript type errors in shared client components - Add default values for destructured bindings in OGDialogTemplate - Replace broken ExtendedFile import with inline type in FileIcon * ci: add TypeScript type-check job to backend review workflow Add a `typecheck` job that runs `tsc --noEmit` on all four TypeScript workspaces (data-provider, data-schemas, @librechat/api, @librechat/client) after the build step. Catches type errors that rollup builds may miss. * fix(data-schemas): add local type declaration for DailyRotateFile transport The `winston-daily-rotate-file` package ships a module augmentation for `winston/lib/winston/transports`, but it fails when winston and winston-daily-rotate-file resolve from different node_modules trees (which happens in this monorepo due to npm hoisting). Add a local `.d.ts` declaration that augments the same module path from within data-schemas' compilation unit, so `tsc --noEmit` passes while keeping the original runtime pattern (`new winston.transports.DailyRotateFile`). * fix: address code review findings from PR #12451 - Restore typed `AnyBulkWriteOperation<AclEntry>[]` on bulkWriteAclEntries, cast to untyped only at the tenantSafeBulkWrite call site (Finding 1) - Type `findUser` model accessor consistently with `findUsers` (Finding 2) - Replace inline `import('mongoose').ClientSession` with top-level import type - Use `toHaveLength` for spy assertions in playwright-expect spec file - Replace numbered Record casts with `.not.toHaveProperty()` in role.methods.spec for SHARED_GLOBAL assertions - Use per-test ObjectIds instead of shared testUserId in openid.spec - Replace inline `import()` type annotations with top-level SessionData import in sessionCache spec - Remove extraneous blank line in user.ts searchUsers * refactor: address remaining review findings (4–7) - Extract OIDCTokens interface in user.ts; deduplicate across IUser fields and oidc.ts FederatedTokens (Finding 4) - Move String.isWellFormed declaration from spec file to project-level src/types/es2024-string.d.ts (Finding 5) - Replace verbose `= undefined` defaults in OGDialogTemplate with null coalescing pattern (Finding 6) - Replace `Record<string, unknown>` TestConfig with named interface containing explicit test fields (Finding 7)
416 lines
13 KiB
YAML
416 lines
13 KiB
YAML
name: Backend Unit Tests
|
|
on:
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
- dev
|
|
- dev-staging
|
|
- release/*
|
|
paths:
|
|
- 'api/**'
|
|
- 'packages/**'
|
|
|
|
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 20.19
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20.19'
|
|
|
|
- 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 }}-20.19-${{ 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/rollup.config.js', '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/rollup.config.js', 'packages/data-schemas/package.json', 'packages/data-provider/src/**', 'packages/data-provider/tsconfig*.json', 'packages/data-provider/rollup.config.js', '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/server-rollup.config.js', 'packages/api/package.json', 'packages/data-provider/src/**', 'packages/data-provider/tsconfig*.json', 'packages/data-provider/rollup.config.js', 'packages/data-provider/package.json', 'packages/data-schemas/src/**', 'packages/data-schemas/tsconfig*.json', 'packages/data-schemas/rollup.config.js', '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 20.19
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20.19'
|
|
|
|
- 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 }}-20.19-${{ 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 20.19
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20.19'
|
|
|
|
- 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 }}-20.19-${{ 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'
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 15
|
|
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 20.19
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20.19'
|
|
|
|
- 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 }}-20.19-${{ 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
|
|
run: cd api && npm run test:ci
|
|
|
|
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 20.19
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20.19'
|
|
|
|
- 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 }}-20.19-${{ 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 20.19
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20.19'
|
|
|
|
- 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 }}-20.19-${{ 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'
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 10
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Use Node.js 20.19
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: '20.19'
|
|
|
|
- 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 }}-20.19-${{ 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
|
|
run: cd packages/api && npm run test:ci
|