Skip to main content

๐Ÿงช MCP ADR Analysis Server Testing Guide

Comprehensive testing guide for developers and contributors

Version: 2.1.0 | Test Files: 70+ | Coverage: 100% (1,739 tests passing)


๐Ÿ“– Table of Contentsโ€‹

  1. Testing Overview
  2. Test Suite Structure
  3. Running Tests
  4. Test Categories
  5. Writing New Tests
  6. CI/CD Integration
  7. Troubleshooting Tests
  8. Performance Testing

๐ŸŽฏ Testing Overviewโ€‹

The MCP ADR Analysis Server has a comprehensive test suite with 1,739 passing tests across 70+ test files, achieving 100% test success rate. Our testing strategy follows methodological pragmatism principles with systematic verification and explicit acknowledgment of test coverage.

Test Statisticsโ€‹

  • Total Tests: 1,739 passing
  • Test Suites: 66 suites
  • Test Files: 70+ files
  • Coverage: >80% target achieved
  • Execution Time: ~34 seconds
  • Success Rate: 100%

Testing Philosophyโ€‹

  • Methodological Pragmatism: Evidence-based testing with confidence scoring
  • Integration-Focused: Real-world scenario testing over unit isolation
  • Quality Gates: Zero-tolerance for failing tests in production
  • Continuous Validation: Automated testing in CI/CD pipeline

๐Ÿ“ Test Suite Structureโ€‹

Core Test Categoriesโ€‹

tests/
โ”œโ”€โ”€ ๐Ÿ“‹ Core Framework Tests
โ”‚ โ”œโ”€โ”€ ape.test.ts # APE framework testing
โ”‚ โ”œโ”€โ”€ cache.test.ts # Caching system tests
โ”‚ โ”œโ”€โ”€ config.test.ts # Configuration validation
โ”‚ โ”œโ”€โ”€ index.test.ts # Main server tests
โ”‚ โ”œโ”€โ”€ knowledge-generation.test.ts # AI knowledge generation
โ”‚ โ”œโ”€โ”€ mcp-server.test.ts # MCP protocol tests
โ”‚ โ”œโ”€โ”€ reflexion.test.ts # Reflexion framework
โ”‚ โ””โ”€โ”€ types.test.ts # Type system validation
โ”‚
โ”œโ”€โ”€ ๐Ÿ› ๏ธ Tool Tests (18 core tools)
โ”‚ โ”œโ”€โ”€ adr-bootstrap-validation-tool.test.ts
โ”‚ โ”œโ”€โ”€ adr-suggestion-tool.test.ts
โ”‚ โ”œโ”€โ”€ content-masking-tool.test.ts
โ”‚ โ”œโ”€โ”€ deployment-analysis-tool.test.ts
โ”‚ โ”œโ”€โ”€ deployment-guidance-tool.test.ts
โ”‚ โ”œโ”€โ”€ deployment-readiness-tool.test.ts
โ”‚ โ”œโ”€โ”€ environment-analysis-tool.test.ts
โ”‚ โ”œโ”€โ”€ interactive-adr-planning-tool.test.ts
โ”‚ โ”œโ”€โ”€ mcp-planning-tool.test.ts
โ”‚ โ”œโ”€โ”€ memory-loading-tool.test.ts
โ”‚ โ”œโ”€โ”€ research-integration-tool.test.ts
โ”‚ โ”œโ”€โ”€ review-existing-adrs-tool.test.ts
โ”‚ โ”œโ”€โ”€ rule-generation-tool.test.ts
โ”‚ โ”œโ”€โ”€ smart-git-push-tool-v2.test.ts
โ”‚ โ”œโ”€โ”€ smart-git-push-tool.test.ts
โ”‚ โ”œโ”€โ”€ tool-chain-orchestrator.test.ts
โ”‚ โ””โ”€โ”€ troubleshoot-guided-workflow-tool.test.ts
โ”‚
โ”œโ”€โ”€ ๐Ÿ”ง Utility Tests
โ”‚ โ”œโ”€โ”€ ai-executor.test.ts
โ”‚ โ”œโ”€โ”€ deployment-analysis.test.ts
โ”‚ โ”œโ”€โ”€ gitleaks-detector.test.ts
โ”‚ โ”œโ”€โ”€ interactive-approval.test.ts
โ”‚ โ”œโ”€โ”€ llm-artifact-detector.test.ts
โ”‚ โ”œโ”€โ”€ location-filter.test.ts
โ”‚ โ”œโ”€โ”€ mcp-response-validator.test.ts
โ”‚ โ”œโ”€โ”€ memory-entity-manager.test.ts
โ”‚ โ”œโ”€โ”€ memory-relationship-mapper.test.ts
โ”‚ โ”œโ”€โ”€ memory-rollback-manager.test.ts
โ”‚ โ”œโ”€โ”€ memory-transformation.test.ts
โ”‚ โ”œโ”€โ”€ output-masking.test.ts
โ”‚ โ”œโ”€โ”€ prompt-composition.test.ts
โ”‚ โ”œโ”€โ”€ prompt-execution.test.ts
โ”‚ โ”œโ”€โ”€ release-readiness-detector.test.ts
โ”‚ โ”œโ”€โ”€ research-documentation.test.ts
โ”‚ โ”œโ”€โ”€ research-integration.test.ts
โ”‚ โ”œโ”€โ”€ research-questions.test.ts
โ”‚ โ”œโ”€โ”€ rule-format.test.ts
โ”‚ โ”œโ”€โ”€ rule-generation.test.ts
โ”‚ โ”œโ”€โ”€ test-helpers.test.ts
โ”‚ โ”œโ”€โ”€ test-infrastructure.test.ts
โ”‚ โ”œโ”€โ”€ todo-file-watcher.test.ts
โ”‚ โ””โ”€โ”€ tree-sitter-analyzer.test.ts
โ”‚
โ”œโ”€โ”€ ๐ŸŽฏ Prompt Tests
โ”‚ โ”œโ”€โ”€ deployment-analysis-prompts.test.ts
โ”‚ โ”œโ”€โ”€ environment-analysis-prompts.test.ts
โ”‚ โ”œโ”€โ”€ research-integration-prompts.test.ts
โ”‚ โ”œโ”€โ”€ research-question-prompts.test.ts
โ”‚ โ”œโ”€โ”€ rule-generation-prompts.test.ts
โ”‚ โ””โ”€โ”€ security-prompts.test.ts
โ”‚
โ”œโ”€โ”€ ๐Ÿ—๏ธ Integration Tests
โ”‚ โ”œโ”€โ”€ memory-migration-integration.test.ts
โ”‚ โ”œโ”€โ”€ memory-migration-simple.test.ts
โ”‚ โ””โ”€โ”€ memory-system-integration.test.ts
โ”‚
โ”œโ”€โ”€ โšก Performance Tests
โ”‚ โ””โ”€โ”€ memory-performance.test.ts
โ”‚
โ””โ”€โ”€ ๐Ÿ“Š Configuration Tests
โ””โ”€โ”€ ai-config.test.ts

