From e8bf3ea63e7f633ff88573d4a52b993c3fedd469 Mon Sep 17 00:00:00 2001 From: Merge Sim Date: Mon, 7 Sep 2026 13:11:35 -0700 Subject: [PATCH] fix(native-chat): authorize external attachment paths before preview --- .../native-chat-composer-drop-scope.test.tsx | 133 +++++++++++++++--- ...-native-chat-external-attachments.test.tsx | 48 ++++++- .../use-native-chat-external-attachments.ts | 18 ++- 3 files changed, 180 insertions(+), 19 deletions(-) diff --git a/src/renderer/src/components/native-chat/native-chat-composer-drop-scope.test.tsx b/src/renderer/src/components/native-chat/native-chat-composer-drop-scope.test.tsx index 8e12ec6fbe8..e535a59fad0 100644 --- a/src/renderer/src/components/native-chat/native-chat-composer-drop-scope.test.tsx +++ b/src/renderer/src/components/native-chat/native-chat-composer-drop-scope.test.tsx @@ -1,9 +1,12 @@ // @vitest-environment happy-dom import { EventEmitter } from 'node:events' -import { afterEach, beforeAll, describe, expect, it, vi } from 'vitest' -import { act, cleanup, render } from '@testing-library/react' +import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest' +import { act, cleanup, render, screen } from '@testing-library/react' import { useRef } from 'react' +import { useNativeChatExternalAttachments } from './use-native-chat-external-attachments' +import { NativeChatImageAttachmentPreview } from './NativeChatImageAttachmentPreview' +import { resetLocalImageSrcStateForTests } from '../editor/useLocalImageSrc' import { useComposerDropListener } from '../../hooks/composer-state/composer-drop-listener' import type { NativeFileDropPayload } from '../../../../shared/native-file-drop' import { useNativeChatFileAttachmentActions } from './use-native-chat-file-attachment-actions' @@ -20,6 +23,18 @@ const electron = vi.hoisted(() => ({ getPathForFile: vi.fn((file: File) => `/repro/${file.name}`) })) +const intake = vi.hoisted(() => ({ + owner: { kind: 'local' } as { kind: string; connectionId?: string }, + authorizeExternalPath: vi.fn(), + readFile: vi.fn(), + upload: vi.fn() +})) +vi.mock('@/store', () => ({ useAppStore: { getState: () => ({}) } })) +vi.mock('./native-chat-attachment-upload', () => ({ + resolveNativeChatAttachmentOwner: () => intake.owner, + uploadNativeChatAttachmentPaths: intake.upload +})) + vi.mock('electron', () => ({ ipcRenderer: electron, webUtils: { getPathForFile: electron.getPathForFile } @@ -47,7 +62,13 @@ function ComposerProbe({ pane, hidden = false }: { pane: string; hidden?: boolea setDraft: () => {}, setNotice: () => {} }) - useNativeChatFileAttachmentActions(pane, attachments.attachResolvedPaths) + const { attachExternalPaths } = useNativeChatExternalAttachments({ + terminalTabId: pane, + disabled: false, + attachResolvedPaths: attachments.attachResolvedPaths, + setNotice: () => {} + }) + useNativeChatFileAttachmentActions(pane, attachExternalPaths) return (