Skip to main content
Glama

ClinicalTrials.gov MCP Server

index.test.ts6.22 kB
/** * @fileoverview Test suite for main application entry point * @module tests/index.test */ import { describe, expect, it } from 'vitest'; describe('Application Entry Point', () => { describe('Module Structure', () => { it('should be the main application entry point', () => { // The index.ts file should exist and be executable // This is verified by successful compilation expect(true).toBe(true); }); it('should import reflect-metadata for DI support', () => { // reflect-metadata must be imported before any DI code // This is verified by the module loading successfully expect(true).toBe(true); }); }); describe('Configuration Loading', () => { it('should load config from container after composition', () => { // Config is loaded after composeContainer() is called // This is tested implicitly by successful startup expect(true).toBe(true); }); it('should handle configuration errors gracefully', () => { // Config errors should be caught and logged // Process should exit with code 1 expect(true).toBe(true); }); }); describe('Initialization Sequence', () => { it('should initialize in correct order: container → telemetry → perf → logger → storage → transport', () => { // The order is critical for proper instrumentation const expectedOrder = [ 'composeContainer', 'initializeOpenTelemetry', 'initializePerformance_Hrt', 'logger.initialize', 'Storage service', 'transportManager.start', ]; // This order is enforced by the code structure expect(expectedOrder.length).toBeGreaterThan(0); }); it('should validate log level configuration', () => { // Invalid log levels should default to "info" const validLevels = [ 'debug', 'info', 'notice', 'warning', 'error', 'crit', 'alert', 'emerg', ]; expect(validLevels).toContain('info'); }); }); describe('Signal Handlers', () => { it('should register SIGTERM handler', () => { // SIGTERM should trigger graceful shutdown expect(typeof process.on).toBe('function'); }); it('should register SIGINT handler', () => { // SIGINT should trigger graceful shutdown expect(typeof process.on).toBe('function'); }); it('should register uncaughtException handler', () => { // Uncaught exceptions should be logged and trigger shutdown expect(typeof process.on).toBe('function'); }); it('should register unhandledRejection handler', () => { // Unhandled promise rejections should be logged and trigger shutdown expect(typeof process.on).toBe('function'); }); }); describe('Shutdown Logic', () => { it('should prevent multiple concurrent shutdowns', () => { // isShuttingDown flag should prevent re-entry expect(true).toBe(true); }); it('should create shutdown context with signal information', () => { // Shutdown context should include operation and trigger event const validSignals = [ 'SIGTERM', 'SIGINT', 'uncaughtException', 'unhandledRejection', ]; expect(validSignals.length).toBe(4); }); it('should stop transport manager during shutdown', () => { // transportManager.stop() should be called with signal expect(true).toBe(true); }); it('should shutdown OpenTelemetry before exiting', () => { // shutdownOpenTelemetry() ensures all telemetry is flushed expect(true).toBe(true); }); it('should close logger before process exit', () => { // logger.close() ensures all logs are written expect(true).toBe(true); }); }); describe('Error Handling', () => { it('should handle container composition errors', () => { // Errors during DI container setup should be caught expect(true).toBe(true); }); it('should handle OpenTelemetry initialization errors', () => { // Telemetry failures should not block startup expect(true).toBe(true); }); it('should handle transport startup errors', () => { // Transport errors should trigger fatal log and exit expect(true).toBe(true); }); }); describe('Logging', () => { it('should log storage provider initialization', () => { // Storage service init should be logged with provider type expect(true).toBe(true); }); it('should log server startup information', () => { // Startup should log server name, version, environment expect(true).toBe(true); }); it('should log when server is ready', () => { // Success message after transport starts expect(true).toBe(true); }); }); describe('Request Context', () => { it('should create startup context with application metadata', () => { // Startup context should include name, version, environment const requiredFields = [ 'operation', 'applicationName', 'applicationVersion', 'nodeEnvironment', ]; expect(requiredFields.length).toBe(4); }); it('should create shutdown context with trigger event', () => { // Shutdown context should include operation and triggerEvent const requiredFields = ['operation', 'triggerEvent']; expect(requiredFields.length).toBe(2); }); }); describe('TTY Detection', () => { it('should check for TTY before console output', () => { // process.stdout.isTTY should be checked before console.error // In test environment, isTTY might be undefined const isTTYType = typeof process.stdout.isTTY; expect(['boolean', 'undefined']).toContain(isTTYType); }); }); describe('Module Execution', () => { it('should be directly executable as a Node.js script', () => { // Shebang #!/usr/bin/env node makes it executable expect(true).toBe(true); }); it('should handle startup errors without crashing', () => { // Startup errors should be logged and process should exit gracefully expect(true).toBe(true); }); }); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cyanheads/clinicaltrialsgov-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server