coverage.py¶
clew/coverage.py
Index COVERAGE — how much of what was indexed actually yielded anything.
alarming
bool clew.coverage.IndexCoverage.alarming(self)
Whether the barren share is high enough to be worth saying out loud.
Source · 10 lines
def alarming(self) -> bool:
"""Both terms are required. The ratio alone fires on a two-file toy index;
the sample size alone says nothing about coverage.
@brief Does this measurement warrant a warning?
@return True when substantive_files >= floor and ratio >= WARN_RATIO.
@version 1
"""
return self.substantive_files >= MIN_SUBSTANTIVE_FILES and self.barren_ratio >= WARN_RATIO
Activity · 1 steps
Requirements
as_meta
dict[str, str] clew.coverage.IndexCoverage.as_meta(self)
Flatten to string values for build_meta persistence.
Source · 37 lines
def as_meta(self) -> dict[str, str]:
"""Persisted because a coverage number that lives only in a warning has
exactly the defect CLAUDE.md records for scope provenance: the pipeline
computed it into the build LOG, which is gone by the time anyone queries.
Values are STRINGS because `write_build_signature` drops falsy values, and
a measured zero must be recorded — `"0"` is truthy, `0` is not.
@brief Coverage facts as build_meta values.
@return Unprefixed key → string value.
@version 3
"""
return {
"indexed_files": str(self.indexed_files),
"substantive_files": str(self.substantive_files),
"barren_files": str(self.barren_files),
"barren_ratio": f"{self.barren_ratio:.3f}",
"largest_barren": ", ".join(f"{f.path}:{f.lines}" for f in self.offenders),
## gh#11. Persisted BESIDE the overall numbers rather than instead of them,
## because they answer different questions and a consumer needs both: the
## barren ratio says whether the index can be reasoned about, the
## undocumented ratio says whether it can be read.
"undocumented_files": str(self.undocumented_files),
"undocumented_ratio": f"{self.undocumented_ratio:.3f}",
"largest_undocumented": ", ".join(
f"{f.path}:{f.lines}" for f in self.undocumented_offenders
),
## gh#335. Persisted even when ZERO, because "this repo vendors nothing"
## and "this index predates the tag" are different facts and a consumer
## reading a healthy first-party ratio needs to tell them apart. `"0"` is
## truthy where `0` is not, which is why every value here is a string.
"external_files": str(self.external_files),
"external_roots": ", ".join(self.external_roots),
"unresolved_files": str(self.unresolved_files),
}
Activity · 1 steps
Requirements
barren
bool clew.coverage.FileYield.barren(self)
Whether this file yielded essentially nothing.
Source · 11 lines
def barren(self) -> bool:
"""At most ONE row, not zero: mbedtls's `threading.c` yields exactly one
symbol (`_POSIX_C_SOURCE`, a define) with its entire body guarded out, so
a strict-zero test misses the canonical case.
@brief Did this file yield at most one symbol?
@return True when symbols <= 1.
@version 1
"""
return self.symbols <= 1
Activity · 1 steps
Requirements
barren_ratio
float clew.coverage.IndexCoverage.barren_ratio(self)
Barren share of the substantive file set.
Source · 10 lines
def barren_ratio(self) -> float:
"""@brief Fraction of judgeable files that yielded nothing.
@return barren/substantive, or 0.0 when the denominator is zero.
@version 1
"""
if not self.substantive_files:
return 0.0
return self.barren_files / self.substantive_files
Activity · 3 steps
Requirements
measure_index_coverage
IndexCoverage clew.coverage.measure_index_coverage(Path db_path, Path repo_root, IndexCache|None cache=None)
Measure how much of the indexed file set actually yielded symbols.
Called by report_index_coverage
Tested by 14 tests
test_a_cpp_body_attributed_only_by_bodyfile_id_is_not_barren, test_a_header_that_only_DECLARES_is_not_barren, test_a_nested_tree_with_no_indexed_file_is_not_reported, test_a_prose_file_is_not_counted_as_barren, test_a_small_barren_file_is_below_the_line_floor, test_a_tiny_index_never_alarms_however_barren, test_admitting_a_submodule_leaves_first_party_coverage_identical, test_an_unreadable_database_fails_soft, test_an_unresolved_include_is_neither_first_party_nor_external, test_coverage_is_persisted_into_build_meta_and_reaches_status, test_markdown_that_yielded_no_prose_is_still_not_barren, test_recovery_lowers_the_barren_ratio_and_leaves_the_documented_gap_visible
Calls _file_yields
Source · 49 lines
def measure_index_coverage(
db_path: Path, repo_root: Path, cache: IndexCache | None = None
) -> IndexCoverage:
"""FAILS SOFT to an all-zero measurement. This describes a build that has
already succeeded; a measurement that raises must not destroy the index it is
describing. An all-zero coverage is also what `alarming` correctly reads as
"not enough sample to judge", so a failure here cannot manufacture an alarm.
EXTERNAL FILES ARE PARTITIONED OUT BEFORE ANYTHING IS COUNTED (gh#335), which is
also the control that says the tagging works: admitting a submodule must raise
`external_files` and leave every first-party figure IDENTICAL. If a first-party
number moves when a nested tree is admitted, the tag is wrong — that is a
stronger check than any assertion about the matcher, because it holds whatever
the matcher does.
@brief Measure index coverage over one built database.
@return The coverage measurement, first party unless a field says otherwise.
@version 3
"""
try:
conn = sqlite3.connect(f"file:{db_path}?mode=ro", uri=True)
except sqlite3.Error:
return IndexCoverage(0, 0, 0, ())
try:
yields = _file_yields(conn, Path(repo_root), cache)
except sqlite3.Error:
yields = ()
finally:
conn.close()
resolved = [f for f in yields if f.resolved]
external = [f for f in resolved if f.external_root]
first_party = [f for f in resolved if not f.external_root]
substantive = [f for f in first_party if f.substantive]
barren = [f for f in substantive if f.barren]
undocumented = [f for f in substantive if f.undocumented]
return IndexCoverage(
indexed_files=len(first_party),
substantive_files=len(substantive),
barren_files=len(barren),
offenders=tuple(sorted(barren, key=lambda f: -f.lines)[:OFFENDER_LIMIT]),
undocumented_files=len(undocumented),
undocumented_offenders=tuple(sorted(undocumented, key=lambda f: -f.lines)[:OFFENDER_LIMIT]),
external_files=len(external),
external_roots=tuple(sorted({f.external_root for f in external})),
unresolved_files=len(yields) - len(resolved),
)
Activity · 15 steps
Requirements
recovered_but_undocumented
bool clew.coverage.IndexCoverage.recovered_but_undocumented(self)
Whether the DOCUMENTATION gap is worth saying out loud on its own.
Source · 17 lines
def recovered_but_undocumented(self) -> bool:
"""The condition under which gh#11's recovery has hidden gh#6's signal: the
graph is now populated (`barren_ratio` below the threshold, so `alarming` is
False) while the prose is not. Requires a STRICT gap between the two ratios
— without it this fires on every alarming build as a duplicate of the main
warning, which is how a second warning trains a reader to skip the first.
@brief Does the documentation gap need its own warning?
@return True when recovery closed the graph gap but not the prose gap.
@version 1
"""
return (
self.substantive_files >= MIN_SUBSTANTIVE_FILES
and self.undocumented_ratio >= WARN_RATIO
and self.undocumented_files > self.barren_files
)
Activity · 1 steps
Requirements
report_index_coverage
IndexCoverage clew.coverage.report_index_coverage(Path db_path, Path repo_root, IndexCache|None cache=None)
Measure index coverage, report it, and return it for persistence.
Called by _build_stages
Tested by
Calls _log_coverage, measure_index_coverage, warn_if_no_function_bodies
Source · 25 lines
def report_index_coverage(
db_path: Path, repo_root: Path, cache: IndexCache | None = None
) -> IndexCoverage:
"""The single pipeline entry point, composing the TOTAL-absence term with the
PARTIAL-absence one rather than competing with it.
`doxygen.warn_if_no_function_bodies` is the all-or-nothing case: implementation
files indexed and NOT ONE body anywhere. It keeps its own extension-based notion
of an implementation file because that is what makes a header-only library safe,
and it owns the most actionable advice we have. It is called FIRST and its
warning suppresses this one, so a build that extracted literally nothing gets one
precise message instead of two overlapping ones.
@brief Measure, log and return index coverage.
@return The coverage measurement.
@version 2
"""
from .doxygen import (
warn_if_no_function_bodies,
)
coverage = measure_index_coverage(Path(db_path), Path(repo_root), cache)
if not warn_if_no_function_bodies(Path(db_path)):
_log_coverage(coverage)
return coverage1 more lines, not shown
Activity · 5 steps
Requirements
substantive
bool clew.coverage.FileYield.substantive(self)
Whether this file is large enough for its yield to mean anything.
Source · 8 lines
def substantive(self) -> bool:
"""@brief Is the file big enough to judge?
@return True when at or above the line floor.
@version 1
"""
return self.lines >= MIN_SUBSTANTIVE_LINES
Activity · 1 steps
Requirements
undocumented
bool clew.coverage.FileYield.undocumented(self)
Whether this file yielded essentially no DOCUMENTED symbol.
Source · 16 lines
def undocumented(self) -> bool:
"""The same test over doxygen-sourced rows ONLY (gh#11). Once
`ast_symbols.recover_ast_symbols` inserts parser-recovered rows, `barren`
correctly stops firing — the index really does hold those symbols now — and
this property is what keeps the DOCUMENTATION gap visible. A file that is
`undocumented` but not `barren` is one whose graph was recovered and whose
prose was not, which is precisely the case where declaring `PREDEFINED`
(gh#17) is still the better answer.
@brief Did this file yield at most one documented symbol?
@return True when documented_symbols <= 1.
@version 1
"""
return self.documented_symbols <= 1
Activity · 1 steps
Requirements
undocumented_ratio
float clew.coverage.IndexCoverage.undocumented_ratio(self)
Undocumented share of the substantive file set.
Source · 13 lines
def undocumented_ratio(self) -> float:
"""Always >= `barren_ratio`, because a documented symbol is also a symbol.
The two are equal on a build with no recovered rows, which is why adding
this measurement changed no existing number on a healthy target.
@brief Fraction of judgeable files with no documented symbol.
@return undocumented/substantive, or 0.0 when the denominator is zero.
@version 1
"""
if not self.substantive_files:
return 0.0
return self.undocumented_files / self.substantive_files