6Integration tests for the health dashboard.
10Verify end-to-end health report generation with complete projects.
14- Test terminal output format.
15- Test JSON output format and schema.
16- Test verbose output mode.
17- Test health report with various project states.
24 L3 — full report generation
25 L4 — output validation and schema verification
29- JSON output is valid JSON with correct schema.
30- Terminal output includes all sections.
31- Verbose mode shows per-file breakdown.
36from pathlib
import Path
40from tests.tests_health.conftest
import make_compliant_file, make_func_pattern_violation_file
44 """Test that terminal output includes all sections."""
45 (temp_project_root /
"good.py").write_text(make_compliant_file(
"good.py"), encoding=
"utf-8")
47 run_health(temp_project_root)
49 captured = capsys.readouterr()
52 assert "OCT HEALTH REPORT" in output
53 assert "Lint Compliance:" in output
54 assert "Fixable Violations:" in output
55 assert "Documentation:" in output
56 assert "Tests:" in output
57 assert "oc_diagnostics:" in output
61 """Test that JSON output is valid and has correct schema."""
62 (temp_project_root /
"good.py").write_text(make_compliant_file(
"good.py"), encoding=
"utf-8")
64 run_health(temp_project_root, json_mode=
True)
66 captured = capsys.readouterr()
67 data = json.loads(captured.out)
69 assert "project" in data
70 assert "oct_version" in data
71 assert "timestamp" in data
73 assert "fixable" in data
75 assert "tests" in data
76 assert "compat" in data
80 """Test that JSON lint section has correct schema."""
81 (temp_project_root /
"good.py").write_text(make_compliant_file(
"good.py"), encoding=
"utf-8")
83 run_health(temp_project_root, json_mode=
True)
85 captured = capsys.readouterr()
86 data = json.loads(captured.out)
89 assert "total_files" in lint
90 assert "fully_compliant" in lint
91 assert "compliance_pct" in lint
92 assert "checks" in lint
96 """Test that JSON fixable section has correct schema."""
97 (temp_project_root /
"good.py").write_text(make_compliant_file(
"good.py"), encoding=
"utf-8")
99 run_health(temp_project_root, json_mode=
True)
101 captured = capsys.readouterr()
102 data = json.loads(captured.out)
104 fixable = data[
"fixable"]
105 assert "total" in fixable
106 assert "header" in fixable
107 assert "docstring" in fixable
108 assert "dbg_import" in fixable
109 assert "func_pattern" in fixable
113 """Test that verbose mode shows per-file breakdown."""
114 (temp_project_root /
"good.py").write_text(make_compliant_file(
"good.py"), encoding=
"utf-8")
116 run_health(temp_project_root, verbose=
True)
118 captured = capsys.readouterr()
119 output = captured.out
121 assert "OCT HEALTH REPORT" in output
125 """Test health report on empty project."""
126 run_health(temp_project_root, json_mode=
True)
128 captured = capsys.readouterr()
129 data = json.loads(captured.out)
131 assert data[
"lint"][
"total_files"] == 0
132 assert data[
"lint"][
"compliance_pct"] == 0.0
133 assert data[
"fixable"][
"total"] == 0
137 """Test that missing tests/ directory is handled."""
139 shutil.rmtree(temp_project_root /
"tests")
141 run_health(temp_project_root, json_mode=
True)
143 captured = capsys.readouterr()
144 data = json.loads(captured.out)
146 assert data[
"tests"][
"status"] ==
"not_run"
150 """Test that compat check returns valid structure."""
151 result = check_compat_health()
153 assert "installed" in result
154 assert "version" in result
155 assert "compatible" in result
156 assert "message" in result
157 assert isinstance(result[
"installed"], bool)
161 """Test fallback to diagnostics/ directory."""
163 shutil.rmtree(temp_project_root /
"oc_diagnostics")
164 (temp_project_root /
"diagnostics").mkdir()
166 run_health(temp_project_root, json_mode=
True)
168 captured = capsys.readouterr()
169 data = json.loads(captured.out)
172 assert "lint" in data
173 assert "docs" in data
181 """Explicit test_timeout parameter is threaded through to check_test_health (OI-413)."""
186 def fake_check(project_root, timeout=300, **_kwargs):
187 captured[
"timeout"] = timeout
191 "summary":
"0 passed",
193 "coverage_pct":
None,
194 "coverage_threshold":
None,
195 "coverage_blocking":
False,
198 monkeypatch.setattr(oct_health,
"check_test_health", fake_check)
199 run_health(temp_project_root, json_mode=
True, test_timeout=37)
200 assert captured.get(
"timeout") == 37
204 """health.test_timeout in .octrc.json is honored when no explicit value (OI-413)."""
207 (temp_project_root /
".octrc.json").write_text(
208 json.dumps({
"health": {
"test_timeout": 55}}), encoding=
"utf-8"
212 def fake_check(project_root, timeout=300, **_kwargs):
213 captured[
"timeout"] = timeout
215 "status":
"pass",
"exit_code": 0,
216 "summary":
"0 passed",
"details": [],
217 "coverage_pct":
None,
"coverage_threshold":
None,
218 "coverage_blocking":
False,
221 monkeypatch.setattr(oct_health,
"check_test_health", fake_check)
222 run_health(temp_project_root, json_mode=
True)
223 assert captured.get(
"timeout") == 55
227 """Explicit test_timeout wins over .octrc.json health.test_timeout (OI-413)."""
230 (temp_project_root /
".octrc.json").write_text(
231 json.dumps({
"health": {
"test_timeout": 55}}), encoding=
"utf-8"
235 def fake_check(project_root, timeout=300, **_kwargs):
236 captured[
"timeout"] = timeout
238 "status":
"pass",
"exit_code": 0,
239 "summary":
"0 passed",
"details": [],
240 "coverage_pct":
None,
"coverage_threshold":
None,
241 "coverage_blocking":
False,
244 monkeypatch.setattr(oct_health,
"check_test_health", fake_check)
245 run_health(temp_project_root, json_mode=
True, test_timeout=99)
246 assert captured.get(
"timeout") == 99
254 """Verbose fixable check must list files with func_pattern violations."""
255 (temp_project_root /
"bad.py").write_text(
256 make_func_pattern_violation_file(
"bad.py"), encoding=
"utf-8",
259 result = check_fixable_health(
260 temp_project_root, linter_ctx, verbose=
True,
263 assert result[
"func_pattern"] == 1
264 assert "files" in result
265 paths = [f[
"path"]
for f
in result[
"files"]]
266 assert any(
"bad.py" in p
for p
in paths)
268 fixes = result[
"files"][0][
"fixes"]
269 assert "func_pattern" in fixes
273 """Non-verbose fixable check must not include a 'files' key (backward compat)."""
274 (temp_project_root /
"bad.py").write_text(
275 make_func_pattern_violation_file(
"bad.py"), encoding=
"utf-8",
278 result = check_fixable_health(
279 temp_project_root, linter_ctx, verbose=
False,
282 assert result[
"func_pattern"] == 1
283 assert "files" not in result
287 """Verbose fixable check with a compliant file must return empty files list."""
288 (temp_project_root /
"good.py").write_text(
289 make_compliant_file(
"good.py"), encoding=
"utf-8",
292 result = check_fixable_health(
293 temp_project_root, linter_ctx, verbose=
True,
296 assert result[
"total"] == 0
297 assert result[
"files"] == []
test_fixable_verbose_lists_violating_files(Path temp_project_root, LinterContext linter_ctx)
test_health_empty_project(Path temp_project_root, capsys)
test_health_test_status_no_tests_dir(Path temp_project_root, capsys)
test_health_compat_check()
test_fixable_non_verbose_omits_files_key(Path temp_project_root, LinterContext linter_ctx)
test_fixable_verbose_no_violations_empty_files(Path temp_project_root, LinterContext linter_ctx)
test_health_diagnostics_dir_fallback(Path temp_project_root, capsys)
test_health_json_output(Path temp_project_root, capsys)
test_health_test_timeout_explicit_overrides_default(Path temp_project_root, monkeypatch)
test_health_test_timeout_from_octrc(Path temp_project_root, monkeypatch)
test_health_json_lint_schema(Path temp_project_root, capsys)
test_health_json_fixable_schema(Path temp_project_root, capsys)
test_health_verbose_output(Path temp_project_root, capsys)
test_health_explicit_timeout_overrides_octrc(Path temp_project_root, monkeypatch)
test_health_terminal_output(Path temp_project_root, capsys)