๐Ÿš€ Running Testsโ€‹

Basic Test Commandsโ€‹

# Run all tests
npm test

# Run tests with coverage
npm run test:coverage

# Run tests in watch mode (development)
npm run test:watch

# Run specific test file
npm test -- tests/tools/adr-suggestion-tool.test.ts

# Run tests matching pattern
npm test -- --testNamePattern="memory"

# Run tests with verbose output
npm test -- --verbose

Advanced Test Commandsโ€‹

# Run integration tests only
npm run test:integration

# Run unit tests only
npm run test:unit

# Run performance tests
npm run test:performance

# Run advanced prompting tests
npm run test:advanced

# Run smoke tests (quick validation)
npm test -- tests/smoke.test.ts

Make Commandsโ€‹

# Run all tests (same as npm test)
make test

# Run tests with coverage report
make test-coverage

# Run lint and tests together
make check

# Clean and test
make clean test

๐ŸŽจ Test Categoriesโ€‹

1. Unit Testsโ€‹

Purpose: Test individual functions and components in isolation

// Example: Function unit test
describe('generateAdrFromDecision', () => {
it('should generate ADR with proper structure', async () => {
const decision = {
title: 'Use React for Frontend',
context: 'Need modern UI framework',
decision: 'Adopt React 18',
};

const result = await generateAdrFromDecision(decision);

expect(result.title).toBe('Use React for Frontend');
expect(result.status).toBe('proposed');
expect(result.content).toContain('## Context');
});
});

2. Integration Testsโ€‹

Purpose: Test tool interactions and workflows

