Option C Tools
Loading...
Searching...
No Matches
test_docs_health.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# tests/tests_health/test_docs_health.py
4
5"""
6Tests for documentation health check.
7
8Purpose
9-------
10Verify that check_docs_health correctly validates required documentation files.
11
12Responsibilities
13----------------
14- Test all docs present.
15- Test individual missing files.
16- Test completely missing docs.
17
18Diagnostics
19-----------
20Domain: TESTS.HEALTH
21Levels:
22 L2 — test lifecycle
23 L3 — docs validation
24 L4 — per-file presence checks
25
26Contracts
27---------
28- All four required files are checked.
29- Counts match actual file presence.
30"""
31
32import pytest
33from pathlib import Path
34
35from oct.health.oct_health import check_docs_health
36
37
38def test_docs_health_all_present(temp_project_root: Path):
39 """Test that all required docs are detected when present."""
40 (temp_project_root / "docs" / "ARCHITECTURE.md").write_text("# Arch", encoding="utf-8")
41 (temp_project_root / "CHANGELOG.md").write_text("# Changelog", encoding="utf-8")
42 (temp_project_root / "tests" / "Tests_README.md").write_text("# Tests", encoding="utf-8")
43 (temp_project_root / "tests" / "run_tests.py").write_text("# runner", encoding="utf-8")
44 (temp_project_root / "oc_diagnostics" / "debug_config.json").write_text("{}", encoding="utf-8")
45
46 result = check_docs_health(temp_project_root)
47
48 # Standard maturity: 5 required (CHANGELOG.md added), SECURITY.md is optional.
49 assert result["total_required"] == 5
50 assert result["total_present"] == 5
51
52
53def test_docs_health_missing_architecture(temp_project_root: Path):
54 """Test detection of missing ARCHITECTURE.md."""
55 (temp_project_root / "CHANGELOG.md").write_text("# Changelog", encoding="utf-8")
56 (temp_project_root / "tests" / "Tests_README.md").write_text("# Tests", encoding="utf-8")
57 (temp_project_root / "tests" / "run_tests.py").write_text("# runner", encoding="utf-8")
58 (temp_project_root / "oc_diagnostics" / "debug_config.json").write_text("{}", encoding="utf-8")
59
60 result = check_docs_health(temp_project_root)
61
62 assert result["total_present"] == 4
63 arch_file = next(f for f in result["files"] if f["name"] == "ARCHITECTURE.md")
64 assert arch_file["present"] is False
65
66
67def test_docs_health_missing_config(temp_project_root: Path):
68 """Test detection of missing debug_config.json."""
69 (temp_project_root / "docs" / "ARCHITECTURE.md").write_text("# Arch", encoding="utf-8")
70 (temp_project_root / "CHANGELOG.md").write_text("# Changelog", encoding="utf-8")
71 (temp_project_root / "tests" / "Tests_README.md").write_text("# Tests", encoding="utf-8")
72 (temp_project_root / "tests" / "run_tests.py").write_text("# runner", encoding="utf-8")
73
74 result = check_docs_health(temp_project_root)
75
76 assert result["total_present"] == 4
77 config_file = next(f for f in result["files"] if f["name"] == "debug_config.json")
78 assert config_file["present"] is False
79
80
81def test_docs_health_missing_changelog(temp_project_root: Path):
82 """CHANGELOG.md is required at Standard maturity (drift item B1)."""
83 (temp_project_root / "docs" / "ARCHITECTURE.md").write_text("# Arch", encoding="utf-8")
84 (temp_project_root / "tests" / "Tests_README.md").write_text("# Tests", encoding="utf-8")
85 (temp_project_root / "tests" / "run_tests.py").write_text("# runner", encoding="utf-8")
86 (temp_project_root / "oc_diagnostics" / "debug_config.json").write_text("{}", encoding="utf-8")
87
88 result = check_docs_health(temp_project_root)
89
90 assert result["total_present"] == 4
91 changelog_file = next(f for f in result["files"] if f["name"] == "CHANGELOG.md")
92 assert changelog_file["present"] is False
93 assert changelog_file["required"] is True
94
95
97 """SECURITY.md is shown but not required outside Production maturity."""
98 result = check_docs_health(temp_project_root)
99
100 security_file = next(f for f in result["files"] if f["name"] == "SECURITY.md")
101 assert security_file["present"] is False
102 assert security_file["required"] is False
103 # SECURITY.md absence does not contribute to total_required.
104 assert result["total_required"] == 5
105
106
108 """SECURITY.md is required when production_mode=True (Appendix H Level 2)."""
109 result = check_docs_health(temp_project_root, production_mode=True)
110
111 assert result["total_required"] == 6
112 security_file = next(f for f in result["files"] if f["name"] == "SECURITY.md")
113 assert security_file["required"] is True
114
115
116def test_docs_health_all_missing(temp_project_root: Path):
117 """Test when no required docs exist."""
118 result = check_docs_health(temp_project_root)
119
120 assert result["total_required"] == 5
121 assert result["total_present"] == 0
122
123
124def test_docs_health_file_list_structure(temp_project_root: Path):
125 """Test that file list has correct structure."""
126 result = check_docs_health(temp_project_root)
127
128 # 5 required + 1 optional (SECURITY.md) at Standard maturity.
129 assert len(result["files"]) == 6
130 for file_info in result["files"]:
131 assert "name" in file_info
132 assert "present" in file_info
133 assert "required" in file_info
test_docs_health_missing_architecture(Path temp_project_root)
test_docs_health_security_required_in_production(Path temp_project_root)
test_docs_health_all_present(Path temp_project_root)
test_docs_health_missing_config(Path temp_project_root)
test_docs_health_file_list_structure(Path temp_project_root)
test_docs_health_missing_changelog(Path temp_project_root)
test_docs_health_all_missing(Path temp_project_root)
test_docs_health_security_optional_outside_production(Path temp_project_root)