Skip to content

The agent that grows with you

test(webapp): move the composer drop-warning tests into their own file

unsupportedpastels31b9f9eee6f1
diff --git a/apps/desktop/src/app/chat/hooks/use-composer-actions.drop-warnings.test.ts b/apps/desktop/src/app/chat/hooks/use-composer-actions.drop-warnings.test.ts
new file mode 100644
index 00000000000..21ed119908c
--- /dev/null
+++ b/apps/desktop/src/app/chat/hooks/use-composer-actions.drop-warnings.test.ts
@@ -0,0 +1,124 @@
+import { act, renderHook } from '@testing-library/react'
+import { afterEach, describe, expect, it, vi } from 'vitest'
+
+import { $notifications } from '@/store/notifications'
+
+import { useComposerActions } from './use-composer-actions'
+
+// A drop item the composer cannot attach is reported in one bounded warning, never dropped silently.
+describe('useComposerActions drop warnings', () => {
+ afterEach(() => {
+ Reflect.deleteProperty(window, 'hermesDesktop')
+ vi.unstubAllGlobals()
+ vi.clearAllMocks()
+ })
+
+ it('warns about a dropped folder it cannot attach instead of staging its File', async () => {
+ const stageFileForAttach = vi.fn(async () => '/srv/uploads/web-my-repo')
+ const value = { getPathForFile: () => '', stageFileForAttach }
+ Object.defineProperty(window, 'hermesDesktop', { configurable: true, value })
+
+ const { result } = renderHook(() =>
+ useComposerActions({ activeSessionId: null, currentCwd: '/w', requestGateway: vi.fn() })
+ )
+
+ let attached = true
+
+ await act(async () => {
+ attached = await result.current.attachDroppedItems([{ file: new File([], 'shots.png'), isDirectory: true, path: '' }])
+ })
+
+ expect(attached).toBe(false)
+ expect(stageFileForAttach).not.toHaveBeenCalled()
+ expect($notifications.get().at(-1)).toMatchObject({ kind: 'warning' })
+ expect($notifications.get().at(-1)?.message).toContain("Could not attach shots.png: Folders can't be attached")
+ })
+
+ // A drop that attached some files must still name the ones it left out.
+ it('reports the items a mixed drop could not attach alongside the ones it did', async () => {
+ const stageFileForAttach = vi.fn(async (file: File) => {
+ if (file.name === 'big.zip') {
+ throw new Error('Upload request is too large')
+ }
+
+ return `/srv/uploads/web-${file.name}`
+ })
+
+ const value = { getPathForFile: () => '', stageFileForAttach }
+ Object.defineProperty(window, 'hermesDesktop', { configurable: true, value })
+
+ const add = vi.fn()
+
+ const { result } = renderHook(() =>
+ useComposerActions({
+ activeSessionId: null,
+ currentCwd: '/w',
+ requestGateway: vi.fn(),
+ scope: { add, remove: vi.fn(() => null), target: 'main', update: vi.fn(() => true), updateIfCurrent: vi.fn(() => true) }
+ })
+ )
+
+ let attached = false
+
+ await act(async () => {
+ attached = await result.current.attachDroppedItems([
+ { file: new File(['x'], 'notes.txt'), path: '' },
+ { file: new File(['x'], 'big.zip'), path: '' },
+ { file: new File([], 'my-repo'), isDirectory: true, path: '' }
+ ])
+ })
+
+ expect(attached).toBe(true)
+ expect(add).toHaveBeenCalledOnce()
+ expect(add).toHaveBeenCalledWith(expect.objectContaining({ path: '/srv/uploads/web-notes.txt' }))
+
+ const warning = $notifications.get().find(notice => notice.message.includes('big.zip'))
+
+ expect(warning).toMatchObject({ kind: 'warning' })
+ expect(warning?.message).toContain('Could not attach big.zip: Upload request is too large')
+ expect(warning?.message).toContain("Could not attach my-repo: Folders can't be attached")
+ })
+
+ // 50 oversized files must not grow one toast off screen: name a few, count the rest.
+ it('bounds the warning for a large mixed drop and keeps the full list in its detail', async () => {
+ const stageFileForAttach = vi.fn(async (file: File) => {
+ if (file.name.startsWith('huge-')) {
+ throw new Error('Upload request is too large')
+ }
+
+ return `/srv/uploads/web-${file.name}`
+ })
+
+ const value = { getPathForFile: () => '', stageFileForAttach }
+ Object.defineProperty(window, 'hermesDesktop', { configurable: true, value })
+
+ const add = vi.fn()
+
+ const { result } = renderHook(() =>
+ useComposerActions({
+ activeSessionId: null,
+ currentCwd: '/w',
+ requestGateway: vi.fn(),
+ scope: { add, remove: vi.fn(() => null), target: 'main', update: vi.fn(() => true), updateIfCurrent: vi.fn(() => true) }
+ })
+ )
+
+ const huge = Array.from({ length: 50 }, (_, index) => ({ file: new File(['x'], `huge-${index}.zip`), path: '' }))
+
+ await act(async () => {
+ await result.current.attachDroppedItems([{ file: new File(['x'], 'notes.txt'), path: '' }, ...huge])
+ })
+
+ expect(add).toHaveBeenCalledOnce()
+
+ const warning = $notifications.get().find(notice => notice.message.includes('huge-0.zip'))
+
+ expect(warning).toMatchObject({ kind: 'warning' })
+ expect(warning?.message).toContain('huge-2.zip')
+ expect(warning?.message).not.toContain('huge-3.zip')
+ expect(warning?.message).toMatch(/and 47 more$/)
+ expect(warning?.message.length).toBeLessThan(300)
+ expect(warning?.detail?.split('\n')).toHaveLength(50)
+ expect(warning?.detail).toContain('huge-49.zip')
+ })
+})
diff --git a/apps/desktop/src/app/chat/hooks/use-composer-actions.test.ts b/apps/desktop/src/app/chat/hooks/use-composer-actions.test.ts
index 8781e59ce39..290b00b9fb4 100644
--- a/apps/desktop/src/app/chat/hooks/use-composer-actions.test.ts
+++ b/apps/desktop/src/app/chat/hooks/use-composer-actions.test.ts
@@ -2,7 +2,6 @@ import { act, renderHook, waitFor } from '@testing-library/react'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { $composerAttachments, type ComposerAttachment, updateComposerAttachment } from '@/store/composer'
-import { $notifications } from '@/store/notifications'
import { $connection } from '@/store/session'
import { droppedFileInlineRefs } from '../composer/inline-refs'
@@ -405,115 +404,6 @@ describe('useComposerActions native image drops', () => {
expect(add).not.toHaveBeenCalled()
})
- it('warns about a dropped folder it cannot attach instead of staging its File', async () => {
- const stageFileForAttach = vi.fn(async () => '/srv/uploads/web-my-repo')
- const value = { getPathForFile: () => '', stageFileForAttach }
- Object.defineProperty(window, 'hermesDesktop', { configurable: true, value })
-
- const { result } = renderHook(() =>
- useComposerActions({ activeSessionId: null, currentCwd: '/w', requestGateway: vi.fn() })
- )
-
- let attached = true
-
- await act(async () => {
- attached = await result.current.attachDroppedItems([{ file: new File([], 'shots.png'), isDirectory: true, path: '' }])
- })
-
- expect(attached).toBe(false)
- expect(stageFileForAttach).not.toHaveBeenCalled()
- expect($notifications.get().at(-1)).toMatchObject({ kind: 'warning' })
- expect($notifications.get().at(-1)?.message).toContain("Could not attach shots.png: Folders can't be attached")
- })
-
- // A drop that attached some files must still name the ones it left out.
- it('reports the items a mixed drop could not attach alongside the ones it did', async () => {
- const stageFileForAttach = vi.fn(async (file: File) => {
- if (file.name === 'big.zip') {
- throw new Error('Upload request is too large')
- }
-
- return `/srv/uploads/web-${file.name}`
- })
-
- const value = { getPathForFile: () => '', stageFileForAttach }
- Object.defineProperty(window, 'hermesDesktop', { configurable: true, value })
-
- const add = vi.fn()
-
- const { result } = renderHook(() =>
- useComposerActions({
- activeSessionId: null,
- currentCwd: '/w',
- requestGateway: vi.fn(),
- scope: { add, remove: vi.fn(() => null), target: 'main', update: vi.fn(() => true), updateIfCurrent: vi.fn(() => true) }
- })
- )
-
- let attached = false
-
- await act(async () => {
- attached = await result.current.attachDroppedItems([
- { file: new File(['x'], 'notes.txt'), path: '' },
- { file: new File(['x'], 'big.zip'), path: '' },
- { file: new File([], 'my-repo'), isDirectory: true, path: '' }
- ])
- })
-
- expect(attached).toBe(true)
- expect(add).toHaveBeenCalledOnce()
- expect(add).toHaveBeenCalledWith(expect.objectContaining({ path: '/srv/uploads/web-notes.txt' }))
-
- const warning = $notifications.get().find(notice => notice.message.includes('big.zip'))
-
- expect(warning).toMatchObject({ kind: 'warning' })
- expect(warning?.message).toContain('Could not attach big.zip: Upload request is too large')
- expect(warning?.message).toContain("Could not attach my-repo: Folders can't be attached")
- })
-
- // 50 oversized files must not grow one toast off screen: name a few, count the rest.
- it('bounds the warning for a large mixed drop and keeps the full list in its detail', async () => {
- const stageFileForAttach = vi.fn(async (file: File) => {
- if (file.name.startsWith('huge-')) {
- throw new Error('Upload request is too large')
- }
-
- return `/srv/uploads/web-${file.name}`
- })
-
- const value = { getPathForFile: () => '', stageFileForAttach }
- Object.defineProperty(window, 'hermesDesktop', { configurable: true, value })
-
- const add = vi.fn()
-
- const { result } = renderHook(() =>
- useComposerActions({
- activeSessionId: null,
- currentCwd: '/w',
- requestGateway: vi.fn(),
- scope: { add, remove: vi.fn(() => null), target: 'main', update: vi.fn(() => true), updateIfCurrent: vi.fn(() => true) }
- })
- )
-
- const huge = Array.from({ length: 50 }, (_, index) => ({ file: new File(['x'], `huge-${index}.zip`), path: '' }))
-
- await act(async () => {
- await result.current.attachDroppedItems([{ file: new File(['x'], 'notes.txt'), path: '' }, ...huge])
- })
-
- expect(add).toHaveBeenCalledOnce()
-
- const warning = $notifications.get().find(notice => notice.message.includes('huge-0.zip'))
-
- expect(warning).toMatchObject({ kind: 'warning' })
- expect(warning?.message).toContain('huge-2.zip')
- expect(warning?.message).not.toContain('huge-3.zip')
- expect(warning?.message).toMatch(/and 47 more$/)
- expect(warning?.message.length).toBeLessThan(300)
- expect(warning?.detail?.split('\n')).toHaveLength(50)
- expect(warning?.detail).toContain('huge-49.zip')
- })
-
it('copies dropped screenshot bytes before trusting a transient macOS path', async () => {
const transientPath =
'/var/folders/x7/example/T/TemporaryItems/NSIRD_screencaptureui_4roSuW/Screen Shot 2026-08-11.png'