"""Fixtures shared across the release tests.

The keypairs are session-scoped because generating one in pure Python costs
about two seconds. Once per run is fine; once per test would not be.
"""

from __future__ import annotations

import pytest

from tests.rsa_support import generate


@pytest.fixture(scope="session")
def test_key():
    """Stands in for the offline release key."""
    return generate(seed=20260729)


@pytest.fixture(scope="session")
def other_key():
    """Somebody else's key — the whole point of signing is telling them apart."""
    return generate(seed=999)


@pytest.fixture(autouse=True)
def _fresh_intake_bookkeeping():
    """Module-level intake state must not leak between tests.

    __main__ keeps two small dicts: _REFERENCES (message -> CMS reference) and
    _TAKEN (message -> take-in outcome, added with the announce-on-arrival
    pass). In production both are per-batch and popped as each message's turn
    ends; in tests, files reuse ids like "msg-1", so a cached outcome from one
    test silently answers the next — sixteen tests failed that way the day
    _TAKEN was added, every one of them green in isolation.
    """
    from app import __main__ as entry

    entry._REFERENCES.clear()
    entry._TAKEN.clear()

    yield

    entry._REFERENCES.clear()
    entry._TAKEN.clear()
