e115934061
Publish `@librechat/data-schemas` to NPM / pack (push) Failing after 8s
Publish `@librechat/client` to NPM / pack (push) Failing after 0s
GitNexus Index / index (push) Failing after 1s
Sync Locize Translations & Create Translation PR / Create Translation PR on Version Published (push) Has been skipped
Sync Helm Chart Tags / Sync chart tags (push) Failing after 2s
Publish `librechat-data-provider` to NPM / pack (push) Failing after 1s
Docker Dev Images Build / build (Dockerfile, librechat-dev, node) (push) Failing after 1s
Docker Dev Images Build / build (Dockerfile.multi, librechat-dev-api, api-build) (push) Failing after 0s
Sync Helm Chart Tags / Ignore non-main push (push) Has been skipped
Sync Locize Translations & Create Translation PR / Sync Translation Keys with Locize (push) Failing after 1s
Publish `@librechat/client` to NPM / publish-npm (push) Has been cancelled
Publish `librechat-data-provider` to NPM / publish-npm (push) Has been cancelled
GitNexus Index / post-index (push) Has been cancelled
Publish `@librechat/data-schemas` to NPM / publish-npm (push) Has been cancelled
123 lines
4.0 KiB
JavaScript
123 lines
4.0 KiB
JavaScript
// ── Mocks ──────────────────────────────────────────────────────────────
|
|
|
|
const mockClearAppConfigCache = jest.fn().mockResolvedValue(undefined);
|
|
const mockClearOverrideCache = jest.fn().mockResolvedValue(undefined);
|
|
|
|
jest.mock('~/cache/getLogStores', () => {
|
|
return jest.fn(() => ({}));
|
|
});
|
|
|
|
jest.mock('~/server/services/start/tools', () => ({
|
|
loadAndFormatTools: jest.fn(() => ({})),
|
|
}));
|
|
|
|
jest.mock('../loadCustomConfig', () => jest.fn().mockResolvedValue({}));
|
|
|
|
jest.mock('@librechat/data-schemas', () => {
|
|
const actual = jest.requireActual('@librechat/data-schemas');
|
|
return { ...actual, AppService: jest.fn(() => ({ availableTools: {} })) };
|
|
});
|
|
|
|
jest.mock('~/models', () => ({
|
|
getApplicableConfigs: jest.fn().mockResolvedValue([]),
|
|
getUserPrincipals: jest.fn().mockResolvedValue([]),
|
|
}));
|
|
|
|
const mockInvalidateCachedTools = jest.fn().mockResolvedValue(undefined);
|
|
jest.mock('../getCachedTools', () => ({
|
|
setCachedTools: jest.fn().mockResolvedValue(undefined),
|
|
invalidateCachedTools: mockInvalidateCachedTools,
|
|
}));
|
|
|
|
const mockClearMcpConfigCache = jest.fn().mockResolvedValue(undefined);
|
|
jest.mock('@librechat/api', () => ({
|
|
createAppConfigService: jest.fn(() => ({
|
|
getAppConfig: jest.fn().mockResolvedValue({ availableTools: {} }),
|
|
clearAppConfigCache: mockClearAppConfigCache,
|
|
clearOverrideCache: mockClearOverrideCache,
|
|
})),
|
|
clearMcpConfigCache: mockClearMcpConfigCache,
|
|
}));
|
|
|
|
// ── Tests ──────────────────────────────────────────────────────────────
|
|
|
|
const { invalidateConfigCaches } = require('../app');
|
|
|
|
describe('invalidateConfigCaches', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it('clears all caches', async () => {
|
|
await invalidateConfigCaches();
|
|
|
|
expect(mockClearAppConfigCache).toHaveBeenCalledTimes(1);
|
|
expect(mockClearOverrideCache).toHaveBeenCalledTimes(1);
|
|
expect(mockInvalidateCachedTools).toHaveBeenCalledWith({ invalidateGlobal: true });
|
|
expect(mockClearMcpConfigCache).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('passes tenantId through to clearOverrideCache', async () => {
|
|
await invalidateConfigCaches('tenant-a');
|
|
|
|
expect(mockClearOverrideCache).toHaveBeenCalledWith('tenant-a');
|
|
expect(mockClearAppConfigCache).toHaveBeenCalledTimes(1);
|
|
expect(mockInvalidateCachedTools).toHaveBeenCalledWith({ invalidateGlobal: true });
|
|
});
|
|
|
|
it('all operations run in parallel (not sequentially)', async () => {
|
|
const order = [];
|
|
|
|
mockClearAppConfigCache.mockImplementation(
|
|
() =>
|
|
new Promise((r) =>
|
|
setTimeout(() => {
|
|
order.push('base');
|
|
r();
|
|
}, 10),
|
|
),
|
|
);
|
|
mockClearOverrideCache.mockImplementation(
|
|
() =>
|
|
new Promise((r) =>
|
|
setTimeout(() => {
|
|
order.push('override');
|
|
r();
|
|
}, 10),
|
|
),
|
|
);
|
|
mockInvalidateCachedTools.mockImplementation(
|
|
() =>
|
|
new Promise((r) =>
|
|
setTimeout(() => {
|
|
order.push('tools');
|
|
r();
|
|
}, 10),
|
|
),
|
|
);
|
|
mockClearMcpConfigCache.mockImplementation(
|
|
() =>
|
|
new Promise((r) =>
|
|
setTimeout(() => {
|
|
order.push('mcp');
|
|
r();
|
|
}, 10),
|
|
),
|
|
);
|
|
|
|
await invalidateConfigCaches();
|
|
|
|
expect(order).toHaveLength(4);
|
|
expect(new Set(order)).toEqual(new Set(['base', 'override', 'tools', 'mcp']));
|
|
});
|
|
|
|
it('resolves even when clearAppConfigCache throws (partial failure)', async () => {
|
|
mockClearAppConfigCache.mockRejectedValueOnce(new Error('cache connection lost'));
|
|
|
|
await expect(invalidateConfigCaches()).resolves.not.toThrow();
|
|
|
|
expect(mockClearOverrideCache).toHaveBeenCalledTimes(1);
|
|
expect(mockInvalidateCachedTools).toHaveBeenCalledWith({ invalidateGlobal: true });
|
|
});
|
|
});
|