Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions packages/client/ui-chat/tests/chat-view.client.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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<void>>()
.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(<h.ChatView {...h.props} />)
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<void>>()
.mockRejectedValueOnce(new MissingFileError('/w/report.pdf'))
const onMissing = vi.fn()
const h = makeHarness({ nodes: [toolResult(3, 'a')] })
h.props.openFile = openFile
render(<h.ChatView {...h.props} />)
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<void>>()
Expand Down
28 changes: 28 additions & 0 deletions packages/client/ui-deliverables/tests/file-links.client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cwd>/<basename>', 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()
Expand Down