Buckets:

download
raw
3.04 kB
"""
Shared fixtures for Adaptive Governance Engine tests.
Constitutional Hash: 608508a9bd224290
"""
from unittest.mock import patch
import pytest
from enhanced_agent_bus._compat.constants import CONSTITUTIONAL_HASH as SHARED_CONSTITUTIONAL_HASH
CONST_HASH = SHARED_CONSTITUTIONAL_HASH
_MLFLOW_PATCH = "mlflow.set_tracking_uri"
_IMPACT_MLFLOW = (
"enhanced_agent_bus.adaptive_governance.impact_scorer.ImpactScorer._initialize_mlflow"
)
_THRESH_MLFLOW = (
"enhanced_agent_bus.adaptive_governance.threshold_manager.AdaptiveThresholds._initialize_mlflow"
)
def _make_features(risk_score: float = 0.3, confidence: float = 0.9):
from enhanced_agent_bus.adaptive_governance.models import ImpactFeatures
return ImpactFeatures(
message_length=50,
agent_count=2,
tenant_complexity=0.5,
temporal_patterns=[0.1, 0.2],
semantic_similarity=0.4,
historical_precedence=1,
resource_utilization=0.2,
network_isolation=0.8,
risk_score=risk_score,
confidence_level=confidence,
)
def _make_decision(risk_score: float = 0.3, action_allowed: bool = True):
from enhanced_agent_bus.adaptive_governance.models import (
GovernanceDecision,
ImpactLevel,
)
features = _make_features(risk_score=risk_score)
return GovernanceDecision(
action_allowed=action_allowed,
impact_level=ImpactLevel.LOW,
confidence_score=0.9,
reasoning="test reasoning",
recommended_threshold=0.5,
features_used=features,
)
@pytest.fixture
def engine():
"""Create an AdaptiveGovernanceEngine with all heavy deps suppressed."""
with (
patch(_IMPACT_MLFLOW),
patch(_THRESH_MLFLOW),
patch(
"enhanced_agent_bus.adaptive_governance.governance_engine.FEEDBACK_HANDLER_AVAILABLE",
False,
),
patch(
"enhanced_agent_bus.adaptive_governance.governance_engine.DRIFT_MONITORING_AVAILABLE",
False,
),
patch(
"enhanced_agent_bus.adaptive_governance.governance_engine.ONLINE_LEARNING_AVAILABLE",
False,
),
patch(
"enhanced_agent_bus.adaptive_governance.governance_engine.AB_TESTING_AVAILABLE",
False,
),
patch(
"enhanced_agent_bus.adaptive_governance.governance_engine.ANOMALY_MONITORING_AVAILABLE",
False,
),
):
from enhanced_agent_bus.adaptive_governance.governance_engine import (
AdaptiveGovernanceEngine,
)
return AdaptiveGovernanceEngine(CONST_HASH)
@pytest.fixture
def sample_message():
return {
"from_agent": "agent-a",
"to_agent": "agent-b",
"content": "Hello world",
"tenant_id": "tenant-1",
"constitutional_hash": CONST_HASH,
}
@pytest.fixture
def sample_context():
return {
"tenant_id": "tenant-1",
"agent_type": "standard",
"permissions": ["read"],
}

Xet Storage Details

Size:
3.04 kB
·
Xet hash:
964817a20bf291c8f2d9784f28f6a577e510fecfca466b735ad44b99e340fa5f

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.