// Example: Integration test
describe('Memory System Integration', () => {
it('should load ADRs and query entities', async () => {
// Load ADRs into memory
const loadResult = await memoryTool.execute({
action: 'load_adrs',
forceReload: true,
});

expect(loadResult.isError).toBeFalsy();

// Query loaded entities
const queryResult = await memoryTool.execute({
action: 'query_entities',
query: { entityTypes: ['architectural_decision'] },
});

expect(queryResult.entities.length).toBeGreaterThan(0);
});
});

3. Tool Testsโ€‹

Purpose: Test MCP tool functionality and parameters

// Example: Tool test
describe('analyze_project_ecosystem', () => {
it('should analyze project with enhanced mode', async () => {
const result = await analyzeProjectEcosystem({
projectPath: '/test/project',
enhancedMode: true,
knowledgeEnhancement: true,
analysisDepth: 'comprehensive',
});

expect(result.content).toBeDefined();
expect(result.confidence).toBeGreaterThan(0.8);
expect(result.technologies).toContain('typescript');
});
});

4. Prompt Testsโ€‹

Purpose: Validate prompt generation and AI integration

// Example: Prompt test
describe('generateAdrSuggestionPrompt', () => {
it('should generate comprehensive prompt', () => {
const prompt = generateAdrSuggestionPrompt({
projectContext: 'React application',
technologies: ['react', 'typescript'],
analysisResults: mockAnalysis,
});

expect(prompt).toContain('React application');
expect(prompt).toContain('typescript');
expect(prompt.length).toBeGreaterThan(100);
});
});

5. Performance Testsโ€‹

Purpose: Validate system performance and resource usage

// Example: Performance test
describe('Memory Performance', () => {
it('should handle large entity sets efficiently', async () => {
const startTime = Date.now();
const entities = generateLargeEntitySet(1000);

await memoryManager.batchUpsertEntities(entities);

const duration = Date.now() - startTime;
expect(duration).toBeLessThan(5000); // 5 seconds max
});
});

โœ๏ธ Writing New Testsโ€‹

Test File Templateโ€‹

/**
* Test file for [COMPONENT_NAME]
*
* Tests cover:
* - Basic functionality
* - Edge cases
* - Error handling
* - Integration scenarios
*/

import { describe, it, expect, beforeEach, afterEach } from '@jest/globals';
import { [COMPONENT_NAME] } from '../src/path/to/component.js';

describe('[COMPONENT_NAME]', () => {
beforeEach(() => {
// Setup before each test
});

afterEach(() => {
// Cleanup after each test
});

describe('basic functionality', () => {
it('should perform expected operation', () => {
// Test implementation
expect(true).toBe(true);
});
});

describe('edge cases', () => {
it('should handle empty input', () => {
// Edge case testing
});
});

describe('error handling', () => {
it('should throw on invalid input', () => {
expect(() => {
// Error condition
}).toThrow();
});
});
});

Testing Best Practicesโ€‹

1. Test Structure (AAA Pattern)โ€‹

it('should describe what it tests', () => {
// Arrange - Set up test data
const input = { test: 'data' };

// Act - Execute the function
const result = functionUnderTest(input);

// Assert - Verify the result
expect(result).toBe(expectedValue);
});

2. Descriptive Test Namesโ€‹

// โŒ Bad
it('should work', () => {});

// โœ… Good
it('should generate ADR with proper MADR format when template is specified', () => {});

3. Test Data Managementโ€‹

// Use factories for complex test data
const createMockAnalysis = (overrides = {}) => ({
projectPath: '/test/project',
technologies: ['typescript', 'react'],
confidence: 0.95,
...overrides,
});

4. Async Testingโ€‹

// Proper async test handling
it('should handle async operations', async () => {
const result = await asyncFunction();
expect(result).toBeDefined();
});

Test Coverage Requirementsโ€‹

  • Minimum Coverage: 80% (currently exceeding this)
  • Function Coverage: All exported functions must be tested
  • Branch Coverage: All conditional branches tested
  • Integration Coverage: All tool interactions tested

๐Ÿ”„ CI/CD Integrationโ€‹

GitHub Actions Workflowโ€‹

The test suite runs automatically on:

  • Pull Requests: All tests must pass
  • Push to Main: Full test suite execution
  • Scheduled: Daily test runs for regression detection
# .github/workflows/test.yml
name: Test Suite
on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
- run: npm test
- run: npm run test:coverage

Pre-commit Hooksโ€‹

