test: fix async fixture isolation, add fuzz marks, parallelize with xdist

- Rebuild repo.engine and repo.session_factory per-test using unique
  in-memory SQLite URIs — fixes KeyError: 'access_token' caused by
  stale session_factory pointing at production DB
- Add @pytest.mark.fuzz to all Hypothesis and Schemathesis tests;
  default run excludes them (addopts = -m 'not fuzz')
- Add missing fuzz tests to bounty, fleet, histogram, and repository
- Use tmp_path for state file in patch_state_file/mock_state_file to
  eliminate file-path race conditions under xdist parallelism
- Set default addopts: -v -q -x -n logical (26 tests in ~7s)
This commit is contained in:
2026-04-09 18:32:46 -04:00
parent 6fc1a2a3ea
commit d15c106b44
11 changed files with 136 additions and 34 deletions

View File

@@ -9,7 +9,9 @@ import json
import pytest
from datetime import datetime, timedelta
from freezegun import freeze_time
from hypothesis import given, settings, strategies as st
from decnet.web.db.sqlite.repository import SQLiteRepository
from ..conftest import _FUZZ_SETTINGS
@pytest.fixture
@@ -98,3 +100,18 @@ async def test_histogram_search_filter(repo):
result = await repo.get_log_histogram(search="service:ssh", interval_minutes=15)
total = sum(r["count"] for r in result)
assert total == 1
@pytest.mark.fuzz
@pytest.mark.anyio
@settings(**_FUZZ_SETTINGS)
@given(
search=st.one_of(st.none(), st.text(max_size=512)),
interval_minutes=st.integers(min_value=1, max_value=10000),
)
async def test_fuzz_histogram(repo, search: str | None, interval_minutes: int) -> None:
"""Fuzz histogram params — must never raise uncaught exceptions."""
try:
await repo.get_log_histogram(search=search, interval_minutes=interval_minutes)
except Exception as exc:
pytest.fail(f"get_log_histogram raised unexpectedly: {exc}")