Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(providers): add test case for editing messages with attachments

Steven Enamakel6fb12bdd6f35
diff --git a/app/src/providers/__tests__/useOpenHumanExternalStore.quote.test.tsx b/app/src/providers/__tests__/useOpenHumanExternalStore.quote.test.tsx
index f3646aedfc..843aed5b38 100644
--- a/app/src/providers/__tests__/useOpenHumanExternalStore.quote.test.tsx
+++ b/app/src/providers/__tests__/useOpenHumanExternalStore.quote.test.tsx
@@ -16,6 +16,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
import chatRuntimeReducer from '../../store/chatRuntimeSlice';
import threadReducer from '../../store/threadSlice';
+import { editMessage } from '../../services/chatService';
+import { loadThreadMessages } from '../../store/threadSlice';
import { registerChatSurface } from '../chatSurfaceHandlers';
import { useOpenHumanExternalStore } from '../useOpenHumanExternalStore';
@@ -32,6 +34,10 @@ vi.mock('../../services/api/threadApi', () => ({
}),
},
}));
+vi.mock('../../services/chatService', () => ({
+ editMessage: vi.fn().mockResolvedValue(undefined),
+ regenerateMessage: vi.fn().mockResolvedValue(undefined),
+}));
const THREAD_ID = 't-quote';
@@ -55,10 +61,9 @@ function withQuote(text: string): AppendMessage {
} as unknown as Partial<AppendMessage>);
}
-function mount() {
- const store = configureStore({
- reducer: { thread: threadReducer, chatRuntime: chatRuntimeReducer },
- });
+function mount(store = configureStore({
+ reducer: { thread: threadReducer, chatRuntime: chatRuntimeReducer },
+})) {
const wrapper = ({ children }: { children: ReactNode }) => (
<Provider store={store}>{children}</Provider>
);
@@ -109,4 +114,51 @@ describe('a quoted excerpt reaching the core', () => {
expect(sent).toEqual(['what does this mean?']);
});
+
+ it('keeps the source row opaque attachments when editing its text', async () => {
+ const store = configureStore({
+ reducer: { thread: threadReducer, chatRuntime: chatRuntimeReducer },
+ });
+ const attachment = {
+ kind: 'image' as const,
+ media: { opaqueId: 'stored-image-1', contentType: 'image/png' },
+ caption: null,
+ altText: null,
+ };
+ store.dispatch(
+ loadThreadMessages.fulfilled(
+ {
+ threadId: THREAD_ID,
+ messages: [
+ {
+ id: 'user-image-row',
+ content: 'describe this',
+ type: 'text',
+ extraMetadata: {},
+ sender: 'user',
+ createdAt: new Date().toISOString(),
+ attachments: [attachment],
+ },
+ ],
+ },
+ 'load-image-row',
+ THREAD_ID
+ )
+ );
+ const { result } = mount(store);
+
+ await result.current.onEdit(
+ appended({
+ sourceId: 'user-image-row',
+ content: [{ type: 'text', text: 'describe this more carefully' }],
+ })
+ );
+
+ expect(editMessage).toHaveBeenCalledWith({
+ threadId: THREAD_ID,
+ messageId: 'user-image-row',
+ content: 'describe this more carefully',
+ attachments: [attachment],
+ });
+ });
});