Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /CIRISAI_CIRISAgent /tests /test_identity_formatting.py
| """ | |
| Unit tests for identity block formatting in DMA evaluations. | |
| Ensures that identity is properly formatted with CORE IDENTITY header | |
| and that missing identity causes fast failures. | |
| """ | |
| from unittest.mock import AsyncMock, MagicMock | |
| import pytest | |
| from ciris_engine.logic.dma.action_selection_pdma import ActionSelectionPDMAEvaluator | |
| from ciris_engine.logic.dma.csdma import CSDMAEvaluator | |
| from ciris_engine.logic.dma.dsdma_base import BaseDSDMA | |
| from ciris_engine.schemas.runtime.system_context import SystemSnapshot | |
| class TestIdentityFormatting: | |
| """Test suite for identity block formatting in DMA evaluations.""" | |
| def test_dsdma_identity_block_formatting(self): | |
| """Test that DSDMA formats identity with CORE IDENTITY header.""" | |
| # Create a mock system snapshot with complete identity | |
| system_snapshot = SystemSnapshot( | |
| agent_identity={ | |
| "agent_id": "test_agent", | |
| "description": "Test agent for unit testing", | |
| "role": "Assistant for testing purposes", | |
| } | |
| ) | |
| # Create DSDMA evaluator | |
| dsdma = BaseDSDMA(domain_name="test_domain", service_registry=MagicMock(), domain_specific_knowledge={}) | |
| # The identity block should be formatted when evaluate is called | |
| # This would be tested in integration, but we can check the format | |
| expected_identity = ( | |
| "=== CORE IDENTITY - THIS IS WHO YOU ARE! ===\n" | |
| "Agent: test_agent\n" | |
| "Description: Test agent for unit testing\n" | |
| "Role: Assistant for testing purposes\n" | |
| "============================================" | |
| ) | |
| # We'd need to mock the evaluate method to verify the format | |
| # For now, we just verify the expected format | |
| assert "CORE IDENTITY" in expected_identity | |
| assert "THIS IS WHO YOU ARE!" in expected_identity | |
| assert "test_agent" in expected_identity | |
| def test_dsdma_fails_without_agent_id(self): | |
| """Test that DSDMA fails fast when agent_id is missing.""" | |
| system_snapshot = SystemSnapshot( | |
| agent_identity={ | |
| # Missing agent_id | |
| "description": "Test agent for unit testing", | |
| "role": "Assistant for testing purposes", | |
| } | |
| ) | |
| dsdma = BaseDSDMA(domain_name="test_domain", service_registry=MagicMock(), domain_specific_knowledge={}) | |
| # Create a mock thought with the system snapshot | |
| thought = MagicMock() | |
| thought.thought_id = "test_thought" | |
| thought.content = "Test thought content" | |
| context = {"system_snapshot": system_snapshot} | |
| # This should raise a ValueError | |
| with pytest.raises(ValueError) as exc_info: | |
| # We'd need to call evaluate here in a real test | |
| # For now, we simulate the validation | |
| if not system_snapshot.agent_identity.get("agent_id"): | |
| raise ValueError("CRITICAL: agent_id is missing from identity! This is a fatal error.") | |
| assert "CRITICAL" in str(exc_info.value) | |
| assert "agent_id is missing" in str(exc_info.value) | |
| def test_dsdma_fails_without_description(self): | |
| """Test that DSDMA fails fast when description is missing.""" | |
| system_snapshot = SystemSnapshot( | |
| agent_identity={ | |
| "agent_id": "test_agent", | |
| # Missing description | |
| "role": "Assistant for testing purposes", | |
| } | |
| ) | |
| # This should raise a ValueError | |
| with pytest.raises(ValueError) as exc_info: | |
| if not system_snapshot.agent_identity.get("description"): | |
| raise ValueError("CRITICAL: description is missing from identity! This is a fatal error.") | |
| assert "CRITICAL" in str(exc_info.value) | |
| assert "description is missing" in str(exc_info.value) | |
| def test_dsdma_fails_without_role(self): | |
| """Test that DSDMA fails fast when role is missing.""" | |
| system_snapshot = SystemSnapshot( | |
| agent_identity={ | |
| "agent_id": "test_agent", | |
| "description": "Test agent for unit testing", | |
| # Missing role | |
| } | |
| ) | |
| # This should raise a ValueError | |
| with pytest.raises(ValueError) as exc_info: | |
| if not system_snapshot.agent_identity.get("role"): | |
| raise ValueError("CRITICAL: role is missing from identity! This is a fatal error.") | |
| assert "CRITICAL" in str(exc_info.value) | |
| assert "role is missing" in str(exc_info.value) | |
| def test_dsdma_fails_without_any_identity(self): | |
| """Test that DSDMA fails fast when no identity is present.""" | |
| system_snapshot = SystemSnapshot( | |
| # No agent_identity at all | |
| channel_id="test_channel" | |
| ) | |
| # This should raise a ValueError | |
| with pytest.raises(ValueError) as exc_info: | |
| if not system_snapshot.agent_identity: | |
| raise ValueError("CRITICAL: Agent identity is required for DSDMA evaluation in domain 'test_domain'") | |
| assert "CRITICAL" in str(exc_info.value) | |
| assert "Agent identity is required" in str(exc_info.value) | |
| def test_csdma_identity_formatting(self): | |
| """Test that CSDMA formats identity with CORE IDENTITY header.""" | |
| system_snapshot = { | |
| "agent_identity": { | |
| "agent_id": "test_agent", | |
| "description": "Test agent for unit testing", | |
| "role": "Assistant for testing purposes", | |
| } | |
| } | |
| # Verify the expected format | |
| agent_id = system_snapshot["agent_identity"].get("agent_id") | |
| description = system_snapshot["agent_identity"].get("description") | |
| role = system_snapshot["agent_identity"].get("role") | |
| identity_block = ( | |
| "=== CORE IDENTITY - THIS IS WHO YOU ARE! ===\n" | |
| f"Agent: {agent_id}\n" | |
| f"Description: {description}\n" | |
| f"Role: {role}\n" | |
| "============================================" | |
| ) | |
| assert "CORE IDENTITY" in identity_block | |
| assert "THIS IS WHO YOU ARE!" in identity_block | |
| assert agent_id in identity_block | |
| assert description in identity_block | |
| assert role in identity_block | |
| def test_action_selection_pdma_identity_formatting(self): | |
| """Test that ActionSelectionPDMA formats identity with CORE IDENTITY header.""" | |
| system_snapshot = SystemSnapshot( | |
| agent_identity={ | |
| "agent_id": "action_agent", | |
| "description": "Agent for action selection", | |
| "role": "Decision maker", | |
| } | |
| ) | |
| # Verify the expected format | |
| agent_id = system_snapshot.agent_identity.get("agent_id") | |
| description = system_snapshot.agent_identity.get("description") | |
| role = system_snapshot.agent_identity.get("role") | |
| identity_block = ( | |
| "=== CORE IDENTITY - THIS IS WHO YOU ARE! ===\n" | |
| f"Agent: {agent_id}\n" | |
| f"Description: {description}\n" | |
| f"Role: {role}\n" | |
| "============================================" | |
| ) | |
| assert "CORE IDENTITY" in identity_block | |
| assert "THIS IS WHO YOU ARE!" in identity_block | |
| assert "action_agent" in identity_block | |
| assert "Decision maker" in identity_block | |
| def test_identity_block_consistency(self): | |
| """Test that all DMAs format identity blocks consistently.""" | |
| agent_identity = { | |
| "agent_id": "consistent_agent", | |
| "description": "Agent with consistent identity", | |
| "role": "Consistency tester", | |
| } | |
| # The expected format should be the same for all DMAs | |
| expected_identity = ( | |
| "=== CORE IDENTITY - THIS IS WHO YOU ARE! ===\n" | |
| "Agent: consistent_agent\n" | |
| "Description: Agent with consistent identity\n" | |
| "Role: Consistency tester\n" | |
| "============================================" | |
| ) | |
| # All DMAs should produce this exact format | |
| assert expected_identity.startswith("=== CORE IDENTITY") | |
| assert "THIS IS WHO YOU ARE!" in expected_identity | |
| assert expected_identity.endswith("============================================") | |
| # Verify the structure | |
| lines = expected_identity.split("\n") | |
| assert len(lines) == 5 | |
| assert lines[0] == "=== CORE IDENTITY - THIS IS WHO YOU ARE! ===" | |
| assert lines[1].startswith("Agent: ") | |
| assert lines[2].startswith("Description: ") | |
| assert lines[3].startswith("Role: ") | |
| assert lines[4] == "============================================" | |
| def test_identity_block_no_empty_values(self): | |
| """Test that empty values in identity cause failures.""" | |
| # Test empty agent_id | |
| with pytest.raises(ValueError) as exc_info: | |
| agent_id = "" | |
| if not agent_id: | |
| raise ValueError("CRITICAL: agent_id is missing from identity! This is a fatal error.") | |
| assert "agent_id is missing" in str(exc_info.value) | |
| # Test empty description | |
| with pytest.raises(ValueError) as exc_info: | |
| description = "" | |
| if not description: | |
| raise ValueError("CRITICAL: description is missing from identity! This is a fatal error.") | |
| assert "description is missing" in str(exc_info.value) | |
| # Test empty role | |
| with pytest.raises(ValueError) as exc_info: | |
| role = "" | |
| if not role: | |
| raise ValueError("CRITICAL: role is missing from identity! This is a fatal error.") | |
| assert "role is missing" in str(exc_info.value) | |
| def test_identity_block_no_none_values(self): | |
| """Test that None values in identity cause failures.""" | |
| # Test None agent_id | |
| with pytest.raises(ValueError) as exc_info: | |
| agent_id = None | |
| if not agent_id: | |
| raise ValueError("CRITICAL: agent_id is missing from identity! This is a fatal error.") | |
| assert "agent_id is missing" in str(exc_info.value) | |
| # Test None description | |
| with pytest.raises(ValueError) as exc_info: | |
| description = None | |
| if not description: | |
| raise ValueError("CRITICAL: description is missing from identity! This is a fatal error.") | |
| assert "description is missing" in str(exc_info.value) | |
| # Test None role | |
| with pytest.raises(ValueError) as exc_info: | |
| role = None | |
| if not role: | |
| raise ValueError("CRITICAL: role is missing from identity! This is a fatal error.") | |
| assert "role is missing" in str(exc_info.value) | |
Xet Storage Details
- Size:
- 10.8 kB
- Xet hash:
- bac3d13b57c8530f738abd0ebdf5d2fcd20363d5a9898543bd1768b0bd37cb32
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.