"""Suite-wide fixtures.

The git isolation below is not a convenience — without it the suite is
**unrunnable** on any machine whose user has commit signing configured.
"""

from __future__ import annotations

import os
from collections.abc import Iterator

import pytest


@pytest.fixture(autouse=True, scope="session")
def _hermetic_git_config() -> Iterator[None]:
    """Run every git-touching test against an EMPTY global/system git config.

    Several tests build a real repo in ``tmp_path`` and commit to it. They invoke
    a bare ``git commit``, which reads the *developer's* ``~/.gitconfig`` — and
    this estate signs commits with an SSH key via the desktop agent (FC-06,
    ``commit.gpgsign true``). On a developer machine that turns a unit test into a
    blocking call on the signing agent: the suite **hangs indefinitely** rather
    than failing, which reads as a stuck machine, not a test defect. It cost a
    15-minute timeout before it was diagnosed.

    The hang needs the agent to actually prompt, so it strikes on the *first* use
    of the signing key in a desktop session and not afterwards — which makes it
    intermittent, and makes "it works on my machine" a genuine report from anyone
    who happened to commit before running the suite. That is exactly why this is
    fixed by removing the dependency rather than by documenting a workaround.

    The canonical CI image has no global git config at all, so CI never saw this
    and stayed green — the suite was green there and unrunnable here, which is the
    worst shape a gate can take: it disagrees with reality only on the machine
    where someone is trying to work.

    Pointing both config paths at ``os.devnull`` reproduces the CI environment
    exactly, so a local run and a CI run mean the same thing. Tests that commit
    already set ``user.name`` / ``user.email`` on the repo itself — they must, or
    they would never have passed in CI.
    """
    with pytest.MonkeyPatch.context() as mp:
        mp.setenv("GIT_CONFIG_GLOBAL", os.devnull)
        mp.setenv("GIT_CONFIG_SYSTEM", os.devnull)
        yield