Tests run automatically before commits:

# .husky/pre-commit
#!/usr/bin/env sh
npm run lint
npm test
npm run build

Quality Gatesโ€‹

  • Zero Failing Tests: No commits allowed with failing tests
  • Coverage Threshold: Must maintain >80% coverage
  • Performance Regression: Tests must complete within time limits
  • Security Validation: Security-focused tests must pass

๐Ÿ”ง Troubleshooting Testsโ€‹

Common Test Issuesโ€‹

1. Memory/Timeout Issuesโ€‹

# Increase Jest timeout
npm test -- --testTimeout=30000

# Run tests with more memory
node --max-old-space-size=4096 node_modules/.bin/jest

2. Path Resolution Issuesโ€‹

// Use dynamic path resolution
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const testWorkspace = join(__dirname, '../../test-workspace');

3. Mock Issuesโ€‹

// Proper mock cleanup
afterEach(() => {
jest.clearAllMocks();
jest.resetModules();
});

4. Tree-sitter Parser Issuesโ€‹

# Tree-sitter parsers may fail in test environment
# Tests gracefully handle parser failures
console.warn('Tree-sitter parser failed, falling back to regex analysis');

Debugging Testsโ€‹

# Run single test with debugging
node --inspect-brk node_modules/.bin/jest tests/specific-test.test.ts

# Run with verbose logging
DEBUG=* npm test

# Run with Jest debugging
npm test -- --detectOpenHandles --forceExit

โšก Performance Testingโ€‹

Performance Test Categoriesโ€‹

1. Memory Performanceโ€‹

describe('Memory Performance', () => {
it('should handle large datasets efficiently', async () => {
const startMemory = process.memoryUsage().heapUsed;

// Perform memory-intensive operation
await processLargeDataset();

const endMemory = process.memoryUsage().heapUsed;
const memoryIncrease = endMemory - startMemory;

expect(memoryIncrease).toBeLessThan(100 * 1024 * 1024); // 100MB limit
});
});

2. Execution Time Performanceโ€‹

describe('Execution Performance', () => {
it('should complete analysis within time limit', async () => {
const startTime = performance.now();

await analyzeProjectEcosystem({ projectPath: '/large/project' });

const duration = performance.now() - startTime;
expect(duration).toBeLessThan(10000); // 10 second limit
});
});

3. Concurrent Operation Performanceโ€‹

describe('Concurrency Performance', () => {
it('should handle multiple simultaneous requests', async () => {
const requests = Array(10)
.fill()
.map(() => analyzeContentSecurity({ content: 'test content' }));

const results = await Promise.all(requests);

expect(results).toHaveLength(10);
results.forEach(result => {
expect(result.isError).toBeFalsy();
});
});
});

๐Ÿ“Š Test Metrics and Reportingโ€‹

Coverage Reportsโ€‹

# Generate coverage report
npm run test:coverage

# View coverage in browser
open coverage/lcov-report/index.html

Test Resultsโ€‹

Current test metrics:

  • Total Tests: 1,739 โœ…
  • Test Suites: 66 โœ…
  • Success Rate: 100% โœ…
  • Execution Time: ~34 seconds โœ…
  • Coverage: >80% target achieved โœ…

Continuous Monitoringโ€‹

  • Daily Test Runs: Automated regression detection
  • Performance Tracking: Monitor test execution times
  • Coverage Tracking: Ensure coverage doesn't decrease
  • Flaky Test Detection: Identify unstable tests

๐ŸŽฏ Contributing to Testsโ€‹

Adding New Testsโ€‹

  1. Identify Test Category: Unit, integration, or performance
  2. Follow Naming Convention: component-name.test.ts
  3. Use Test Template: Follow established patterns
  4. Ensure Coverage: Test all branches and edge cases
  5. Add Documentation: Document complex test scenarios

Test Review Checklistโ€‹

  • Tests follow AAA pattern (Arrange, Act, Assert)
  • Descriptive test names explain what is being tested
  • Edge cases and error conditions covered
  • No hardcoded paths or environment-specific code
  • Proper async/await handling
  • Mock cleanup in afterEach hooks
  • Performance considerations addressed

๐Ÿ“š Additional Resourcesโ€‹


๐Ÿงช Your test suite is comprehensive and production-ready with 100% success rate!

This testing guide follows methodological pragmatism principles with systematic verification and explicit acknowledgment of test coverage and limitations.