Skip to Content

Running Tests

Prerequisites

Before running any tests, ensure you have the following installed:

  • Python 3.12 via pyenv (pinned in .python-version at repo root)
  • Poetry for dependency management
  • Docker and Docker Compose (required for flaring-monitor integration tests and the full integration test script)

Per-Service Test Commands

Each Python service has its own test suite. Navigate to the service directory and run pytest through Poetry:

# General pattern cd services/{service-name} poetry install # Install dependencies (first time or after changes) poetry run pytest # Run all tests # With verbose output poetry run pytest -v # Run a specific test file poetry run pytest tests/test_api.py # Run a specific test class or method poetry run pytest tests/test_api.py::TestCreateApproval::test_create_named_individual

Quick Reference

ServiceDirectoryCommand
Memory Serviceservices/memory-servicecd services/memory-service && poetry run pytest
Approval Serviceservices/approval-servicecd services/approval-service && poetry run pytest
Auth Serviceservices/auth-servicecd services/auth-service && poetry run pytest
Ingestion Serviceservices/ingestion-servicecd services/ingestion-service && poetry run pytest
Compliance Monitorservices/compliance-monitorcd services/compliance-monitor && poetry run pytest
Flaring Monitorservices/flaring-monitorcd services/flaring-monitor && poetry run pytest
Knowledge Graph Serviceservices/knowledge-graph-servicecd services/knowledge-graph-service && poetry run pytest
Orchestration Engineservices/orchestration-enginecd services/orchestration-engine && poetry run pytest

Pytest Configuration

All services share the same pytest configuration in their pyproject.toml:

[tool.pytest.ini_options] asyncio_mode = "auto"

This single setting enables automatic handling of async def test_* functions without needing @pytest.mark.asyncio decorators. There is no separate pytest.ini or setup.cfg — all configuration lives in pyproject.toml.

Running All Service Tests

To run tests across all services in sequence:

# From the repo root for svc in memory-service approval-service auth-service ingestion-service \ compliance-monitor flaring-monitor knowledge-graph-service \ orchestration-engine; do echo "=== Testing $svc ===" (cd "services/$svc" && poetry run pytest -v) || echo "FAILED: $svc" done

Most services run entirely in-memory with no external dependencies. The exception is flaring-monitor, which requires a running PostgreSQL instance for its integration tests. Start infrastructure first with docker compose up -d.

Integration Test Runner

The full end-to-end integration test is at infrastructure/scripts/integration-test.sh. It tests the entire AEGIS platform pipeline from data ingestion through agent execution to HITL approval.

Prerequisites for Integration Tests

All services must be running:

# Start all infrastructure and services ./infrastructure/scripts/start-all.sh

This boots Docker infrastructure (PostgreSQL, Redis, Kafka), all 8 Python services, and the Go API gateway.

Running the Integration Test

./infrastructure/scripts/integration-test.sh

What the Integration Test Covers

The script runs 7 sequential steps, each with pass/fail verification:

StepWhat It Tests
1. Health checksEvery service responds with HTTP 200 on /health (ports 8001-8009 and gateway 8000)
2. AuthenticationObtains a JWT token by posting the test email/password (AEGIS_TEST_EMAIL / AEGIS_TEST_PASSWORD, default admin@aegis.local / aegis-dev-admin) to /api/v1/auth/token
3. Data ingestionTriggers the RRC scraper endpoint, verifies 20 wells and other entity types are extracted
4. Knowledge graphAssembles context for well 42-329-40001-0000 (Mitchell Ranch 1H), verifies well name
5. Agent executionExecutes the Rule 37 agent via the gateway, verifies HITL pause status and token usage
6. HITL approvalApproves the pending filing, verifies status transitions (pending -> approved)
7. EmissionsPosts a flaring event to the flaring monitor, verifies CO2e calculation returns > 0

The script authenticates with AEGIS_TEST_EMAIL / AEGIS_TEST_PASSWORD (defaulting to admin@aegis.local / aegis-dev-admin) and uses color-coded output for pass/fail results.

Interpreting Results

─── Step 1: Health checks ─── ✓ PASS: http://localhost:8001 healthy ✓ PASS: http://localhost:8002 healthy ... ═══════════════════════════════════════════════════ AEGIS Integration Test — ALL STEPS PASSED ═══════════════════════════════════════════════════

If any step fails, the script exits immediately with a FAIL message indicating which service or assertion failed.

Useful Pytest Flags

# Show print output and logging poetry run pytest -s # Run only tests matching a keyword poetry run pytest -k "test_create" # Stop at first failure poetry run pytest -x # Run with coverage (if coverage is installed) poetry run pytest --cov=memory --cov-report=term-missing # Show the slowest 10 tests poetry run pytest --durations=10

Troubleshooting Test Failures

”Module not found” errors

Make sure you have installed the service’s dependencies, including the shared library:

cd services/{service-name} poetry install

The shared library (aegis-shared) is installed as a path dependency pointing to ../../shared. If shared models have changed, re-run poetry install in the service directory.

Async test not running

If an async test appears to be skipped or not discovered, verify that asyncio_mode = "auto" is set in the service’s pyproject.toml under [tool.pytest.ini_options].

Flaring monitor tests fail with connection errors

The flaring-monitor integration tests require a live PostgreSQL database:

# Start just PostgreSQL docker compose up -d postgres # Verify it is healthy docker compose ps postgres

Import errors in conftest.py

Some conftest files import from the service source package (e.g., from memory.working import WorkingMemory). This requires the Poetry virtual environment to be active. Always run tests via poetry run pytest, not bare pytest.

Last updated on