-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔐 feat: Toggle Access to Prompts via
librechat.yaml
(#3735)
* chore: update CONFIG_VERSION to '1.1.6' * chore: update package version to 0.7.415 * feat: toggle USER role access to prompts via librechat.yaml * refactor: set prompts to true when loadDefaultInterface returns true * ci(AppService): mock updatePromptsAccess
- Loading branch information
1 parent
0c5568b
commit 596ecc6
Showing
9 changed files
with
176 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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,73 @@ | ||
jest.mock('~/models/Role', () => ({ | ||
initializeRoles: jest.fn(), | ||
updatePromptsAccess: jest.fn(), | ||
getRoleByName: jest.fn(), | ||
updateRoleByName: jest.fn(), | ||
})); | ||
|
||
jest.mock('~/config', () => ({ | ||
logger: { | ||
info: jest.fn(), | ||
warn: jest.fn(), | ||
error: jest.fn(), | ||
}, | ||
})); | ||
|
||
jest.mock('./Config/loadCustomConfig', () => jest.fn()); | ||
jest.mock('./start/interface', () => ({ | ||
loadDefaultInterface: jest.fn(), | ||
})); | ||
jest.mock('./ToolService', () => ({ | ||
loadAndFormatTools: jest.fn().mockReturnValue({}), | ||
})); | ||
jest.mock('./start/checks', () => ({ | ||
checkVariables: jest.fn(), | ||
checkHealth: jest.fn(), | ||
checkConfig: jest.fn(), | ||
checkAzureVariables: jest.fn(), | ||
})); | ||
|
||
const AppService = require('./AppService'); | ||
const { loadDefaultInterface } = require('./start/interface'); | ||
|
||
describe('AppService interface.prompts configuration', () => { | ||
let app; | ||
let mockLoadCustomConfig; | ||
|
||
beforeEach(() => { | ||
app = { locals: {} }; | ||
jest.resetModules(); | ||
jest.clearAllMocks(); | ||
mockLoadCustomConfig = require('./Config/loadCustomConfig'); | ||
}); | ||
|
||
it('should set prompts to true when loadDefaultInterface returns true', async () => { | ||
mockLoadCustomConfig.mockResolvedValue({}); | ||
loadDefaultInterface.mockResolvedValue({ prompts: true }); | ||
|
||
await AppService(app); | ||
|
||
expect(app.locals.interfaceConfig.prompts).toBe(true); | ||
expect(loadDefaultInterface).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should set prompts to false when loadDefaultInterface returns false', async () => { | ||
mockLoadCustomConfig.mockResolvedValue({ interface: { prompts: false } }); | ||
loadDefaultInterface.mockResolvedValue({ prompts: false }); | ||
|
||
await AppService(app); | ||
|
||
expect(app.locals.interfaceConfig.prompts).toBe(false); | ||
expect(loadDefaultInterface).toHaveBeenCalled(); | ||
}); | ||
|
||
it('should not set prompts when loadDefaultInterface returns undefined', async () => { | ||
mockLoadCustomConfig.mockResolvedValue({}); | ||
loadDefaultInterface.mockResolvedValue({}); | ||
|
||
await AppService(app); | ||
|
||
expect(app.locals.interfaceConfig.prompts).toBeUndefined(); | ||
expect(loadDefaultInterface).toHaveBeenCalled(); | ||
}); | ||
}); |
This file contains 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 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 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 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,45 @@ | ||
const { SystemRoles } = require('librechat-data-provider'); | ||
const { updatePromptsAccess } = require('~/models/Role'); | ||
const { loadDefaultInterface } = require('./interface'); | ||
|
||
jest.mock('~/models/Role', () => ({ | ||
updatePromptsAccess: jest.fn(), | ||
})); | ||
|
||
describe('loadDefaultInterface', () => { | ||
it('should call updatePromptsAccess with the correct parameters when prompts is true', async () => { | ||
const config = { interface: { prompts: true } }; | ||
const configDefaults = { interface: {} }; | ||
|
||
await loadDefaultInterface(config, configDefaults); | ||
|
||
expect(updatePromptsAccess).toHaveBeenCalledWith(SystemRoles.USER, true); | ||
}); | ||
|
||
it('should call updatePromptsAccess with false when prompts is false', async () => { | ||
const config = { interface: { prompts: false } }; | ||
const configDefaults = { interface: {} }; | ||
|
||
await loadDefaultInterface(config, configDefaults); | ||
|
||
expect(updatePromptsAccess).toHaveBeenCalledWith(SystemRoles.USER, false); | ||
}); | ||
|
||
it('should call updatePromptsAccess with undefined when prompts is not specified in config', async () => { | ||
const config = {}; | ||
const configDefaults = { interface: {} }; | ||
|
||
await loadDefaultInterface(config, configDefaults); | ||
|
||
expect(updatePromptsAccess).toHaveBeenCalledWith(SystemRoles.USER, undefined); | ||
}); | ||
|
||
it('should call updatePromptsAccess with undefined when prompts is explicitly undefined', async () => { | ||
const config = { interface: { prompts: undefined } }; | ||
const configDefaults = { interface: {} }; | ||
|
||
await loadDefaultInterface(config, configDefaults); | ||
|
||
expect(updatePromptsAccess).toHaveBeenCalledWith(SystemRoles.USER, undefined); | ||
}); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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