|
@@ -16,8 +16,8 @@ let home: string, store: WorkspaceStore, manager: OpenVikingConfigurationManager
|
|
|
const files = new Map<string, string>()
|
|
const files = new Map<string, string>()
|
|
|
const removed = new Set<string>()
|
|
const removed = new Set<string>()
|
|
|
const admin = {
|
|
const admin = {
|
|
|
- adminRegisterUser: vi.fn(async () => ({ apiKey: `user-key-${admin.adminRegisterUser.mock.calls.length}` })),
|
|
|
|
|
- adminRegenerateKey: vi.fn(async () => ({ apiKey: 'regenerated-key' })),
|
|
|
|
|
|
|
+ adminRegisterUser: vi.fn(async () => ({ user_key: `user-key-${admin.adminRegisterUser.mock.calls.length}` })),
|
|
|
|
|
+ adminRegenerateKey: vi.fn(async () => ({ user_key: 'regenerated-key' })),
|
|
|
adminRemoveUser: vi.fn(async () => ({ ok: true })),
|
|
adminRemoveUser: vi.fn(async () => ({ ok: true })),
|
|
|
}
|
|
}
|
|
|
const clients = new Map<string, { apiKey: string; client: unknown }>()
|
|
const clients = new Map<string, { apiKey: string; client: unknown }>()
|
|
@@ -93,6 +93,18 @@ describe('OpenViking memory provider', () => {
|
|
|
expect(admin.adminRemoveUser).toHaveBeenCalledWith('account', binding.userId)
|
|
expect(admin.adminRemoveUser).toHaveBeenCalledWith('account', binding.userId)
|
|
|
expect(store.require(owner, 'openviking-binding', a.id).status).toBe('removed')
|
|
expect(store.require(owner, 'openviking-binding', a.id).status).toBe('removed')
|
|
|
})
|
|
})
|
|
|
|
|
+ it('recovers an existing remote user without a local key binding', async () => {
|
|
|
|
|
+ admin.adminRegisterUser.mockResolvedValueOnce({})
|
|
|
|
|
+ await expect(service.ensureUser(owner, a)).rejects.toThrowError(expect.objectContaining({ code: 'openviking_unavailable' }))
|
|
|
|
|
+
|
|
|
|
|
+ admin.adminRegisterUser.mockRejectedValueOnce(new OpenVikingError('user exists', { code: 'USER_EXISTS', statusCode: 409 }))
|
|
|
|
|
+ const binding = await service.ensureUser(owner, a)
|
|
|
|
|
+ expect(binding.userId).toBe(openVikingUserId(a.id))
|
|
|
|
|
+ expect(JSON.stringify(binding)).not.toContain('regenerated-key')
|
|
|
|
|
+ expect(admin.adminRegenerateKey).toHaveBeenCalledWith('account', binding.userId, `yaoyao:${a.id}`)
|
|
|
|
|
+ expect(service.userClient(owner, a.id)).toBeTruthy()
|
|
|
|
|
+ expect(clients.get(binding.userId)?.apiKey).toBe('regenerated-key')
|
|
|
|
|
+ })
|
|
|
it('keeps user memory isolated per contributing Bot', async () => {
|
|
it('keeps user memory isolated per contributing Bot', async () => {
|
|
|
await knowledge.writeMemory(owner, { requestId: randomUUID(), scope: 'user', agentId: a.id, topic: '接口', content: '甲认为使用版本一', tier: 'profile' })
|
|
await knowledge.writeMemory(owner, { requestId: randomUUID(), scope: 'user', agentId: a.id, topic: '接口', content: '甲认为使用版本一', tier: 'profile' })
|
|
|
await knowledge.writeMemory(owner, { requestId: randomUUID(), scope: 'user', agentId: b.id, topic: '接口', content: '乙认为使用版本二', tier: 'profile' })
|
|
await knowledge.writeMemory(owner, { requestId: randomUUID(), scope: 'user', agentId: b.id, topic: '接口', content: '乙认为使用版本二', tier: 'profile' })
|