LibreChat/api/server/services/Tools/search.spec.js
Danny Avila d8427ffc5e
🛂 test: Cover Tool Approval Workflows End to End (#14427)
* 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
2026-07-26 21:58:25 -04:00

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 },
]);
}
});
});