Spaces:
Running
Running
| import test from 'node:test'; | |
| import assert from 'node:assert/strict'; | |
| import { prepareConversation } from '../src/engines/conversation-preparation.js'; | |
| test('single-image messages retain the native image then text structure', () => { | |
| const prepared = prepareConversation([{ | |
| role: 'user', | |
| content: [ | |
| { type: 'image', value: 'blob:one' }, | |
| { type: 'text', value: 'Describe this image.' }, | |
| ], | |
| }]); | |
| assert.deepEqual(prepared.imageUrls, ['blob:one']); | |
| assert.deepEqual(prepared.messages[0].content, [ | |
| { type: 'image' }, | |
| { type: 'text', text: 'Describe this image.' }, | |
| ]); | |
| }); | |
| test('multi-image messages add ordered textual boundaries around every image', () => { | |
| const prepared = prepareConversation([{ | |
| role: 'user', | |
| content: [ | |
| { type: 'image', value: 'blob:one' }, | |
| { type: 'image', value: 'blob:two' }, | |
| { type: 'image', value: 'blob:three' }, | |
| { type: 'text', value: 'What is in each image?' }, | |
| ], | |
| }]); | |
| assert.deepEqual(prepared.imageUrls, ['blob:one', 'blob:two', 'blob:three']); | |
| assert.deepEqual(prepared.messages[0].content, [ | |
| { type: 'text', text: 'Media-1' }, | |
| { type: 'image' }, | |
| { type: 'text', text: '\n' }, | |
| { type: 'text', text: 'Media-2' }, | |
| { type: 'image' }, | |
| { type: 'text', text: '\n' }, | |
| { type: 'text', text: 'Media-3' }, | |
| { type: 'image' }, | |
| { type: 'text', text: '\n' }, | |
| { type: 'text', text: 'What is in each image?' }, | |
| ]); | |
| }); | |
| test('media numbering restarts for each user message while URL order stays global', () => { | |
| const prepared = prepareConversation([ | |
| { role: 'user', content: [{ type: 'image', value: 'blob:a' }, { type: 'image', value: 'blob:b' }, { type: 'text', value: 'Compare.' }] }, | |
| { role: 'assistant', content: 'Done.' }, | |
| { role: 'user', content: [{ type: 'image', value: 'blob:c' }, { type: 'image', value: 'blob:d' }, { type: 'text', value: 'Compare these.' }] }, | |
| ]); | |
| assert.deepEqual(prepared.imageUrls, ['blob:a', 'blob:b', 'blob:c', 'blob:d']); | |
| assert.equal(prepared.messages[0].content[0].text, 'Media-1'); | |
| assert.equal(prepared.messages[2].content[0].text, 'Media-1'); | |
| }); | |