mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-16 13:00:55 +00:00
🗝️ fix: Resolve Config-Scoped Custom Providers (#16687)
Some checks are pending
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Votes / vote (full suite) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
Some checks are pending
Backend Unit Tests / Build packages (push) Waiting to run
Backend Unit Tests / Codegraph select (push) Waiting to run
Backend Unit Tests / TypeScript type checks (push) Blocked by required conditions
Backend Unit Tests / Circular dependency checks (push) Waiting to run
Backend Unit Tests / Tests: api (shard 1/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 2/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: api (shard 3/3) (push) Blocked by required conditions
Backend Unit Tests / Tests: data-provider (push) Blocked by required conditions
Backend Unit Tests / Tests: data-schemas (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 1/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 2/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 3/4) (push) Blocked by required conditions
Backend Unit Tests / Tests: @librechat/api (shard 4/4) (push) Blocked by required conditions
Codegraph E2E Votes / vote (full suite) (push) Waiting to run
Docker Dev Branch Images Build / publish (push) Waiting to run
Frontend Unit Tests / Client build recovery regression (push) Waiting to run
Frontend Unit Tests / Codegraph select (push) Waiting to run
Frontend Unit Tests / Build packages (push) Waiting to run
Frontend Unit Tests / TypeScript type checks (client) (push) Blocked by required conditions
Frontend Unit Tests / Tests: @librechat/client (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 1/2) (push) Blocked by required conditions
Frontend Unit Tests / Tests: Ubuntu (shard 2/2) (push) Blocked by required conditions
Frontend Unit Tests / Vite build verification (push) Blocked by required conditions
* fix: prefer tenant custom endpoints over global providers * test: use generic config scope fixtures
This commit is contained in:
parent
f88f3fb2fe
commit
67a5fe247c
2 changed files with 66 additions and 6 deletions
|
|
@ -165,6 +165,55 @@ describe('createAppConfigService', () => {
|
|||
expect(custom).toHaveLength(2);
|
||||
});
|
||||
|
||||
it.each([false, true])(
|
||||
'prefers tenant providers over same-named global providers (tenant first: %s)',
|
||||
async (tenantFirst) => {
|
||||
const global = {
|
||||
name: 'Claude',
|
||||
apiKey: 'global-key',
|
||||
baseURL: 'https://global.example',
|
||||
models: { default: ['global-model'], fetch: false },
|
||||
};
|
||||
const tenants = ['tenant-a', 'tenant-b'].map((tenantId) => ({
|
||||
...global,
|
||||
name: 'Claude',
|
||||
tenantId,
|
||||
apiKey: 'tenant-key',
|
||||
baseURL: 'https://tenant.example',
|
||||
models: { default: ['tenant-model'], fetch: false },
|
||||
}));
|
||||
const custom = tenantFirst ? [...tenants, global] : [global, ...tenants];
|
||||
const modelSpecs = {
|
||||
list: [{ name: 'agent-spec', preset: { endpoint: 'Claude' } }],
|
||||
addedEndpoints: ['agents'],
|
||||
};
|
||||
const deps = createDeps({
|
||||
loadBaseConfig: jest.fn().mockResolvedValue({
|
||||
endpoints: { custom },
|
||||
modelSpecs,
|
||||
config: { endpoints: { custom }, modelSpecs },
|
||||
}),
|
||||
});
|
||||
const { getAppConfig } = createAppConfigService(deps);
|
||||
|
||||
for (const tenantId of ['tenant-a', 'tenant-c', 'tenant-b', 'tenant-a']) {
|
||||
const config = await getAppConfig({ role: 'USER', tenantId });
|
||||
const expected = tenants.find((endpoint) => endpoint.tenantId === tenantId) ?? global;
|
||||
expect(config.endpoints?.custom).toEqual([expected]);
|
||||
expect(config.config.endpoints?.custom).toEqual([expected]);
|
||||
expect(config.modelSpecs).toEqual(modelSpecs);
|
||||
const provider = getProviderConfig({ provider: 'Claude', appConfig: config });
|
||||
expect(provider.customEndpointConfig?.apiKey).toBe(expected.apiKey);
|
||||
expect(provider.customEndpointConfig?.models).toEqual(expected.models);
|
||||
}
|
||||
|
||||
const base = await getAppConfig({ baseOnly: true });
|
||||
expect(base.endpoints?.custom).toEqual([global]);
|
||||
expect(custom).toHaveLength(3);
|
||||
expect(deps.loadBaseConfig).toHaveBeenCalledTimes(1);
|
||||
},
|
||||
);
|
||||
|
||||
it('removes a prioritized spec when its only endpoint belongs to another tenant', async () => {
|
||||
const deps = createDeps({
|
||||
loadBaseConfig: jest.fn().mockResolvedValue({
|
||||
|
|
|
|||
|
|
@ -52,12 +52,23 @@ function scopeEndpointList<T extends { name?: string; tenantId?: string }>(
|
|||
hiddenEndpoints: ReadonlySet<string>,
|
||||
): T[] | undefined {
|
||||
if (!endpoints) return endpoints;
|
||||
const scoped = endpoints.filter(
|
||||
(endpoint) =>
|
||||
(!endpoint.tenantId || endpoint.tenantId === tenantId) &&
|
||||
!hiddenEndpoints.has(normalizeEndpointName(endpoint.name ?? '')),
|
||||
);
|
||||
return scoped.length === endpoints.length ? endpoints : scoped;
|
||||
const tenantNames = new Set<string>();
|
||||
const scoped = endpoints.filter((endpoint) => {
|
||||
const name = normalizeEndpointName(endpoint.name ?? '');
|
||||
if ((endpoint.tenantId && endpoint.tenantId !== tenantId) || hiddenEndpoints.has(name)) {
|
||||
return false;
|
||||
}
|
||||
if (endpoint.tenantId) tenantNames.add(name);
|
||||
return true;
|
||||
});
|
||||
const selected =
|
||||
tenantNames.size === 0
|
||||
? scoped
|
||||
: scoped.filter(
|
||||
(endpoint) =>
|
||||
endpoint.tenantId || !tenantNames.has(normalizeEndpointName(endpoint.name ?? '')),
|
||||
);
|
||||
return selected.length === endpoints.length ? endpoints : selected;
|
||||
}
|
||||
|
||||
function scopeModelSpecs(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue