|
1 | 1 | import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; |
2 | 2 | import type { Message } from '../types'; |
3 | | -import { normalizeRelayDmMessageTargets } from './relaycastMessageAdapters.js'; |
| 3 | +import { getRelayDmParticipantName, normalizeRelayDmMessageTargets } from './relaycastMessageAdapters.js'; |
4 | 4 |
|
5 | 5 | function setRelayUsername(value?: string): void { |
6 | 6 | const storage = (globalThis as { localStorage?: Storage }).localStorage; |
@@ -93,6 +93,35 @@ describe('normalizeRelayDmMessageTargets', () => { |
93 | 93 | expect(normalized[0]?.to).toBe('Natty'); |
94 | 94 | }); |
95 | 95 |
|
| 96 | + it('maps dm_* targets to object participants using agent_name', () => { |
| 97 | + const messages: Message[] = [ |
| 98 | + { |
| 99 | + id: 'msg-2a', |
| 100 | + from: 'Natty', |
| 101 | + to: 'dm_7b62c72644b9316e7e10a992', |
| 102 | + content: 'hello', |
| 103 | + timestamp: '2026-02-24T12:00:06.000Z', |
| 104 | + }, |
| 105 | + ]; |
| 106 | + |
| 107 | + const normalized = normalizeRelayDmMessageTargets(messages, [ |
| 108 | + { |
| 109 | + id: 'dm_7b62c72644b9316e7e10a992', |
| 110 | + participants: [{ agent_name: 'Natty' }, { agent_name: 'test-broker-new' }], |
| 111 | + }, |
| 112 | + ]); |
| 113 | + |
| 114 | + expect(normalized[0]?.to).toBe('test-broker-new'); |
| 115 | + }); |
| 116 | + |
| 117 | + it('normalizes participant names using getRelayDmParticipantName', () => { |
| 118 | + expect(getRelayDmParticipantName({ agent_name: 'Lead', name: 'ignored' })).toBe('Lead'); |
| 119 | + expect(getRelayDmParticipantName({ agentName: 'Codex-Worker' })).toBe('Codex-Worker'); |
| 120 | + expect(getRelayDmParticipantName('Test-Broker')).toBe('Test-Broker'); |
| 121 | + expect(getRelayDmParticipantName({ username: 'human-user' })).toBe('human-user'); |
| 122 | + expect(getRelayDmParticipantName(123)).toBeNull(); |
| 123 | + }); |
| 124 | + |
96 | 125 | it('leaves non-dm and unknown dm targets unchanged', () => { |
97 | 126 | const messages: Message[] = [ |
98 | 127 | { |
|
0 commit comments