update tests

This commit is contained in:
Nate Kelley 2025-03-06 10:16:14 -07:00
parent 91008d0c96
commit 0fe011396d
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
2 changed files with 77 additions and 148 deletions

View File

@ -16,6 +16,26 @@ import type {
BusterChatMessageReasoning_pillContainer BusterChatMessageReasoning_pillContainer
} from '@/api/asset_interfaces'; } from '@/api/asset_interfaces';
const createBaseMessage = (
messageId: string,
reasoningMessages: Record<string, any> = {}
): IBusterChatMessage => ({
id: messageId,
isCompletedStream: false,
request_message: {
request: 'test request',
sender_id: 'user1',
sender_name: 'Test User',
sender_avatar: null
},
response_message_ids: [],
reasoning_message_ids: Object.keys(reasoningMessages),
response_messages: {},
reasoning_messages: reasoningMessages,
created_at: new Date().toISOString(),
final_reasoning_message: null
});
describe('initializeOrUpdateMessage', () => { describe('initializeOrUpdateMessage', () => {
it('should initialize a new message when currentMessage is undefined', () => { it('should initialize a new message when currentMessage is undefined', () => {
const messageId = 'test-id'; const messageId = 'test-id';
@ -36,22 +56,7 @@ describe('initializeOrUpdateMessage', () => {
it('should update an existing message', () => { it('should update an existing message', () => {
const messageId = 'test-id'; const messageId = 'test-id';
const currentMessage: IBusterChatMessage = { const currentMessage = createBaseMessage(messageId);
id: messageId,
isCompletedStream: false,
request_message: {
request: 'original request',
sender_id: 'user1',
sender_name: 'Test User',
sender_avatar: null
},
response_message_ids: [],
reasoning_message_ids: [],
response_messages: {},
reasoning_messages: {},
created_at: new Date().toISOString(),
final_reasoning_message: null
};
const updateFn = (draft: IBusterChatMessage) => { const updateFn = (draft: IBusterChatMessage) => {
if (draft.request_message) { if (draft.request_message) {
@ -158,28 +163,15 @@ describe('updateResponseMessage', () => {
}); });
it('should update existing message with new response', () => { it('should update existing message with new response', () => {
const currentMessage: IBusterChatMessage = { const currentMessage: IBusterChatMessage = createBaseMessage('test-message-id');
id: 'test-message-id', currentMessage.response_message_ids = ['response-1'];
isCompletedStream: false, currentMessage.response_messages = {
request_message: { 'response-1': {
request: 'test request', id: 'response-1',
sender_id: 'user1', type: 'text',
sender_name: 'Test User', message: 'Hello',
sender_avatar: null message_chunk: undefined
}, }
response_message_ids: ['response-1'],
reasoning_message_ids: [],
response_messages: {
'response-1': {
id: 'response-1',
type: 'text',
message: 'Hello',
message_chunk: undefined
}
},
reasoning_messages: {},
created_at: new Date().toISOString(),
final_reasoning_message: null
}; };
const mockEvent: ChatEvent_GeneratingResponseMessage = { const mockEvent: ChatEvent_GeneratingResponseMessage = {
@ -317,32 +309,17 @@ describe('updateReasoningMessage', () => {
}); });
it('should update existing text reasoning message with streaming chunks', () => { it('should update existing text reasoning message with streaming chunks', () => {
const currentMessage: IBusterChatMessage = { const currentMessage = createBaseMessage('test-message-id', {
id: 'test-message-id', 'reasoning-1': {
isCompletedStream: false, id: 'reasoning-1',
request_message: { type: 'text',
request: 'test request', message: 'Initial reasoning',
sender_id: 'user1', message_chunk: undefined,
sender_name: 'Test User', title: 'Test Title',
sender_avatar: null secondary_title: 'Test Secondary Title',
}, status: 'loading'
response_message_ids: [], }
reasoning_message_ids: ['reasoning-1'], });
response_messages: {},
reasoning_messages: {
'reasoning-1': {
id: 'reasoning-1',
type: 'text',
message: 'Initial reasoning',
message_chunk: undefined,
title: 'Test Title',
secondary_title: 'Test Secondary Title',
status: 'loading'
}
},
created_at: new Date().toISOString(),
final_reasoning_message: null
};
const reasoning: BusterChatMessageReasoning_text = { const reasoning: BusterChatMessageReasoning_text = {
id: 'reasoning-1', id: 'reasoning-1',
@ -376,34 +353,19 @@ describe('updateReasoningMessage', () => {
} }
}; };
const currentMessage: IBusterChatMessage = { const currentMessage = createBaseMessage('test-message-id', {
id: 'test-message-id', 'reasoning-1': {
isCompletedStream: false, id: 'reasoning-1',
request_message: { type: 'files',
request: 'test request', file_ids: ['file-1'],
sender_id: 'user1', files: {
sender_name: 'Test User', 'file-1': reasoningFile
sender_avatar: null },
}, title: 'Test Title',
response_message_ids: [], secondary_title: 'Test Secondary Title',
reasoning_message_ids: ['reasoning-1'], status: 'loading'
response_messages: {}, }
reasoning_messages: { });
'reasoning-1': {
id: 'reasoning-1',
type: 'files',
file_ids: ['file-1'],
files: {
'file-1': reasoningFile
},
title: 'Test Title',
secondary_title: 'Test Secondary Title',
status: 'loading'
}
},
created_at: new Date().toISOString(),
final_reasoning_message: null
};
const reasoning: BusterChatMessageReasoning_files = { const reasoning: BusterChatMessageReasoning_files = {
id: 'reasoning-1', id: 'reasoning-1',
@ -446,31 +408,16 @@ describe('updateReasoningMessage', () => {
] ]
}; };
const currentMessage: IBusterChatMessage = { const currentMessage = createBaseMessage('test-message-id', {
id: 'test-message-id', 'reasoning-1': {
isCompletedStream: false, id: 'reasoning-1',
request_message: { type: 'pills',
request: 'test request', pill_containers: [pillContainer],
sender_id: 'user1', title: 'Test Title',
sender_name: 'Test User', secondary_title: 'Test Secondary Title',
sender_avatar: null status: 'loading'
}, }
response_message_ids: [], });
reasoning_message_ids: ['reasoning-1'],
response_messages: {},
reasoning_messages: {
'reasoning-1': {
id: 'reasoning-1',
type: 'pills',
pill_containers: [pillContainer],
title: 'Test Title',
secondary_title: 'Test Secondary Title',
status: 'loading'
}
},
created_at: new Date().toISOString(),
final_reasoning_message: null
};
const reasoning: BusterChatMessageReasoning_pills = { const reasoning: BusterChatMessageReasoning_pills = {
id: 'reasoning-1', id: 'reasoning-1',
@ -528,34 +475,19 @@ describe('updateReasoningMessage', () => {
} }
}; };
const currentMessage: IBusterChatMessage = { const currentMessage = createBaseMessage('test-message-id', {
id: 'test-message-id', 'reasoning-1': {
isCompletedStream: false, id: 'reasoning-1',
request_message: { type: 'files',
request: 'test request', file_ids: ['file-1'],
sender_id: 'user1', files: {
sender_name: 'Test User', 'file-1': reasoningFile1
sender_avatar: null },
}, title: 'Test Title',
response_message_ids: [], secondary_title: 'Test Secondary Title',
reasoning_message_ids: ['reasoning-1'], status: 'loading'
response_messages: {}, }
reasoning_messages: { });
'reasoning-1': {
id: 'reasoning-1',
type: 'files',
file_ids: ['file-1'],
files: {
'file-1': reasoningFile1
},
title: 'Test Title',
secondary_title: 'Test Secondary Title',
status: 'loading'
}
},
created_at: new Date().toISOString(),
final_reasoning_message: null
};
const reasoning: BusterChatMessageReasoning_files = { const reasoning: BusterChatMessageReasoning_files = {
id: 'reasoning-1', id: 'reasoning-1',

View File

@ -23,7 +23,6 @@ import { queryKeys } from '@/api/query_keys';
import { useQueryClient } from '@tanstack/react-query'; import { useQueryClient } from '@tanstack/react-query';
import { create } from 'mutative'; import { create } from 'mutative';
import { import {
initializeOrUpdateMessage,
updateChatTitle, updateChatTitle,
updateResponseMessage, updateResponseMessage,
updateReasoningMessage updateReasoningMessage
@ -122,13 +121,11 @@ export const useChatStreamMessage = () => {
const _generatingResponseMessageCallback = useMemoizedFn( const _generatingResponseMessageCallback = useMemoizedFn(
(_: null, d: ChatEvent_GeneratingResponseMessage) => { (_: null, d: ChatEvent_GeneratingResponseMessage) => {
const { message_id } = d; const { message_id } = d;
const updatedMessage = updateResponseMessage( const updatedMessage = updateResponseMessage(
message_id, message_id,
chatRefMessages.current[message_id], chatRefMessages.current[message_id],
d d
); );
onUpdateChatMessageTransition({ onUpdateChatMessageTransition({
id: message_id, id: message_id,
response_messages: updatedMessage?.response_messages, response_messages: updatedMessage?.response_messages,