from __future__ import annotations

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent))

from chekan.accept import detect, load_profiles


def test_load_profiles_valid() -> None:
    profiles, fallback = load_profiles()
    assert isinstance(profiles, list)
    assert isinstance(fallback, dict)
    profile_ids = [p["id"] for p in profiles]
    assert "chekan" in profile_ids
    assert "android" in profile_ids
    assert "golang" in profile_ids
    assert "rust" in profile_ids


def test_detect_android(tmp_path: Path) -> None:
    (tmp_path / "gradlew").touch()
    (tmp_path / "settings.gradle").touch()
    profile = detect(tmp_path)
    assert profile["id"] == "android"
    assert "./gradlew testDebugUnitTest -q" in profile["checks"]


def test_detect_golang(tmp_path: Path) -> None:
    (tmp_path / "go.mod").write_text("module example.com/test\n", encoding="utf-8")
    profile = detect(tmp_path)
    assert profile["id"] == "golang"
    assert "go test ./..." in profile["checks"]


def test_detect_rust(tmp_path: Path) -> None:
    (tmp_path / "Cargo.toml").write_text("[package]\nname = 'test'\n", encoding="utf-8")
    profile = detect(tmp_path)
    assert profile["id"] == "rust"
    assert "cargo test" in profile["checks"]
