Skip to content

Commit fdf7862

Browse files
committed
fix(desktop): answer local-file consent dialogs through the shared closing-dialog helper
1 parent 63cfea1 commit fdf7862

1 file changed

Lines changed: 21 additions & 60 deletions

File tree

‎apps/desktop/e2e/local-files.spec.ts‎

Lines changed: 21 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type { DesktopLocalFileRequest, SimDesktopApi } from '@sim/desktop-bridge
1717
import { build } from 'esbuild'
1818
import postcss from 'postcss'
1919
import loadPostcssConfig from 'postcss-load-config'
20+
import { answerShellDialog } from './executor-sim'
2021

2122
const DESKTOP_DIR = fileURLToPath(new URL('..', import.meta.url))
2223
const SIM_DIR = fileURLToPath(new URL('../../sim/', import.meta.url))
@@ -223,9 +224,7 @@ createRoot(document.getElementById('settings')).render(
223224
process.env.DESKTOP_LOCAL_FILES_REPORT_PATH ??
224225
test.info().outputPath('local-file-consent.png'),
225226
})
226-
await denial
227-
.getByRole('button', { name: "Don't allow", exact: true })
228-
.click({ noWaitAfter: true })
227+
await answerShellDialog(denial, "Don't allow")
229228
await expect.poll(() => deniedResults.length).toBe(2)
230229
expect(deniedResults).toEqual([
231230
{ ok: false, error: expect.any(String) },
@@ -244,9 +243,7 @@ createRoot(document.getElementById('settings')).render(
244243
expect(
245244
await folderConsent.evaluate(() => typeof (globalThis as { simDesktop?: unknown }).simDesktop)
246245
).toBe('undefined')
247-
await folderConsent
248-
.getByRole('button', { name: 'Allow folder', exact: true })
249-
.click({ noWaitAfter: true })
246+
await answerShellDialog(folderConsent, 'Allow folder')
250247
expect(await folderRead).toMatchObject({ ok: true, data: { representation: 'directory' } })
251248
expect(await queuedRead).toMatchObject({ ok: true, data: { text: 'native file contents' } })
252249
const canonicalRequest = {
@@ -352,9 +349,7 @@ createRoot(document.getElementById('settings')).render(
352349
await invoke({ operation: 'cancel', toolCallId: 'sharedLeader' })
353350
expect(await leader.result).toMatchObject({ ok: false })
354351
await expect(leader.prompt.getByRole('dialog')).toBeVisible()
355-
await leader.prompt
356-
.getByRole('button', { name: 'Allow folder', exact: true })
357-
.click({ noWaitAfter: true })
352+
await answerShellDialog(leader.prompt, 'Allow folder')
358353
expect(await survivor).toMatchObject({ ok: true, data: { text: 'shared contents' } })
359354
})
360355
await test.step('expired requests cannot enable Full file access from a confirmation', async () => {
@@ -368,14 +363,10 @@ createRoot(document.getElementById('settings')).render(
368363
toolCallId: 'expiringFullAccess',
369364
})
370365
const shown = app.waitForEvent('window')
371-
await permission.prompt
372-
.getByRole('button', { name: 'Full file access', exact: true })
373-
.click({ noWaitAfter: true })
366+
await answerShellDialog(permission.prompt, 'Full file access')
374367
const confirmation = await shown
375368
calls.expiringFullAccess = undefined
376-
await confirmation
377-
.getByRole('button', { name: 'Enable', exact: true })
378-
.click({ noWaitAfter: true })
369+
await answerShellDialog(confirmation, 'Enable')
379370
expect(await permission.result).toMatchObject({ ok: false })
380371
expect(
381372
await window.evaluate(async () =>
@@ -399,15 +390,11 @@ createRoot(document.getElementById('settings')).render(
399390
).not.toBeChecked()
400391
const permission = await requestPermission({ operation: 'read', toolCallId: 'fullAccess' })
401392
const confirmationShown = app.waitForEvent('window')
402-
await permission.prompt
403-
.getByRole('button', { name: 'Full file access', exact: true })
404-
.click({ noWaitAfter: true })
393+
await answerShellDialog(permission.prompt, 'Full file access')
405394
const confirmation = await confirmationShown
406395
await expect(confirmation.getByRole('button', { name: 'Cancel', exact: true })).toBeFocused()
407396
const returnedPrompt = app.waitForEvent('window')
408-
await confirmation
409-
.getByRole('button', { name: 'Cancel', exact: true })
410-
.click({ noWaitAfter: true })
397+
await answerShellDialog(confirmation, 'Cancel')
411398
const folderPrompt = await returnedPrompt
412399
expect(
413400
await window.evaluate(async () =>
@@ -417,16 +404,12 @@ createRoot(document.getElementById('settings')).render(
417404
)
418405
).toMatchObject({ fullFileAccess: false })
419406
const acceptedConfirmation = app.waitForEvent('window')
420-
await folderPrompt
421-
.getByRole('button', { name: 'Full file access', exact: true })
422-
.click({ noWaitAfter: true })
407+
await answerShellDialog(folderPrompt, 'Full file access')
423408
const allowAll = await acceptedConfirmation
424409
await allowAll.screenshot({
425410
path: test.info().outputPath('full-file-access-confirmation.png'),
426411
})
427-
await allowAll
428-
.getByRole('button', { name: 'Enable', exact: true })
429-
.click({ noWaitAfter: true })
412+
await answerShellDialog(allowAll, 'Enable')
430413
expect(await permission.result).toMatchObject({
431414
ok: true,
432415
data: { text: 'full access contents' },
@@ -499,9 +482,7 @@ createRoot(document.getElementById('settings')).render(
499482
window.getByRole('switch', { name: 'Full file access', exact: true })
500483
).not.toBeChecked()
501484
const revoked = await requestPermission({ operation: 'read', toolCallId: 'fullAccess' })
502-
await revoked.prompt
503-
.getByRole('button', { name: "Don't allow", exact: true })
504-
.click({ noWaitAfter: true })
485+
await answerShellDialog(revoked.prompt, "Don't allow")
505486
expect(await revoked.result).toMatchObject({ ok: false })
506487
})
507488
await test.step('a folder grant works in another chat but does not permit symlink escapes', async () => {
@@ -526,9 +507,7 @@ createRoot(document.getElementById('settings')).render(
526507
await expect(escapedRead.prompt.getByRole('dialog')).toContainText(
527508
JSON.stringify(realpathSync(outside))
528509
)
529-
await escapedRead.prompt
530-
.getByRole('button', { name: "Don't allow", exact: true })
531-
.click({ noWaitAfter: true })
510+
await answerShellDialog(escapedRead.prompt, "Don't allow")
532511
expect(await escapedRead.result).toMatchObject({ ok: false })
533512
rmSync(join(source, 'linked.txt'))
534513
})
@@ -538,9 +517,7 @@ createRoot(document.getElementById('settings')).render(
538517
const stale = await requestPermission({ operation: 'read', toolCallId: 'stale' })
539518
if (changed) calls.stale.args.path = join(source, 'report.txt')
540519
else calls.stale = undefined
541-
await stale.prompt
542-
.getByRole('button', { name: 'Allow folder', exact: true })
543-
.click({ noWaitAfter: true })
520+
await answerShellDialog(stale.prompt, 'Allow folder')
544521
expect(await stale.result).toMatchObject({ ok: false })
545522
}
546523
})
@@ -791,9 +768,7 @@ createRoot(document.getElementById('settings')).render(
791768
await closed
792769
expect(await cancelled.result).toMatchObject({ ok: false })
793770
const again = await requestPermission({ operation: 'read', toolCallId: 'cancelled' })
794-
await again.prompt
795-
.getByRole('button', { name: "Don't allow", exact: true })
796-
.click({ noWaitAfter: true })
771+
await answerShellDialog(again.prompt, "Don't allow")
797772
expect(await again.result).toMatchObject({ ok: false })
798773
})
799774
await test.step('consent escapes direction controls in folder names', async () => {
@@ -802,18 +777,14 @@ createRoot(document.getElementById('settings')).render(
802777
calls.bidi = { toolName: 'read_local_file', args: { path: folder } }
803778
const bidi = await requestPermission({ operation: 'read', toolCallId: 'bidi' })
804779
await expect(bidi.prompt.getByRole('dialog')).toContainText('Bidi\\u061c\\u200e\\u200f')
805-
await bidi.prompt
806-
.getByRole('button', { name: "Don't allow", exact: true })
807-
.click({ noWaitAfter: true })
780+
await answerShellDialog(bidi.prompt, "Don't allow")
808781
expect(await bidi.result).toMatchObject({ ok: false })
809782
})
810783
await test.step('an unanswered prompt does not block approved folders', async () => {
811784
calls.blocker = { toolName: 'read_local_file', args: { path: join(outside, 'private.txt') } }
812785
const blocker = await requestPermission({ operation: 'read', toolCallId: 'blocker' })
813786
expect(await invoke({ operation: 'read', toolCallId: 'text' })).toMatchObject({ ok: true })
814-
await blocker.prompt
815-
.getByRole('button', { name: "Don't allow", exact: true })
816-
.click({ noWaitAfter: true })
787+
await answerShellDialog(blocker.prompt, "Don't allow")
817788
expect(await blocker.result).toMatchObject({ ok: false })
818789
})
819790
await test.step('cancelled calls cannot reuse an approved folder', async () => {
@@ -831,9 +802,7 @@ createRoot(document.getElementById('settings')).render(
831802
renameSync(proposed, join(root, 'Original'))
832803
mkdirSync(proposed)
833804
writeFileSync(join(proposed, 'unapproved.txt'), 'replacement folder contents')
834-
await retargeted.prompt
835-
.getByRole('button', { name: 'Allow folder', exact: true })
836-
.click({ noWaitAfter: true })
805+
await answerShellDialog(retargeted.prompt, 'Allow folder')
837806
expect(await retargeted.result).toMatchObject({ ok: false })
838807
})
839808
const result = await invoke({ operation: 'manifest', toolCallId: 'import' })
@@ -908,9 +877,7 @@ createRoot(document.getElementById('settings')).render(
908877
'Local files'
909878
)
910879
const revoked = await requestPermission({ operation: 'read', toolCallId: 'text' })
911-
await revoked.prompt
912-
.getByRole('button', { name: 'Allow folder', exact: true })
913-
.click({ noWaitAfter: true })
880+
await answerShellDialog(revoked.prompt, 'Allow folder')
914881
expect(await revoked.result).toMatchObject({ ok: true })
915882
})
916883

@@ -925,16 +892,12 @@ createRoot(document.getElementById('settings')).render(
925892
'Local files'
926893
)
927894
const replaced = await requestPermission({ operation: 'read', toolCallId: 'text' })
928-
await replaced.prompt
929-
.getByRole('button', { name: "Don't allow", exact: true })
930-
.click({ noWaitAfter: true })
895+
await answerShellDialog(replaced.prompt, "Don't allow")
931896
expect(await replaced.result).toMatchObject({ ok: false })
932897
rmSync(source, { recursive: true })
933898
renameSync(join(root, 'Original-reports'), source)
934899
const restored = await requestPermission({ operation: 'read', toolCallId: 'text' })
935-
await restored.prompt
936-
.getByRole('button', { name: 'Allow folder', exact: true })
937-
.click({ noWaitAfter: true })
900+
await answerShellDialog(restored.prompt, 'Allow folder')
938901
expect(await restored.result).toMatchObject({ ok: true })
939902
})
940903

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

0 commit comments

Comments
 (0)