|
|
@@ -33,20 +33,29 @@ it('adds an authorized native desktop to hybrid tools while leaving the default
|
|
|
function drive(handle:(c:any)=>unknown=c=>c.operation==='view'?{data:Buffer.from('fixture frame').toString('base64'),width:1280,height:800}:{ok:true}){let results:any[]=[];service.exchange({host,results});const p=setInterval(()=>{const value=service.exchange({host,results});results=value.commands.map(c=>({id:c.id,value:handle(c)}))},5);pollers.add(p);poller=p}
|
|
|
const HOST_A='11111111-aaaa-4bbb-8ccc-111111111111',HOST_B='22222222-aaaa-4bbb-8ccc-222222222222'
|
|
|
function driveRemote(id:string,hostInfo:any,handle:(c:any)=>unknown=c=>c.operation==='view'?{data:Buffer.from('remote frame').toString('base64'),width:1280,height:800}:{ok:true}){let results:any[]=[];service.remoteExchange(id,{host:hostInfo,results});const p=setInterval(()=>{const value=service.remoteExchange(id,{host:hostInfo,results});results=value.commands.map(c=>({id:c.id,value:handle(c)}))},5);pollers.add(p);poller=p}
|
|
|
-it('routes a bound agent to its remote desktop host and keeps hosts isolated',async()=>{
|
|
|
+it('defaults bot work to the server desktop and falls back to a legacy binding only when it is away',async()=>{
|
|
|
agent=store.updateAgent('owner',agent.id,{computer:'local',desktopHost:HOST_A})
|
|
|
const remoteHost={...host,name:'客厅 Mac Pro'}
|
|
|
driveRemote(HOST_A,remoteHost)
|
|
|
- service.exchange({host,results:[]})
|
|
|
+ drive()
|
|
|
+ const state=(await request(app()).get(base()+'/desktop-environment')).body
|
|
|
+ expect(state.hostName??state.host?.name).toBe('测试 Mac')
|
|
|
+ const named=(await request(app()).get(base()+'/computer?backend=desktop&host='+encodeURIComponent('客厅 Mac Pro'))).body
|
|
|
+ expect(named.hostName).toBe('客厅 Mac Pro')
|
|
|
+ vi.useFakeTimers()
|
|
|
+ clearInterval(poller)
|
|
|
+ vi.advanceTimersByTime(9000)
|
|
|
+ const fallback=(await request(app()).get(base()+'/desktop-environment')).body
|
|
|
+ expect(fallback.hostName??fallback.host?.name).toBe('客厅 Mac Pro')
|
|
|
const epoch=service.hostEpoch('owner',agent)
|
|
|
expect(epoch).toBe(remoteHost.id)
|
|
|
const result=await service.call('owner',agent.id,'desktop_environment_view',{},new AbortController().signal,()=>{},'local',epoch)
|
|
|
expect(result.content[0].type).toBe('image')
|
|
|
expect(JSON.parse(result.content[1].text).host).toBe('客厅 Mac Pro')
|
|
|
- const state=(await request(app()).get(base()+'/desktop-environment')).body
|
|
|
- expect(state.hostName??state.host?.name).toBe('客厅 Mac Pro')
|
|
|
- expect(state.hosts.map((h:any)=>h.id)).toEqual(['local',HOST_A])
|
|
|
- expect(state.hosts.find((h:any)=>h.id===HOST_A)).toMatchObject({name:'客厅 Mac Pro',online:true})
|
|
|
+ vi.useRealTimers()
|
|
|
+ const hosts=(await request(app()).get(base()+'/desktop-environment')).body
|
|
|
+ expect(hosts.hosts.map((h:any)=>h.id)).toEqual(['local',HOST_A])
|
|
|
+ expect(hosts.hosts.find((h:any)=>h.id===HOST_A)).toMatchObject({name:'客厅 Mac Pro',online:true})
|
|
|
})
|
|
|
it('requires an explicit binding when several remote hosts are connected',async()=>{
|
|
|
agent=store.updateAgent('owner',agent.id,{computer:'local'})
|