/** * Unit tests for centralized enums in @illuma-ai/agents. * Verifies enum values remain stable — these are part of the public API * and are referenced by host validation schemas and MongoDB documents. */ import { EdgeType, Constants, Providers, FinishReasons, MessageTypes, GraphEvents, GraphNodeKeys, ContentTypes, StepTypes, ToolCallTypes, EnvVar, } from '@/common'; describe('EdgeType enum', () => { it('has correct HANDOFF value (one-way routing — parent exits, child takes over)', () => { expect(EdgeType.HANDOFF).toBe('handoff'); }); it('has correct DIRECT value (fixed graph edges with Ranger fan-in / parallel / approval-gate logic)', () => { expect(EdgeType.DIRECT).toBe('direct'); }); it('has two members: handoff, direct', () => { const values = Object.values(EdgeType); expect(values).toHaveLength(2); expect(values).toEqual(expect.arrayContaining(['handoff', 'direct'])); }); }); describe('Constants enum', () => { it('has ASK_USER for the HITL structured question tool', () => { expect(Constants.ASK_USER).toBe('ask_user'); }); it('has EXECUTE_CODE for code execution tool', () => { expect(Constants.EXECUTE_CODE).toBe('execute_code'); }); it('has LC_TRANSFER_TO_ prefix for LangChain handoff routing tools', () => { expect(Constants.LC_TRANSFER_TO_).toBe('lc_transfer_to_'); }); it('has MCP_DELIMITER for MCP tool naming', () => { expect(Constants.MCP_DELIMITER).toBe('_mcp_'); }); }); describe('Providers enum', () => { it('has all expected provider values', () => { expect(Providers.OPENAI).toBe('openAI'); expect(Providers.BEDROCK).toBe('bedrock'); expect(Providers.ANTHROPIC).toBe('anthropic'); expect(Providers.GOOGLE).toBe('google'); expect(Providers.AZURE).toBe('azureOpenAI'); expect(Providers.DEEPSEEK).toBe('deepseek'); expect(Providers.OPENROUTER).toBe('openrouter'); expect(Providers.XAI).toBe('xai'); }); }); describe('FinishReasons enum', () => { it('has max_tokens for Anthropic/Bedrock truncation detection', () => { expect(FinishReasons.MAX_TOKENS).toBe('max_tokens'); }); it('has length for OpenAI/Azure truncation detection', () => { expect(FinishReasons.LENGTH).toBe('length'); }); it('has stop and end_turn for normal completion', () => { expect(FinishReasons.STOP).toBe('stop'); expect(FinishReasons.END_TURN).toBe('end_turn'); }); it('has tool_use and tool_calls for tool invocation signals', () => { expect(FinishReasons.TOOL_USE).toBe('tool_use'); expect(FinishReasons.TOOL_CALLS).toBe('tool_calls'); }); }); describe('MessageTypes enum', () => { it('has all LangChain message types for instanceof-free checks', () => { expect(MessageTypes.HUMAN).toBe('human'); expect(MessageTypes.AI).toBe('ai'); expect(MessageTypes.SYSTEM).toBe('system'); expect(MessageTypes.TOOL).toBe('tool'); expect(MessageTypes.FUNCTION).toBe('function'); expect(MessageTypes.DEVELOPER).toBe('developer'); expect(MessageTypes.REMOVE).toBe('remove'); }); }); describe('GraphEvents enum', () => { it('has custom multi-agent events', () => { expect(GraphEvents.ON_AGENT_UPDATE).toBe('on_agent_update'); expect(GraphEvents.ON_RUN_STEP).toBe('on_run_step'); expect(GraphEvents.ON_MESSAGE_DELTA).toBe('on_message_delta'); expect(GraphEvents.ON_REASONING_DELTA).toBe('on_reasoning_delta'); expect(GraphEvents.ON_STRUCTURED_OUTPUT).toBe('on_structured_output'); expect(GraphEvents.ON_TOOL_EXECUTE).toBe('on_tool_execute'); expect(GraphEvents.ON_TOOL_APPROVAL_REQUIRED).toBe( 'on_tool_approval_required' ); }); it('has standard LangChain events', () => { expect(GraphEvents.CHAT_MODEL_START).toBe('on_chat_model_start'); expect(GraphEvents.CHAT_MODEL_STREAM).toBe('on_chat_model_stream'); expect(GraphEvents.CHAT_MODEL_END).toBe('on_chat_model_end'); expect(GraphEvents.TOOL_START).toBe('on_tool_start'); expect(GraphEvents.TOOL_END).toBe('on_tool_end'); }); }); describe('ContentTypes enum', () => { it('has provider-specific reasoning content types', () => { expect(ContentTypes.THINK).toBe('think'); expect(ContentTypes.THINKING).toBe('thinking'); expect(ContentTypes.REASONING).toBe('reasoning'); expect(ContentTypes.REASONING_CONTENT).toBe('reasoning_content'); }); }); describe('EnvVar enum', () => { it('has code executor environment variable names', () => { expect(EnvVar.CODE_API_KEY).toBe('CODE_EXECUTOR_API_KEY'); expect(EnvVar.CODE_BASEURL).toBe('CODE_EXECUTOR_BASEURL'); }); });