Skip to content

Testing Guide

Sekha maintains high code quality standards across all repositories with comprehensive testing and continuous integration.

Coverage Dashboard

Repository Coverage CI Status Testing Framework
sekha-controller codecov CI cargo test + tarpaulin
sekha-llm-bridge codecov CI pytest + pytest-cov
sekha-python-sdk codecov CI pytest + pytest-cov
sekha-js-sdk codecov CI vitest
sekha-mcp codecov CI pytest + pytest-cov
sekha-cli codecov CI pytest + pytest-cov
sekha-vscode codecov CI vitest/mocha

Testing Standards by Language

Rust (sekha-controller)

Linting & Formatting:

cargo fmt -- --check
cargo clippy --all-targets --all-features

Running Tests:

# All tests
cargo test

# Unit tests only
cargo test --lib

# Integration tests
cargo test --test integration

# API tests
cargo test --test api_test

# Benchmarks
cargo test --release --test benchmark

Coverage:

# Install tarpaulin
cargo install cargo-tarpaulin --locked

# Generate coverage report
cargo tarpaulin --out Html --output-dir coverage

# Open report
open coverage/index.html

Python (bridge, SDKs, CLI, MCP)

Linting & Formatting:

# Using ruff (modern, fast)
ruff check .
ruff format --check .

# Or black (traditional)
black --check .

Running Tests:

# Install dependencies
pip install -e ".[test]"

# Run all tests
pytest

# With coverage
pytest --cov=<module> --cov-report=html

# Verbose output
pytest -v

# Specific test file
pytest tests/test_client.py

Coverage:

pytest --cov=<module> --cov-report=term-missing
pytest --cov=<module> --cov-report=html
open htmlcov/index.html

TypeScript/JavaScript (JS SDK, VS Code)

Linting & Formatting:

npm run lint
# or
yarn lint

Running Tests:

# Run all tests
npm test

# With coverage
npm run test:coverage

# Watch mode
npm run test:watch

# Specific test
npm test -- path/to/test.spec.ts

Coverage:

npm run test:coverage
open coverage/index.html

CI/CD Pipelines

All repositories use GitHub Actions for continuous integration.

Controller CI Workflow

# .github/workflows/ci.yml
jobs:
  test-controller:
    steps:
      - cargo fmt -- --check
      - cargo clippy
      - cargo test --lib
      - cargo test --test integration
      - cargo test --test api_test
      - cargo tarpaulin --out Xml
      - Upload to codecov

Python CI Workflow

# .github/workflows/ci.yml
jobs:
  test:
    steps:
      - ruff check .
      - ruff format --check .
      - pytest --cov --cov-report=xml
      - Upload to codecov

TypeScript CI Workflow

# .github/workflows/ci.yml
jobs:
  test:
    steps:
      - npm run lint
      - npm test -- --coverage
      - Upload to codecov

Writing Tests

Unit Tests

Unit tests should be fast, isolated, and test single units of functionality.

Rust Example:

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_conversation_label_validation() {
        let result = validate_label("Valid Label");
        assert!(result.is_ok());
    }
}

Python Example:

def test_client_initialization():
    config = ClientConfig(
        api_key="test-key",
        base_url="http://localhost:8080"
    )
    client = SekhaClient(config)
    assert client.config.api_key == "test-key"

TypeScript Example:

describe('MemoryController', () => {
  it('should initialize with config', () => {
    const memory = new MemoryController({
      apiKey: 'test-key',
      baseURL: 'http://localhost:8080'
    });
    expect(memory.config.apiKey).toBe('test-key');
  });
});

Integration Tests

Integration tests verify multiple components working together.

Controller Integration Test:

#[tokio::test]
async fn test_full_conversation_flow() {
    let app = setup_test_app().await;

    // Store conversation
    let response = app.post("/api/v1/conversations")
        .json(&new_conversation)
        .send()
        .await;

    assert_eq!(response.status(), 201);
}

Test Data

Use fixtures and factories for consistent test data.

Python Fixtures:

@pytest.fixture
def sample_conversation():
    return NewConversation(
        label="Test Conversation",
        folder="/test",
        messages=[
            MessageDto(role="user", content="Test message")
        ]
    )

def test_create_conversation(sample_conversation):
    result = client.create_conversation(sample_conversation)
    assert result.id is not None

Coverage Goals

  • Controller (Rust): >80% (enforced in CI)
  • LLM Bridge (Python): >80%
  • Python SDK: >90% (highest standard)
  • JS SDK: >80%
  • MCP Server: >80%
  • CLI: >80%
  • VS Code: >70% (UI testing harder)

Running Tests Locally

Before Submitting PR

# 1. Format code
cargo fmt  # or ruff format . or npm run format

# 2. Lint
cargo clippy  # or ruff check . or npm run lint

# 3. Run all tests
cargo test  # or pytest or npm test

# 4. Check coverage
cargo tarpaulin  # or pytest --cov or npm run test:coverage

Quick Test Script

Each repo has a scripts/test.sh for convenience:

./scripts/test.sh          # Run all tests
./scripts/test.sh lint     # Lint only
./scripts/test.sh unit     # Unit tests only
./scripts/test.sh coverage # With coverage report

Troubleshooting Tests

Tests Fail Locally But Pass in CI

  • Check service dependencies (Chroma, Redis, Ollama)
  • Verify environment variables match CI
  • Check file permissions

Flaky Integration Tests

  • Add proper waits for async operations
  • Use test isolation (separate databases)
  • Increase timeouts for slow operations

Low Coverage

  • Focus on business logic first
  • Mock external dependencies
  • Use coverage reports to find gaps

Contributing Tests

When adding new features:

  1. Write tests FIRST (TDD approach)
  2. Ensure tests pass locally
  3. Check coverage meets repo standards
  4. Update this guide if adding new patterns

See Contributing Guide for full workflow.

Resources