diff --git a/anchor/runtime/__init__.py b/anchor/runtime/__init__.py index 429290b..38cdd95 100644 --- a/anchor/runtime/__init__.py +++ b/anchor/runtime/__init__.py @@ -3,9 +3,10 @@ Public API for the Anchor Interceptor SDK (Layer 1, V5.0.3). -One import activates full runtime governance across ALL AI providers: +Explicit activation is required to run runtime governance: - import anchor.runtime # auto-activates (BLOCK mode) + import anchor.runtime + anchor.runtime.activate(mode='block') # auto-activates (BLOCK mode) # or: anchor.runtime.activate(mode='warn') # warn but don't block anchor.runtime.activate(mode='audit') # log only, no interruptions @@ -84,6 +85,9 @@ def activate( logger.debug("[Anchor] Runtime already active, skipping re-activation.") return get_session_stats() + # Load custom providers from policy.anchor + _load_custom_providers_from_policy() + mode_enum = InterceptorMode(mode.lower()) _current_mode = mode_enum _session_stats = SessionStats() @@ -258,13 +262,6 @@ def wrapper(*args, **kwargs): return decorator -# --------------------------------------------------------------------------- -# Auto-activate on import (BLOCK mode, no verbose) -# --------------------------------------------------------------------------- -_load_custom_providers_from_policy() -activate() - - # Re-export for convenience __all__ = [ "activate", diff --git a/tests/runtime/test_runtime_interceptors.py b/tests/runtime/test_runtime_interceptors.py index 0cfe7be..0feda71 100644 --- a/tests/runtime/test_runtime_interceptors.py +++ b/tests/runtime/test_runtime_interceptors.py @@ -38,9 +38,13 @@ from anchor.runtime.interceptors.framework import activate_framework_patches, get_active_patches print("5. framework.py imports: OK") -# 6: full runtime (auto-activated on import) +# 6: full runtime (explicitly activated) import anchor.runtime as rt s = rt.get_session_stats() -print(f"6. runtime/__init__.py: OK (status={s['status']}, mode={s.get('mode', '?')})") +assert s["status"] == "inactive", f"Expected inactive on import, got {s['status']}" +rt.activate() +s2 = rt.get_session_stats() +assert s2["status"] == "active", f"Expected active after activate(), got {s2['status']}" +print(f"6. runtime/__init__.py: OK (status={s2['status']}, mode={s2.get('mode', '?')})") print("\nALL SMOKE TESTS PASSED")