mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
fix(browser): create This-device link tabs on the opener's runtime without reading the active server
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { showClientCreationActionError } from '@/lib/workspace/creation/surface-policy/client-creation-action-error'
|
||||
import { runtimeEnvironmentIdOrLocalUnlessTwin } from '@/lib/workspace/ownership/worktree-runtime-owner'
|
||||
import { createWebRuntimeSessionBrowserTab } from '@/runtime/browser/creation/web-runtime-browser-creation'
|
||||
import { createWebRuntimeSessionBrowserTabOnHost } from '@/runtime/browser/creation/web-runtime-browser-creation'
|
||||
import { useAppStore } from '@/store/index'
|
||||
import { isClientHostedBrowserPageHandle } from '@/store/slices/browser/hosts/browser-host-state'
|
||||
import { findPage, findWorkspace } from '@/store/slices/browser/pages/browser-page-records'
|
||||
@@ -24,10 +23,7 @@ export function openClientHostedUrlBesideBrowserPage(args: {
|
||||
const sourcePage = findPage(store.browserPagesByWorkspace, args.sourcePageId)
|
||||
const handle = store.remoteBrowserPageHandlesByPageId?.[args.sourcePageId]
|
||||
const environmentId =
|
||||
handle?.environmentId?.trim() ||
|
||||
runtimeEnvironmentIdOrLocalUnlessTwin(store, args.worktreeId) ||
|
||||
sourcePage?.browserRuntimeEnvironmentId?.trim() ||
|
||||
null
|
||||
handle?.environmentId?.trim() || sourcePage?.browserRuntimeEnvironmentId?.trim() || null
|
||||
// A client-hosted row with no named runtime cannot ask the paired host, so keep the local opener.
|
||||
if (!environmentId) {
|
||||
openUrlInTabBesideBrowserPage(args)
|
||||
@@ -41,19 +37,21 @@ export function openClientHostedUrlBesideBrowserPage(args: {
|
||||
const sourceUnifiedTab = resolveBrowserSourceUnifiedTab(store, args.sourcePageId, args.worktreeId)
|
||||
// Why not createBrowserTab: that lands in the streamed pane, which a headless runtime cannot show.
|
||||
// Omit placementPreference so preparation uses the same auto choice as the new-tab button.
|
||||
void createWebRuntimeSessionBrowserTab({
|
||||
worktreeId: args.worktreeId,
|
||||
environmentId,
|
||||
url: args.url,
|
||||
...(profileId ? { profileId } : {}),
|
||||
...(sourceUnifiedTab ? { clientAfterTabId: sourceUnifiedTab.id } : {}),
|
||||
...(args.onOpened ? { onMaterialized: args.onOpened } : {}),
|
||||
focusOnCreate: args.activate,
|
||||
selectWorktree: false,
|
||||
stagedTitle: redactKagiSessionToken(args.url),
|
||||
stagedFocusAddressBar: false,
|
||||
failureLogMode: 'operation-only'
|
||||
}).catch(showClientCreationActionError)
|
||||
void createWebRuntimeSessionBrowserTabOnHost(
|
||||
{
|
||||
worktreeId: args.worktreeId,
|
||||
url: args.url,
|
||||
...(profileId ? { profileId } : {}),
|
||||
...(sourceUnifiedTab ? { clientAfterTabId: sourceUnifiedTab.id } : {}),
|
||||
...(args.onOpened ? { onMaterialized: args.onOpened } : {}),
|
||||
focusOnCreate: args.activate,
|
||||
selectWorktree: false,
|
||||
stagedTitle: redactKagiSessionToken(args.url),
|
||||
stagedFocusAddressBar: false,
|
||||
failureLogMode: 'operation-only'
|
||||
},
|
||||
environmentId
|
||||
).catch(showClientCreationActionError)
|
||||
}
|
||||
|
||||
/** Local pages keep createBrowserTab. Client-hosted pages on a paired server follow the new-tab route. */
|
||||
|
||||
@@ -45,7 +45,15 @@ export async function createWebRuntimeSessionBrowserTab(
|
||||
args.environmentId?.trim() ??
|
||||
useAppStore.getState().settings?.activeRuntimeEnvironmentId?.trim() ??
|
||||
null
|
||||
if (!environmentId || !isWebRuntimeSessionActive(environmentId)) {
|
||||
return environmentId ? createWebRuntimeSessionBrowserTabOnHost(args, environmentId) : false
|
||||
}
|
||||
|
||||
/** Creates the tab on the named runtime, for callers that already route by the page's owner. */
|
||||
export async function createWebRuntimeSessionBrowserTabOnHost(
|
||||
args: CreateWebRuntimeSessionBrowserTabArgs,
|
||||
environmentId: string
|
||||
): Promise<boolean> {
|
||||
if (!isWebRuntimeSessionActive(environmentId)) {
|
||||
return false
|
||||
}
|
||||
const context = createWebRuntimeBrowserCreationContext(args, environmentId)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { createServer, type Server } from 'node:http'
|
||||
import type { AddressInfo } from 'node:net'
|
||||
import type { Page } from '@stablyai/playwright-test'
|
||||
import { expect, test } from './helpers/orca-app'
|
||||
import { launchHeadlessPairedRuntimeHost } from './helpers/headless-paired-runtime-host'
|
||||
@@ -45,7 +44,11 @@ async function startFixture(): Promise<{ server: Server; origin: string }> {
|
||||
}
|
||||
})
|
||||
await new Promise<void>((resolve) => server.listen(0, '127.0.0.1', resolve))
|
||||
return { server, origin: `http://127.0.0.1:${(server.address() as AddressInfo).port}` }
|
||||
const address = server.address()
|
||||
if (!address || typeof address === 'string') {
|
||||
throw new Error('fixture server has no port')
|
||||
}
|
||||
return { server, origin: `http://127.0.0.1:${address.port}` }
|
||||
}
|
||||
|
||||
function readPagePlacements(page: Page, worktreeId: string): Promise<Record<string, string>> {
|
||||
@@ -105,9 +108,9 @@ async function clickInGuest(
|
||||
const guest = webContents
|
||||
.getAllWebContents()
|
||||
.find((contents) => contents.getType() === 'webview' && contents.getURL() === url)!
|
||||
const { x, y } = (await guest.executeJavaScript(
|
||||
const { x, y }: { x: number; y: number } = await guest.executeJavaScript(
|
||||
`(() => { const r = document.querySelector(${JSON.stringify(selector)}).getBoundingClientRect(); return { x: Math.round(r.x + r.width / 2), y: Math.round(r.y + r.height / 2) } })()`
|
||||
)) as { x: number; y: number }
|
||||
)
|
||||
guest.sendInputEvent({ type: 'mouseDown', x, y, button: 'left', clickCount: 1 })
|
||||
guest.sendInputEvent({ type: 'mouseUp', x, y, button: 'left', clickCount: 1 })
|
||||
},
|
||||
@@ -118,6 +121,7 @@ async function clickInGuest(
|
||||
test('a This-device page opens new tabs on this device and keeps OAuth popups working', async ({
|
||||
testRepoPath
|
||||
}, testInfo) => {
|
||||
// Boots a headless host and a paired client, then waits on two tab creations and a popup round trip.
|
||||
test.setTimeout(300_000)
|
||||
const { server, origin } = await startFixture()
|
||||
const host = await launchHeadlessPairedRuntimeHost()
|
||||
|
||||
Reference in New Issue
Block a user