import { afterEach, beforeEach, describe, expect, it } from 'bun:test'; import { closeSessionDb, getInboundDb, initTestSessionDb } from './db/connection.js'; import { buildSystemPromptAddendum } from './destinations.js'; beforeEach(() => { initTestSessionDb(); }); afterEach(() => { closeSessionDb(); }); function seedDestination(name: string, displayName: string, channelType: string, platformId: string): void { getInboundDb() .prepare( `INSERT INTO destinations (name, display_name, type, channel_type, platform_id, agent_group_id) VALUES (?, ?, 'channel', ?, ?, NULL)`, ) .run(name, displayName, channelType, platformId); } describe('buildSystemPromptAddendum — multi-destination routing guidance', () => { it('includes default-routing nudge when there are >1 destinations', () => { seedDestination('casa', 'Casa', 'whatsapp', 'group-1@g.us'); seedDestination('whatsapp-mg-17780', 'whatsapp-mg-17780', 'whatsapp', 'phone-2@s.whatsapp.net'); const prompt = buildSystemPromptAddendum('Casa'); expect(prompt).toContain('Default routing'); expect(prompt).toContain('from="name"'); expect(prompt).toContain('`casa`'); expect(prompt).toContain('`whatsapp-mg-17780`'); }); it('omits the default-routing nudge for a single destination (short-circuited)', () => { seedDestination('casa', 'Casa', 'whatsapp', 'group-1@g.us'); const prompt = buildSystemPromptAddendum('Casa'); // Single-destination path uses the simpler "no special wrapping needed" copy expect(prompt).toContain('no special wrapping needed'); expect(prompt).not.toContain('Default routing'); }); it('handles the no-destination case without crashing', () => { const prompt = buildSystemPromptAddendum('Casa'); expect(prompt).toContain('no configured destinations'); expect(prompt).not.toContain('Default routing'); }); });