|
@@ -23,6 +23,8 @@ it('protects preparation, removes the old catalog API and scopes sharing to the
|
|
|
app.use(async(ctx,next)=>{try{await next()}catch(e){ctx.status=(e as any).status||500;ctx.body={error:String(e)}}});app.use(bodyParser());app.use(service.router().routes())
|
|
app.use(async(ctx,next)=>{try{await next()}catch(e){ctx.status=(e as any).status||500;ctx.body={error:String(e)}}});app.use(bodyParser());app.use(service.router().routes())
|
|
|
try{
|
|
try{
|
|
|
const first=store.createAgent('alice',{name:'甲',profile:'default',execution:'computer'}),second=store.createAgent('alice',{name:'乙',profile:'default',execution:'computer'})
|
|
const first=store.createAgent('alice',{name:'甲',profile:'default',execution:'computer'}),second=store.createAgent('alice',{name:'乙',profile:'default',execution:'computer'})
|
|
|
|
|
+ const chatting=store.createAgent('alice',{name:'普通聊天成员',profile:'server'})
|
|
|
|
|
+ store.put('alice','turn','ordinary-chat',{agentId:chatting.id,status:'running'})
|
|
|
const other=store.createAgent('bob',{name:'其他账号',profile:'default',execution:'computer'})
|
|
const other=store.createAgent('bob',{name:'其他账号',profile:'default',execution:'computer'})
|
|
|
const id=randomUUID(),base='/api/app/admin/local-vm'
|
|
const id=randomUUID(),base='/api/app/admin/local-vm'
|
|
|
await request(app.callback()).post(base+'/prepare').send({requestId:id}).expect(403)
|
|
await request(app.callback()).post(base+'/prepare').send({requestId:id}).expect(403)
|
|
@@ -35,6 +37,7 @@ it('protects preparation, removes the old catalog API and scopes sharing to the
|
|
|
await request(app.callback()).put(base+'/policy').set('x-admin','yes').send({requestId:randomUUID(),mode:'shared',maxInstances:2}).expect(200)
|
|
await request(app.callback()).put(base+'/policy').set('x-admin','yes').send({requestId:randomUUID(),mode:'shared',maxInstances:2}).expect(200)
|
|
|
const a=store.require<any>('alice','agent',first.id),b=store.require<any>('alice','agent',second.id)
|
|
const a=store.require<any>('alice','agent',first.id),b=store.require<any>('alice','agent',second.id)
|
|
|
expect(a.computerEnvironmentId).toBeTruthy();expect(b.computerEnvironmentId).toBe(a.computerEnvironmentId)
|
|
expect(a.computerEnvironmentId).toBeTruthy();expect(b.computerEnvironmentId).toBe(a.computerEnvironmentId)
|
|
|
|
|
+ expect(store.require('alice','agent',chatting.id)).toEqual(chatting)
|
|
|
const later=store.createAgent('alice',{name:'后加入成员',profile:'default',execution:'computer'})
|
|
const later=store.createAgent('alice',{name:'后加入成员',profile:'default',execution:'computer'})
|
|
|
expect(later.computerEnvironmentId).toBe(a.computerEnvironmentId)
|
|
expect(later.computerEnvironmentId).toBe(a.computerEnvironmentId)
|
|
|
const disabled=await request(app.callback()).put(`/api/app/agents/${later.id}/local-vm`).send({enabled:false}).expect(200)
|
|
const disabled=await request(app.callback()).put(`/api/app/agents/${later.id}/local-vm`).send({enabled:false}).expect(200)
|
|
@@ -43,6 +46,13 @@ it('protects preparation, removes the old catalog API and scopes sharing to the
|
|
|
expect(store.require<any>('bob','agent',other.id).computerEnvironmentId).toBeUndefined()
|
|
expect(store.require<any>('bob','agent',other.id).computerEnvironmentId).toBeUndefined()
|
|
|
await request(app.callback()).put(base+'/policy').set('x-admin','yes').send({requestId:randomUUID(),mode:'per-bot',maxInstances:2}).expect(200)
|
|
await request(app.callback()).put(base+'/policy').set('x-admin','yes').send({requestId:randomUUID(),mode:'per-bot',maxInstances:2}).expect(200)
|
|
|
expect(store.require<any>('alice','agent',first.id).computerEnvironmentId).toBeUndefined()
|
|
expect(store.require<any>('alice','agent',first.id).computerEnvironmentId).toBeUndefined()
|
|
|
|
|
+ expect(store.require('alice','agent',chatting.id)).toEqual(chatting)
|
|
|
|
|
+ store.put('alice','turn','active-vm',{agentId:first.id,status:'uncertain'})
|
|
|
|
|
+ hub.localVm.mockClear()
|
|
|
|
|
+ const blocked=await request(app.callback()).put(base+'/policy').set('x-admin','yes').send({requestId:randomUUID(),mode:'shared',maxInstances:2}).expect(409)
|
|
|
|
|
+ expect(blocked.body.error).toContain('请先停止「甲」')
|
|
|
|
|
+ expect(hub.localVm).not.toHaveBeenCalled()
|
|
|
|
|
+ store.remove('alice','turn','active-vm')
|
|
|
const helper=store.createAgent('alice',{name:'临时任务助手',profile:'default',execution:'computer'},{createdByAgentId:first.id,createdFromRunId:randomUUID(),temporaryGoalId:randomUUID()})
|
|
const helper=store.createAgent('alice',{name:'临时任务助手',profile:'default',execution:'computer'},{createdByAgentId:first.id,createdFromRunId:randomUUID(),temporaryGoalId:randomUUID()})
|
|
|
await request(app.callback()).post(`/api/app/agents/${helper.id}/local-vm/create`).send({}).expect(409)
|
|
await request(app.callback()).post(`/api/app/agents/${helper.id}/local-vm/create`).send({}).expect(409)
|
|
|
active=false;expect(service.allowed(id,runner.id)).toBe(false)
|
|
active=false;expect(service.allowed(id,runner.id)).toBe(false)
|