This commit is contained in:
Bastian Wagner
2026-06-12 14:23:55 +02:00
parent 26e0ba5caf
commit d75c0ecc68
2 changed files with 79 additions and 2 deletions

View File

@@ -128,6 +128,58 @@ describe('AssistantService', () => {
);
});
it('extracts the final assistant message from multi-completion responses', async () => {
const providerResponse = {
id: 'chatcmpl-test',
object: 'chat.multi_completion',
choices: [
{
messages: [
{
role: 'assistant',
index: 0,
content: '',
tool_calls: [
{
id: 'call-1',
type: 'function',
function: {
name: 'listify_list_existing_lists',
arguments: '{"includeItems": false}',
},
},
],
},
{
role: 'tool',
index: 1,
content: [{ type: 'text', text: '{"lists":[]}' }],
},
{
role: 'assistant',
index: 2,
content: 'Hier sind deine bestehenden Listen.',
},
],
finish_reason: 'stop',
},
],
};
mockMistralResponse(providerResponse);
const result = await service.chat('user-1', {
messages: [{ role: 'user', content: 'Welche Listen habe ich?' }],
});
expect(result.message.content).toBe('Hier sind deine bestehenden Listen.');
expect(chatLogsRepository.save).toHaveBeenCalledWith(
expect.objectContaining({
responsePayload: providerResponse,
assistantContent: 'Hier sind deine bestehenden Listen.',
}),
);
});
it('fails clearly when the api key is missing', async () => {
delete process.env.MISTRAL_API_KEY;