Skip to main content
Glama

Polymarket MCP Server

TEST_SUMMARY.mdβ€’13.9 kB
# Test Implementation Summary Comprehensive testing and CI/CD improvements for the Polymarket MCP Server. ## What Was Implemented ### 1. GitHub Actions Workflows #### Main Test Workflow (.github/workflows/tests.yml) **Comprehensive CI/CD pipeline with 11 parallel job stages:** - **Smoke Test** - Quick validation (5 min timeout) - Runs first to fail fast - Tests basic imports and API connectivity - **Lint & Format** - Code quality checks - Ruff linting with GitHub annotations - Black formatting validation - MyPy type checking - Bandit security scanning - Safety dependency vulnerability checks - Uploads security reports as artifacts - **Unit Tests** - Matrix testing across platforms - Python versions: 3.10, 3.11, 3.12 - Operating systems: Ubuntu, macOS, Windows - Parallel execution with pytest-xdist - Demo mode testing - 15 min timeout per matrix job - **Coverage** - Code coverage analysis - 80% minimum coverage requirement - HTML, XML, and terminal reports - Uploads to Codecov - Stores HTML report as artifact - **Integration Tests** - Real API testing - Tests Gamma API connectivity - Tests CLOB API connectivity - Validates market discovery tools - 10 min timeout - **End-to-End Tests** - Complete workflow validation - Server initialization - Tool execution - Response validation - 15 min timeout - **Performance Tests** - Benchmarks - API latency measurements - Concurrent request handling - Memory usage tracking - Results saved to JSON - **Docker Tests** - Container validation - Builds Docker image (if Dockerfile exists) - Tests container functionality - 15 min timeout - **Install Script Tests** - Installation validation - Tests on Ubuntu and macOS - Validates pip installation - Checks package imports - **Tool Verification** - Tool count validation - Ensures 25+ tools available in read-only mode - Validates tool module imports - **Test Summary** - Aggregate results - Collects all job results - Prints comprehensive summary - Fails if critical tests failed **Triggers:** - Push to main/develop branches - Pull requests to main/develop - Daily schedule (2 AM UTC) - catches API changes #### Release Workflow (.github/workflows/release.yml) **Automated release pipeline:** 1. **Pre-Release Tests** - Full test suite 2. **Build Package** - Python package build with twine validation 3. **Docker Build** - Multi-architecture Docker images 4. **Changelog Generation** - Auto-generated from commits 5. **GitHub Release** - Creates release with artifacts 6. **PyPI Publishing** - Publishes to PyPI (with trusted publishing) 7. **Documentation Update** - Updates version badges 8. **Notifications** - Release status summary **Triggers:** Version tags (v*.*.*) ### 2. Pre-commit Hooks (.pre-commit-config.yaml) **17 automated checks before commits:** **File Checks:** - Trailing whitespace removal - End-of-file fixing - YAML/JSON/TOML validation - Large file detection (1MB limit) - Merge conflict detection - Private key detection - Line ending normalization **Code Quality:** - Black formatting (100 char line length) - isort import sorting - Ruff linting with auto-fix - MyPy type checking - Pydocstyle (Google convention) **Security:** - Bandit security scanning - detect-secrets baseline checking **Testing:** - Fast unit tests (commit stage) - Import verification **Usage:** ```bash pip install pre-commit pre-commit install pre-commit run --all-files ``` ### 3. Test Suites #### Integration Tests (tests/test_integration.py) **Comprehensive real API testing - NO MOCKS:** - **TestAPIConnectivity** (4 tests) - Gamma API market discovery - CLOB API ping - Trending markets endpoint - Market details retrieval - **TestMarketDiscovery** (3 tests) - Market search functionality - Category filtering - Closing soon markets - **TestMarketAnalysis** (2 tests) - Orderbook retrieval - Market volume data - **TestErrorHandling** (3 tests) - Invalid market ID handling - Invalid token ID handling - Malformed request handling - **TestRateLimiting** (2 tests) - Rapid request handling - Concurrent different endpoints - **TestDemoMode** (2 tests) - Demo mode initialization - No credentials operation - **TestWebSocketConnectivity** (1 test) - WebSocket connection validation - **TestSafetyValidation** (2 tests) - Safety limits initialization - Order size validation - **Full Integration Flow** (1 test) - Complete discoverβ†’analyzeβ†’validate workflow **Total: 20 integration tests** #### End-to-End Tests (tests/test_e2e.py) **Complete lifecycle testing:** - **TestServerInitialization** (3 tests) - Package imports - Configuration loading - Tool availability - **TestToolExecution** (4 tests) - search_markets tool - get_trending_markets tool - filter_markets_by_category tool - get_market_details tool - **TestResourceAccess** (2 tests) - Status resource reading - Config resource reading - **TestErrorScenarios** (3 tests) - Invalid arguments handling - Missing required arguments - Unknown tool calls - **TestFullWorkflow** (2 tests) - Market discovery workflow - Market analysis workflow - **TestInstallationFlow** (3 tests) - Package structure validation - pyproject.toml validation - README existence - **Complete E2E Flow** (1 test) - Initializeβ†’List Toolsβ†’Executeβ†’Validateβ†’Cleanup **Total: 18 E2E tests** #### Performance Tests (tests/test_performance.py) **Comprehensive benchmarking:** - **TestAPIPerformance** (3 benchmarks) - Market search latency - Market details latency - CLOB API latency - **TestConcurrentPerformance** (2 tests) - Concurrent market searches - Mixed endpoint requests - **TestRateLimiterPerformance** (2 tests) - Rate limiter overhead - Concurrent rate checking - **TestMemoryUsage** (2 tests) - Tool execution memory - Concurrent execution memory - **TestToolPerformance** (3 benchmarks) - Search tool performance - Trending tool performance - Filter tool performance - **TestStressScenarios** (2 tests) - Rapid tool execution (50 requests) - Sustained load (10 seconds) - **TestWebSocketPerformance** (1 test) - WebSocket connection time **Total: 15 performance tests** **Metrics tracked:** - Response times - Throughput (req/s) - Memory usage (MB) - Success rates - Concurrency handling ### 4. Smoke Test (smoke_test.py) **Quick validation script (runs in ~10 seconds):** Tests: 1. Project structure validation 2. Package imports 3. Configuration loading 4. API connectivity (Gamma + CLOB) 5. Tool initialization (45 tools) 6. Basic tool execution 7. Rate limiter functionality 8. Safety limits initialization **Output:** - Colored terminal output (green/red/yellow) - Individual test results - Summary statistics - Exit code (0=pass, 1=fail) **Usage:** ```bash python smoke_test.py # Or in CI ./smoke_test.py ``` ### 5. Testing Documentation (TESTING.md) **Comprehensive 400+ line guide covering:** - Test categories and philosophy - Running tests (15+ command examples) - Test markers and filtering - Writing tests (best practices) - CI/CD pipeline details - Coverage reporting - Performance benchmarking - Troubleshooting guide **Key sections:** - Quick start guide - Common commands - Test markers - Environment variables - Best practices (NO MOCKS policy) - Async testing - Parametrized tests - Pre-commit hooks - Coverage configuration - Benchmark usage ### 6. Configuration Updates #### pyproject.toml **Enhanced testing dependencies:** ```toml [project.optional-dependencies] dev = [ # Testing (6 packages) "pytest>=8.0.0", "pytest-asyncio>=0.23.0", "pytest-cov>=4.1.0", "pytest-xdist>=3.5.0", "pytest-timeout>=2.2.0", "pytest-benchmark>=4.0.0", # Code quality (4 packages) "black>=24.0.0", "ruff>=0.3.0", "mypy>=1.8.0", "isort>=5.13.0", # Security (2 packages) "bandit>=1.7.0", "safety>=3.0.0", # Utilities (3 packages) "httpx>=0.27.0", "psutil>=5.9.0", "websockets>=12.0", ] ``` **Test configuration:** - Custom markers (integration, slow, real_api, performance) - Timeout settings (120s default) - Coverage configuration (80% minimum) - MyPy settings - isort configuration #### Coverage Configuration ```toml [tool.coverage.run] source = ["src/polymarket_mcp"] branch = true [tool.coverage.report] precision = 2 show_missing = true skip_covered = false exclude_lines = [...] # Standard exclusions ``` #### Pytest Configuration ```toml [tool.pytest.ini_options] asyncio_mode = "auto" testpaths = ["tests"] markers = [...] addopts = ["--strict-markers", "--tb=short", "--maxfail=10"] timeout = 120 ``` ### 7. Additional Files **conftest.py** - Pytest configuration - Custom marker registration - Shared fixtures (test_env_vars, clean_env, api_config) - Benchmark customization **.codecov.yml** - Codecov configuration - 80% coverage target - Patch coverage requirements - Ignore patterns - Comment layout **.secrets.baseline** - Secret detection baseline - detect-secrets configuration - Prevents false positives ## Testing Strategy ### NO MOCKS Policy All tests use real services: - Real Polymarket APIs - Real WebSocket connections - Real HTTP clients - No mocked responses **Benefits:** - Tests reflect actual behavior - API changes caught immediately - Integration issues discovered early - Realistic performance data ### Test Pyramid ``` /\ /E2E\ 18 tests - Complete workflows /------\ / INT \ 20 tests - Real API integration /--------\ / UNIT \ Fast tests - Individual components /------------\ / SMOKE \ Quick validation - 8 tests /----------------\ ``` ### Test Execution Levels **Level 1: Smoke Test** (~10s) ```bash python smoke_test.py ``` Quick validation before commits **Level 2: Fast Unit Tests** (~30s) ```bash pytest -m "not slow and not integration" ``` Pre-push validation **Level 3: Full Test Suite** (~5min) ```bash pytest tests/ ``` Pre-release validation **Level 4: Complete + Benchmarks** (~10min) ```bash pytest tests/ --benchmark-only pytest tests/ --cov --cov-report=html ``` Release validation ## CI/CD Pipeline Flow ### On Push/PR: 1. **Smoke Test** (fail fast) β†’ 2. **Lint & Security** (parallel) β†’ 3. **Unit Tests** (matrix: 3 Python Γ— 3 OS) β†’ 4. **Coverage** + **Integration** + **Performance** (parallel) β†’ 5. **E2E Tests** β†’ 6. **Verification** (tools, Docker, install) β†’ 7. **Summary** ### On Tag Push (v*.*.* ): 1. **Full Test Suite** β†’ 2. **Build** (Python package + Docker) β†’ 3. **Changelog** β†’ 4. **Release** (GitHub + PyPI) β†’ 5. **Docs Update** β†’ 6. **Notify** ## Quality Gates ### Pre-Commit: - βœ… Code formatted (black) - βœ… Imports sorted (isort) - βœ… Linting passed (ruff) - βœ… No security issues (bandit) - βœ… Fast tests passed ### Pre-Push: - βœ… Smoke test passed - βœ… Unit tests passed - βœ… No type errors (mypy) ### Pre-Merge: - βœ… All CI tests passed - βœ… Coverage β‰₯80% - βœ… Integration tests passed - βœ… E2E tests passed ### Pre-Release: - βœ… Full test suite passed - βœ… Performance benchmarks acceptable - βœ… Security scan clean - βœ… Package builds successfully ## Metrics & Monitoring ### Coverage Targets: - **Minimum**: 80% (CI enforced) - **Target**: 90%+ - **Report**: HTML + XML + Terminal ### Performance Targets: - **API Latency**: <500ms - **Tool Execution**: <1s - **Concurrent Throughput**: >10 req/s - **Memory Increase**: <100MB ### Success Rates: - **Unit Tests**: 100% - **Integration**: β‰₯80% (API dependent) - **E2E**: 100% - **Stress Tests**: β‰₯80% ## Files Created 1. `.github/workflows/tests.yml` (468 lines) 2. `.github/workflows/release.yml` (250 lines) 3. `.pre-commit-config.yaml` (180 lines) 4. `tests/test_integration.py` (450 lines) 5. `tests/test_e2e.py` (550 lines) 6. `tests/test_performance.py` (450 lines) 7. `tests/conftest.py` (100 lines) 8. `TESTING.md` (600 lines) 9. `smoke_test.py` (250 lines) 10. `.codecov.yml` (40 lines) 11. `.secrets.baseline` (60 lines) 12. Updated `pyproject.toml` (coverage + test config) **Total: ~3,400 lines of testing infrastructure** ## Usage Examples ### Local Development: ```bash # Quick check python smoke_test.py # Run tests during development pytest tests/ -m "not slow" -n auto # Check coverage pytest tests/ --cov --cov-report=html open htmlcov/index.html # Run benchmarks pytest tests/test_performance.py --benchmark-only ``` ### Pre-commit: ```bash # Install hooks pip install pre-commit pre-commit install # Run all hooks pre-commit run --all-files # Skip for quick commit SKIP=pytest-fast git commit -m "WIP" ``` ### CI/CD: ```bash # Trigger tests (automatic on push) git push origin feature-branch # Trigger release git tag v1.0.0 git push origin v1.0.0 ``` ## Benefits Delivered βœ… **Comprehensive Testing** - 53+ tests across 4 categories βœ… **NO MOCKS** - All real API testing βœ… **Fast Feedback** - Smoke test in 10s βœ… **Quality Gates** - 80% coverage enforced βœ… **Security** - Automated scanning (bandit, safety) βœ… **Performance** - Benchmarks tracked βœ… **Multi-platform** - Tests on Ubuntu, macOS, Windows βœ… **Multi-version** - Python 3.10, 3.11, 3.12 βœ… **Automated Release** - Tag-based deployment βœ… **Documentation** - Comprehensive guide βœ… **Pre-commit Hooks** - 17 automated checks ## Next Steps 1. **Run smoke test**: `python smoke_test.py` 2. **Install pre-commit**: `pre-commit install` 3. **Run full test suite**: `pytest tests/ -v` 4. **Check coverage**: `pytest tests/ --cov` 5. **Review TESTING.md** for detailed guide 6. **Push to trigger CI**: Tests run automatically ## Support - **TESTING.md** - Complete testing guide - **GitHub Actions** - Logs available in Actions tab - **Coverage Reports** - HTML reports in artifacts - **Benchmark Results** - JSON in artifacts

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/caiovicentino/polymarket-mcp-server'

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