"""Fixtures for the real-kernel concurrency suite (concurrency-restructure plan, 19 cases).

NOT part of the default `pytest tests/unit` gate — run explicitly with `pytest tests/concurrency
-q` (docs/concurrency.md). Locks live in a per-test tmp dir (CCCI_APP_LOCK_DIR); helper
subprocesses hold REAL flocks / install the REAL prctl+signal guards and are always reaped in
fixture finalizers (no leaked children in the test VM).
"""

from __future__ import annotations

import os
import sys

import pytest

sys.path.insert(0, os.path.dirname(__file__))
from concutil import HelperPool  # noqa: E402


@pytest.fixture
def lock_dir(tmp_path, monkeypatch):
    """Sandbox lock dir, exported so BOTH this process's lifecycle calls and helper subprocesses
    (which inherit os.environ) resolve their lockfiles here — never /run/lock."""
    d = tmp_path / "locks"
    d.mkdir()
    monkeypatch.setenv("CCCI_APP_LOCK_DIR", str(d))
    return str(d)


@pytest.fixture
def pool(tmp_path):
    hp = HelperPool(str(tmp_path))
    yield hp
    hp.cleanup()
