Buckets:

download
raw
3.96 kB
"""
conftest.py — patches broken deps BEFORE any module is imported,
so real source code gets loaded and coverage is real.
"""
import importlib as _importlib
import sys
import types
from unittest.mock import MagicMock
# ── 1. Fix bcrypt/passlib incompatibility ──────────────────────────────────
import bcrypt as _bcrypt_lib
_original_hashpw = _bcrypt_lib.hashpw
def _safe_hashpw(password, salt):
if isinstance(password, (bytes, bytearray)) and len(password) > 72:
password = password[:72]
return _original_hashpw(password, salt)
_bcrypt_lib.hashpw = _safe_hashpw
if not hasattr(_bcrypt_lib, "__about__"):
_bcrypt_lib.__about__ = MagicMock(__version__="4.0.0")
# ── 2. Stub ONLY truly unavailable external packages ──────────────────────
# Rule: only stub packages that are NOT installed.
# This lets real project code run while blocking network/tool imports.
def _make_stub(name, **attrs):
"""Create a stub module and register it + all parent paths."""
parts = name.split(".")
for i in range(len(parts)):
path = ".".join(parts[: i + 1])
if path not in sys.modules:
m = types.ModuleType(path)
sys.modules[path] = m
mod = sys.modules[name]
for k, v in attrs.items():
setattr(mod, k, v)
return mod
# Only stub packages that literally don't exist on this Kali install:
_MISSING_PACKAGES = [
"playwright",
"kimi_auth_bridge",
"scoutsuite_integration",
"scoutsuite",
"zapv2",
"metasploit",
"bloodhound",
"crackmapexec",
"impacket",
"aircrack",
"aioredis", # only if not installed
]
def _is_installed(pkg):
try:
_importlib.import_module(pkg.split(".")[0])
return True
except Exception:
return False
for pkg in _MISSING_PACKAGES:
if not _is_installed(pkg):
_make_stub(pkg)
# Stub specific submodules that some tools try to import
_make_stub(
"scoutsuite_integration.scout_integration",
ScoutSuiteScanner=MagicMock,
ScoutSuiteConfig=MagicMock,
)
# ── 3. Patch os.environ so modules don't crash on missing API keys ─────────
import os
_ENV_DEFAULTS = {
"OPENAI_API_KEY": "test-key-not-real",
"ANTHROPIC_API_KEY": "test-key-not-real",
"DATABASE_URL": "sqlite:///:memory:",
"SECRET_KEY": "test-secret-key-for-tests-only",
"JWT_SECRET": "test-jwt-secret",
"SLACK_WEBHOOK_URL": "https://hooks.slack.com/test",
"REDIS_URL": "redis://localhost:6379",
}
for k, v in _ENV_DEFAULTS.items():
os.environ.setdefault(k, v)
# ── 4. Exclude broken test directories ────────────────────────────────────
collect_ignore = [
"tests/e2e/playwright",
"tests/unit/test_modules.py",
]
# ── 5. Verify real imports work — print which ones succeed ────────────────
def pytest_sessionstart(session):
import importlib as _importlib
_to_check = [
"core.cache",
"autonomous.agent_loop",
"autonomous.memory",
"risk_engine.false_positive_engine",
"core.orchestrator",
"agents.agent_base",
"api.main",
]
print("\n── Import health check ──")
for mod_path in _to_check:
try:
_importlib.import_module(mod_path)
print(f" ✓ {mod_path}")
except Exception as e:
print(f" ✗ {mod_path}: {e}")
print("─────────────────────────\n")
# Fix aioredis stub __spec__
import types as _types
if "aioredis" not in sys.modules or sys.modules["aioredis"].__spec__ is None:
_am = _types.ModuleType("aioredis")
_am.__spec__ = _types.SimpleNamespace(name="aioredis")
sys.modules["aioredis"] = _am

Xet Storage Details

Size:
3.96 kB
·
Xet hash:
326a080ea8bcaa3cf8f10d8913e7a8aea890fca311e84a2e381eb8ccba811905

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