Skip to content

Running Tests

Terminal window
pytest tests/ -v

Expected output ends with:

804 passed in X.XXs

No running LLM is required. All LLM calls are mocked in the test suite.

tests/
├── kernel/
│ ├── test_cortex.py
│ ├── test_engram.py
│ ├── test_pulse.py
│ ├── test_chronicle.py
│ └── test_aegis.py
├── inference/
│ ├── test_provider.py
│ ├── test_local.py
│ ├── test_openai_provider.py
│ ├── test_anthropic_provider.py
│ ├── test_router.py
│ └── test_llm.py
├── messaging/
│ ├── test_bridge.py
│ ├── test_telegram.py
│ ├── test_discord.py
│ └── test_manager.py
├── modules/
│ ├── test_oracle.py
│ ├── test_sentry.py
│ ├── test_atlas.py
│ ├── test_prism.py
│ ├── test_cipher.py
│ ├── test_wraith.py
│ ├── test_echo.py
│ ├── test_sigil.py
│ ├── test_herald.py
│ ├── test_weave.py
│ ├── test_specter.py
│ ├── test_serendipity.py
│ ├── test_forge.py
│ ├── test_collective.py
│ ├── test_legacy.py
│ ├── test_general.py
│ ├── test_dream_loop.py
│ ├── test_adversarial.py
│ ├── test_tripwire.py
│ ├── test_provenance.py
│ ├── test_sandbox.py
│ ├── test_symbiosis.py
│ ├── test_consciousness.py
│ ├── test_ethical_prism.py
│ ├── test_scribe.py
│ ├── test_vex.py
│ ├── test_ledger.py
│ ├── test_arbiter.py
│ ├── test_thesis.py
│ ├── test_scaffold.py
│ ├── test_remedy.py
│ ├── test_compass.py
│ ├── test_tally.py
│ ├── test_redline.py
│ ├── test_carve.py
│ ├── test_vigil.py
│ ├── test_mandate.py
│ ├── test_flux.py
│ ├── test_kindle.py
│ ├── test_quarry.py
│ ├── test_bastion.py
│ ├── test_dispatch.py
│ ├── test_gauge.py
│ ├── test_mnemonic.py
│ ├── test_sentinel.py
│ ├── test_mint.py
│ ├── test_axiom.py
│ ├── test_loom.py
│ └── test_rune.py
├── community/
│ ├── test_validator.py
│ ├── test_registry.py
│ └── test_installer.py
└── integration/
└── test_message_flow.py

By file:

Terminal window
pytest tests/kernel/test_cortex.py -v
pytest tests/modules/test_atlas.py -v

By test name:

Terminal window
pytest tests/ -k "test_handle_calls_llm" -v

By keyword (matches test names and file paths):

Terminal window
pytest tests/ -k "cortex" -v
pytest tests/ -k "trust or aegis" -v

Just integration tests:

Terminal window
pytest tests/integration/ -v

Follow this pattern for every module test file. Each module should have at minimum four tests: attributes, handle behavior, memory storage, and a logic-specific test.

import pytest
from unittest.mock import AsyncMock
from nexus.modules.your_module import YourModule
@pytest.fixture
def module():
return YourModule()
@pytest.fixture
def context():
"""Standard mock context — matches what the kernel injects at runtime."""
return {
"llm": AsyncMock(),
"engram": AsyncMock(),
"chronicle": AsyncMock(),
"pulse": AsyncMock(),
"aegis": AsyncMock(),
}
def test_module_attributes(module):
"""Every module must have name, description, and version."""
assert module.name
assert module.description
assert module.version
@pytest.mark.asyncio
async def test_handle_returns_string(module, context):
"""handle() must always return a string."""
context["llm"].complete.return_value = "response"
context["engram"].query_episodic.return_value = []
result = await module.handle("test input", context)
assert isinstance(result, str)
@pytest.mark.asyncio
async def test_handle_stores_to_memory(module, context):
"""Verify the module writes to episodic memory."""
context["llm"].complete.return_value = "stored response"
context["engram"].query_episodic.return_value = []
await module.handle("test input", context)
context["engram"].store_episodic.assert_called_once()
@pytest.mark.asyncio
async def test_your_specific_logic(module, context):
"""Test the module's unique behavior."""
context["llm"].complete.return_value = "specific output"
context["engram"].query_episodic.return_value = []
result = await module.handle("trigger phrase", context)
assert "expected content" in result.lower()

Testing Pulse events:

await module.handle("input", context)
context["pulse"].publish.assert_called_with(
"your_module.completed", {"result": "..."}
)

Testing LLM prompt content:

await module.handle("input", context)
call_args = context["llm"].complete.call_args
assert "expected keyword" in call_args[0][0] # positional prompt arg

Testing error handling:

context["llm"].complete.side_effect = Exception("LLM unavailable")
result = await module.handle("input", context)
assert result # should return a string, not raise

NEXUS uses standard pytest configuration. The pyproject.toml or pytest.ini at the project root sets asyncio_mode = "auto" so @pytest.mark.asyncio decorators are optional for async tests (though explicit marking is preferred for clarity).

Terminal window
# Run with coverage
pytest tests/ --cov=nexus --cov-report=term-missing
# Run and stop at first failure
pytest tests/ -x
# Run and show slowest tests
pytest tests/ --durations=10