Skip to content

Commit 77066dd

Browse files
committed
fix(desktop-e2e): drive Full file access through Sim's real Desktop settings page again
The #10390 migration swapped the bundled Desktop settings component for an inline stand-in, so nothing exercised the switch users get: setFullFileAccess from a real click, onFullFileAccessChanged, and Sim's own failed-save error. Bundle the real component through the harness's bundleSimFixture again.
1 parent 2fbc5f3 commit 77066dd

1 file changed

Lines changed: 46 additions & 25 deletions

File tree

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

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
import { answerShellDialog } from './executor-sim'
1818
import {
1919
test as base,
20+
bundleSimFixture,
2021
type DesktopApp,
2122
type DesktopBridge,
2223
expect,
@@ -28,40 +29,48 @@ const PNG =
2829
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAusB9Y9Zl1sAAAAASUVORK5CYII='
2930

3031
/**
31-
* The app's own page stands in for Sim: a Forget button and a Full file access switch that drive
32-
* the same bridge calls Sim's Desktop settings make (a real click supplies the user activation the
33-
* setter requires), and the switch shows whatever the desktop last reported.
32+
* Sim's real Desktop settings page, so the Full file access switch is the one users get: a real
33+
* click supplies the user activation the setter requires, and a failed save shows Sim's own error.
34+
* The Forget button stands in for Sim's chat-side folder removal, which has no settings UI.
3435
*/
35-
const FIXTURE_PAGE = `<!doctype html><title>Local file fixture</title><h1>Local files</h1>
36+
const SETTINGS_SOURCE = `import { createRoot } from 'react-dom/client';
37+
import { ToastProvider } from '@sim/emcn';
38+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
39+
import { AppRouterContext } from 'next/dist/shared/lib/app-router-context.shared-runtime';
40+
import { PathParamsContext } from 'next/dist/shared/lib/hooks-client-context.shared-runtime';
41+
import { Desktop } from '@/app/workspace/[workspaceId]/settings/components/desktop/desktop';
42+
import { FeatureFlagsProvider } from '@/app/workspace/[workspaceId]/providers/feature-flags-provider';
43+
import { SettingsHeaderProvider, SettingsHeaderShell } from '@/components/settings/settings-header';
44+
import { SettingsSectionProvider } from '@/components/settings/settings-panel';
45+
const router = { back() {}, forward() {}, refresh() {}, push() {}, replace() {}, prefetch() {} };
46+
const flags = { dashboards: false, 'workflow-tests': false, 'workflow-code': false, changelog: false, 'mothership-model-selector': false, 'mothership-plan-mode': false };
47+
createRoot(document.getElementById('settings')).render(
48+
<AppRouterContext.Provider value={router}>
49+
<PathParamsContext.Provider value={{ workspaceId: 'fixture' }}>
50+
<QueryClientProvider client={new QueryClient({ defaultOptions: { queries: { retry: false } } })}>
51+
<ToastProvider><SettingsHeaderProvider><SettingsHeaderShell><FeatureFlagsProvider flags={flags}>
52+
<SettingsSectionProvider plane='workspace' section='desktop'><Desktop /></SettingsSectionProvider>
53+
</FeatureFlagsProvider></SettingsHeaderShell></SettingsHeaderProvider></ToastProvider>
54+
</QueryClientProvider>
55+
</PathParamsContext.Provider>
56+
</AppRouterContext.Provider>
57+
);`
58+
59+
const FIXTURE_PAGE = `<!doctype html><title>Local file fixture</title><link rel="stylesheet" href="/settings.css">
60+
<h1>Local files</h1>
3661
<button id="forget">Forget folders</button>
37-
<label><input id="full-access" type="checkbox" role="switch" disabled> Full file access</label>
38-
<output id="full-access-status"></output>
62+
<div id="settings" style="height:calc(100vh - 80px)"></div>
3963
<script>
40-
const api = window.simDesktop
4164
const forget = document.getElementById('forget')
4265
forget.addEventListener('click', async () => {
66+
const api = window.simDesktop
4367
const result = await api.localFilesystem({ operation: 'list_mounts' })
4468
for (const mount of result.data.mounts)
4569
await api.localFilesystem({ operation: 'forget_mount', uri: mount.uri })
4670
forget.textContent = 'Forgotten'
4771
})
48-
const toggle = document.getElementById('full-access')
49-
const status = document.getElementById('full-access-status')
50-
const show = (preferences) => {
51-
toggle.checked = preferences.fullFileAccess === true
52-
toggle.disabled = false
53-
}
54-
api.settings.getPreferences().then(show)
55-
api.settings.onFullFileAccessChanged(show)
56-
toggle.addEventListener('change', () => {
57-
toggle.disabled = true
58-
status.textContent = ''
59-
api.settings.setFullFileAccess(toggle.checked).then(show, () => {
60-
status.textContent = 'Not saved'
61-
toggle.disabled = false
62-
})
63-
})
64-
</script>`
72+
</script>
73+
<script src="/settings.js"></script>`
6574

6675
type LocalFileResponse = Awaited<ReturnType<NonNullable<SimDesktopApi['localFiles']>>>
6776

@@ -143,7 +152,14 @@ const test = base.extend<{ localFiles: LocalFilesFixture }>({
143152
args: { path: source, targetWorkspaceId: 'target-workspace' },
144153
},
145154
}
155+
const settings = await bundleSimFixture({ source: SETTINGS_SOURCE }, { external: ['postgres'] })
146156
const server = await serve(async (request, response, url) => {
157+
if (url.pathname === '/settings.js' || url.pathname === '/settings.css') {
158+
const script = url.pathname.endsWith('.js')
159+
response.writeHead(200, { 'Content-Type': script ? 'text/javascript' : 'text/css' })
160+
response.end(script ? settings.js : settings.css)
161+
return
162+
}
147163
if (url.pathname === '/api/auth/get-session') {
148164
response
149165
.writeHead(200, { 'Content-Type': 'application/json' })
@@ -672,7 +688,12 @@ test('Full file access is opt-in, survives restart, turns off cleanly, and fails
672688
mkdirSync(settingsPath)
673689
try {
674690
await session.fullAccess.click()
675-
await expect(session.window.getByRole('status')).toHaveText('Not saved')
691+
await expect(
692+
session.window.getByText(
693+
'Could not save file access settings. Your previous setting may return after restarting Sim.',
694+
{ exact: true }
695+
)
696+
).toBeVisible()
676697
await expect(session.fullAccess).not.toBeChecked()
677698
expect(await session.preferences()).toMatchObject({ fullFileAccess: false })
678699
expect(await session.invoke({ operation: 'read', toolCallId: 'text' })).toMatchObject({

0 commit comments

Comments
 (0)