test_guard_checks_extended.py¶
tests/guard/test_guard_checks_extended.py
Tests for extended validation checks (Phase 5).
test_analyze_coverage_structure
test_guard_checks_extended.TestCoverageSubcommand.test_analyze_coverage_structure(self)
tests/guard/test_guard_checks_extended.py:175
Checks
assert "total_requirements" in reportassert "covered" in reportassert "uncovered" in reportassert "orphan_refs" in reportassert isinstance(report["covered"], list)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_analyze_coverage_structure → analyze_coverage → covered_via → read_catalog_at → git_text → git_argv |
| REQ-DDB-CONFIG-009 | measured | test_analyze_coverage_structure → analyze_coverage → collect_tagged_functions → find_source_files → gate_exclusion |
| REQ-DDB-GUARD-011 | measured | test_analyze_coverage_structure → analyze_coverage → load_requirements_full |
| REQ-DDB-GUARD-013 | measured | test_analyze_coverage_structure → analyze_coverage → collect_tagged_functions → find_source_files |
| REQ-DDB-GUARD-016 | measured | test_analyze_coverage_structure → analyze_coverage → load_requirements_full → _get_requirements_config → resolve_contained_path |
| REQ-DDB-GUARD-018 | measured | test_analyze_coverage_structure → analyze_coverage → collect_tagged_functions → _process_source_file → parse_source_file_with_content |
| REQ-DDB-GUARD-019 | measured | test_analyze_coverage_structure → analyze_coverage → collect_tagged_functions → _process_source_file → parse_source_file_with_content → parse_content_for_file → parse_functions → parse_functions_ts → _collect_functions → _find_preceding_doxygen → parse_doxygen_tags |
| REQ-DDB-GUARD-020 | measured | test_analyze_coverage_structure → analyze_coverage → collect_tagged_functions → _process_source_file → parse_source_file_with_content → parse_content_for_file → language_for_file |
| REQ-DDB-GUARD-021 | inferred | test_analyze_coverage_structure → analyze_coverage → collect_tagged_functions → _process_source_file → parse_source_file_with_content → parse_content_for_file → parse_functions → parse_functions_ts → _collect_functions → _find_preceding_doxygen → _find_python_docstring_block |
| REQ-DDB-GUARD-022 | measured | test_analyze_coverage_structure → analyze_coverage |
| REQ-DDB-GUARD-024 | inferred | test_analyze_coverage_structure → analyze_coverage → collect_tagged_functions → _process_source_file → parse_source_file_with_content → parse_content_for_file → parse_functions → parse_functions_ts → _collect_functions → _is_rust_test_item |
| REQ-DDB-GUARD-025 | measured | test_analyze_coverage_structure → analyze_coverage → collect_tagged_functions → _process_source_file → parse_source_file_with_content → parse_content_for_file → parse_functions → parse_functions_ts → _collect_functions → _js_returns_void |
| REQ-DDB-GUARD-027 | inferred | test_analyze_coverage_structure → analyze_coverage → covered_via → read_catalog_at |
| REQ-DDB-PIPE-011 | measured | test_analyze_coverage_structure → analyze_coverage → collect_tagged_functions → find_source_files → gate_exclusion → binary_file |
| REQ-DDB-SCHEMA-015 | inferred | test_analyze_coverage_structure → analyze_coverage → covered_via → _realised → link_ids |
| REQ-DDB-WIKI-054 | inferred | test_analyze_coverage_structure → analyze_coverage → collect_tagged_functions → find_source_files → gate_exclusion → _gate_matcher → load_toolchain_config → _string_list → all |
Source · 22 lines
def test_analyze_coverage_structure(self):
from clew.guard.coverage import analyze_coverage
source_dir = str(FIXTURES_DIR / "sources")
config = deep_merge(
BASE_CONFIG,
{
"requirements": {
"file": str(FIXTURES_DIR / "sources" / "requirements.csv"),
"id_column": "Req ID",
"name_column": "Name",
"format": "csv",
},
},
)
report = analyze_coverage([source_dir], config)
assert "total_requirements" in report
assert "covered" in report
assert "uncovered" in report
assert "orphan_refs" in report
assert isinstance(report["covered"], list)
Activity · 9 steps
test_c_file_missing_tags_fails
test_guard_checks_extended.TestCheckFilePresence.test_c_file_missing_tags_fails(self)
tests/guard/test_guard_checks_extended.py:121
Checks
assert len(violations) >= 1assert any("@brief" in v.message or "@version" in v.message for v in violations)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-006 | measured | test_c_file_missing_tags_fails → check_file_presence |
| REQ-DDB-GUARD-019 | measured | test_c_file_missing_tags_fails → check_file_presence → _check_file_block_tags → parse_doxygen_tags |
| REQ-DDB-GUARD-024 | inferred | test_c_file_missing_tags_fails → check_file_presence → _check_file_block_tags → apply_autobrief |
Source · 7 lines
def test_c_file_missing_tags_fails(self):
content = "/** @file sensor_driver.c */\nvoid func(void) {}\n"
config = deep_merge(BASE_CONFIG, {"validate": {"presence": {"require_file_doxygen": True}}})
violations = check_file_presence("a.c", content, config)
assert len(violations) >= 1
assert any("@brief" in v.message or "@version" in v.message for v in violations)
Activity · 5 steps
test_c_file_with_complete_block_passes
test_guard_checks_extended.TestCheckFilePresence.test_c_file_with_complete_block_passes(self)
tests/guard/test_guard_checks_extended.py:113
Checks
assert len(violations) == 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-006 | measured | test_c_file_with_complete_block_passes → check_file_presence |
| REQ-DDB-GUARD-019 | measured | test_c_file_with_complete_block_passes → check_file_presence → _check_file_block_tags → parse_doxygen_tags |
| REQ-DDB-GUARD-024 | inferred | test_c_file_with_complete_block_passes → check_file_presence → _check_file_block_tags → apply_autobrief |
Source · 8 lines
def test_c_file_with_complete_block_passes(self):
content = (
"/**\n * @file\n * @brief Sensor driver.\n * @version 1.0\n */\nvoid func(void) {}\n"
)
config = deep_merge(BASE_CONFIG, {"validate": {"presence": {"require_file_doxygen": True}}})
violations = check_file_presence("a.c", content, config)
assert len(violations) == 0
Activity · 4 steps
test_c_file_without_file_block_fails
test_guard_checks_extended.TestCheckFilePresence.test_c_file_without_file_block_fails(self)
tests/guard/test_guard_checks_extended.py:128
Checks
assert len(violations) == 1
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-006 | measured | test_c_file_without_file_block_fails → check_file_presence |
| REQ-DDB-GUARD-019 | inferred | test_c_file_without_file_block_fails → check_file_presence → _check_file_block_tags → parse_doxygen_tags |
| REQ-DDB-GUARD-024 | inferred | test_c_file_without_file_block_fails → check_file_presence → _check_file_block_tags → apply_autobrief |
Source · 6 lines
def test_c_file_without_file_block_fails(self):
content = "void func(void) {}\n"
config = deep_merge(BASE_CONFIG, {"validate": {"presence": {"require_file_doxygen": True}}})
violations = check_file_presence("a.c", content, config)
assert len(violations) == 1
Activity · 4 steps
test_disabled_by_config
test_guard_checks_extended.TestCheckUnknownTags.test_disabled_by_config(self)
tests/guard/test_guard_checks_extended.py:83
Checks
assert len(violations) == 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-001 | measured | test_disabled_by_config → check_unknown_tags |
Source · 7 lines
def test_disabled_by_config(self):
config = deep_merge(BASE_CONFIG, {"validate": {"known_tags_warn": False}})
func = _make_func("f", tags={"brief": ["desc"], "bogus": ["val"]})
violations = check_unknown_tags(func, "a.c", config)
assert len(violations) == 0
Activity · 4 steps
test_disabled_by_default
test_guard_checks_extended.TestCheckFilePresence.test_disabled_by_default(self)
tests/guard/test_guard_checks_extended.py:140
Checks
assert len(violations) == 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-006 | measured | test_disabled_by_default → check_file_presence |
| REQ-DDB-GUARD-019 | inferred | test_disabled_by_default → check_file_presence → _check_file_block_tags → parse_doxygen_tags |
| REQ-DDB-GUARD-024 | inferred | test_disabled_by_default → check_file_presence → _check_file_block_tags → apply_autobrief |
Source · 5 lines
def test_disabled_by_default(self):
content = "void func(void) {}\n"
violations = check_file_presence("a.c", content, BASE_CONFIG)
assert len(violations) == 0
Activity · 3 steps
test_extra_tags_accepted
test_guard_checks_extended.TestCheckUnknownTags.test_extra_tags_accepted(self)
tests/guard/test_guard_checks_extended.py:77
Checks
assert len(violations) == 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-001 | measured | test_extra_tags_accepted → check_unknown_tags |
Source · 6 lines
def test_extra_tags_accepted(self):
config = deep_merge(BASE_CONFIG, {"validate": {"extra_tags": ["custom"]}})
func = _make_func("f", tags={"brief": ["desc"], "custom": ["val"]})
violations = check_unknown_tags(func, "a.c", config)
assert len(violations) == 0
Activity · 4 steps
test_format_coverage_markdown
test_guard_checks_extended.TestCoverageSubcommand.test_format_coverage_markdown(self)
tests/guard/test_guard_checks_extended.py:197
Checks
assert "# Requirements Coverage" in mdassert "REQ-003" in md
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-022 | measured | test_format_coverage_markdown → format_coverage_markdown |
Source · 14 lines
def test_format_coverage_markdown(self):
from clew.guard.coverage import format_coverage_markdown
report = {
"total_requirements": 5,
"covered": ["REQ-001", "REQ-002"],
"uncovered": ["REQ-003"],
"supports_only": [],
"orphan_refs": [],
"unmapped_functions": ["helper"],
}
md = format_coverage_markdown(report)
assert "# Requirements Coverage" in md
assert "REQ-003" in md1 more lines, not shown
Activity · 5 steps
test_include_guards_skipped
test_guard_checks_extended.TestCheckFilePresence.test_include_guards_skipped(self)
tests/guard/test_guard_checks_extended.py:145
Checks
assert len(violations) == 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-006 | measured | test_include_guards_skipped → check_file_presence |
| REQ-DDB-GUARD-019 | measured | test_include_guards_skipped → check_file_presence → _check_file_block_tags → parse_doxygen_tags |
| REQ-DDB-GUARD-024 | inferred | test_include_guards_skipped → check_file_presence → _check_file_block_tags → apply_autobrief |
Source · 11 lines
def test_include_guards_skipped(self):
content = (
"#ifndef FOO_H\n#define FOO_H\n"
"/**\n * @file\n * @brief Header.\n * @version 1.0\n */\n"
"void f(void);\n#endif\n"
)
config = deep_merge(BASE_CONFIG, {"validate": {"presence": {"require_file_doxygen": True}}})
violations = check_file_presence("a.h", content, config)
assert len(violations) == 0
Activity · 4 steps
test_known_tag_no_violation
test_guard_checks_extended.TestCheckUnknownTags.test_known_tag_no_violation(self)
tests/guard/test_guard_checks_extended.py:43
Checks
assert len(violations) == 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-001 | measured | test_known_tag_no_violation → check_unknown_tags |
Source · 5 lines
def test_known_tag_no_violation(self):
func = _make_func("f", tags={"brief": ["desc"], "version": ["1.0"]})
violations = check_unknown_tags(func, "a.c", BASE_CONFIG)
assert len(violations) == 0
Activity · 3 steps
test_levenshtein_suggestion
test_guard_checks_extended.TestCheckUnknownTags.test_levenshtein_suggestion(self)
tests/guard/test_guard_checks_extended.py:54
Checks
assert "did you mean @version?" in violations[0].message
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-001 | measured | test_levenshtein_suggestion → check_unknown_tags |
Source · 5 lines
def test_levenshtein_suggestion(self):
func = _make_func("f", tags={"brief": ["desc"], "verison": ["1.0"]})
violations = check_unknown_tags(func, "a.c", BASE_CONFIG)
assert "did you mean @version?" in violations[0].message
Activity · 3 steps
test_missing_brief_has_fix_hint
test_guard_checks_extended.TestFixHints.test_missing_brief_has_fix_hint(self)
tests/guard/test_guard_checks_extended.py:164
Checks
assert len(brief_violations) == 1assert "add" in brief_violations[0].message.lower()
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-001 | measured | test_missing_brief_has_fix_hint → check_presence |
| REQ-DDB-GUARD-005 | inferred | test_missing_brief_has_fix_hint → check_presence → _is_void_function |
Source · 8 lines
def test_missing_brief_has_fix_hint(self):
func = _make_func("f", tags={"version": ["1.0"]})
violations = check_presence([func], "a.c", BASE_CONFIG)
brief_violations = [v for v in violations if "brief" in v.message.lower()]
assert len(brief_violations) == 1
assert "add" in brief_violations[0].message.lower()
Activity · 5 steps
test_missing_doxygen_has_fix_hint
test_guard_checks_extended.TestFixHints.test_missing_doxygen_has_fix_hint(self)
tests/guard/test_guard_checks_extended.py:159
Checks
assert any("@brief" in v.message for v in violations)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-001 | measured | test_missing_doxygen_has_fix_hint → check_presence |
| REQ-DDB-GUARD-005 | inferred | test_missing_doxygen_has_fix_hint → check_presence → _is_void_function |
Source · 5 lines
def test_missing_doxygen_has_fix_hint(self):
func = Function(name="helper", def_line=5, body_end=7, doxygen=None)
violations = check_presence([func], "a.c", BASE_CONFIG)
assert any("@brief" in v.message for v in violations)
Activity · 3 steps
test_no_req_ids_skips
test_guard_checks_extended.TestCheckReqExists.test_no_req_ids_skips(self)
tests/guard/test_guard_checks_extended.py:104
Checks
assert len(violations) == 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-001 | measured | test_no_req_ids_skips → check_req_exists |
| REQ-DDB-GUARD-027 | inferred | test_no_req_ids_skips → check_req_exists → _uncheckable |
Source · 6 lines
def test_no_req_ids_skips(self):
func = _make_func("f", tags={"brief": ["d"], "req": ["REQ-001"]})
violations = check_req_exists(func, "a.c", BASE_CONFIG, req_ids=None)
assert len(violations) == 0
Activity · 3 steps
test_python_file_with_complete_block_passes
test_guard_checks_extended.TestCheckFilePresence.test_python_file_with_complete_block_passes(self)
tests/guard/test_guard_checks_extended.py:134
Checks
assert len(violations) == 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-006 | measured | test_python_file_with_complete_block_passes → check_file_presence |
| REQ-DDB-GUARD-019 | measured | test_python_file_with_complete_block_passes → check_file_presence → _check_file_block_tags → parse_doxygen_tags |
| REQ-DDB-GUARD-024 | inferred | test_python_file_with_complete_block_passes → check_file_presence → _check_file_block_tags → apply_autobrief |
Source · 6 lines
def test_python_file_with_complete_block_passes(self):
content = "## @file\n## @brief Module.\n## @version 1.0\ndef func(): pass\n"
config = deep_merge(BASE_CONFIG, {"validate": {"presence": {"require_file_doxygen": True}}})
violations = check_file_presence("a.py", content, config)
assert len(violations) == 0
Activity · 4 steps
test_retired_tags_can_be_readmitted_via_extra_tags
test_guard_checks_extended.TestCheckUnknownTags.test_retired_tags_can_be_readmitted_via_extra_tags(self)
Migration path for repos still carrying them.
tests/guard/test_guard_checks_extended.py:71
Checks
assert check_unknown_tags(func, "a.c", config) == []
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-001 | measured | test_retired_tags_can_be_readmitted_via_extra_tags → check_unknown_tags |
Source · 6 lines
def test_retired_tags_can_be_readmitted_via_extra_tags(self):
"""Migration path for repos still carrying them."""
config = deep_merge(BASE_CONFIG, {"validate": {"extra_tags": ["participant", "loop"]}})
func = _make_func("f", tags={"brief": ["d"], "participant": ["E"], "loop": ["E2"]})
assert check_unknown_tags(func, "a.c", config) == []
Activity · 3 steps
test_retired_tracer_tags_are_unknown
test_guard_checks_extended.TestCheckUnknownTags.test_retired_tracer_tags_are_unknown(self)
The diagram tags went with the tracer; a tag the tool cannot act on is unknown.
tests/guard/test_guard_checks_extended.py:59
Checks
assert len(violations) == 1assert "@participant" in violations[0].message
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-001 | measured | test_retired_tracer_tags_are_unknown → check_unknown_tags |
Source · 12 lines
def test_retired_tracer_tags_are_unknown(self):
"""The diagram tags went with the tracer; a tag the tool cannot act on is unknown.
2.0.0 (R5-CFG F10): `@sends` and `@receives` are also EVENT words the index reads (they build
event edges), so they are known through the shared event vocabulary; a retired tracer tag
that is not an event word — `@participant` — stays unknown.
"""
func = _make_func("f", tags={"brief": ["desc"], "participant": ["Bus"]})
violations = check_unknown_tags(func, "a.c", BASE_CONFIG)
assert len(violations) == 1
assert "@participant" in violations[0].message
Activity · 4 steps
test_stale_req_violation
test_guard_checks_extended.TestCheckReqExists.test_stale_req_violation(self)
tests/guard/test_guard_checks_extended.py:98
Checks
assert len(violations) == 1assert "REQ-MISSING" in violations[0].message
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-001 | measured | test_stale_req_violation → check_req_exists |
| REQ-DDB-GUARD-027 | inferred | test_stale_req_violation → check_req_exists → _uncheckable |
Source · 6 lines
def test_stale_req_violation(self):
func = _make_func("f", tags={"brief": ["d"], "req": ["REQ-MISSING"]})
violations = check_req_exists(func, "a.c", BASE_CONFIG, req_ids={"REQ-001"})
assert len(violations) == 1
assert "REQ-MISSING" in violations[0].message
Activity · 4 steps
test_unknown_tag_produces_violation
test_guard_checks_extended.TestCheckUnknownTags.test_unknown_tag_produces_violation(self)
tests/guard/test_guard_checks_extended.py:48
Checks
assert len(violations) == 1assert "sendd" in violations[0].message
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-001 | measured | test_unknown_tag_produces_violation → check_unknown_tags |
Source · 6 lines
def test_unknown_tag_produces_violation(self):
func = _make_func("f", tags={"brief": ["desc"], "sendd": ["EVENT_X"]})
violations = check_unknown_tags(func, "a.c", BASE_CONFIG)
assert len(violations) == 1
assert "sendd" in violations[0].message
Activity · 4 steps
test_valid_req_no_violation
test_guard_checks_extended.TestCheckReqExists.test_valid_req_no_violation(self)
tests/guard/test_guard_checks_extended.py:93
Checks
assert len(violations) == 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-GUARD-001 | measured | test_valid_req_no_violation → check_req_exists |
| REQ-DDB-GUARD-027 | inferred | test_valid_req_no_violation → check_req_exists → _uncheckable |
Source · 5 lines
def test_valid_req_no_violation(self):
func = _make_func("f", tags={"brief": ["d"], "req": ["REQ-001"]})
violations = check_req_exists(func, "a.c", BASE_CONFIG, req_ids={"REQ-001"})
assert len(violations) == 0