From 68e06c33250c2d8eef86283d02864aabd49999ca Mon Sep 17 00:00:00 2001 From: olibaron Date: Mon, 23 Nov 2026 20:26:48 +0100 Subject: [PATCH] test(#761): pin the missing-file dialog, the stored-copy fallback, and basename links Covers the acceptance cases #761 lists: a path missing on this Host shows a reader sentence naming the file and folder with Open folder and no Retry, never the opener's command line; a caller holding a stored copy downloads it instead of the dialog; a basename link opens the produced path. Co-Authored-By: Claude Opus 5.5 --- .../ui-chat/tests/chat-view.client.spec.tsx | 32 +++++++++++++++++++ .../tests/file-links.client.spec.ts | 28 ++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/packages/client/ui-chat/tests/chat-view.client.spec.tsx b/packages/client/ui-chat/tests/chat-view.client.spec.tsx index b81f73cea4..443a1ff4b5 100644 --- a/packages/client/ui-chat/tests/chat-view.client.spec.tsx +++ b/packages/client/ui-chat/tests/chat-view.client.spec.tsx @@ -37,6 +37,7 @@ import { TurnMaxTokensNodeView, UnknownNodeView, UserMessageNodeView, } from '../src/client/chat/MessageItem.tsx' import { TurnTailNodeView } from '../src/client/chat/TurnTailNodeView.tsx' +import { MissingFileError } from '../src/client/contract/missing-file.ts' import { TurnProcessNodeView } from '../src/client/chat/TurnProcessNodeView.tsx' import { SystemPromptNodeView } from '../src/client/chat/SystemPromptRow.tsx' import { formatRunDuration } from '../src/client/chat/message-chrome.ts' @@ -2775,6 +2776,37 @@ describe('ChatView', () => { }) }) + it('words a path missing on this Host for the reader and offers its folder instead of a retry (#761)', async () => { + const openFile = vi.fn<(path: string) => Promise>() + .mockRejectedValueOnce(new MissingFileError('/Users/elizabethtrejo/.aeven/chats/Rainbow_High_Set_of_6_Dolls.jpg')) + .mockResolvedValueOnce(undefined) + const h = makeHarness({ nodes: [toolResult(3, 'a')] }) + h.props.openFile = openFile + render() + await act(async () => { h.toolOwners[0]!.openFile('Rainbow_High_Set_of_6_Dolls.jpg') }) + const dialog = await waitFor(() => screen.getByRole('dialog', { name: '无法打开文件' })) + // The reader sees the file and the folder, never the opener's command line. + expect(dialog.textContent).toContain('/Users/elizabethtrejo/.aeven/chats') + expect(dialog.textContent).toContain('Rainbow_High_Set_of_6_Dolls.jpg') + expect(dialog.textContent).not.toContain('Command failed') + expect(dialog.textContent).not.toContain('path open failed') + expect(screen.queryByRole('button', { name: '重试' })).toBeNull() + await act(async () => { fireEvent.click(screen.getByRole('button', { name: '打开文件夹' })) }) + expect(openFile).toHaveBeenNthCalledWith(2, '.') + }) + + it('hands a missing path to the caller that holds a stored copy, without the dialog (#761)', async () => { + const openFile = vi.fn<(path: string) => Promise>() + .mockRejectedValueOnce(new MissingFileError('/w/report.pdf')) + const onMissing = vi.fn() + const h = makeHarness({ nodes: [toolResult(3, 'a')] }) + h.props.openFile = openFile + render() + await act(async () => { h.toolOwners[0]!.openFile('report.pdf', onMissing) }) + await waitFor(() => { expect(onMissing).toHaveBeenCalledOnce() }) + expect(screen.queryByRole('dialog')).toBeNull() + }) + it('ignores a Host refusal that settles after the dialog is dismissed', async () => { let rejectRetry!: (error: unknown) => void const openFile = vi.fn<(path: string) => Promise>() diff --git a/packages/client/ui-deliverables/tests/file-links.client.spec.ts b/packages/client/ui-deliverables/tests/file-links.client.spec.ts index 6b0da73280..8e8e8fd2cb 100644 --- a/packages/client/ui-deliverables/tests/file-links.client.spec.ts +++ b/packages/client/ui-deliverables/tests/file-links.client.spec.ts @@ -81,6 +81,34 @@ describe('openProducedFile', () => { }) }) +describe('a produced file missing on this Host (#761)', () => { + it('opens the path on the desktop and downloads the stored copy when the Host has nothing there', async () => { + const downloads = captureDownloads() + const local = opening(false, true) + openProducedFile({ path: 'Rainbow_High_Set_of_6_Dolls.jpg', attachmentId: 'sha256:2abf' }, local) + await vi.waitFor(() => { expect(local.openFile).toHaveBeenCalled() }) + const [path, onMissing] = local.openFile.mock.calls[0] ?? [] + expect(path).toBe('Rainbow_High_Set_of_6_Dolls.jpg') + expect(downloads).toEqual([]) + onMissing?.() + expect(downloads).toEqual(['https://app.test/attachment?id=sha256:2abf&download']) + }) + + it('leaves a file without a stored copy to the refusal dialog', async () => { + const local = opening(false, true) + openProducedFile({ path: 'notes.txt' }, local) + await vi.waitFor(() => { expect(local.openFile).toHaveBeenCalledWith('notes.txt') }) + }) + + it('opens the produced path a basename link names, not /', async () => { + const routes = opening(false, true) + const link = producedFileLinks('/w', () => [{ path: '/w/out/crops/Rainbow.jpg' }], routes).resolve('Rainbow.jpg') + expect(link?.href).toBe('https://app.test/file?path=/w/out/crops/Rainbow.jpg') + link?.open() + await vi.waitFor(() => { expect(routes.openFile).toHaveBeenCalledWith('/w/out/crops/Rainbow.jpg') }) + }) +}) + describe('producedFileLinks', () => { it('links a path to its workspace file and opens it the way a produced file opens', async () => { const downloads = captureDownloads()