8Tests for the git health section in ``oct health`` (Phase 4E — G-E5, G-E10).
12- Validate ``check_git_health`` returns correct statuses.
13- Verify graceful degradation when git is absent or not a repo.
25- Uses ``temp_git_project`` fixture for real git repo scenarios.
26- Non-repo scenarios use bare tmp_path.
31from pathlib
import Path
38pytestmark = pytest.mark.skipif(
39 not _git_available(), reason=
"git binary not available on PATH",
49 """Tests for check_git_health()."""
53 result = check_git_health(temp_git_project)
54 assert result[
"is_repo"][
"status"] ==
"OK"
58 result = check_git_health(tmp_path)
59 assert result[
"is_repo"][
"status"] ==
"FAIL"
61 for key
in (
"branch",
"naming_conformant",
"clean_worktree",
62 "ahead_behind",
"hooks_installed",
"last_commit_conventional"):
63 assert result[key][
"status"] ==
"SKIP"
67 result = check_git_health(temp_git_project)
68 assert result[
"clean_worktree"][
"status"] ==
"OK"
73 (temp_git_project /
"src" /
"dirty.py").write_text(
"# dirty\n", encoding=
"utf-8")
74 _git(temp_git_project,
"add",
"src/dirty.py")
75 result = check_git_health(temp_git_project)
76 assert result[
"clean_worktree"][
"status"] ==
"WARN"
80 _git(temp_git_project,
"checkout",
"-b",
"feature/conv")
81 commit_file(temp_git_project,
"src/conv.py",
"# conv\n",
"feat: conventional commit")
82 result = check_git_health(temp_git_project)
83 assert result[
"last_commit_conventional"][
"status"] ==
"OK"
89 _git(temp_git_project,
"checkout",
"-b",
"feature/nonconv")
90 commit_file(temp_git_project,
"src/nc.py",
"# nc\n",
"just a random commit")
91 result = check_git_health(temp_git_project)
92 assert result[
"last_commit_conventional"][
"status"] ==
"WARN"
96 _git(temp_git_project,
"checkout",
"-b",
"feature/valid-name")
97 result = check_git_health(temp_git_project)
98 assert result[
"naming_conformant"][
"status"] ==
"OK"
102 _git(temp_git_project,
"checkout",
"-b",
"bad-name")
103 result = check_git_health(temp_git_project)
104 assert result[
"naming_conformant"][
"status"] ==
"WARN"
109 result = check_git_health(temp_git_project)
110 assert result[
"hooks_installed"][
"status"] ==
"WARN"
114 result = check_git_health(temp_git_project)
115 assert result[
"branch"][
"status"] ==
"OK"
116 assert result[
"branch"][
"detail"] ==
"main"
119 """Integration: run_health report includes git section."""
126 with contextlib.redirect_stdout(f):
127 run_health(temp_git_project, json_mode=
True)
129 output = f.getvalue()
130 data = json.loads(output)
132 assert "is_repo" in data[
"git"]
None test_non_conventional_last_commit_warn(self, Path temp_git_project)
None test_valid_branch_name_ok(self, Path temp_git_project)
None test_conventional_last_commit_ok(self, Path temp_git_project)
None test_hooks_missing_warn(self, Path temp_git_project)
None test_is_repo_ok(self, Path temp_git_project)
None test_branch_present(self, Path temp_git_project)
None test_run_health_includes_git(self, Path temp_git_project)
None test_invalid_branch_name_warn(self, Path temp_git_project)
None test_clean_worktree_ok(self, Path temp_git_project)
None test_not_a_repo(self, Path tmp_path)
None test_dirty_worktree_warn(self, Path temp_git_project)