Skip to main content

Test Suite

The test suite covers all five major components: memory store, health monitor, reasoning engine, sandbox, and the Sovereign Script compiler. 35+ test cases in tests/test_starter.py (324 LOC).

Running Tests

python -m pytest tests/ -v

Test Coverage

TestMemoryStore — 7 Tests

The persistent memory engine:

TestWhat It Verifies
test_remember_and_recallStore entry → recall by keyword → correct content and tags
test_recall_by_tagsTag-based retrieval works correctly
test_countInternal entry count tracking
test_statsMemory statistics (total, db size, types)
test_decayImportance decay reduces value over iterations
test_identity_tags_immune_to_decayEntries tagged identity survive decay

Each test creates a temporary SQLite DB that is deleted after the test.

TestHealthMonitor — 5 Tests

Pipeline health monitoring and input sanitization:

TestWhat It Verifies
test_track_successSuccess recording increases score
test_quarantine_after_failures3 consecutive failures trigger quarantine
test_release_from_quarantineQuarantined component can be released
test_reflex_rate_limitingRate limiter blocks after threshold
test_summaryHealth summary returns correct structure

TestReasoningEngine — 3 Tests

The decision engine:

TestWhat It Verifies
test_rule_based_analysisRules fire correctly for given metrics
test_confidence_thresholdDecisions below 0.6 confidence are rejected
test_statsEngine statistics track calls and decisions

TestSandbox — 5 Tests

Pipeline execution safety:

TestWhat It Verifies
test_blocks_evaleval() is caught by static analysis
test_blocks_osos.system() is caught
test_allows_safe_codeLegitimate code passes all checks
test_sandbox_code_injectionSandbox header is correctly injected
test_blocks_class_escape__class__.__bases__ escape vector blocked

TestSovereignScript — 8 Tests

The full compiler pipeline:

TestWhat It Verifies
test_tokenize_pipelineLexer produces correct token types
test_parse_pipelineParser generates correct AST structure
test_codegen_pipelineCode generator outputs valid Python
test_full_roundtripSource → compile → execute produces expected output
test_pipe_operator|> desugars to nested function calls
test_if_elseConditional compilation works
test_for_loopFor loop compilation works
test_function_defFunction definition + call roundtrip

Writing New Tests

Follow the existing pattern:

class TestNewModule:
"""Your new module tests."""

def setup_method(self):
"""Create fresh instances for each test."""
self.module = NewModule()

def teardown_method(self):
"""Clean up any resources."""
self.module.close()

def test_basic_functionality(self):
result = self.module.do_something()
assert result is not None
assert result.status == "success"

Test Fixtures

  • Memory tests use a temp file path (/tmp/test_memory_*.db) and delete it on teardown
  • Reasoning tests run with LLM_PROVIDER=none to test rule-based mode only
  • Sandbox tests use inline code strings — no file I/O needed

Next: Advanced →