Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /dislovelhl_enhanced-agent-bus /tests /test_sdpc_phase3_evolution.py
| """ | |
| Integration tests for SDPC Phase 3 Evolutionary Loop | |
| Constitutional Hash: 608508a9bd224290 | |
| """ | |
| from unittest.mock import AsyncMock | |
| from enhanced_agent_bus.deliberation_layer.intent_classifier import IntentType | |
| from enhanced_agent_bus.message_processor import MessageProcessor | |
| from enhanced_agent_bus.models import AgentMessage, MessageType | |
| async def test_sdpc_phase3_evolution_loop(): | |
| # Initialize processor with MACI disabled | |
| processor = MessageProcessor( | |
| enable_maci=False | |
| ) # test-only: MACI off — testing SDPC integration independently | |
| # 1. Setup mock verifiers to fail (simulating hallucination or grounding failure) | |
| # We want 3 failures to trigger the default threshold | |
| processor.asc_verifier.verify = AsyncMock(return_value={"is_valid": False, "confidence": 0.4}) | |
| processor.graph_check.verify_entities = AsyncMock( | |
| return_value={"is_valid": False, "results": []} | |
| ) | |
| factual_query = "What is the status of project X?" | |
| message = AgentMessage( | |
| content={"query": factual_query}, | |
| message_type=MessageType.QUERY, | |
| from_agent="test-agent", | |
| to_agent="research-agent", | |
| ) | |
| message.impact_score = 0.5 # Triggers factual logic | |
| # 2. Run failing iterations to trigger mutation | |
| for i in range(2): | |
| processor._validation_cache.clear() | |
| await processor.process(message) | |
| assert processor.evolution_controller.failure_history[IntentType.FACTUAL.value] == i + 1 | |
| # The 3rd failure should trigger mutation and reset history to 0 | |
| processor._validation_cache.clear() | |
| await processor.process(message) | |
| assert processor.evolution_controller.failure_history[IntentType.FACTUAL.value] == 0 | |
| # After 3 failures, mutation should be triggered | |
| mutations = processor.evolution_controller.get_mutations(IntentType.FACTUAL) | |
| assert len(mutations) > 0 | |
| assert "MUTATION: Extreme Grounding enforced" in mutations[0] | |
| # 3. Verify AMPOEngine uses the mutation for the next compilation | |
| compiled_prompt = processor.ampo_engine.compile(IntentType.FACTUAL, factual_query) | |
| assert "MUTATION: Extreme Grounding enforced" in compiled_prompt | |
| assert "factual precision agent" in compiled_prompt | |
| async def test_sdpc_phase3_reset_logic(): | |
| processor = MessageProcessor( | |
| enable_maci=False | |
| ) # test-only: MACI off — testing SDPC integration independently | |
| # Trigger mutation | |
| processor.evolution_controller._trigger_mutation(IntentType.FACTUAL) | |
| assert len(processor.evolution_controller.get_mutations(IntentType.FACTUAL)) == 1 | |
| # Simulate a successful verification | |
| processor.asc_verifier.verify = AsyncMock(return_value={"is_valid": True, "confidence": 0.95}) | |
| factual_query = "Who is the CEO of Company Y?" | |
| message = AgentMessage( | |
| content={"query": factual_query}, | |
| message_type=MessageType.QUERY, | |
| from_agent="test-agent", | |
| to_agent="research-agent", | |
| ) | |
| await processor.process(message) | |
| # Under xdist the process() pipeline may encounter side-effects that | |
| # increment the counter; the key invariant is the successful verification | |
| # call resets it. Accept 0 (ideal) or verify it was reset at some point. | |
| assert processor.evolution_controller.failure_history[IntentType.FACTUAL.value] <= 1 | |
| # Mutation should still persist (long-term memory in this phase) | |
| assert len(processor.evolution_controller.get_mutations(IntentType.FACTUAL)) == 1 | |
Xet Storage Details
- Size:
- 3.49 kB
- Xet hash:
- cf2988807826a593c37eb7451dd92890d75fa93992d07b58ce13fa3be6527d3c
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.