LibreChat/packages/data-provider/specs/models-query.spec.ts
lia-by-librechat[bot] b4afbb3a1e
🛝 perf: Render Chats Independently of Catalog Discovery (#17692)
* 🛝 perf: Render Chats Independently of Catalog Discovery

* Preserve Target Authorization and Passive Startup Intent

* Keep Startup Selection, Readiness, and Catalog Keys Consistent

* Preserve Remembered Targets and Validate Scoped Presets

* Retain Remembered Assistant Resource Aliases Across Endpoint Switches

* Apply URL Targets Before Waiting for Send Readiness

* Fix First-Page Agent Discovery and Await Model Selection

* Preserve Spec Access and Refresh Selected Assistant State

* Preserve Builder Deletion State and Start History Reads Earlier

* fix: Preserve Startup Recovery and History Read Ownership

* fix: Retain Express Query Routing in Assistant Lookups

* fix: Prioritize Route Reads and Recover Credential Changes

* fix: Bind Credential Revocation to Its Requested Scope

* fix: Refresh Credential Metadata After Pending Key Reads

* fix: Revalidate Inactive Credential Metadata on Target Mount

* fix: Preserve Reviewed Chat Resolutions After Rebase

* fix: Resolve Dev Conflicts and Preserve Startup Boundaries

* test: Preserve the ChatView Slot Target Boundary

* fix: Defer Terminal Delivery Until Subscription Attachment Completes

* fix: Contain Deferred Terminal Callback Failures

* test: Classify Historical Tool Name Capability Reads

* fix: Activate Requested Catalogs and Isolate Provider Failures

* fix: Keep Healthy Provider Choices Available During Catalog Recovery

* test: Exclude Copied Trace Bundles From Dependency Comparison

---------

Co-authored-by: Lia <lia@librechat.ai>
2026-11-09 11:11:22 -05:00

56 lines
2.2 KiB
TypeScript

import { useQuery } from '@tanstack/react-query';
import { useGetModelsQuery, useGetEndpointModelsQuery } from '../src/react-query';
import { initialModelsConfig } from '../src/config';
import { QueryKeys } from '../src/keys';
jest.mock('@tanstack/react-query', () => ({ useQuery: jest.fn() }));
jest.mock('../src/data-service', () => ({ getModels: jest.fn() }));
import { getModels } from '../src/data-service';
function queryCall() {
const calls = jest.mocked(useQuery).mock.calls;
return calls[calls.length - 1];
}
describe('model discovery query hooks', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('gives each endpoint a distinct cache key and no fabricated initial catalog', () => {
useGetEndpointModelsQuery('openAI');
const [key, query, options] = queryCall();
expect(key).toEqual([QueryKeys.models, 'openAI']);
expect(options).not.toHaveProperty('initialData');
expect(options).not.toHaveProperty('placeholderData');
expect(options).toEqual(expect.objectContaining({ staleTime: Infinity, enabled: true }));
(query as () => void)();
expect(getModels).toHaveBeenCalledWith('openAI');
useGetEndpointModelsQuery('anthropic');
expect(queryCall()[0]).toEqual([QueryKeys.models, 'anthropic']);
});
it('lets callers disable scoped discovery and preserves query options', () => {
useGetEndpointModelsQuery('openAI', { enabled: false, retry: false });
expect(queryCall()[2]).toEqual(expect.objectContaining({ enabled: false, retry: false }));
});
it('never fetches an empty endpoint automatically', () => {
useGetEndpointModelsQuery('', { enabled: true });
expect(queryCall()[2]).toEqual(expect.objectContaining({ enabled: false }));
expect(getModels).not.toHaveBeenCalled();
});
it('keeps aggregate observers backward compatible and explicitly disableable', () => {
useGetModelsQuery({ enabled: false });
const [key, query, options] = queryCall();
expect(key).toEqual([QueryKeys.models]);
expect(options).toEqual(
expect.objectContaining({ initialData: initialModelsConfig, enabled: false }),
);
(query as () => void)();
expect(getModels).toHaveBeenCalledWith();
});
});