"""CLI tests for `attractor init`."""

from __future__ import annotations

import os
from pathlib import Path

from click.testing import CliRunner

from attractor.cli.main import cli


# [unit->REQ-CLI-SCAFFOLD]
def test_init_in_git_repo_exits_zero(seeded_repo: Path) -> None:
    """`attractor init` in a git repo prints OK and exits 0."""
    cwd = os.getcwd()
    try:
        os.chdir(seeded_repo)
        runner = CliRunner()
        result = runner.invoke(cli, ["init"])
        assert result.exit_code == 0
        assert "repo OK" in result.output
    finally:
        os.chdir(cwd)


# [unit->REQ-CLI-SCAFFOLD]
def test_init_outside_git_repo_exits_two(tmp_path: Path) -> None:
    """Not-a-git-repo maps to exit 2 with a clear hint."""
    not_a_repo = tmp_path / "scratch"
    not_a_repo.mkdir()
    cwd = os.getcwd()
    try:
        os.chdir(not_a_repo)
        runner = CliRunner()
        result = runner.invoke(cli, ["init"])
        assert result.exit_code == 2
        assert "not inside a git repository" in (result.stderr or "")
    finally:
        os.chdir(cwd)
