mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-16 13:00:55 +00:00
* fix: Harden Timer Sweeps, SSE Writes, and Violation Counters Guard SSE writes against ended or destroyed responses through one helper, catch and single-flight the job store and TTL cache cleanup timers, serialize in-process counter updates, cap the violation log, prune stale OAuth failure records, batch the active-job lookup, and count Redis keys with DBSIZE. * refactor: Drop the redundant violation log entry copy * refactor: Log single-flight sweep failures from the API package * test: Cover active generation listing and client disconnect mid-stream * refactor: Configure violation log retention and move title timeout into the API package * feat: Configure OAuth failure retention through mcpSettings * fix: Prune OAuth failures promptly under short retention
78 lines
2.8 KiB
JavaScript
78 lines
2.8 KiB
JavaScript
const mockCreateOAuthReconnectionManager = jest.fn();
|
|
const mockGetAppConfig = jest.fn();
|
|
const mockPrepareMCPAuthorizationMutation = jest.fn();
|
|
|
|
jest.mock('@librechat/data-schemas', () => ({
|
|
logger: { info: jest.fn(), error: jest.fn() },
|
|
getTenantId: jest.fn(() => 'tenant-a'),
|
|
}));
|
|
|
|
jest.mock('@librechat/api', () => ({
|
|
createOAuthReconnectionTracker: (config) => ({ type: 'tracker', config }),
|
|
prepareMCPAuthorizationMutation: (...args) => mockPrepareMCPAuthorizationMutation(...args),
|
|
}));
|
|
|
|
jest.mock('librechat-data-provider', () => ({
|
|
CacheKeys: { FLOWS: 'flows' },
|
|
}));
|
|
|
|
jest.mock('~/config', () => ({
|
|
createOAuthReconnectionManager: (...args) => mockCreateOAuthReconnectionManager(...args),
|
|
getFlowStateManager: jest.fn(() => ({ type: 'flow-manager' })),
|
|
getMCPManager: jest.fn(() => ({ clearCatalogRecoveryState: jest.fn() })),
|
|
}));
|
|
|
|
jest.mock('~/models', () => ({
|
|
findToken: jest.fn(),
|
|
updateToken: jest.fn(),
|
|
createToken: jest.fn(),
|
|
deleteTokens: jest.fn(),
|
|
}));
|
|
|
|
jest.mock('~/cache', () => ({ getLogStores: jest.fn(() => ({})) }));
|
|
|
|
jest.mock('~/server/services/Config', () => ({
|
|
getAppConfig: (...args) => mockGetAppConfig(...args),
|
|
invalidateCachedTools: jest.fn(),
|
|
}));
|
|
|
|
jest.mock('~/server/services/MCPAuthorizationFenceRetry', () => ({
|
|
clearMCPAuthorizationFenceRetry: jest.fn(),
|
|
persistMCPAuthorizationFenceRetry: jest.fn(),
|
|
}));
|
|
|
|
const initializeOAuthReconnectManager = require('./initializeOAuthReconnectManager');
|
|
|
|
describe('initializeOAuthReconnectManager', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
mockCreateOAuthReconnectionManager.mockResolvedValue(undefined);
|
|
mockGetAppConfig.mockResolvedValue({
|
|
mcpSettings: {
|
|
catalogRecovery: {
|
|
authorizationFenceRetryMs: [0, 25],
|
|
authorizationFenceTimeoutMs: 750,
|
|
},
|
|
},
|
|
});
|
|
mockPrepareMCPAuthorizationMutation.mockResolvedValue(jest.fn());
|
|
});
|
|
|
|
it('resolves the effective user policy when a reconnect refresh prepares its write', async () => {
|
|
await initializeOAuthReconnectManager();
|
|
|
|
/* Startup reads only the base config for the tracker; the per-user policy stays lazy. */
|
|
expect(mockGetAppConfig).toHaveBeenCalledTimes(1);
|
|
expect(mockGetAppConfig).toHaveBeenCalledWith({ baseOnly: true });
|
|
expect(mockCreateOAuthReconnectionManager.mock.calls[0][2]).toMatchObject({ type: 'tracker' });
|
|
const prepareRefresh = mockCreateOAuthReconnectionManager.mock.calls[0][4];
|
|
const scope = { userId: 'user-1', serverName: 'github' };
|
|
await prepareRefresh(scope);
|
|
|
|
expect(mockGetAppConfig).toHaveBeenCalledWith({ tenantId: 'tenant-a', userId: 'user-1' });
|
|
expect(mockPrepareMCPAuthorizationMutation).toHaveBeenCalledWith(
|
|
scope,
|
|
expect.objectContaining({ retryDelaysMs: [0, 25], attemptTimeoutMs: 750 }),
|
|
);
|
|
});
|
|
});
|