mirror of
https://github.com/stablyai/orca.git
synced 2026-11-06 03:57:35 +00:00
fix(browser): keep snapshot refs on server browsers that use an external Chromium (#36276)
Every command re-selected its tab first, and agent-browser drops the last snapshot's refs on any tab select, so each @ref failed as Unknown ref. Select the tab only when it is not already active.
This commit is contained in:
@@ -167,6 +167,32 @@ describe('orcad external-chromium agent-browser environment', () => {
|
||||
expect(issued).not.toContain('open')
|
||||
})
|
||||
|
||||
it('selects a tab only when it is not already active, keeping the snapshot refs', async () => {
|
||||
runProcessMock.mockImplementation(() => {
|
||||
const tabs = [
|
||||
{ active: true, tabId: 't1', title: 'a', url: 'about:blank' },
|
||||
{ active: false, tabId: 't2', title: 'b', url: 'about:blank' }
|
||||
]
|
||||
return Promise.resolve({
|
||||
code: 0,
|
||||
signal: null,
|
||||
stdout: JSON.stringify({ success: true, data: { tabs } }),
|
||||
stderr: '',
|
||||
timedOut: false
|
||||
})
|
||||
})
|
||||
const session = new ExternalChromiumBrowserSession(
|
||||
'/opt/orca/agent-browser',
|
||||
{ executablePath: BASE.executablePath, provider: 'chromium' },
|
||||
'/state'
|
||||
)
|
||||
|
||||
await session.selectPage('t1')
|
||||
expect(commands()).toEqual([['tab']])
|
||||
await session.selectPage('t2')
|
||||
expect(commands()).toEqual([['tab'], ['tab'], ['tab', 't2']])
|
||||
})
|
||||
|
||||
it('reclaims a session that answers nothing, then opens', async () => {
|
||||
let listed = 0
|
||||
runProcessMock.mockImplementation((spec: Spec) => {
|
||||
|
||||
@@ -138,6 +138,10 @@ export class ExternalChromiumBrowserSession {
|
||||
}
|
||||
|
||||
async selectPage(agentPageId: string): Promise<void> {
|
||||
// Selecting any tab, even the active one, discards the refs of the last snapshot.
|
||||
if ((await this.readTabs()).some((tab) => tab.tabId === agentPageId && tab.active)) {
|
||||
return
|
||||
}
|
||||
await this.run(['tab', agentPageId])
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user