Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /dislovelhl_enhanced-agent-bus /tests /constitutional_saga /testsagaresume.py
| """ | |
| Comprehensive tests for Constitutional Saga workflow module. | |
| Constitutional Hash: 608508a9bd224290 | |
| Coverage targets: | |
| - SagaStatus and StepStatus enums | |
| - SagaCompensation, SagaStep, SagaContext, SagaResult, SagaState dataclasses | |
| - FileSagaPersistenceProvider | |
| - DefaultSagaActivities | |
| - Saga execution and compensation flow | |
| """ | |
| import asyncio | |
| import json | |
| import tempfile | |
| from datetime import datetime, timezone | |
| from pathlib import Path | |
| from unittest.mock import AsyncMock, MagicMock | |
| import pytest | |
| from enhanced_agent_bus.deliberation_layer.workflows.constitutional_saga import ( | |
| CONSTITUTIONAL_HASH, | |
| ConstitutionalSagaWorkflow, | |
| DefaultSagaActivities, | |
| FileSagaPersistenceProvider, | |
| SagaCompensation, | |
| SagaContext, | |
| SagaResult, | |
| SagaState, | |
| SagaStatus, | |
| SagaStep, | |
| StepStatus, | |
| ) | |
| class TestSagaResume: | |
| """Tests for saga resume functionality.""" | |
| def provider(self, tmp_path): | |
| """Create persistence provider.""" | |
| return FileSagaPersistenceProvider(str(tmp_path)) | |
| async def test_resume_nonexistent_saga(self, provider): | |
| """Test resuming non-existent saga returns None.""" | |
| saga = await ConstitutionalSagaWorkflow.resume( | |
| saga_id="nonexistent", | |
| persistence_provider=provider, | |
| ) | |
| assert saga is None | |
| async def test_resume_existing_saga(self, provider): | |
| """Test resuming existing saga.""" | |
| # Save state first | |
| state = SagaState( | |
| saga_id="resume-test", | |
| status=SagaStatus.EXECUTING, | |
| completed_steps=["step1"], | |
| failed_step=None, | |
| compensated_steps=[], | |
| failed_compensations=[], | |
| context={"step1": "result1"}, | |
| version="2.0.0", | |
| ) | |
| await provider.save_state(state) | |
| # Resume | |
| saga = await ConstitutionalSagaWorkflow.resume( | |
| saga_id="resume-test", | |
| persistence_provider=provider, | |
| ) | |
| assert saga is not None | |
| assert saga.saga_id == "resume-test" | |
| assert saga._status == SagaStatus.EXECUTING | |
| assert saga._completed_steps == ["step1"] | |
| assert saga.version == "2.0.0" | |
Xet Storage Details
- Size:
- 2.21 kB
- Xet hash:
- 858f71adb30402c8d62e22ddb085d433e1731c131e167e97f20bdb2fa403ead8
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.