-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
feat(admin): add atomic config mutations and revision rollback #15458
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
romy651
wants to merge
7
commits into
danny-avila:dev
Choose a base branch
from
fdj-united:feat/admin-config-atomic-mutate
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
7 commits
Select commit
Hold shift + click to select a range
7f245ce
feat: add atomic admin configuration mutations
92c585c
Merge branch 'dev' into feat/admin-config-atomic-mutate
romy651 f9cab26
Merge branch 'dev' into feat/admin-config-atomic-mutate
romy651 0f1ca2b
fix(admin): address atomic config review findings
a643dd4
fix(admin): harden atomic config isolation and secret lifecycle
fcdd514
Merge upstream dev into feat/admin-config-atomic-mutate
5cb1dfb
Merge branch 'dev' into feat/admin-config-atomic-mutate
romy651 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| const { tenantStorage } = require('@librechat/data-schemas'); | ||
|
|
||
| const mockGetAppConfig = jest.fn().mockResolvedValue({ ok: true }); | ||
| jest.mock('~/server/services/Config', () => ({ | ||
| getAppConfig: (...args) => mockGetAppConfig(...args), | ||
| })); | ||
|
|
||
| const configMiddleware = require('./app'); | ||
|
|
||
| describe('configMiddleware — tenant resolution', () => { | ||
| afterEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| function runInTenantContext(tenantId, fn) { | ||
| return tenantStorage.run({ tenantId }, fn); | ||
| } | ||
|
|
||
| /** | ||
| * Reproduces the exact mismatch the review flagged: a deployment that | ||
| * resolves the authoritative tenant server-side (ALS, seeded from | ||
| * `req.tenantId` by `tenantContextMiddleware`) must not have `req.config` | ||
| * loaded — or cached — under a *different*, stale `req.user.tenantId` JWT | ||
| * claim. Every other admin capability check and write already trusts ALS | ||
| * via `getEffectiveTenantId`; `configMiddleware` must match. | ||
| */ | ||
| it('loads config for the ALS-resolved tenant, not a mismatched user.tenantId claim', async () => { | ||
| const req = { user: { tenantId: 'tenant-A-from-jwt', role: 'admin' }, path: '/api/config' }; | ||
| const next = jest.fn(); | ||
|
|
||
| await runInTenantContext('tenant-B-from-als', () => configMiddleware(req, {}, next)); | ||
|
|
||
| expect(mockGetAppConfig).toHaveBeenCalledWith( | ||
| expect.objectContaining({ tenantId: 'tenant-B-from-als' }), | ||
| ); | ||
| expect(next).toHaveBeenCalledWith(); | ||
| }); | ||
|
|
||
| it('falls back to the ALS-resolved tenant (not the user claim) on the error-recovery path too', async () => { | ||
| mockGetAppConfig.mockRejectedValueOnce(new Error('boom')).mockResolvedValueOnce({ ok: true }); | ||
| const req = { user: { tenantId: 'tenant-A-from-jwt', role: 'admin' }, path: '/api/config' }; | ||
| const next = jest.fn(); | ||
|
|
||
| await runInTenantContext('tenant-B-from-als', () => configMiddleware(req, {}, next)); | ||
|
|
||
| expect(mockGetAppConfig).toHaveBeenLastCalledWith({ tenantId: 'tenant-B-from-als' }); | ||
| expect(next).toHaveBeenCalledWith(); | ||
| }); | ||
|
|
||
| it('falls back to the user claim when no ALS tenant is active (no divergence to resolve)', async () => { | ||
| const req = { user: { tenantId: 'tenant-A-from-jwt', role: 'admin' }, path: '/api/config' }; | ||
| const next = jest.fn(); | ||
|
|
||
| await configMiddleware(req, {}, next); | ||
|
|
||
| expect(mockGetAppConfig).toHaveBeenCalledWith( | ||
| expect.objectContaining({ tenantId: 'tenant-A-from-jwt' }), | ||
| ); | ||
| }); | ||
| }); |
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.
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.
The supported
backend:experimentalentry point connects inapi/server/experimental.jswithout calling this new initializer. When that deployment runs withMONGO_AUTO_INDEX=false, the config, revision, and epoch uniqueness indexes and the deduplication migration are never installed before the atomic route accepts traffic; two concurrent first saves of an absent base config can therefore both commit separate config and epoch documents instead of one losing with a version conflict. Mirror this blocking initialization in the experimental startup path as well.Useful? React with 👍 / 👎.