|
| 1 | +# Copyright (c) Microsoft Corporation. |
| 2 | +# Licensed under the MIT License. |
| 3 | +"""Smoke tests for the agent-runtime package (#493). |
| 4 | +
|
| 5 | +Verifies that all re-exported symbols from ``agent_runtime`` are importable, |
| 6 | +key classes can be instantiated where feasible, and the version string exists. |
| 7 | +""" |
| 8 | + |
| 9 | +from __future__ import annotations |
| 10 | + |
| 11 | +import pytest |
| 12 | + |
| 13 | +# --------------------------------------------------------------------------- |
| 14 | +# 1. All re-exported symbols are importable |
| 15 | +# --------------------------------------------------------------------------- |
| 16 | + |
| 17 | +ALL_EXPORTS = [ |
| 18 | + "__version__", |
| 19 | + # Core |
| 20 | + "Hypervisor", |
| 21 | + # Models |
| 22 | + "ConsistencyMode", |
| 23 | + "ExecutionRing", |
| 24 | + "ReversibilityLevel", |
| 25 | + "SessionConfig", |
| 26 | + "SessionState", |
| 27 | + # Session |
| 28 | + "SharedSessionObject", |
| 29 | + "SessionVFS", |
| 30 | + "VFSEdit", |
| 31 | + "VFSPermissionError", |
| 32 | + "VectorClock", |
| 33 | + "VectorClockManager", |
| 34 | + "CausalViolationError", |
| 35 | + "IntentLockManager", |
| 36 | + "LockIntent", |
| 37 | + "LockContentionError", |
| 38 | + "DeadlockError", |
| 39 | + "IsolationLevel", |
| 40 | + # Liability |
| 41 | + "VouchRecord", |
| 42 | + "VouchingEngine", |
| 43 | + "SlashingEngine", |
| 44 | + "LiabilityMatrix", |
| 45 | + "CausalAttributor", |
| 46 | + "AttributionResult", |
| 47 | + "QuarantineManager", |
| 48 | + "QuarantineReason", |
| 49 | + "LiabilityLedger", |
| 50 | + "LedgerEntryType", |
| 51 | + # Rings |
| 52 | + "RingEnforcer", |
| 53 | + "ActionClassifier", |
| 54 | + "RingElevationManager", |
| 55 | + "RingElevation", |
| 56 | + "ElevationDenialReason", |
| 57 | + "RingBreachDetector", |
| 58 | + "BreachSeverity", |
| 59 | + # Reversibility |
| 60 | + "ReversibilityRegistry", |
| 61 | + # Saga |
| 62 | + "SagaOrchestrator", |
| 63 | + "SagaTimeoutError", |
| 64 | + "SagaState", |
| 65 | + "StepState", |
| 66 | + "FanOutOrchestrator", |
| 67 | + "FanOutPolicy", |
| 68 | + "CheckpointManager", |
| 69 | + "SemanticCheckpoint", |
| 70 | + "SagaDSLParser", |
| 71 | + "SagaDefinition", |
| 72 | + # Audit |
| 73 | + "DeltaEngine", |
| 74 | + "CommitmentEngine", |
| 75 | + "EphemeralGC", |
| 76 | + # Verification |
| 77 | + "TransactionHistoryVerifier", |
| 78 | + # Observability |
| 79 | + "HypervisorEventBus", |
| 80 | + "EventType", |
| 81 | + "HypervisorEvent", |
| 82 | + "CausalTraceId", |
| 83 | + # Security |
| 84 | + "AgentRateLimiter", |
| 85 | + "RateLimitExceeded", |
| 86 | + "KillSwitch", |
| 87 | + "KillResult", |
| 88 | +] |
| 89 | + |
| 90 | + |
| 91 | +@pytest.mark.parametrize("symbol", ALL_EXPORTS) |
| 92 | +def test_symbol_importable(symbol: str): |
| 93 | + """Every symbol listed in __all__ should be importable.""" |
| 94 | + import agent_runtime |
| 95 | + |
| 96 | + obj = getattr(agent_runtime, symbol, None) |
| 97 | + assert obj is not None, f"{symbol} is not accessible on agent_runtime" |
| 98 | + |
| 99 | + |
| 100 | +def test_all_list_matches_exports(): |
| 101 | + """__all__ should contain exactly the expected symbols.""" |
| 102 | + import agent_runtime |
| 103 | + |
| 104 | + assert set(agent_runtime.__all__) == set(ALL_EXPORTS) |
| 105 | + |
| 106 | + |
| 107 | +# --------------------------------------------------------------------------- |
| 108 | +# 2. Version string exists and is well-formed |
| 109 | +# --------------------------------------------------------------------------- |
| 110 | + |
| 111 | + |
| 112 | +def test_version_string_exists(): |
| 113 | + """agent_runtime.__version__ should be a non-empty string.""" |
| 114 | + import agent_runtime |
| 115 | + |
| 116 | + assert isinstance(agent_runtime.__version__, str) |
| 117 | + assert len(agent_runtime.__version__) > 0 |
| 118 | + |
| 119 | + |
| 120 | +def test_version_has_parts(): |
| 121 | + """Version should have at least major.minor structure.""" |
| 122 | + import agent_runtime |
| 123 | + |
| 124 | + parts = agent_runtime.__version__.split(".") |
| 125 | + assert len(parts) >= 2, f"Expected at least major.minor, got {agent_runtime.__version__}" |
| 126 | + |
| 127 | + |
| 128 | +# --------------------------------------------------------------------------- |
| 129 | +# 3. Key classes / enums can be instantiated or inspected |
| 130 | +# --------------------------------------------------------------------------- |
| 131 | + |
| 132 | + |
| 133 | +def test_instantiate_vector_clock(): |
| 134 | + from agent_runtime import VectorClock |
| 135 | + |
| 136 | + vc = VectorClock() |
| 137 | + assert vc is not None |
| 138 | + |
| 139 | + |
| 140 | +def test_instantiate_vector_clock_manager(): |
| 141 | + from agent_runtime import VectorClockManager |
| 142 | + |
| 143 | + mgr = VectorClockManager() |
| 144 | + assert mgr is not None |
| 145 | + |
| 146 | + |
| 147 | +def test_instantiate_intent_lock_manager(): |
| 148 | + from agent_runtime import IntentLockManager |
| 149 | + |
| 150 | + mgr = IntentLockManager() |
| 151 | + assert mgr is not None |
| 152 | + |
| 153 | + |
| 154 | +def test_enum_consistency_mode(): |
| 155 | + from agent_runtime import ConsistencyMode |
| 156 | + |
| 157 | + assert hasattr(ConsistencyMode, "__members__") |
| 158 | + assert len(ConsistencyMode.__members__) > 0 |
| 159 | + |
| 160 | + |
| 161 | +def test_enum_execution_ring(): |
| 162 | + from agent_runtime import ExecutionRing |
| 163 | + |
| 164 | + assert hasattr(ExecutionRing, "__members__") |
| 165 | + assert len(ExecutionRing.__members__) > 0 |
| 166 | + |
| 167 | + |
| 168 | +def test_enum_reversibility_level(): |
| 169 | + from agent_runtime import ReversibilityLevel |
| 170 | + |
| 171 | + assert hasattr(ReversibilityLevel, "__members__") |
| 172 | + assert len(ReversibilityLevel.__members__) > 0 |
| 173 | + |
| 174 | + |
| 175 | +def test_enum_isolation_level(): |
| 176 | + from agent_runtime import IsolationLevel |
| 177 | + |
| 178 | + assert hasattr(IsolationLevel, "__members__") |
| 179 | + assert len(IsolationLevel.__members__) > 0 |
| 180 | + |
| 181 | + |
| 182 | +def test_enum_quarantine_reason(): |
| 183 | + from agent_runtime import QuarantineReason |
| 184 | + |
| 185 | + assert hasattr(QuarantineReason, "__members__") |
| 186 | + assert len(QuarantineReason.__members__) > 0 |
| 187 | + |
| 188 | + |
| 189 | +def test_enum_breach_severity(): |
| 190 | + from agent_runtime import BreachSeverity |
| 191 | + |
| 192 | + assert hasattr(BreachSeverity, "__members__") |
| 193 | + assert len(BreachSeverity.__members__) > 0 |
| 194 | + |
| 195 | + |
| 196 | +def test_enum_event_type(): |
| 197 | + from agent_runtime import EventType |
| 198 | + |
| 199 | + assert hasattr(EventType, "__members__") |
| 200 | + assert len(EventType.__members__) > 0 |
| 201 | + |
| 202 | + |
| 203 | +def test_enum_ledger_entry_type(): |
| 204 | + from agent_runtime import LedgerEntryType |
| 205 | + |
| 206 | + assert hasattr(LedgerEntryType, "__members__") |
| 207 | + assert len(LedgerEntryType.__members__) > 0 |
| 208 | + |
| 209 | + |
| 210 | +def test_enum_saga_state(): |
| 211 | + from agent_runtime import SagaState |
| 212 | + |
| 213 | + assert hasattr(SagaState, "__members__") |
| 214 | + assert len(SagaState.__members__) > 0 |
| 215 | + |
| 216 | + |
| 217 | +def test_enum_step_state(): |
| 218 | + from agent_runtime import StepState |
| 219 | + |
| 220 | + assert hasattr(StepState, "__members__") |
| 221 | + assert len(StepState.__members__) > 0 |
| 222 | + |
| 223 | + |
| 224 | +def test_elevation_denial_reason_importable(): |
| 225 | + from agent_runtime import ElevationDenialReason |
| 226 | + |
| 227 | + assert ElevationDenialReason is not None |
| 228 | + |
| 229 | + |
| 230 | +def test_kill_result_importable(): |
| 231 | + from agent_runtime import KillResult |
| 232 | + |
| 233 | + assert KillResult is not None |
| 234 | + |
| 235 | + |
| 236 | +def test_exception_classes_are_exceptions(): |
| 237 | + """Error / exception symbols should be subclasses of Exception.""" |
| 238 | + from agent_runtime import ( |
| 239 | + CausalViolationError, |
| 240 | + DeadlockError, |
| 241 | + LockContentionError, |
| 242 | + RateLimitExceeded, |
| 243 | + SagaTimeoutError, |
| 244 | + VFSPermissionError, |
| 245 | + ) |
| 246 | + |
| 247 | + for exc_cls in [ |
| 248 | + CausalViolationError, |
| 249 | + DeadlockError, |
| 250 | + LockContentionError, |
| 251 | + RateLimitExceeded, |
| 252 | + SagaTimeoutError, |
| 253 | + VFSPermissionError, |
| 254 | + ]: |
| 255 | + assert issubclass(exc_cls, Exception), f"{exc_cls.__name__} is not an Exception subclass" |
| 256 | + |
| 257 | + |
| 258 | +def test_hypervisor_event_bus_instantiation(): |
| 259 | + from agent_runtime import HypervisorEventBus |
| 260 | + |
| 261 | + bus = HypervisorEventBus() |
| 262 | + assert bus is not None |
| 263 | + |
| 264 | + |
| 265 | +def test_session_config_instantiation(): |
| 266 | + from agent_runtime import SessionConfig |
| 267 | + |
| 268 | + cfg = SessionConfig() |
| 269 | + assert cfg is not None |
| 270 | + |
| 271 | + |
| 272 | +def test_causal_trace_id_instantiation(): |
| 273 | + from agent_runtime import CausalTraceId |
| 274 | + |
| 275 | + tid = CausalTraceId() |
| 276 | + assert tid is not None |
0 commit comments