Repository navigation
🧳 feat: Register Principal-Owned Code Environments #15365
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
43b8f50
feat: add principal-owned code environments
danny-avila d4c687b
fix: address code environment CI coverage
danny-avila d25cf36
fix: expose principal code environments in endpoint config
danny-avila 3423b71
fix: reject missing code environment bodies
danny-avila 8f7edd4
fix: harden code environment lifecycle
danny-avila 22e2804
fix: revalidate principal code environments
danny-avila 15b979a
fix: synchronize code environment authorization
danny-avila 0eff28a
fix: bind code environments to current principals
danny-avila e8704a8
fix: fail closed on code ACL cache errors
danny-avila 414db13
fix: prevent code environment override shadowing
danny-avila b27a2ed
fix: preserve principal environment defaults
danny-avila 5525060
fix: suppress revoked code environment aliases
danny-avila c0452c2
fix: fail closed on environment augmentation
danny-avila f01831d
fix: narrow code environment defaults
danny-avila 3f7f0ab
fix: isolate code environment fallback
danny-avila d31916f
style: sort code config imports
danny-avila 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
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
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,27 @@ | ||
| const express = require('express'); | ||
| const { createCodeEnvironmentHttpHandlers } = require('@librechat/api'); | ||
| const { SystemCapabilities } = require('@librechat/data-schemas'); | ||
| const { requireCapability } = require('~/server/middleware/roles/capabilities'); | ||
| const { getAppConfig, getCodeEnvironmentRegistry } = require('~/server/services/Config'); | ||
| const { requireJwtAuth } = require('~/server/middleware'); | ||
|
|
||
| const router = express.Router(); | ||
| let handlers; | ||
| function getHandlers() { | ||
| if (handlers == null) { | ||
| handlers = createCodeEnvironmentHttpHandlers({ | ||
| getAppConfig, | ||
| registry: getCodeEnvironmentRegistry(), | ||
| }); | ||
| } | ||
| return handlers; | ||
| } | ||
| const requireCodeEnvironmentManage = requireCapability(SystemCapabilities.MANAGE_CODE_ENVIRONMENTS); | ||
|
|
||
| router.use(requireJwtAuth); | ||
| router.get('/', (req, res, next) => getHandlers().list(req, res, next)); | ||
| router.post('/', requireCodeEnvironmentManage, (req, res, next) => | ||
| getHandlers().register(req, res, next), | ||
| ); | ||
|
|
||
| module.exports = router; |
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,77 @@ | ||
| const express = require('express'); | ||
| const request = require('supertest'); | ||
|
|
||
| const middlewareCalls = []; | ||
| const mockRequireJwtAuth = jest.fn((req, _res, next) => { | ||
| middlewareCalls.push('jwt'); | ||
| req.user = { id: '68b2f0c498f24c1e78fa0001', role: 'USER' }; | ||
| next(); | ||
| }); | ||
| const mockRequireCapability = jest.fn((capability) => (req, _res, next) => { | ||
| middlewareCalls.push(capability); | ||
| next(); | ||
| }); | ||
| const mockRegistry = {}; | ||
| const mockGetCodeEnvironmentRegistry = jest.fn(() => mockRegistry); | ||
| const mockHandlers = { | ||
| list: jest.fn((_req, res) => res.status(200).json({ environments: [] })), | ||
| register: jest.fn((_req, res) => res.status(201).json({ environment: { id: 'code-1' } })), | ||
| }; | ||
|
|
||
| jest.mock('@librechat/data-schemas', () => ({ | ||
| SystemCapabilities: { MANAGE_CODE_ENVIRONMENTS: 'manage:code_environments' }, | ||
| })); | ||
|
|
||
| jest.mock('@librechat/api', () => ({ | ||
| createCodeEnvironmentRegistry: jest.fn(() => mockRegistry), | ||
| createCodeEnvironmentHttpHandlers: jest.fn(() => mockHandlers), | ||
| })); | ||
|
|
||
| jest.mock('~/server/middleware/roles/capabilities', () => ({ | ||
| requireCapability: mockRequireCapability, | ||
| })); | ||
|
|
||
| jest.mock('~/server/middleware', () => ({ requireJwtAuth: mockRequireJwtAuth })); | ||
| jest.mock('~/server/services/Config', () => ({ | ||
| getAppConfig: jest.fn(), | ||
| getCodeEnvironmentRegistry: mockGetCodeEnvironmentRegistry, | ||
| })); | ||
|
|
||
| function createApp() { | ||
| delete require.cache[require.resolve('./code-environments')]; | ||
| const router = require('./code-environments'); | ||
| const app = express(); | ||
| app.use(express.json()); | ||
| app.use('/api/code-environments', router); | ||
| return app; | ||
| } | ||
|
|
||
| describe('code environment routes', () => { | ||
| beforeEach(() => { | ||
| middlewareCalls.length = 0; | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('defers registry initialization until the route is requested', () => { | ||
| createApp(); | ||
|
|
||
| expect(mockGetCodeEnvironmentRegistry).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('allows authenticated discovery without the management capability', async () => { | ||
| await request(createApp()).get('/api/code-environments').expect(200, { environments: [] }); | ||
|
|
||
| expect(middlewareCalls).toEqual(['jwt']); | ||
| expect(mockHandlers.list).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it('requires the management capability before registration', async () => { | ||
| await request(createApp()) | ||
| .post('/api/code-environments') | ||
| .send({ name: 'Personal VM' }) | ||
| .expect(201); | ||
|
|
||
| expect(middlewareCalls).toEqual(['jwt', 'manage:code_environments']); | ||
| expect(mockHandlers.register).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
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
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.
Uh oh!
There was an error while loading. Please reload this page.