How to run tests, understand results, and maintain test quality for agent-homebase.
| File | Phase | Tests | Focus |
|---|---|---|---|
test_contracts.py |
Phase 1 | 27 | JSON Schema validation, FSM transitions |
test_phase2.py |
Phase 2 | 15+ | SQLite persistence, checkpoints, migrations, workflows |
test_phase3.py |
Phase 3 | 15+ | Sandbox isolation, capabilities, security layers |
test_phase4.py |
Phase 4 | 27 | Determinism, Lamport timestamps, replay verification |
cd /path/to/agent-homebase
pytest tests/ -vpytest tests/test_contracts.py -v # Phase 1
pytest tests/test_phase2.py -v # Phase 2
pytest tests/test_phase3.py -v # Phase 3
pytest tests/test_phase4.py -v # Phase 4pytest tests/ --cov=src --cov-report=html
open htmlcov/index.htmlpip install pytest pytest-covFor Phase 3 sandbox tests (optional):
pip install docker
# Docker Desktop must be runningTests for formal verification of agent contracts:
- Tier 1 validation — Analysis-only returns (no artifacts)
- Tier 2 validation — Returns with single artifact
- Tier 3 validation — Composition returns with metadata
- Write permit enforcement — Correct paths per artifact type
- FSM transitions — Valid/invalid state changes
# Example: Test Tier 1 valid return
def test_tier1_valid(validator):
data = {
"tier": 1,
"agent": "planner",
"status": "complete",
"summary": "Analysis complete.",
"findings": []
}
result = validator.validate(json.dumps(data), expected_tier=1)
assert result.validTests for data persistence and recovery:
- SQLite operations — CRUD for ledger, bugs, sprints, checkpoints
- Checkpoint creation — State serialization, compression, hashing
- Checkpoint restore — Resume from snapshot, verify integrity
- Migration utilities — Markdown ↔ SQLite conversion
- Dual-write mode — Parallel writes to both formats
- Workflow engine — Task orchestration, retries, compensation
Tests for sandboxed execution:
- Container lifecycle — Create, run, stop, destroy
- Capability enforcement — File, network, exec permissions
- Resource limits — Memory, CPU, disk, timeout
- Network policies — Deny-all, allow-internal, allow-http
- Violation tracking — Audit trail for denied operations
- Checkpoint integration — Sandbox state in checkpoints
Note: Requires Docker. Tests skip gracefully if unavailable.
Tests for reproducible execution:
- Lamport timestamps — Clock operations, synchronization
- Prompt versioning — SHA256 hashing, change detection
- Deterministic composition — Content-based tie-breaking
- LLM config enforcement — Temperature=0 validation
- Replay verification — Trace comparison, divergence detection
# Example: Test Lamport clock synchronization
def test_lamport_sync():
clock = LogicalClock()
clock.tick() # 1
clock.tick() # 2
clock.update(10) # max(2, 10) + 1 = 11
assert clock.current() == 11============================= test session starts ==============================
collected 84 items
tests/test_contracts.py::TestSubagentReturnValidation::test_tier1_valid PASSED
tests/test_contracts.py::TestSubagentReturnValidation::test_tier1_missing_summary PASSED
...
tests/test_phase4.py::TestReplayVerification::test_trace_comparison PASSED
============================= 84 passed in 2.34s ===============================
| Failure | Cause | Solution |
|---|---|---|
ModuleNotFoundError: yaml |
PyYAML not installed | pip install pyyaml |
ModuleNotFoundError: docker |
Docker SDK not installed | pip install docker (or skip Phase 3) |
docker.errors.DockerException |
Docker not running | Start Docker Desktop |
test_<phase>.pyfor phase-specific teststest_<feature>.pyfor feature-specific tests
def test_<what>_<condition>_<expected>():
"""Test <what> when <condition> returns <expected>."""- Happy path — Valid input produces valid output
- Error handling — Invalid input produces clear error
- Edge cases — Boundary conditions, empty inputs
def test_checkpoint_restore_preserves_state():
"""Test that restoring a checkpoint recovers exact state."""
# Arrange
manager = CheckpointManager(db, sprint_id="042")
original_state = create_test_state()
# Act
checkpoint_id = manager.create_checkpoint("test", original_state)
restored_state = manager.restore_checkpoint(checkpoint_id)
# Assert
assert restored_state.sprint_id == original_state.sprint_id
assert restored_state.fsm_state == original_state.fsm_state
assert restored_state.logical_time == original_state.logical_time# .github/workflows/test.yml
name: Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- run: pip install pytest pytest-cov pyyaml
- run: pytest tests/ -v --cov=src# .git/hooks/pre-commit
#!/bin/bash
pytest tests/test_contracts.py -q || exit 1| Component | Target | Current |
|---|---|---|
src/phase1_verification/ |
90% | ✓ |
src/phase2_durability/ |
85% | ✓ |
src/phase3_isolation/ |
80% | ✓ |
src/phase4_determinism/ |
90% | ✓ |
init.py |
70% | ✓ |
- Check for infinite loops in fixtures
- Reduce Docker container timeouts in Phase 3 tests
- Use
pytest --timeout=30to enforce limits
- Avoid wall-clock time in assertions
- Use deterministic seeds for random data
- Mock external dependencies (network, filesystem)
# Run from project root, not tests/ directory
cd /path/to/agent-homebase
pytest tests/ -v- TROUBLESHOOTING.md — General troubleshooting
- DETERMINISM_GUIDE.md — Writing deterministic tests
- CONTRIBUTING.md — Test requirements for contributions