Skip to content
Merged
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
81 changes: 21 additions & 60 deletions apps/desktop/e2e/local-files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import type { DesktopLocalFileRequest, SimDesktopApi } from '@sim/desktop-bridge
import { build } from 'esbuild'
import postcss from 'postcss'
import loadPostcssConfig from 'postcss-load-config'
import { answerShellDialog } from './executor-sim'

const DESKTOP_DIR = fileURLToPath(new URL('..', import.meta.url))
const SIM_DIR = fileURLToPath(new URL('../../sim/', import.meta.url))
Expand Down Expand Up @@ -223,9 +224,7 @@ createRoot(document.getElementById('settings')).render(
process.env.DESKTOP_LOCAL_FILES_REPORT_PATH ??
test.info().outputPath('local-file-consent.png'),
})
await denial
.getByRole('button', { name: "Don't allow", exact: true })
.click({ noWaitAfter: true })
await answerShellDialog(denial, "Don't allow")
await expect.poll(() => deniedResults.length).toBe(2)
expect(deniedResults).toEqual([
{ ok: false, error: expect.any(String) },
Expand All @@ -244,9 +243,7 @@ createRoot(document.getElementById('settings')).render(
expect(
await folderConsent.evaluate(() => typeof (globalThis as { simDesktop?: unknown }).simDesktop)
).toBe('undefined')
await folderConsent
.getByRole('button', { name: 'Allow folder', exact: true })
.click({ noWaitAfter: true })
await answerShellDialog(folderConsent, 'Allow folder')
expect(await folderRead).toMatchObject({ ok: true, data: { representation: 'directory' } })
expect(await queuedRead).toMatchObject({ ok: true, data: { text: 'native file contents' } })
const canonicalRequest = {
Expand Down Expand Up @@ -352,9 +349,7 @@ createRoot(document.getElementById('settings')).render(
await invoke({ operation: 'cancel', toolCallId: 'sharedLeader' })
expect(await leader.result).toMatchObject({ ok: false })
await expect(leader.prompt.getByRole('dialog')).toBeVisible()
await leader.prompt
.getByRole('button', { name: 'Allow folder', exact: true })
.click({ noWaitAfter: true })
await answerShellDialog(leader.prompt, 'Allow folder')
expect(await survivor).toMatchObject({ ok: true, data: { text: 'shared contents' } })
})
await test.step('expired requests cannot enable Full file access from a confirmation', async () => {
Expand All @@ -368,14 +363,10 @@ createRoot(document.getElementById('settings')).render(
toolCallId: 'expiringFullAccess',
})
const shown = app.waitForEvent('window')
await permission.prompt
.getByRole('button', { name: 'Full file access', exact: true })
.click({ noWaitAfter: true })
await answerShellDialog(permission.prompt, 'Full file access')
const confirmation = await shown
calls.expiringFullAccess = undefined
await confirmation
.getByRole('button', { name: 'Enable', exact: true })
.click({ noWaitAfter: true })
await answerShellDialog(confirmation, 'Enable')
expect(await permission.result).toMatchObject({ ok: false })
expect(
await window.evaluate(async () =>
Expand All @@ -399,15 +390,11 @@ createRoot(document.getElementById('settings')).render(
).not.toBeChecked()
const permission = await requestPermission({ operation: 'read', toolCallId: 'fullAccess' })
const confirmationShown = app.waitForEvent('window')
await permission.prompt
.getByRole('button', { name: 'Full file access', exact: true })
.click({ noWaitAfter: true })
await answerShellDialog(permission.prompt, 'Full file access')
const confirmation = await confirmationShown
await expect(confirmation.getByRole('button', { name: 'Cancel', exact: true })).toBeFocused()
const returnedPrompt = app.waitForEvent('window')
await confirmation
.getByRole('button', { name: 'Cancel', exact: true })
.click({ noWaitAfter: true })
await answerShellDialog(confirmation, 'Cancel')
const folderPrompt = await returnedPrompt
expect(
await window.evaluate(async () =>
Expand All @@ -417,16 +404,12 @@ createRoot(document.getElementById('settings')).render(
)
).toMatchObject({ fullFileAccess: false })
const acceptedConfirmation = app.waitForEvent('window')
await folderPrompt
.getByRole('button', { name: 'Full file access', exact: true })
.click({ noWaitAfter: true })
await answerShellDialog(folderPrompt, 'Full file access')
const allowAll = await acceptedConfirmation
await allowAll.screenshot({
path: test.info().outputPath('full-file-access-confirmation.png'),
})
await allowAll
.getByRole('button', { name: 'Enable', exact: true })
.click({ noWaitAfter: true })
await answerShellDialog(allowAll, 'Enable')
expect(await permission.result).toMatchObject({
ok: true,
data: { text: 'full access contents' },
Expand Down Expand Up @@ -499,9 +482,7 @@ createRoot(document.getElementById('settings')).render(
window.getByRole('switch', { name: 'Full file access', exact: true })
).not.toBeChecked()
const revoked = await requestPermission({ operation: 'read', toolCallId: 'fullAccess' })
await revoked.prompt
.getByRole('button', { name: "Don't allow", exact: true })
.click({ noWaitAfter: true })
await answerShellDialog(revoked.prompt, "Don't allow")
expect(await revoked.result).toMatchObject({ ok: false })
})
await test.step('a folder grant works in another chat but does not permit symlink escapes', async () => {
Expand All @@ -526,9 +507,7 @@ createRoot(document.getElementById('settings')).render(
await expect(escapedRead.prompt.getByRole('dialog')).toContainText(
JSON.stringify(realpathSync(outside))
)
await escapedRead.prompt
.getByRole('button', { name: "Don't allow", exact: true })
.click({ noWaitAfter: true })
await answerShellDialog(escapedRead.prompt, "Don't allow")
expect(await escapedRead.result).toMatchObject({ ok: false })
rmSync(join(source, 'linked.txt'))
})
Expand All @@ -538,9 +517,7 @@ createRoot(document.getElementById('settings')).render(
const stale = await requestPermission({ operation: 'read', toolCallId: 'stale' })
if (changed) calls.stale.args.path = join(source, 'report.txt')
else calls.stale = undefined
await stale.prompt
.getByRole('button', { name: 'Allow folder', exact: true })
.click({ noWaitAfter: true })
await answerShellDialog(stale.prompt, 'Allow folder')
expect(await stale.result).toMatchObject({ ok: false })
}
})
Expand Down Expand Up @@ -791,9 +768,7 @@ createRoot(document.getElementById('settings')).render(
await closed
expect(await cancelled.result).toMatchObject({ ok: false })
const again = await requestPermission({ operation: 'read', toolCallId: 'cancelled' })
await again.prompt
.getByRole('button', { name: "Don't allow", exact: true })
.click({ noWaitAfter: true })
await answerShellDialog(again.prompt, "Don't allow")
expect(await again.result).toMatchObject({ ok: false })
})
await test.step('consent escapes direction controls in folder names', async () => {
Expand All @@ -802,18 +777,14 @@ createRoot(document.getElementById('settings')).render(
calls.bidi = { toolName: 'read_local_file', args: { path: folder } }
const bidi = await requestPermission({ operation: 'read', toolCallId: 'bidi' })
await expect(bidi.prompt.getByRole('dialog')).toContainText('Bidi\\u061c\\u200e\\u200f')
await bidi.prompt
.getByRole('button', { name: "Don't allow", exact: true })
.click({ noWaitAfter: true })
await answerShellDialog(bidi.prompt, "Don't allow")
expect(await bidi.result).toMatchObject({ ok: false })
})
await test.step('an unanswered prompt does not block approved folders', async () => {
calls.blocker = { toolName: 'read_local_file', args: { path: join(outside, 'private.txt') } }
const blocker = await requestPermission({ operation: 'read', toolCallId: 'blocker' })
expect(await invoke({ operation: 'read', toolCallId: 'text' })).toMatchObject({ ok: true })
await blocker.prompt
.getByRole('button', { name: "Don't allow", exact: true })
.click({ noWaitAfter: true })
await answerShellDialog(blocker.prompt, "Don't allow")
expect(await blocker.result).toMatchObject({ ok: false })
})
await test.step('cancelled calls cannot reuse an approved folder', async () => {
Expand All @@ -831,9 +802,7 @@ createRoot(document.getElementById('settings')).render(
renameSync(proposed, join(root, 'Original'))
mkdirSync(proposed)
writeFileSync(join(proposed, 'unapproved.txt'), 'replacement folder contents')
await retargeted.prompt
.getByRole('button', { name: 'Allow folder', exact: true })
.click({ noWaitAfter: true })
await answerShellDialog(retargeted.prompt, 'Allow folder')
expect(await retargeted.result).toMatchObject({ ok: false })
})
const result = await invoke({ operation: 'manifest', toolCallId: 'import' })
Expand Down Expand Up @@ -908,9 +877,7 @@ createRoot(document.getElementById('settings')).render(
'Local files'
)
const revoked = await requestPermission({ operation: 'read', toolCallId: 'text' })
await revoked.prompt
.getByRole('button', { name: 'Allow folder', exact: true })
.click({ noWaitAfter: true })
await answerShellDialog(revoked.prompt, 'Allow folder')
expect(await revoked.result).toMatchObject({ ok: true })
})

Expand All @@ -925,16 +892,12 @@ createRoot(document.getElementById('settings')).render(
'Local files'
)
const replaced = await requestPermission({ operation: 'read', toolCallId: 'text' })
await replaced.prompt
.getByRole('button', { name: "Don't allow", exact: true })
.click({ noWaitAfter: true })
await answerShellDialog(replaced.prompt, "Don't allow")
expect(await replaced.result).toMatchObject({ ok: false })
rmSync(source, { recursive: true })
renameSync(join(root, 'Original-reports'), source)
const restored = await requestPermission({ operation: 'read', toolCallId: 'text' })
await restored.prompt
.getByRole('button', { name: 'Allow folder', exact: true })
.click({ noWaitAfter: true })
await answerShellDialog(restored.prompt, 'Allow folder')
expect(await restored.result).toMatchObject({ ok: true })
})

Expand Down Expand Up @@ -971,9 +934,7 @@ createRoot(document.getElementById('settings')).render(
)
.toMatchObject({ fullFileAccess: false })
const revoked = await requestPermission({ operation: 'read', toolCallId: 'text' })
await revoked.prompt
.getByRole('button', { name: "Don't allow", exact: true })
.click({ noWaitAfter: true })
await answerShellDialog(revoked.prompt, "Don't allow")
expect(await revoked.result).toMatchObject({ ok: false })
})
await test.step('a failed settings write reports the error and leaves Full file access disabled', async () => {
Expand Down
Loading