Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(desktop): cover the document paths the review found untested

Alfredo Lopezc313bdd82ac3
diff --git a/desktop-app/src/__tests__/ipc.fileAttachments.test.ts b/desktop-app/src/__tests__/ipc.fileAttachments.test.ts
index b87dbc148..f058fd92f 100644
--- a/desktop-app/src/__tests__/ipc.fileAttachments.test.ts
+++ b/desktop-app/src/__tests__/ipc.fileAttachments.test.ts
@@ -105,6 +105,11 @@ describe('rpc:invokeHostMessage file attachments', () => {
['sizeBytes', { sizeBytes: 1.5 }],
['digest', { digest: { algorithm: 'md5', hex: 'a'.repeat(64) } }],
['digest', { digest: { algorithm: 'sha256', hex: 'not-hex' } }],
+ // The digest is exactly 64 lowercase hex characters, anchored at both ends.
+ ['digest', { digest: { algorithm: 'sha256', hex: 'a'.repeat(63) } }],
+ ['digest', { digest: { algorithm: 'sha256', hex: 'a'.repeat(65) } }],
+ ['digest', { digest: { algorithm: 'sha256', hex: 'A'.repeat(64) } }],
+ ['digest', { digest: { algorithm: 'sha256', hex: `x${'a'.repeat(64)}` } }],
['digest', { digest: undefined }],
])('rejects a file attachment with a bad %s before it reaches the host', async (field, patch) => {
await expect(
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/sendAgentMessage.documents.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/sendAgentMessage.documents.test.tsx
index 0c16da3f0..1eea21e68 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/sendAgentMessage.documents.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/sendAgentMessage.documents.test.tsx
@@ -219,6 +219,33 @@ describe('sendAgentMessage — a Host without file attachments (#678 D13)', () =
expect(rendered.result.current.failedAgentSend).toBeNull()
})
+ it('recovers a refused send into the composer with its text and its document', async () => {
+ const rendered = renderController()
+ await settleMount()
+ const file = await addReadyFile(rendered)
+ clerum.rpc.invokeHostMessage.mockResolvedValueOnce({
+ success: false,
+ error: { code: 'LLM_INVALID_ATTACHMENT', message: 'Unsupported attachment kind: file' },
+ })
+ await act(async () => {
+ await rendered.result.current.handleSendAgentMessage('Summarize this')
+ })
+ // Witness: the refusal kept the document and emptied the composer.
+ expect(rendered.result.current.failedAgentSend?.answeredWithoutFiles).toBe(false)
+ expect(rendered.result.current.failedAgentSend?.files.map(item => item.id)).toEqual([file.id])
+ expect(rendered.result.current.composerFileAttachments).toEqual([])
+ const chat = rendered.result.current.activeChatId
+
+ act(() => rendered.result.current.handleRecoverFailedAgentSend())
+
+ expect(getComposerDraft(chat, 'agent-x')).toBe('Summarize this')
+ expect(rendered.result.current.composerFileAttachments).toEqual([
+ expect.objectContaining({ id: file.id, status: 'ready', digestHex: NOTES_DIGEST }),
+ ])
+ expect(rendered.result.current.failedAgentSend).toBeNull()
+ expect(clerum.rpc.invokeHostMessage).toHaveBeenCalledTimes(1)
+ })
+
it('does not blame the files for an unrelated LLM_INVALID_ATTACHMENT on a send without any', async () => {
const rendered = renderController()
await settleMount()
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/useComposerAttachments.files.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/useComposerAttachments.files.test.tsx
index 54d462097..808018513 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/useComposerAttachments.files.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/useComposerAttachments.files.test.tsx
@@ -157,6 +157,28 @@ describe('useComposerAttachments — documents (#678)', () => {
await waitFor(() => expect(statuses(result)).toEqual(['ready', 'ready']))
})
+ it('keeps two files that share their bytes but not their name', async () => {
+ const { result } = render()
+
+ act(() => {
+ result.current.handleAddComposerFiles([textFile('first.txt', 'same')], '')
+ })
+ await waitFor(() => expect(statuses(result)).toEqual(['ready']))
+ act(() => {
+ result.current.handleAddComposerFiles([textFile('second.txt', 'same')], '')
+ })
+ // Liveness witness: the second file reached the duplicate check while the
+ // first was ready, as in the same-name test above.
+ expect(statuses(result)).toEqual(['ready', 'reading'])
+
+ await waitFor(() => expect(statuses(result)).toEqual(['ready', 'ready']))
+ const digests = result.current.composerFileAttachments.map(file =>
+ file.status === 'ready' ? file.digestHex : null
+ )
+ expect(digests[0]).toBe(digests[1])
+ expect(result.current.composerFileRefusals).toEqual([])
+ })
+
it('refuses a file over the size limit with a notice, adds no chip and never reads it', () => {
const { result } = render()
const huge = textFile('huge.bin', 'x')
diff --git a/desktop-app/ui/src/lib/__tests__/composerHostRequest.test.ts b/desktop-app/ui/src/lib/__tests__/composerHostRequest.test.ts
index 8f778dc75..76d3d36ec 100644
--- a/desktop-app/ui/src/lib/__tests__/composerHostRequest.test.ts
+++ b/desktop-app/ui/src/lib/__tests__/composerHostRequest.test.ts
@@ -74,6 +74,26 @@ describe('mapComposerAttachmentsToHostRequest (#678)', () => {
expect(file.classification.detectedMediaType).toBe('text/plain')
})
+ it('posts the declared type as mimeType and the sniffed type as detectedMediaType', () => {
+ const declared = 'application/octet-stream'
+ const untyped: ReadyComposerFileAttachment = {
+ ...file,
+ declaredMediaType: declared,
+ classification: classifyBytes({
+ bytes: NOTES,
+ totalByteLength: NOTES.length,
+ declaredMediaType: declared,
+ filename: 'notes.txt',
+ }),
+ }
+ // Precondition: the two types differ, so a swap or a copy is visible.
+ expect(untyped.classification.detectedMediaType).toBe('text/plain')
+
+ const [mapped] = mapComposerAttachmentsToHostRequest([], [untyped])
+
+ expect(mapped).toMatchObject({ mimeType: declared, detectedMediaType: 'text/plain' })
+ })
+
it('posts nothing for an empty composer', () => {
expect(mapComposerAttachmentsToHostRequest([], [])).toEqual([])
})