agentIdentity.test.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { describe, expect, it } from 'vitest'
  2. import {
  3. YAOYAO_AGENT_IDENTITY_NAMESPACE,
  4. AGENT_MASCOT_SHAPES,
  5. agentIdentityFromProfile,
  6. decodeAgentMascotAvatar,
  7. defaultAgentIdentity,
  8. encodeAgentAvatar,
  9. } from '../../src/shared/agentIdentity'
  10. describe('Yaoyao agent identity', () => {
  11. it('inherits the legacy Bots title once but never its avatar asset', () => {
  12. const identity = agentIdentityFromProfile({
  13. name: 'default',
  14. ui_meta: { 'hermes-bots': { title: '竹儿' } },
  15. })
  16. expect(identity.displayName).toBe('竹儿')
  17. expect(identity.avatarMode).toBe('mascot')
  18. expect(encodeAgentAvatar(identity)).toMatch(/^yaoyao-mascot:v1:/)
  19. })
  20. it('reads the independent Yaoyao namespace ahead of legacy data', () => {
  21. const identity = agentIdentityFromProfile({
  22. name: 'researcher',
  23. ui_meta: {
  24. 'hermes-bots': { title: '旧名称' },
  25. [YAOYAO_AGENT_IDENTITY_NAMESPACE]: {
  26. version: 1,
  27. display_name: '新名称',
  28. avatar_mode: 'mascot',
  29. shape: 'triangle',
  30. color: '#0ea5c6',
  31. expression: 'curious',
  32. },
  33. },
  34. })
  35. expect(identity.displayName).toBe('新名称')
  36. expect(decodeAgentMascotAvatar(encodeAgentAvatar(identity))).toEqual({
  37. shape: 'triangle', color: '#0ea5c6', expression: 'curious',
  38. })
  39. })
  40. it('derives the same default shape and color for the same profile', () => {
  41. expect(defaultAgentIdentity('designer')).toEqual(defaultAgentIdentity('designer'))
  42. expect(defaultAgentIdentity('designer')).not.toEqual(defaultAgentIdentity('reviewer'))
  43. })
  44. })
  45. it('round trips every expanded shape including uploaded-avatar alternatives', () => {
  46. expect(AGENT_MASCOT_SHAPES).toHaveLength(8)
  47. for (const shape of AGENT_MASCOT_SHAPES) {
  48. const encoded = encodeAgentAvatar({...defaultAgentIdentity('designer'), shape, color:'#ff2dab'})
  49. expect(decodeAgentMascotAvatar(encoded)).toMatchObject({shape,color:'#ff2dab'})
  50. }
  51. expect(decodeAgentMascotAvatar('yaoyao-mascot:v1:script:ff2dab:friendly')).toBeNull()
  52. })