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.

clew/coverage.py:282

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
lines 290–290return self.substantive_files >= MIN_SUBSTANTIVE_FILES and self.barren_ratio >= WARN_RATIO

Requirements

REQ-DDB-INDEX-003

as_meta

dict[str, str] clew.coverage.IndexCoverage.as_meta(self)

Flatten to string values for build_meta persistence.

clew/coverage.py:296

Show on the map →

Called by none

Calls none

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
lines 308–330return { "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), }

Requirements

REQ-DDB-INDEX-003

barren

bool clew.coverage.FileYield.barren(self)

Whether this file yielded essentially nothing.

clew/coverage.py:153

Show on the map →

Called by none

Calls none

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
lines 162–162return self.symbols <= 1

Requirements

REQ-DDB-INDEX-003

barren_ratio

float clew.coverage.IndexCoverage.barren_ratio(self)

Barren share of the substantive file set.

clew/coverage.py:227

Show on the map →

Called by alarming

Calls none

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
lines 233–233◇ if not self.substantive_fileslines 234–234return 0.0lines 235–235return self.barren_files / self.substantive_files

Requirements

REQ-DDB-INDEX-003

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.

clew/coverage.py:526

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
lines 545–545trylines 546–546conn = sqlite3.connect(f"file:{db_path}?mode=ro", uri=True)lines 547–547except sqlite3.Errorlines 548–548return IndexCoverage(0, 0, 0, ())lines 549–549trylines 550–550yields = _file_yields(conn, Path(repo_root), cache)lines 551–551except sqlite3.Errorlines 552–552yields = ()lines 556–556resolved = [f for f in yields if f.resolved]lines 557–557external = [f for f in resolved if f.external_root]lines 558–558first_party = [f for f in resolved if not f.external_root]lines 559–559substantive = [f for f in first_party if f.substantive]lines 560–560barren = [f for f in substantive if f.barren]lines 561–561undocumented = [f for f in substantive if f.undocumented]lines 562–572return 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), )

Requirements

REQ-DDB-INDEX-003

recovered_but_undocumented

bool clew.coverage.IndexCoverage.recovered_but_undocumented(self)

Whether the DOCUMENTATION gap is worth saying out loud on its own.

clew/coverage.py:260

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
lines 271–275return ( self.substantive_files >= MIN_SUBSTANTIVE_FILES and self.undocumented_ratio >= WARN_RATIO and self.undocumented_files > self.barren_files )

Requirements

REQ-DDB-INDEX-004

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.

clew/coverage.py:660

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 coverage

1 more lines, not shown

Activity · 5 steps
lines 677–679from .doxygen import ( warn_if_no_function_bodies, )lines 681–681coverage = measure_index_coverage(Path(db_path), Path(repo_root), cache)lines 682–682◇ if not warn_if_no_function_bodies(Path(db_path))lines 683–683_log_coverage(coverage)lines 684–684return coverage

Requirements

REQ-DDB-INDEX-003

substantive

bool clew.coverage.FileYield.substantive(self)

Whether this file is large enough for its yield to mean anything.

clew/coverage.py:140

Show on the map →

Called by none

Calls none

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
lines 146–146return self.lines >= MIN_SUBSTANTIVE_LINES

Requirements

REQ-DDB-INDEX-003

undocumented

bool clew.coverage.FileYield.undocumented(self)

Whether this file yielded essentially no DOCUMENTED symbol.

clew/coverage.py:169

Show on the map →

Called by none

Calls none

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
lines 182–182return self.documented_symbols <= 1

Requirements

REQ-DDB-INDEX-004

undocumented_ratio

float clew.coverage.IndexCoverage.undocumented_ratio(self)

Undocumented share of the substantive file set.

clew/coverage.py:242

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
Activity · 3 steps
lines 251–251◇ if not self.substantive_fileslines 252–252return 0.0lines 253–253return self.undocumented_files / self.substantive_files

Requirements

REQ-DDB-INDEX-004