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
25 changes: 25 additions & 0 deletions apps/sim/lib/mothership/tools/client/native-files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,28 @@ it('returns local visual observations through the existing completion path', asy
expect(mocks.complete).toHaveBeenCalledWith('tool', 'success', expect.any(String), data)
expect(mocks.upload).not.toHaveBeenCalled()
})

it('an import the user stopped leaves its outcome to Stop instead of reporting a failure', async () => {
const stop = new AbortController()
mocks.invoke.mockResolvedValueOnce({ ok: true, data: manifest })
mocks.upload.mockImplementationOnce(async () => {
stop.abort('user_stop:client_stopGeneration')
throw new DOMException('The operation was aborted.', 'AbortError')
})
await executeNativeFileTool('tool', 'import_local_files', stop.signal)
expect(mocks.complete).not.toHaveBeenCalled()
expect(mocks.exit).not.toHaveBeenCalled()
})

it('a read the user stopped while the desktop was reading reports nothing', async () => {
const stop = new AbortController()
mocks.invoke.mockImplementationOnce(async () => {
stop.abort('user_stop:client_stopGeneration')
return {
ok: true,
data: { kind: 'read', path: '/notes.txt', representation: 'text', text: 'notes' },
}
})
await executeNativeFileTool('tool', 'read_local_file', stop.signal)
expect(mocks.complete).not.toHaveBeenCalled()
})
4 changes: 4 additions & 0 deletions apps/sim/lib/mothership/tools/client/native-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ export async function executeNativeFileTool(
response.data.kind === 'manifest'
? localFileImportCompletion(await importNativeFiles(toolCallId, response.data, signal))
: localFileReadCompletion(response)
// Cancelled by the user's Stop or by signing out: whoever cancelled it settles the call, as for
// browser actions and granted-folder reads. A failure reported here would race Stop's record.
if (signal?.aborted) return
await reportClientToolCompletion(
toolCallId,
completion.status,
Expand All @@ -153,6 +156,7 @@ export async function executeNativeFileTool(
)
settled = true
} catch (error) {
if (signal?.aborted) return
await reportClientToolCompletion(
toolCallId,
ASYNC_TOOL_CONFIRMATION_STATUS.error,
Expand Down
Loading