Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop-app): follow the user's route before load when no route was requested (R1-M4)
Diego Zacariase100d5f898ab
diff --git a/desktop-app/src/__tests__/appService.sandboxUiLifecycle.test.ts b/desktop-app/src/__tests__/appService.sandboxUiLifecycle.test.tsindex e42d167bf..e135ec230 100644--- a/desktop-app/src/__tests__/appService.sandboxUiLifecycle.test.ts+++ b/desktop-app/src/__tests__/appService.sandboxUiLifecycle.test.ts@@ -1543,6 +1543,59 @@ describe('AppService sandbox-ui route settling', () => {expect(getActiveSandboxUiLocation()).toEqual(location('/welcome'))})+ // Chromium commits a document (`did-navigate`) well before it finishes+ // loading; the fake's commitLoad does both at once, so these emit the commit+ // alone for the URL the driver asked to load.+ function commitWithoutFinishing(+ webContents: InstanceType<typeof electronMocks.FakeWebContentsView>['webContents'],+ url = webContents.pendingUrl+ ) {+ webContents.currentUrl = url+ webContents.emit('did-navigate', {}, url, 200, '')+ }++ it('a view with no requested route follows the user before the document finishes loading', async () => {+ const { service, released, webContents } = await openLoading()+ commitWithoutFinishing(webContents)+ webContents.navigateInPage(`${APP_VIEW_URL}/settings`)+ expect(getActiveSandboxUiLocation()).toEqual(location('/settings'))+ await service.closeSandboxUi()+ expect(released.map(event => event.location)).toEqual([{ routePath: '/settings' }])+ })++ it('a deep link copied before the load finishes points where the user went', async () => {+ const { buildSandboxUiWebLink } = await import('../sandboxUiDeepLinks.js')+ const { config } = await import('../config.js')+ vi.spyOn(config, 'desktopProfileUiBaseUrlExplicit', 'get').mockReturnValue(true)+ const { service, webContents } = await openLoading()+ commitWithoutFinishing(webContents)+ webContents.navigateInPage(`${APP_VIEW_URL}/settings`)+ await expect(service.createSandboxUiDeepLink()).resolves.toEqual({+ url: buildSandboxUiWebLink('https://profile.example.com', location('/settings')),+ })+ })++ it('a view with no requested route reports a document the server redirected it to before it loads', async () => {+ const { webContents } = await openLoading()+ commitWithoutFinishing(webContents, `${APP_VIEW_URL}/welcome`)+ expect(getActiveSandboxUiLocation()).toEqual(location('/welcome'))+ })++ it('a view with no requested route ignores a document committed outside the app', async () => {+ const { webContents } = await openLoading()+ commitWithoutFinishing(webContents, 'https://idp.example/login')+ expect(getActiveSandboxUiLocation()).toEqual(location())+ })++ it('a boot redirect before the load does not replace a requested route', async () => {+ const { service, released, webContents } = await openLoading('/r/first')+ commitWithoutFinishing(webContents)+ webContents.navigateInPage(`${APP_VIEW_URL}/login`)+ expect(getActiveSandboxUiLocation()).toEqual(location('/r/first'))+ await service.closeSandboxUi()+ expect(released.map(event => event.location)).toEqual([{ routePath: '/r/first' }])+ })+it('an in-page navigation before the first load does not replace the requested route', async () => {const { service, webContents } = await openLoading('/r/first')webContents.navigateInPage(`${APP_VIEW_URL}/#boot`)diff --git a/desktop-app/src/sandboxUiDriver.ts b/desktop-app/src/sandboxUiDriver.tsindex c189da30c..10d0bffb4 100644--- a/desktop-app/src/sandboxUiDriver.ts+++ b/desktop-app/src/sandboxUiDriver.ts@@ -660,11 +660,18 @@ export async function mountSandboxUiView(args: MountSandboxUiArgs): Promise<voidconst previousUrl = lastMainFrameUrllastMainFrameUrl = navigatedUrlconst withinApp = isSandboxUiNavigationWithinPrefix(navigatedUrl, allowedNavigationPrefix)- // A new document the user reached after the handoff gave up (a multi-page- // app) is the live route. A reload commits the same URL and the commits a- // pending handoff is still waiting through are not the user's: neither may- // replace the requested route.- if (withinApp && documentLoaded && !clientRouteHandoffPending && navigatedUrl !== previousUrl) {+ // With no requested route there is nothing a boot rewrite could overwrite,+ // so the first document committed inside the app is already the live+ // route; waiting for the load would drop where the user goes meanwhile.+ // Otherwise, a new document the user reached after the handoff gave up (a+ // multi-page app) is the live route. A reload commits the same URL and the+ // commits a pending handoff is still waiting through are not the user's:+ // neither may replace the requested route.+ if (+ withinApp &&+ (!needsClientRouteHandoff ||+ (documentLoaded && !clientRouteHandoffPending && navigatedUrl !== previousUrl))+ ) {active.routeSettled = true}if (httpResponseCode !== 401 || !withinApp) return