"""Tests for myagents.commands.version.""" import subprocess from pathlib import Path from click.testing import CliRunner from myagents.commands import version as ver_mod class TestDescribeTree: def test_installed_runtime_tree(self) -> None: tree = Path("/home/u/.xiaohe/runtime/v1.2.3/contrib/myagents") mode, detail = ver_mod.describe_tree(tree) assert mode == "installed" assert detail == "v1.2.3" def test_development_checkout(self, tmp_path: Path) -> None: repo = tmp_path / "repo" repo.mkdir() (repo / ".git").mkdir() mode, _ = ver_mod.describe_tree(repo) assert mode == "development" def test_unknown_tree(self, tmp_path: Path) -> None: mode, _ = ver_mod.describe_tree(tmp_path) assert mode == "unknown" class TestGitDescribe: def test_describes_real_repo(self, tmp_path: Path) -> None: repo = tmp_path / "repo" repo.mkdir() subprocess.run(["git", "init", "-q"], cwd=repo, check=True) subprocess.run( ["git", "-c", "user.email=t@t", "-c", "user.name=t", "commit", "-q", "--allow-empty", "-m", "init"], cwd=repo, check=True, ) result = ver_mod._git_describe(repo) assert "branch" in result class TestVersionCommand: def test_runs_and_reports(self) -> None: result = CliRunner().invoke(ver_mod.version_cmd) assert result.exit_code == 0 assert "myagents" in result.output