mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-08-04 14:57:42 +00:00
* test: cover tool approval workflows end to end * fix: preserve tool approval state across resume * fix: preserve agent context in mock stream responses * fix: preserve nested approvals in collapsed groups
63 lines
1.5 KiB
JavaScript
63 lines
1.5 KiB
JavaScript
const mockEmitChunk = jest.fn();
|
|
|
|
jest.mock('nanoid', () => ({
|
|
nanoid: jest.fn(() => 'search-attachment'),
|
|
}));
|
|
|
|
jest.mock('@librechat/api', () => ({
|
|
GenerationJobManager: {
|
|
emitChunk: (...args) => mockEmitChunk(...args),
|
|
},
|
|
}));
|
|
|
|
const { createOnSearchResults } = require('./search');
|
|
|
|
describe('createOnSearchResults', () => {
|
|
beforeEach(() => {
|
|
jest.clearAllMocks();
|
|
});
|
|
|
|
it('fences resumable search attachments to the owning generation', () => {
|
|
const callbacks = createOnSearchResults({ headersSent: true }, 'conversation-1', 1234);
|
|
const runnableConfig = {
|
|
metadata: {
|
|
user_id: 'user-1',
|
|
thread_id: 'conversation-1',
|
|
run_id: 'response-1',
|
|
},
|
|
toolCall: {
|
|
id: 'tool-call-1',
|
|
name: 'web_search',
|
|
turn: 0,
|
|
},
|
|
};
|
|
|
|
callbacks.onSearchResults(
|
|
{
|
|
success: true,
|
|
data: {
|
|
organic: [{ link: 'https://example.com' }],
|
|
topStories: [],
|
|
},
|
|
},
|
|
runnableConfig,
|
|
);
|
|
callbacks.onGetHighlights('https://example.com');
|
|
|
|
expect(mockEmitChunk).toHaveBeenCalledTimes(2);
|
|
for (const call of mockEmitChunk.mock.calls) {
|
|
expect(call).toEqual([
|
|
'conversation-1',
|
|
{
|
|
event: 'attachment',
|
|
data: expect.objectContaining({
|
|
messageId: 'response-1',
|
|
toolCallId: 'tool-call-1',
|
|
conversationId: 'conversation-1',
|
|
}),
|
|
},
|
|
{ expectedCreatedAt: 1234 },
|
|
]);
|
|
}
|
|
});
|
|
});
|