Skip to content
This repository was archived by the owner on Jul 11, 2026. It is now read-only.
This repository was archived by the owner on Jul 11, 2026. It is now read-only.

[Testing] Add Unit Test Suite for Core Services and Handlers #23

Description

@gloomcheng

Summary

The codebase currently has no unit tests for the src/ folder. Test coverage analysis shows:

  • 0 test files in src/
  • 154 untested source files
  • 0% test coverage

Scope

Priority 1: Core Services (High Value)

Services with complex logic that would benefit most from testing:

  • code-quality-service.ts - Complexity analysis, scoring algorithm
  • security-service.ts - Pattern matching, vulnerability detection
  • architecture-service.ts - Glob pattern matching, validation rules
  • documentation-service.ts - JSDoc parsing, coverage calculation
  • performance-analyzer.ts - Anti-pattern detection
  • test-coverage/ - Test parsing, smell detection

Priority 2: MCP Handlers (21 handlers)

  • Analysis handlers (7): architecture, ci-pipeline, code-quality, documentation, impact-analysis, performance-analysis, test-coverage
  • Project handlers (7): constitution, danger-zone, dependency, environment, onboard, release, resource
  • Workflow handlers (4): execution, planning, spec, status
  • Other handlers (3): checkpoint, memory, security, team-knowledge, pr-review

Priority 3: Infrastructure

  • registry/tool-registry.ts - Tool discovery, schema generation
  • decorators/ - @mcptool, @MCPParam decorators
  • server.ts - MCP server initialization

Suggested Approach

  1. Setup: Configure Vitest (faster than Jest, native ESM support)
  2. Test Structure: Mirror src/ structure in tests/
  3. Mocking: Use dependency injection for testable services
  4. Coverage Target: Start with 60%, aim for 80%

Test Framework Setup

npm install -D vitest @vitest/coverage-v8
// vitest.config.ts
export default {
  test: {
    globals: true,
    environment: 'node',
    coverage: {
      provider: 'v8',
      reporter: ['text', 'html'],
      include: ['src/**/*.ts'],
      exclude: ['src/**/*.d.ts']
    }
  }
}

Example Test Structure

tests/
├── core/
│   └── mcp/
│       ├── services/
│       │   ├── code-quality-service.test.ts
│       │   ├── security-service.test.ts
│       │   └── architecture-service.test.ts
│       ├── handlers/
│       │   └── analysis/
│       │       └── code-quality-handler.test.ts
│       └── registry/
│           └── tool-registry.test.ts

Acceptance Criteria

  • Vitest configured with coverage reporting
  • At least 10 core service test files created
  • At least 5 handler test files created
  • Minimum 60% code coverage achieved
  • CI pipeline runs tests on PR
  • npm test command works

References

  • Test coverage analysis tool: test-coverage-analyze
  • Current untested files: 154

Activity

  1. gloomcheng commented on Dec 26, 2025

    @gloomcheng
    ContributorAuthor

    Implemented in commit 3779fc5

    Added unit test suite with Vitest:

    • 74 tests all passing
    • Coverage reporting with v8 provider
    • Tests for decorators, registry, and services

    Test coverage areas:

    • @MCPTool decorator metadata storage and inheritance
    • MCPToolRegistry handler registration and tool execution
    • CodeQualityService scoring algorithm
    • ArchitectureService pattern matching
    • SecurityService entropy calculation, severity filtering

    Run tests with:

    npm test           # Run tests
    npm run test:watch # Watch mode
    npm run test:coverage # With coverage report
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions