Skip to main content

Test Suite

The test suite covers all five major components: cortex, immune system, brain, 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

TestCortex — 7 Tests

The persistent memory engine:

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

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

TestImmune — 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

TestBrain — 3 Tests

The reasoning engine:

TestWhat It Verifies
test_rule_based_analysisRules fire correctly for given vitals
test_confidence_thresholdDecisions below 0.6 confidence are rejected
test_statsBrain 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 TestNewOrgan:
"""Your new organ tests."""

def setup_method(self):
"""Create fresh instances for each test."""
self.organ = NewOrgan()

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

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

Test Fixtures

  • Cortex tests use a temp file path (/tmp/test_cortex_*.db) and delete it on teardown
  • Brain 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 →