refactor(tests): move flat tests/*.py into per-subsystem subfolders
Groups every flat test_*.py under the module it exercises, matching the
existing tests/{profiler,sniffer,prober,collector,correlation,cli,web,
topology,swarm,bus,updater,api,docker,geoip,...} layout. New folders:
services/, fleet/, config/, logging/, db/ (+ db/mysql/), telemetry/,
mutator/, core/.
Path-dependent __file__ references bumped an extra .parent in three
files that moved one level deeper:
- tests/sniffer/test_sniffer_ja3.py (template path)
- tests/services/test_ssh_capture_emit.py (template path)
- tests/cli/test_mode_gating.py (REPO root)
- tests/web/test_env_lazy_jwt.py (repo var)
Also drops two SQLite runtime artifacts (test_decnet.db-{shm,wal}) that
were leaking into the repo from a previous test run.
Fixes two test_service_isolation cases that patched asyncio.sleep (no
longer on the profiler main-loop hot path — same pre-existing bug I
fixed earlier in test_attacker_worker.py) by patching asyncio.wait_for
and passing interval=0.
This commit is contained in:
@@ -10,7 +10,7 @@ from pathlib import Path
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
REPO = pathlib.Path(__file__).resolve().parent.parent
|
REPO = pathlib.Path(__file__).resolve().parent.parent.parent
|
||||||
#DECNET_BIN = REPO / ".venv" / "bin" / "decnet"
|
#DECNET_BIN = REPO / ".venv" / "bin" / "decnet"
|
||||||
DECNET_BIN = Path(sys.executable).parent / "decnet"
|
DECNET_BIN = Path(sys.executable).parent / "decnet"
|
||||||
|
|
||||||
0
tests/config/__init__.py
Normal file
0
tests/config/__init__.py
Normal file
0
tests/core/__init__.py
Normal file
0
tests/core/__init__.py
Normal file
0
tests/db/__init__.py
Normal file
0
tests/db/__init__.py
Normal file
0
tests/db/mysql/__init__.py
Normal file
0
tests/db/mysql/__init__.py
Normal file
0
tests/fleet/__init__.py
Normal file
0
tests/fleet/__init__.py
Normal file
0
tests/logging/__init__.py
Normal file
0
tests/logging/__init__.py
Normal file
0
tests/mutator/__init__.py
Normal file
0
tests/mutator/__init__.py
Normal file
0
tests/services/__init__.py
Normal file
0
tests/services/__init__.py
Normal file
@@ -202,15 +202,19 @@ class TestAttackerWorkerIsolation:
|
|||||||
mock_repo.set_state = AsyncMock()
|
mock_repo.set_state = AsyncMock()
|
||||||
|
|
||||||
iterations = 0
|
iterations = 0
|
||||||
|
real_wait_for = asyncio.wait_for
|
||||||
|
|
||||||
async def _controlled_sleep(seconds):
|
async def _controlled_wait_for(awaitable, timeout):
|
||||||
nonlocal iterations
|
nonlocal iterations
|
||||||
iterations += 1
|
iterations += 1
|
||||||
if iterations >= 3:
|
if iterations >= 3:
|
||||||
|
if asyncio.iscoroutine(awaitable):
|
||||||
|
awaitable.close()
|
||||||
raise asyncio.CancelledError()
|
raise asyncio.CancelledError()
|
||||||
|
return await real_wait_for(awaitable, timeout)
|
||||||
|
|
||||||
with patch("decnet.profiler.worker.asyncio.sleep", side_effect=_controlled_sleep):
|
with patch("decnet.profiler.worker.asyncio.wait_for", side_effect=_controlled_wait_for):
|
||||||
task = asyncio.create_task(attacker_profile_worker(mock_repo))
|
task = asyncio.create_task(attacker_profile_worker(mock_repo, interval=0))
|
||||||
with pytest.raises(asyncio.CancelledError):
|
with pytest.raises(asyncio.CancelledError):
|
||||||
await task
|
await task
|
||||||
# Worker should have retried at least twice before we cancelled
|
# Worker should have retried at least twice before we cancelled
|
||||||
@@ -454,15 +458,19 @@ class TestCascadeIsolation:
|
|||||||
mock_repo.get_logs_after_id = AsyncMock(return_value=[])
|
mock_repo.get_logs_after_id = AsyncMock(return_value=[])
|
||||||
|
|
||||||
iterations = 0
|
iterations = 0
|
||||||
|
real_wait_for = asyncio.wait_for
|
||||||
|
|
||||||
async def _controlled_sleep(seconds):
|
async def _controlled_wait_for(awaitable, timeout):
|
||||||
nonlocal iterations
|
nonlocal iterations
|
||||||
iterations += 1
|
iterations += 1
|
||||||
if iterations >= 3:
|
if iterations >= 3:
|
||||||
|
if asyncio.iscoroutine(awaitable):
|
||||||
|
awaitable.close()
|
||||||
raise asyncio.CancelledError()
|
raise asyncio.CancelledError()
|
||||||
|
return await real_wait_for(awaitable, timeout)
|
||||||
|
|
||||||
with patch("decnet.profiler.worker.asyncio.sleep", side_effect=_controlled_sleep):
|
with patch("decnet.profiler.worker.asyncio.wait_for", side_effect=_controlled_wait_for):
|
||||||
task = asyncio.create_task(attacker_profile_worker(mock_repo))
|
task = asyncio.create_task(attacker_profile_worker(mock_repo, interval=0))
|
||||||
with pytest.raises(asyncio.CancelledError):
|
with pytest.raises(asyncio.CancelledError):
|
||||||
await task
|
await task
|
||||||
# Attacker should have run independently
|
# Attacker should have run independently
|
||||||
@@ -19,7 +19,7 @@ import pytest
|
|||||||
|
|
||||||
from decnet.collector.worker import parse_rfc5424
|
from decnet.collector.worker import parse_rfc5424
|
||||||
|
|
||||||
_TEMPLATE_DIR = Path(__file__).resolve().parent.parent / "decnet" / "templates" / "ssh"
|
_TEMPLATE_DIR = Path(__file__).resolve().parent.parent.parent / "decnet" / "templates" / "ssh"
|
||||||
_EMIT_SCRIPT = _TEMPLATE_DIR / "emit_capture.py"
|
_EMIT_SCRIPT = _TEMPLATE_DIR / "emit_capture.py"
|
||||||
|
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ import pytest
|
|||||||
|
|
||||||
# ─── Import sniffer module with mocked syslog_bridge ─────────────────────────
|
# ─── Import sniffer module with mocked syslog_bridge ─────────────────────────
|
||||||
|
|
||||||
_SNIFFER_DIR = str(Path(__file__).parent.parent / "decnet" / "templates" / "sniffer")
|
_SNIFFER_DIR = str(Path(__file__).parent.parent.parent / "decnet" / "templates" / "sniffer")
|
||||||
|
|
||||||
def _load_sniffer():
|
def _load_sniffer():
|
||||||
"""Load decnet/templates/sniffer/server.py with syslog_bridge stubbed out."""
|
"""Load decnet/templates/sniffer/server.py with syslog_bridge stubbed out."""
|
||||||
0
tests/telemetry/__init__.py
Normal file
0
tests/telemetry/__init__.py
Normal file
Binary file not shown.
Binary file not shown.
@@ -41,7 +41,7 @@ def test_agent_cli_imports_without_jwt_secret(monkeypatch, tmp_path):
|
|||||||
}
|
}
|
||||||
clean_env["PATH"] = os.environ["PATH"]
|
clean_env["PATH"] = os.environ["PATH"]
|
||||||
clean_env["HOME"] = str(tmp_path)
|
clean_env["HOME"] = str(tmp_path)
|
||||||
repo = pathlib.Path(__file__).resolve().parent.parent
|
repo = pathlib.Path(__file__).resolve().parent.parent.parent
|
||||||
# binary = repo / ".venv" / "bin" / "decnet"
|
# binary = repo / ".venv" / "bin" / "decnet"
|
||||||
binary = Path(sys.executable).parent / "decnet"
|
binary = Path(sys.executable).parent / "decnet"
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
Reference in New Issue
Block a user