continuum-testing
Skill84 starsChanged 6 months agoApache-2.0View on GitHub
Write tests for Continuum agents — mock LLM and memory clients via the DI Container, use fakeredis for sessions, snapshot agent responses, and run pytest-asyncio. Invoke when the user asks "test my agent", "mock the LLM", "fakeredis", "container injection", "pytest", or wants their CI to validate agent behavior without burning real API tokens.
In this repository49 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .claude/commands/monitoring/agents.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/continuum.mdcCursor rule
- AgentDB Advanced FeaturesSkill
- AgentDB Learning PluginsSkill
- AgentDB Memory PatternsSkill
- AgentDB Performance OptimizationSkill
- AgentDB Vector SearchSkill
- browserSkill
- continuum-agentSkill
- continuum-claude-codeSkill
- continuum-codexSkill
- continuum-cursorSkill
- continuum-evaluationSkill
- continuum-handoffsSkill
- continuum-llm-providersSkill
- continuum-memorySkill
- continuum-observabilitySkill
- continuum-quickstartSkill
- continuum-recipesSkill
- continuum-streamingSkill
- continuum-temporalSkill
- continuum-tools-mcpSkill
- continuum-workflowsSkill
- github-code-reviewSkill
- github-multi-repoSkill
- github-project-managementSkill
- github-release-managementSkill
- github-workflow-automationSkill
- Hooks AutomationSkill
- Pair ProgrammingSkill
- ReasoningBank with AgentDBSkill
- ReasoningBank IntelligenceSkill
- Skill BuilderSkill
- sparc-methodologySkill
- stream-chainSkill
- swarm-advancedSkill
- Swarm OrchestrationSkill
- V3 CLI ModernizationSkill
- V3 Core ImplementationSkill
- V3 DDD ArchitectureSkill
- V3 Deep IntegrationSkill
- V3 MCP OptimizationSkill
- V3 Memory UnificationSkill
- V3 Performance OptimizationSkill
- V3 Security OverhaulSkill
- V3 Swarm CoordinationSkill
- Verification & Quality AssuranceSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 0 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 160
If your MockLLM needs to emit tool calls, populate tool_calls on the LLMResponse:
- Very specific: line 226
Don't await runner.run_stream(...) — it's an async generator.
- Very specific: line 228
Don't mock BaseAgent itself — it's a dataclass.
- Very specific: line 230
Don't reuse Container across tests without reset_container() — the singleton survives between tests and leaks state.
- Very specific: line 232
Don't try to test prompt-injection scanning by passing raw HTML — the scanners run on user input, not arbitrary strings.
- Very specific: line 235
Don't real-Redis your tests in CI without isolation — use fakeredis or a per-test Redis db (SESSION_REDIS_DB).
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Continuum Testing Skill
Continuum's test-friendly seams:
Container(ContainerConfig(auto_initialize=False))— opt out of auto-init and inject mocks.Container.set_*_client(...)accepts the real client, a custom subclass, or any object satisfying theILLMClient/IMemoryClient/ISessionClientprotocols.fakeredis(a dev dependency) drops in for the Redis session provider.reset_container()andreset_global_memory()/reset_global_session()cleanly nuke globals between tests.
Imports
import pytest
from continuum.agent import AgentRunner, BaseAgent
from continuum.core.container import Container, ContainerConfig, reset_container
from continuum.llm.types import LLMResponse, StreamChunk, Usage
from continuum.protocols import ILLMClient1. Mock LLM that satisfies ILLMClient
class MockLLM:
is_enabled = True
def __init__(self, replies: list[str]):
self._replies = list(replies)
async def chat(self, messages, **kw):
text = self._replies.pop(0) if self._replies else "mock reply"
return LLMResponse(model="mock", content=text, role="assistant",
usage=Usage(prompt_tokens=10, completion_tokens=5,
total_tokens=15))
async def chat_stream(self, messages, **kw):
text = self._replies.pop(0) if self._replies else "mock reply"
for ch in text:
yield StreamChunk(model="mock", content=ch)
yield StreamChunk(model="mock", is_finished=True)
def count_tokens(self, messages, model=None) -> int:
return sum(len(m.get("content", "")) // 4 for m in messages)Wire it into the container:
container = Container(ContainerConfig(auto_initialize=False))
container.set_llm_client(MockLLM(["Hello, world!"]))
container.set_memory_client(None)
container.set_session_client(None)
runner = AgentRunner(container=container)
agent = BaseAgent(name="t", instructions="...")
resp = await runner.run(agent, "anything")
assert resp.content == "Hello, world!"2. pytest fixtures
import pytest
from continuum.core.container import reset_container
@pytest.fixture(autouse=True)
def clean_globals():
reset_container()
try:
from continuum.memory.client import reset_global_memory
reset_global_memory()
except ImportError:
pass
try:
from continuum.session.client import reset_global_session
reset_global_session()
except ImportError:
pass
yield
@pytest.fixture
def mock_runner():
container = Container(ContainerConfig(auto_initialize=False))
container.set_llm_client(MockLLM(["mocked"]))
container.set_memory_client(None)
container.set_session_client(None)
return AgentRunner(container=container)@pytest.mark.asyncio
async def test_agent_replies(mock_runner):
agent = BaseAgent(name="echo", instructions="...")
resp = await mock_runner.run(agent, "ping")
assert resp.content == "mocked"pytest-asyncio is in the [dev] extra. With asyncio_mode = "auto"
in pyproject.toml, you don't need the @pytest.mark.asyncio
decorator.
3. fakeredis for session tests
import pytest, fakeredis.aioredis
from continuum.session import SessionClient, SessionConfig
from continuum.session.providers.redis import RedisSessionProvider
@pytest.fixture
async def session_client(monkeypatch):
fake = fakeredis.aioredis.FakeRedis()
cfg = SessionConfig(provider="redis", enabled=True,
redis_host="ignored", redis_port=0)
provider = RedisSessionProvider(cfg, auto_initialize=False)
provider._redis = fake # bypass real Redis connect
provider._initialized = True
return SessionClient(session_config=cfg, provider=provider, auto_initialize=False)Now await session_client.add_message(sid, ChatMessage(...)) round-trips
through fakeredis without a Docker container.
4. Snapshot-style tests against structured output
from pydantic import BaseModel
class Result(BaseModel):
sentiment: str
confidence: float
async def test_sentiment_schema(mock_runner):
mock_runner._container.set_llm_client(
MockLLM(['{"sentiment":"positive","confidence":0.95}'])
)
agent = BaseAgent(name="s", instructions="...", output_schema=Result)
resp = await mock_runner.run(agent, "I love it!")
assert isinstance(resp.structured_output, Result)
assert resp.structured_output.sentiment == "positive"5. Testing tool calls
If your MockLLM needs to emit tool calls, populate tool_calls on the
LLMResponse:
from continuum.llm.types import LLMResponse, ToolCall, FunctionCall
class ToolCallingMock:
is_enabled = True
def __init__(self):
self._step = 0
async def chat(self, messages, **kw):
self._step += 1
if self._step == 1:
return LLMResponse(
model="mock", content=None, role="assistant",
tool_calls=[ToolCall(id="c1", function=FunctionCall(
name="get_weather", arguments='{"city": "Paris"}'))])
return LLMResponse(model="mock", content="It's sunny in Paris.",
role="assistant")
async def chat_stream(self, *a, **kw):
yield StreamChunk(model="mock", is_finished=True)
def count_tokens(self, *a, **kw): return 0Couple this with a fake ToolExecutor to test full tool-loop behaviour
without real MCP servers.
6. Asserting on streaming events
from continuum.agent.types import EventType
async def test_streaming_emits_deltas(mock_runner):
agent = BaseAgent(name="s", instructions="...")
types = [ev.type async for ev in mock_runner.run_stream(agent, "hi")]
assert EventType.RUN_START in types
assert EventType.CONTENT_DELTA in types
assert EventType.RUN_END in types7. End-to-end with a live LLM but no infra
For "happy path" tests against a real LLM but without Redis/Qdrant:
container = Container(ContainerConfig(
enable_memory=False, enable_session=False, enable_langfuse=False,
))
agent = BaseAgent(
name="e2e",
instructions="...",
memory_config=AgentMemoryConfig(search_memories=False, store_memories=False),
)
runner = AgentRunner(container=container)Combine with pytest -m integration markers to gate them behind a key.
Don't
- Don't
await runner.run_stream(...)— it's an async generator; useasync for. - Don't mock
BaseAgentitself — it's a dataclass; mock the LLM client underneath instead. - Don't reuse
Containeracross tests withoutreset_container()— the singleton survives between tests and leaks state. - Don't try to test prompt-injection scanning by passing raw HTML —
the scanners run on user input, not arbitrary strings; pass via
runner.run(agent, payload). - Don't real-Redis your tests in CI without isolation — use
fakeredisor a per-test Redis db (SESSION_REDIS_DB).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

