feat: xiaohe version——显示 bin 跑的是研发检出还是安装快照(含 git describe);uninstall --all 三重确认

This commit is contained in:
Zhengshou Lai
2026-07-16 19:13:51 +08:00
parent 37eae6f283
commit f878a49c8a
5 changed files with 178 additions and 8 deletions
+22 -1
View File
@@ -53,11 +53,32 @@ class TestUninstall:
def test_all_removes_xiaohe_dir(self, fake_home: Path) -> None:
_populate(fake_home)
result = CliRunner().invoke(un_mod.uninstall_cmd, ["--all", "--yes"])
result = CliRunner().invoke(
un_mod.uninstall_cmd, ["--all", "--yes"], input="y\ndelete-all\n"
)
assert result.exit_code == 0
assert not (fake_home / ".xiaohe").exists()
assert (fake_home / "workspace").is_dir() # workspace never touched
def test_all_requires_full_chain_even_with_yes(self, fake_home: Path) -> None:
_populate(fake_home)
# --yes skips only the first gate; declining the second cancels.
result = CliRunner().invoke(
un_mod.uninstall_cmd, ["--all", "--yes"], input="n\n"
)
assert result.exit_code == 0
assert "Cancelled" in result.output
assert (fake_home / ".xiaohe").exists()
def test_all_aborts_on_wrong_phrase(self, fake_home: Path) -> None:
_populate(fake_home)
result = CliRunner().invoke(
un_mod.uninstall_cmd, ["--all", "--yes"], input="y\nnope\n"
)
assert result.exit_code == 0
assert "Cancelled" in result.output
assert (fake_home / ".xiaohe").exists()
def test_cancelled_keeps_everything(self, fake_home: Path) -> None:
_populate(fake_home)
result = CliRunner().invoke(un_mod.uninstall_cmd, [], input="n\n")
+48
View File
@@ -0,0 +1,48 @@
"""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