-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
🥡 feat: Reload Custom Model Lists Across Replicas #16471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lia-by-librechat
wants to merge
3
commits into
dev
Choose a base branch
from
lia/reload-model-catalog-dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| const express = require('express'); | ||
| const request = require('supertest'); | ||
|
|
||
| let mockDenyAdminAccess = false; | ||
| let mockDenyPlatformAccess = false; | ||
| const mockReloadConfig = jest.fn((_req, res) => res.status(200).json({ scope: 'local' })); | ||
| const mockHandlers = { | ||
| listConfigs: jest.fn(), | ||
| getBaseConfig: jest.fn(), | ||
| reloadConfig: mockReloadConfig, | ||
| getConfig: jest.fn(), | ||
| upsertConfigOverrides: jest.fn(), | ||
| patchConfigField: jest.fn(), | ||
| tombstoneConfigField: jest.fn(), | ||
| deleteConfigField: jest.fn(), | ||
| deleteConfigOverrides: jest.fn(), | ||
| toggleConfig: jest.fn(), | ||
| }; | ||
|
|
||
| jest.mock('@librechat/api', () => ({ | ||
| createAdminConfigHandlers: jest.fn(() => mockHandlers), | ||
| })); | ||
|
|
||
| jest.mock('@librechat/data-schemas', () => ({ | ||
| SystemCapabilities: { ACCESS_ADMIN: 'access:admin', MANAGE_CONFIGS: 'manage:configs' }, | ||
| })); | ||
|
|
||
| jest.mock('~/server/middleware/roles/capabilities', () => ({ | ||
| hasCapability: jest.fn(), | ||
| hasConfigCapability: jest.fn(), | ||
| hasAnyConfigReadAccess: jest.fn(), | ||
| getReadableConfigSections: jest.fn(), | ||
| requireCapability: jest.fn((capability, options) => (_req, res, next) => { | ||
| if (mockDenyAdminAccess || (options?.platformOnly && mockDenyPlatformAccess)) { | ||
| return res.status(403).json({ error: 'Forbidden' }); | ||
| } | ||
| next(); | ||
| }), | ||
| })); | ||
|
|
||
| jest.mock('~/server/middleware', () => ({ | ||
| requireJwtAuth: jest.fn((req, _res, next) => { | ||
| req.user = { id: 'admin-1', role: 'ADMIN' }; | ||
| next(); | ||
| }), | ||
| })); | ||
|
|
||
| jest.mock('~/server/services/Config', () => ({ | ||
| getAppConfig: jest.fn(), | ||
| invalidateConfigCaches: jest.fn(), | ||
| reloadCustomConfig: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('~/models', () => ({})); | ||
|
|
||
| function createApp() { | ||
| delete require.cache[require.resolve('./config')]; | ||
| const app = express(); | ||
| app.use('/api/admin/config', require('./config')); | ||
| return app; | ||
| } | ||
|
|
||
| describe('admin config reload route', () => { | ||
| beforeEach(() => { | ||
| mockDenyAdminAccess = false; | ||
| mockDenyPlatformAccess = false; | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('allows an authenticated admin', async () => { | ||
| const response = await request(createApp()).post('/api/admin/config/reload').expect(200); | ||
|
|
||
| expect(response.body).toEqual({ scope: 'local' }); | ||
| expect(mockReloadConfig).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('denies a tenant administrator before reloading deployment YAML', async () => { | ||
| mockDenyPlatformAccess = true; | ||
| await request(createApp()).post('/api/admin/config/reload').expect(403); | ||
| expect(mockReloadConfig).not.toHaveBeenCalled(); | ||
| await request(createApp()).get('/api/admin/config/reload/access').expect(403); | ||
| }); | ||
|
|
||
| it('permits the settings capability probe after a platform grant', async () => { | ||
| const response = await request(createApp()).get('/api/admin/config/reload/access'); | ||
| expect(response.status).toBe(204); | ||
| }); | ||
|
|
||
| it('returns 403 before the handler for a non-admin', async () => { | ||
| mockDenyAdminAccess = true; | ||
|
|
||
| await request(createApp()).post('/api/admin/config/reload').expect(403); | ||
|
|
||
| expect(mockReloadConfig).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| const express = require('express'); | ||
| const request = require('supertest'); | ||
|
|
||
| const mockModels = jest.fn((req, res) => res.json({ model: req.config.model })); | ||
|
|
||
| jest.mock('~/server/middleware/', () => ({ | ||
| requireJwtAuth: (_req, _res, next) => next(), | ||
| })); | ||
|
|
||
| jest.mock('~/server/middleware/config/app', () => (req, _res, next) => { | ||
| req.config = { model: 'current-model' }; | ||
| next(); | ||
| }); | ||
|
|
||
| jest.mock('~/server/controllers/ModelController', () => ({ | ||
| modelController: (...args) => mockModels(...args), | ||
| })); | ||
|
|
||
| const models = require('./models'); | ||
|
|
||
| describe('model route with dev config middleware', () => { | ||
| it('registers a request-scoped config reader and serves models', async () => { | ||
| const app = express(); | ||
| app.use('/api/models', models); | ||
|
|
||
| const response = await request(app).get('/api/models'); | ||
|
|
||
| expect(response.status).toBe(200); | ||
| expect(response.body).toEqual({ model: 'current-model' }); | ||
| expect(mockModels).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the newly added generation lookup and response-header behavior into a TypeScript handler under
packages/api, leaving this legacy CJS controller as wiring only. Calling the config-generation service and implementing the versioned response contract here extends backend behavior in/api, contrary to the repository's explicit module boundary and makes this reload protocol split across the legacy and typed layers.AGENTS.md reference: AGENTS.md:L77-L81
Useful? React with 👍 / 👎.