mirror of
https://github.com/stablyai/orca.git
synced 2026-10-24 00:04:01 +00:00
test(native-chat): pin image frame separator contract
This commit is contained in:
@@ -369,7 +369,16 @@ describe('sendNativeChatMessageWithImageAttachments', () => {
|
||||
expect(sendRuntimePtyInput).toHaveBeenLastCalledWith(SETTINGS, PTY, NATIVE_CHAT_SUBMIT)
|
||||
})
|
||||
|
||||
it('separates multiple image pastes from each other and from following prompt text', () => {
|
||||
it('treats whitespace-only prompt input as attachment-only', () => {
|
||||
sendNativeChatMessageWithImageAttachments(SETTINGS, PTY, ' ', ['/tmp/orca-paste-image.png'])
|
||||
|
||||
expectWriteOrder(sendRuntimePtyInput.mock.calls, [
|
||||
NATIVE_CHAT_CLEAR_UNSUBMITTED_INPUT,
|
||||
'\x1b[200~/tmp/orca-paste-image.png\x1b[201~'
|
||||
])
|
||||
})
|
||||
|
||||
it('keeps multiple image frames bare and separates only the final frame from prompt text', () => {
|
||||
sendNativeChatMessageWithImageAttachments(SETTINGS, PTY, 'hello', ['/tmp/a.png', '/tmp/b.png'])
|
||||
|
||||
expectWriteOrder(sendRuntimePtyInput.mock.calls, [
|
||||
|
||||
@@ -1,34 +1,31 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
IMAGE_PASTE_FOLLOWING_TEXT_SEPARATOR,
|
||||
joinImagePastesAndPrompt
|
||||
imagePasteWritesFollowedByText
|
||||
} from './image-paste-following-text'
|
||||
|
||||
const IMAGE_A = '\x1b[200~/tmp/orca-paste-a.png\x1b[201~'
|
||||
const IMAGE_B = '\x1b[200~/tmp/orca-paste-b.png\x1b[201~'
|
||||
const PROMPT =
|
||||
'add the QR code for wechat group 8 next to group 7. saying if group 7 is full can join group 8'
|
||||
|
||||
describe('joinImagePastesAndPrompt', () => {
|
||||
describe('imagePasteWritesFollowedByText', () => {
|
||||
it('separates an attachment path from following prompt text by a single space', () => {
|
||||
expect(joinImagePastesAndPrompt([IMAGE_A], PROMPT)).toBe(`${IMAGE_A} ${PROMPT}`)
|
||||
expect(joinImagePastesAndPrompt([IMAGE_A], PROMPT)).not.toBe(`${IMAGE_A}${PROMPT}`)
|
||||
expect(joinImagePastesAndPrompt([IMAGE_A], PROMPT)).not.toContain('pngadd')
|
||||
expect(imagePasteWritesFollowedByText([IMAGE_A], true)).toEqual([`${IMAGE_A} `])
|
||||
expect(IMAGE_PASTE_FOLLOWING_TEXT_SEPARATOR).toBe(' ')
|
||||
})
|
||||
|
||||
it('keeps an attachment-only send as the framed path with no trailing separator', () => {
|
||||
expect(joinImagePastesAndPrompt([IMAGE_A], '')).toBe(IMAGE_A)
|
||||
expect(imagePasteWritesFollowedByText([IMAGE_A], false)).toEqual([IMAGE_A])
|
||||
})
|
||||
|
||||
it('leaves prompt-only text unchanged', () => {
|
||||
expect(joinImagePastesAndPrompt([], PROMPT)).toBe(PROMPT)
|
||||
it('returns no writes when there are no image pastes', () => {
|
||||
expect(imagePasteWritesFollowedByText([], true)).toEqual([])
|
||||
})
|
||||
|
||||
it('keeps back-to-back image frames bare and separates only the final frame from prompt text', () => {
|
||||
expect(joinImagePastesAndPrompt([IMAGE_A, IMAGE_B], PROMPT)).toBe(
|
||||
`${IMAGE_A}${IMAGE_B} ${PROMPT}`
|
||||
)
|
||||
expect(joinImagePastesAndPrompt([IMAGE_A, IMAGE_B], '')).toBe(`${IMAGE_A}${IMAGE_B}`)
|
||||
expect(imagePasteWritesFollowedByText([IMAGE_A, IMAGE_B], true)).toEqual([
|
||||
IMAGE_A,
|
||||
`${IMAGE_B} `
|
||||
])
|
||||
expect(imagePasteWritesFollowedByText([IMAGE_A, IMAGE_B], false)).toEqual([IMAGE_A, IMAGE_B])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -23,11 +23,3 @@ export function imagePasteWritesFollowedByText(
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/** Exact PTY bytes for image pastes plus optional prompt text. */
|
||||
export function joinImagePastesAndPrompt(
|
||||
framedImagePastes: readonly string[],
|
||||
prompt: string
|
||||
): string {
|
||||
return `${imagePasteWritesFollowedByText(framedImagePastes, prompt.length > 0).join('')}${prompt}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user