This commit is contained in:
2026-10-24 16:34:02 +08:00
parent 99e5687ce0
commit 7119e04a65
24 changed files with 553 additions and 39 deletions
+23
View File
@@ -27,6 +27,7 @@ const gatewayAutostartMocks = vi.hoisted(() => ({
// Mock hermes-cli
vi.mock('../../packages/server/src/services/hermes/hermes-cli', () => ({
listProfiles: vi.fn(),
listProfilesSnapshot: vi.fn(),
getProfile: vi.fn(),
createProfile: vi.fn(),
deleteProfile: vi.fn(),
@@ -313,6 +314,28 @@ describe('Profile Routes', () => {
})
})
it('lists 20 profiles without waiting for CLI or embedding uploaded images', async () => {
const webUiHome = await mkdtemp(join(tmpdir(), 'hermes-ui-profile-list-'))
tempHomes.push(webUiHome)
process.env.HERMES_WEB_UI_HOME = webUiHome
const { list, updateAvatar, getAvatar } = await import('../../packages/server/src/controllers/hermes/profiles')
await updateAvatar({ params: { name: 'work-0' }, request: { body: { type: 'image', dataUrl: 'data:image/png;base64,YQ==' } } })
vi.mocked(hermesCli.listProfiles).mockReturnValue(new Promise(() => {}))
vi.mocked(hermesCli.listProfilesSnapshot).mockReturnValue(Array.from({ length: 20 }, (_, index) => ({ name: `work-${index}`, active: false, model: 'test', alias: '' })))
const ctx: any = { state: { profile: { name: 'work-0' } } }
await list(ctx)
expect(hermesCli.listProfiles).not.toHaveBeenCalled()
expect(ctx.body.profiles).toHaveLength(20)
expect(ctx.body.profiles[0]).toMatchObject({ active: true, avatar: { type: 'image' } })
expect(ctx.body.profiles[0].avatar.dataUrl).toBeUndefined()
const imageCtx: any = { params: { name: 'work-0' } }
await getAvatar(imageCtx)
expect(imageCtx.body.avatar.dataUrl).toBe('data:image/png;base64,YQ==')
const denied: any = { params: { name: 'work-0' }, state: { user: { id: -123, role: 'admin' } } }
await getAvatar(denied)
expect(denied.status).toBe(403)
})
describe('profile avatars', () => {
it('stores generated avatar metadata under the Web UI home', async () => {
const webUiHome = await mkdtemp(join(tmpdir(), 'hermes-ui-avatar-'))