test_coverage.py

tests/test_coverage.py

Index-coverage detection (gh#6) — the defect case, and the benign case.

test_a_cpp_body_attributed_only_by_bodyfile_id_is_not_barren

None test_coverage.test_a_cpp_body_attributed_only_by_bodyfile_id_is_not_barren(Path tmp_path)

A translation unit known only via bodyfile_id is not barren.

tests/test_coverage.py:195

Show on the map →

Called by none

Calls _coverage_db, measure_index_coverage

Checks

  • assert coverage.barren_files == 0, "bodyfile_id-only attribution must count as a yield"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_a_cpp_body_attributed_only_by_bodyfile_id_is_not_barren → measure_index_coverage → _file_yields → memoized
REQ-DDB-INDEX-003measuredtest_a_cpp_body_attributed_only_by_bodyfile_id_is_not_barren → measure_index_coverage
REQ-DDB-INDEX-004measured
Source · 30 lines
def test_a_cpp_body_attributed_only_by_bodyfile_id_is_not_barren(tmp_path: Path) -> None:
    """THE DECL/DEF DUALITY, and a defect this test was written to catch.

    doxygen records a C++ method declared in a header and defined in a `.cpp` with
    `file_id` = the HEADER and `bodyfile_id` = the `.cpp`. Counting `file_id` alone
    therefore reports a fully-indexed translation unit as barren — measured on
    entropic, `src/mcp/server_manager.cpp` shows 1 row by `file_id` and 33 bodies
    by `bodyfile_id`. The first version of this probe reported 18 of 97 entropic
    `.cpp` files barren for exactly this reason; unioning the two attributions took
    it to 4.

    @brief A translation unit known only via bodyfile_id is not barren.
    @version 1
    """
    db_path, root = _coverage_db(tmp_path, [("src/unit.cpp", BIG, 0)])
    conn = sqlite3.connect(str(db_path))
    for slot in range(33):
        conn.execute(
            "INSERT INTO memberdef (kind, name, file_id, bodyfile_id, bodystart, bodyend)"
            " VALUES ('function', ?, NULL, 1, 1, 9)",
            (f"method_{slot}",),
        )
    conn.commit()
    conn.close()

    coverage = measure_index_coverage(db_path, root)

    assert coverage.barren_files == 0, "bodyfile_id-only attribution must count as a yield"

Activity · 8 steps
lines 209–209db_path, root = _coverage_db(tmp_path, [("src/unit.cpp", BIG, 0)])lines 210–210conn = sqlite3.connect(str(db_path))lines 211–211◇ for slot in range(33)lines 212–216conn.execute( "INSERT INTO memberdef (kind, name, file_id, bodyfile_id, bodystart, bodyend)" " VALUES ('function', ?, NULL, 1, 1, 9)", (f"method_{slot}",), )lines 217–217conn.commit()lines 218–218conn.close()lines 220–220coverage = measure_index_coverage(db_path, root)lines 222–222assert coverage.barren_files == 0, "bodyfile_id-only attribution must count as a yield"

test_a_header_that_only_DECLARES_is_not_barren

None test_coverage.test_a_header_that_only_DECLARES_is_not_barren(Path tmp_path)

Declaration-only headers yield symbols and are not barren.

tests/test_coverage.py:173

Show on the map →

Called by none

Calls _coverage_db, measure_index_coverage

Checks

  • assert coverage.barren_files == 0
  • assert not coverage.alarming

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_a_header_that_only_DECLARES_is_not_barren → measure_index_coverage → _file_yields → memoized
REQ-DDB-INDEX-003measuredtest_a_header_that_only_DECLARES_is_not_barren → measure_index_coverage
REQ-DDB-INDEX-004measured
Source · 22 lines
def test_a_header_that_only_DECLARES_is_not_barren(tmp_path: Path) -> None:
    """WHY THE METRIC IS SYMBOLS AND NOT BODIES, which is the whole reason it can
    be language-agnostic instead of an extension list.

    A real header declares: its declarations ARE memberdef rows, so it yields
    symbols while yielding no bodies. Counting bodies instead would report 85% of
    mbedtls's headers and 54% of entropic's as barren — measured, both benign.
    A guarded-out translation unit is distinguishable precisely because it yields
    NEITHER declarations nor bodies.

    @brief Declaration-only headers yield symbols and are not barren.
    @version 1
    """
    files = [(f"include/api_{n}.h", BIG, 5) for n in range(MIN_SUBSTANTIVE_FILES + 5)]
    db_path, root = _coverage_db(tmp_path, files)

    coverage = measure_index_coverage(db_path, root)

    assert coverage.barren_files == 0
    assert not coverage.alarming

Activity · 5 steps
lines 186–186files = [(f"include/api_{n}.h", BIG, 5) for n in range(MIN_SUBSTANTIVE_FILES + 5)]lines 187–187db_path, root = _coverage_db(tmp_path, files)lines 189–189coverage = measure_index_coverage(db_path, root)lines 191–191assert coverage.barren_files == 0lines 192–192assert not coverage.alarming

test_a_mostly_barren_index_warns_and_names_the_largest_offenders

None test_coverage.test_a_mostly_barren_index_warns_and_names_the_largest_offenders(Path tmp_path, caplog)

A high barren ratio warns and names the biggest barren files.

tests/test_coverage.py:105

Show on the map →

Called by none

Calls _coverage_db, _healthy, report_index_coverage

Checks

  • assert coverage.substantive_files == 31
  • assert coverage.barren_files == 25
  • assert coverage.alarming
  • assert warnings, "a mostly-barren index must warn"
  • assert "80.6%" in message, message
  • assert "library/ssl_tls.c" in message, message
  • assert "9969 lines" in message, message

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-001measuredtest_a_mostly_barren_index_warns_and_names_the_largest_offenders → report_index_coverage → warn_if_no_function_bodies
REQ-DDB-INDEX-002measuredtest_a_mostly_barren_index_warns_and_names_the_largest_offenders → report_index_coverage → measure_index_coverage → _file_yields → memoized
REQ-DDB-INDEX-003measuredtest_a_mostly_barren_index_warns_and_names_the_largest_offenders → report_index_coverage
REQ-DDB-INDEX-004measured
Source · 37 lines
def test_a_mostly_barren_index_warns_and_names_the_largest_offenders(
    tmp_path: Path, caplog
) -> None:
    """THE CASE gh#6 EXISTS FOR, shaped like the measured mbedtls build.

    184 of 221 implementation files yielded at most one symbol, 162 of them over
    100 lines, including a 9,969-line file with zero — while the build announced
    2,555 functions and 28,151 call edges and said nothing. A 198-cell acceptance
    run was then executed against that index and voided, at roughly 318M tokens
    to discover after the fact.

    Asserts the ratio is the headline and that the offenders are NAMED with their
    line counts. Naming them is what makes the warning actionable rather than
    merely alarming: a 9,969-line file with zero symbols is a preprocessor problem
    someone can go and look at.

    @brief A high barren ratio warns and names the biggest barren files.
    @version 1
    """
    files = _healthy(6) + [(f"library/guarded_{n}.c", 500 + n, 0) for n in range(24)]
    files.append(("library/ssl_tls.c", 9969, 0))
    db_path, root = _coverage_db(tmp_path, files)

    with caplog.at_level(logging.WARNING):
        coverage = report_index_coverage(db_path, root)

    assert coverage.substantive_files == 31
    assert coverage.barren_files == 25
    assert coverage.alarming
    warnings = [r.getMessage() for r in caplog.records if r.levelno >= logging.WARNING]
    assert warnings, "a mostly-barren index must warn"
    message = "\n".join(warnings)
    assert "80.6%" in message, message
    assert "library/ssl_tls.c" in message, message
    assert "9969 lines" in message, message

Activity · 14 steps
lines 124–124files = _healthy(6) + [(f"library/guarded_{n}.c", 500 + n, 0) for n in range(24)]lines 125–125files.append(("library/ssl_tls.c", 9969, 0))lines 126–126db_path, root = _coverage_db(tmp_path, files)lines 128–128with caplog.at_level(logging.WARNING)lines 129–129coverage = report_index_coverage(db_path, root)lines 131–131assert coverage.substantive_files == 31lines 132–132assert coverage.barren_files == 25lines 133–133assert coverage.alarminglines 134–134warnings = [r.getMessage() for r in caplog.records if r.levelno >= logging.WARNING]lines 135–135assert warnings, "a mostly-barren index must warn"lines 136–136message = "\n".join(warnings)lines 137–137assert "80.6%" in message, messagelines 138–138assert "library/ssl_tls.c" in message, messagelines 139–139assert "9969 lines" in message, message

test_a_prose_file_is_not_counted_as_barren

None test_coverage.test_a_prose_file_is_not_counted_as_barren(Path tmp_path)

Files that yielded prose are excluded from the barren count.

tests/test_coverage.py:225

Show on the map →

Called by none

Calls _coverage_db, measure_index_coverage

Checks

  • assert coverage.indexed_files == 0, "prose-yielding files are not code and are excluded"
  • assert coverage.barren_files == 0
  • assert not coverage.alarming

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002inferredtest_a_prose_file_is_not_counted_as_barren → measure_index_coverage → _file_yields → memoized
REQ-DDB-INDEX-003measuredtest_a_prose_file_is_not_counted_as_barren → measure_index_coverage
Source · 20 lines
def test_a_prose_file_is_not_counted_as_barren(tmp_path: Path) -> None:
    """A markdown file is not barren; it is not code.

    Measured on mbedtls: 27 substantive `.md` files yield zero memberdef rows, and
    counting them inflated the headline ratio for a reason that has nothing to do
    with the preprocessor. They contributed PROSE, which is a yield.

    @brief Files that yielded prose are excluded from the barren count.
    @version 1
    """
    docs = [(f"docs/guide_{n}.md", BIG, 0) for n in range(MIN_SUBSTANTIVE_FILES + 5)]
    db_path, root = _coverage_db(tmp_path, docs, prose=tuple(name for name, _, _ in docs))

    coverage = measure_index_coverage(db_path, root)

    assert coverage.indexed_files == 0, "prose-yielding files are not code and are excluded"
    assert coverage.barren_files == 0
    assert not coverage.alarming

Activity · 6 steps
lines 235–235docs = [(f"docs/guide_{n}.md", BIG, 0) for n in range(MIN_SUBSTANTIVE_FILES + 5)]lines 236–236db_path, root = _coverage_db(tmp_path, docs, prose=tuple(name for name, _, _ in docs))lines 238–238coverage = measure_index_coverage(db_path, root)lines 240–240assert coverage.indexed_files == 0, "prose-yielding files are not code and are excluded"lines 241–241assert coverage.barren_files == 0lines 242–242assert not coverage.alarming

test_a_small_barren_file_is_below_the_line_floor

None test_coverage.test_a_small_barren_file_is_below_the_line_floor(Path tmp_path)

Files under the line floor are not judged.

tests/test_coverage.py:268

Show on the map →

Called by none

Calls _coverage_db, _healthy, measure_index_coverage

Checks

  • assert coverage.substantive_files == MIN_SUBSTANTIVE_FILES
  • assert coverage.barren_files == 0
  • assert not coverage.alarming

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_a_small_barren_file_is_below_the_line_floor → measure_index_coverage → _file_yields → memoized
REQ-DDB-INDEX-003measuredtest_a_small_barren_file_is_below_the_line_floor → measure_index_coverage
REQ-DDB-INDEX-004measured
Source · 20 lines
def test_a_small_barren_file_is_below_the_line_floor(tmp_path: Path) -> None:
    """A stub header or a re-export `__init__.py` yielding nothing proves nothing.

    This repo's own single offender is `clew/query/__init__.py` — 137 lines
    of re-exports, 1 symbol — and the line floor is what keeps entropic's residue
    at 4 files rather than 32.

    @brief Files under the line floor are not judged.
    @version 1
    """
    files = _healthy(MIN_SUBSTANTIVE_FILES) + [(f"src/stub_{n}.h", 10, 0) for n in range(40)]
    db_path, root = _coverage_db(tmp_path, files)

    coverage = measure_index_coverage(db_path, root)

    assert coverage.substantive_files == MIN_SUBSTANTIVE_FILES
    assert coverage.barren_files == 0
    assert not coverage.alarming

Activity · 6 steps
lines 278–278files = _healthy(MIN_SUBSTANTIVE_FILES) + [(f"src/stub_{n}.h", 10, 0) for n in range(40)]lines 279–279db_path, root = _coverage_db(tmp_path, files)lines 281–281coverage = measure_index_coverage(db_path, root)lines 283–283assert coverage.substantive_files == MIN_SUBSTANTIVE_FILESlines 284–284assert coverage.barren_files == 0lines 285–285assert not coverage.alarming

test_a_tiny_index_never_alarms_however_barren

None test_coverage.test_a_tiny_index_never_alarms_however_barren(Path tmp_path)

Below the sample floor the ratio is not a measurement.

tests/test_coverage.py:288

Show on the map →

Called by none

Calls _coverage_db, measure_index_coverage

Checks

  • assert coverage.barren_ratio == 0.5
  • assert not coverage.alarming, "a two-file index is not evidence of anything"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_a_tiny_index_never_alarms_however_barren → measure_index_coverage → _file_yields → memoized
REQ-DDB-INDEX-003measuredtest_a_tiny_index_never_alarms_however_barren → measure_index_coverage
REQ-DDB-INDEX-004measured
Source · 16 lines
def test_a_tiny_index_never_alarms_however_barren(tmp_path: Path) -> None:
    """A ratio needs a denominator worth dividing by: two files, one barren, is
    50% and means nothing. Every real target measures 116 substantive files or
    more, so the floor cannot mask a real case.

    @brief Below the sample floor the ratio is not a measurement.
    @version 1
    """
    db_path, root = _coverage_db(tmp_path, [("src/a.c", BIG, 0), ("src/b.c", BIG, 6)])

    coverage = measure_index_coverage(db_path, root)

    assert coverage.barren_ratio == 0.5
    assert not coverage.alarming, "a two-file index is not evidence of anything"

Activity · 4 steps
lines 296–296db_path, root = _coverage_db(tmp_path, [("src/a.c", BIG, 0), ("src/b.c", BIG, 6)])lines 298–298coverage = measure_index_coverage(db_path, root)lines 300–300assert coverage.barren_ratio == 0.5lines 301–301assert not coverage.alarming, "a two-file index is not evidence of anything"

test_an_unreadable_database_fails_soft

None test_coverage.test_an_unreadable_database_fails_soft(Path tmp_path)

An unreadable index measures to all-zero and does not alarm.

tests/test_coverage.py:304

Checks

  • assert coverage == IndexCoverage(0, 0, 0, ())
  • assert not coverage.alarming

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002inferredtest_an_unreadable_database_fails_soft → measure_index_coverage → _file_yields → memoized
REQ-DDB-INDEX-003measuredtest_an_unreadable_database_fails_soft → measure_index_coverage
Source · 17 lines
def test_an_unreadable_database_fails_soft(tmp_path: Path) -> None:
    """Coverage describes a build that has ALREADY SUCCEEDED, so a measurement that
    raises must not destroy the index it describes. An all-zero measurement is also
    what `alarming` correctly reads as "not enough sample", so failing soft cannot
    manufacture an alarm either.

    @brief An unreadable index measures to all-zero and does not alarm.
    @version 1
    """
    missing = tmp_path / "nope.db"

    coverage = measure_index_coverage(missing, tmp_path)

    assert coverage == IndexCoverage(0, 0, 0, ())
    assert not coverage.alarming

Activity · 4 steps
lines 313–313missing = tmp_path / "nope.db"lines 315–315coverage = measure_index_coverage(missing, tmp_path)lines 317–317assert coverage == IndexCoverage(0, 0, 0, ())lines 318–318assert not coverage.alarming

test_coverage_is_persisted_into_build_meta_and_reaches_status

None test_coverage.test_coverage_is_persisted_into_build_meta_and_reaches_status(Path tmp_path)

Coverage round-trips through build_meta into db_status.

tests/test_coverage.py:321

Show on the map →

Called by none

Calls _coverage_db, _healthy, db_status, measure_index_coverage, write_build_signature

Checks

  • assert reported["substantive_files"] == str(MIN_SUBSTANTIVE_FILES + 4)
  • assert reported["barren_files"] == "0", "a measured zero must be recorded, not omitted"
  • assert reported["barren_ratio"] == "0.000"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measuredtest_coverage_is_persisted_into_build_meta_and_reaches_status → db_status
REQ-DDB-CONFIG-007measuredtest_coverage_is_persisted_into_build_meta_and_reaches_status → db_status
REQ-DDB-INDEX-002measuredtest_coverage_is_persisted_into_build_meta_and_reaches_status → measure_index_coverage → _file_yields → memoized
REQ-DDB-INDEX-003measuredtest_coverage_is_persisted_into_build_meta_and_reaches_status → measure_index_coverage
REQ-DDB-INDEX-004measured
REQ-DDB-MCP-001measuredtest_coverage_is_persisted_into_build_meta_and_reaches_status → db_status
REQ-DDB-MCP-004measuredtest_coverage_is_persisted_into_build_meta_and_reaches_status → db_status
REQ-DDB-PIPE-005measuredtest_coverage_is_persisted_into_build_meta_and_reaches_status → write_build_signature
Source · 31 lines
def test_coverage_is_persisted_into_build_meta_and_reaches_status(tmp_path: Path) -> None:
    """gh#6 part 2. A coverage number that lives only in a build 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 the database.

    `status` was the surface that reported the voided index as present, current and
    healthy. Staleness answers "does this describe the code as it is now"; coverage
    answers "does it describe the code at all".

    Asserts a measured ZERO survives too — `write_build_signature` drops falsy
    values, so coverage passes strings deliberately, and a build with no barren
    files must still record `barren_files=0` rather than omitting it.

    @brief Coverage round-trips through build_meta into db_status.
    @version 1
    """
    from clew.mcp_server.state import Target, db_status
    from clew.signature import write_build_signature

    db_path, root = _coverage_db(tmp_path, _healthy(MIN_SUBSTANTIVE_FILES + 4))
    coverage = measure_index_coverage(db_path, root)
    write_build_signature(db_path, coverage=coverage.as_meta())

    status = db_status(Target(repo_path=str(root), slug="t", db_path=str(db_path)))
    reported = status["coverage"]

    assert reported["substantive_files"] == str(MIN_SUBSTANTIVE_FILES + 4)
    assert reported["barren_files"] == "0", "a measured zero must be recorded, not omitted"
    assert reported["barren_ratio"] == "0.000"

Activity · 10 steps
lines 337–337from clew.mcp_server.state import Target, db_statuslines 338–338from clew.signature import write_build_signaturelines 340–340db_path, root = _coverage_db(tmp_path, _healthy(MIN_SUBSTANTIVE_FILES + 4))lines 341–341coverage = measure_index_coverage(db_path, root)lines 342–342write_build_signature(db_path, coverage=coverage.as_meta())lines 344–344status = db_status(Target(repo_path=str(root), slug="t", db_path=str(db_path)))lines 345–345reported = status["coverage"]lines 347–347assert reported["substantive_files"] == str(MIN_SUBSTANTIVE_FILES + 4)lines 348–348assert reported["barren_files"] == "0", "a measured zero must be recorded, not omitted"lines 349–349assert reported["barren_ratio"] == "0.000"

test_markdown_that_yielded_no_prose_is_still_not_barren

None test_coverage.test_markdown_that_yielded_no_prose_is_still_not_barren(Path tmp_path)

Markdown absent from supplementary_docs is excluded from the barren count.

tests/test_coverage.py:245

Show on the map →

Called by none

Calls _coverage_db, measure_index_coverage

Checks

  • assert coverage.indexed_files == 0, "markdown is not code, ingested or not"
  • assert coverage.barren_files == 0
  • assert not coverage.alarming

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002inferredtest_markdown_that_yielded_no_prose_is_still_not_barren → measure_index_coverage → _file_yields → memoized
REQ-DDB-INDEX-003measuredtest_markdown_that_yielded_no_prose_is_still_not_barren → measure_index_coverage
Source · 23 lines
def test_markdown_that_yielded_no_prose_is_still_not_barren(tmp_path: Path) -> None:
    """`supplementary_docs` membership is a PROXY for "this file is prose", and it
    holds only while every indexed markdown file is also ingested. Ingestion has its
    own file set, so a wide INPUT indexes markdown that never reaches it — measured on
    this repo's own whole-repo index, where 894 `.md` files took `barren_ratio` from
    0.015 to 0.795 and tripped `alarming` on a build whose code coverage had not moved.

    The rule this module states is about the FILE, not about the ingestion: a markdown
    file is not barren, it is not code.

    @brief Markdown absent from supplementary_docs is excluded from the barren count.
    @version 1
    """
    docs = [(f"evidence/cell_{n}.md", BIG, 0) for n in range(MIN_SUBSTANTIVE_FILES + 5)]
    db_path, root = _coverage_db(tmp_path, docs, prose=())

    coverage = measure_index_coverage(db_path, root)

    assert coverage.indexed_files == 0, "markdown is not code, ingested or not"
    assert coverage.barren_files == 0
    assert not coverage.alarming

Activity · 6 steps
lines 258–258docs = [(f"evidence/cell_{n}.md", BIG, 0) for n in range(MIN_SUBSTANTIVE_FILES + 5)]lines 259–259db_path, root = _coverage_db(tmp_path, docs, prose=())lines 261–261coverage = measure_index_coverage(db_path, root)lines 263–263assert coverage.indexed_files == 0, "markdown is not code, ingested or not"lines 264–264assert coverage.barren_files == 0lines 265–265assert not coverage.alarming

test_status_on_a_PRE_COVERAGE_index_says_nothing_rather_than_guessing

None test_coverage.test_status_on_a_PRE_COVERAGE_index_says_nothing_rather_than_guessing(Path tmp_path)

A pre-coverage index reports an empty coverage mapping.

tests/test_coverage.py:375

Checks

  • assert status["coverage"] == {}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measuredtest_status_on_a_PRE_COVERAGE_index_says_nothing_rather_than_guessing → db_status
REQ-DDB-CONFIG-007measuredtest_status_on_a_PRE_COVERAGE_index_says_nothing_rather_than_guessing → db_status
REQ-DDB-INDEX-003measuredtest_status_on_a_PRE_COVERAGE_index_says_nothing_rather_than_guessing → db_status → _coverage_meta
REQ-DDB-MCP-001measuredtest_status_on_a_PRE_COVERAGE_index_says_nothing_rather_than_guessing → db_status
REQ-DDB-MCP-004measuredtest_status_on_a_PRE_COVERAGE_index_says_nothing_rather_than_guessing → db_status
REQ-DDB-PIPE-005measuredtest_status_on_a_PRE_COVERAGE_index_says_nothing_rather_than_guessing → write_build_signature
Source · 21 lines
def test_status_on_a_PRE_COVERAGE_index_says_nothing_rather_than_guessing(tmp_path: Path) -> None:
    """An index built before build 18 cannot supply these fields, and an absent key
    honestly reads as "not recorded". Fabricating a healthy-looking default would be
    the same class of defect as the whole issue: a number that looks like a
    measurement and is not.

    @brief A pre-coverage index reports an empty coverage mapping.
    @version 1
    """
    from clew.mcp_server.state import Target, db_status
    from clew.signature import write_build_signature

    db = tmp_path / "clew.db"
    sqlite3.connect(str(db)).close()
    write_build_signature(db)

    status = db_status(Target(repo_path=str(tmp_path), slug="t", db_path=str(db)))

    assert status["coverage"] == {}

Activity · 7 steps
lines 384–384from clew.mcp_server.state import Target, db_statuslines 385–385from clew.signature import write_build_signaturelines 387–387db = tmp_path / "clew.db"lines 388–388sqlite3.connect(str(db)).close()lines 389–389write_build_signature(db)lines 391–391status = db_status(Target(repo_path=str(tmp_path), slug="t", db_path=str(db)))lines 393–393assert status["coverage"] == {}

test_status_publishes_the_barren_ratio_and_offenders

None test_coverage.test_status_publishes_the_barren_ratio_and_offenders(Path tmp_path)

status carries the ratio and the largest offenders.

tests/test_coverage.py:352

Show on the map →

Called by none

Calls _coverage_db, _healthy, db_status, measure_index_coverage, write_build_signature

Checks

  • assert reported["barren_ratio"] == "0.806"
  • assert "library/guarded_" in reported["largest_barren"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measuredtest_status_publishes_the_barren_ratio_and_offenders → db_status
REQ-DDB-CONFIG-007measuredtest_status_publishes_the_barren_ratio_and_offenders → db_status
REQ-DDB-INDEX-002measuredtest_status_publishes_the_barren_ratio_and_offenders → measure_index_coverage → _file_yields → memoized
REQ-DDB-INDEX-003measuredtest_status_publishes_the_barren_ratio_and_offenders → measure_index_coverage
REQ-DDB-INDEX-004measured
REQ-DDB-MCP-001measuredtest_status_publishes_the_barren_ratio_and_offenders → db_status
REQ-DDB-MCP-004measuredtest_status_publishes_the_barren_ratio_and_offenders → db_status
REQ-DDB-PIPE-005measuredtest_status_publishes_the_barren_ratio_and_offenders → write_build_signature
Source · 23 lines
def test_status_publishes_the_barren_ratio_and_offenders(tmp_path: Path) -> None:
    """The consumer-facing half: a thin index must be visible to an agent that never
    saw the build log, WITH the offenders, so `status` alone is enough to refuse an
    expensive run against a hollow index.

    @brief status carries the ratio and the largest offenders.
    @version 1
    """
    from clew.mcp_server.state import Target, db_status
    from clew.signature import write_build_signature

    files = _healthy(6) + [(f"library/guarded_{n}.c", 500, 0) for n in range(25)]
    db_path, root = _coverage_db(tmp_path, files)
    coverage = measure_index_coverage(db_path, root)
    write_build_signature(db_path, coverage=coverage.as_meta())

    status = db_status(Target(repo_path=str(root), slug="t", db_path=str(db_path)))
    reported = status["coverage"]

    assert reported["barren_ratio"] == "0.806"
    assert "library/guarded_" in reported["largest_barren"]

Activity · 10 steps
lines 360–360from clew.mcp_server.state import Target, db_statuslines 361–361from clew.signature import write_build_signaturelines 363–363files = _healthy(6) + [(f"library/guarded_{n}.c", 500, 0) for n in range(25)]lines 364–364db_path, root = _coverage_db(tmp_path, files)lines 365–365coverage = measure_index_coverage(db_path, root)lines 366–366write_build_signature(db_path, coverage=coverage.as_meta())lines 368–368status = db_status(Target(repo_path=str(root), slug="t", db_path=str(db_path)))lines 369–369reported = status["coverage"]lines 371–371assert reported["barren_ratio"] == "0.806"lines 372–372assert "library/guarded_" in reported["largest_barren"]

test_the_benign_entropic_case_does_NOT_warn

None test_coverage.test_the_benign_entropic_case_does_NOT_warn(Path tmp_path, caplog)

A small legitimate barren residue must stay silent.

tests/test_coverage.py:142

Show on the map →

Called by none

Calls _coverage_db, _healthy, report_index_coverage

Checks

  • assert coverage.substantive_files == 177
  • assert coverage.barren_files == 7
  • assert round(coverage.barren_ratio, 3) == 0.04
  • assert not coverage.alarming
  • assert not [r for r in caplog.records if r.levelno >= logging.WARNING], ("entropic's inapplicable platform files are not a defect and must not warn" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-001measuredtest_the_benign_entropic_case_does_NOT_warn → report_index_coverage → warn_if_no_function_bodies
REQ-DDB-INDEX-002measuredtest_the_benign_entropic_case_does_NOT_warn → report_index_coverage → measure_index_coverage → _file_yields → memoized
REQ-DDB-INDEX-003measuredtest_the_benign_entropic_case_does_NOT_warn → report_index_coverage
REQ-DDB-INDEX-004measured
Source · 31 lines
def test_the_benign_entropic_case_does_NOT_warn(tmp_path: Path, caplog) -> None:
    """THE FALSE-ALARM GUARD, and it is the reason the threshold is a ratio.

    entropic measures 7 barren of 177 substantive files (4.0%). Its barren files
    are Windows and Darwin platform sources inside a vendored fuzzer — genuinely
    inapplicable code, not a missing preprocessor definition. A check that fired
    here would be worse than no check at all: it converts "unchecked" into
    "checked and fine", which is how the identifier leak, the disarmed coverage
    gate and a voided 36-cell grid all happened.

    @brief A small legitimate barren residue must stay silent.
    @version 1
    """
    files = _healthy(170) + [
        (f"vendor/Fuzzer/FuzzerUtil{platform}.cpp", 200, 0)
        for platform in ("Windows", "Darwin", "Posix", "IOWindows", "Merge", "Main", "Extra")
    ]
    db_path, root = _coverage_db(tmp_path, files)

    with caplog.at_level(logging.WARNING):
        coverage = report_index_coverage(db_path, root)

    assert coverage.substantive_files == 177
    assert coverage.barren_files == 7
    assert round(coverage.barren_ratio, 3) == 0.04
    assert not coverage.alarming
    assert not [r for r in caplog.records if r.levelno >= logging.WARNING], (
        "entropic's inapplicable platform files are not a defect and must not warn"
    )

Activity · 9 steps
lines 155–158files = _healthy(170) + [ (f"vendor/Fuzzer/FuzzerUtil{platform}.cpp", 200, 0) for platform in ("Windows", "Darwin", "Posix", "IOWindows", "Merge", "Main", "Extra") ]lines 159–159db_path, root = _coverage_db(tmp_path, files)lines 161–161with caplog.at_level(logging.WARNING)lines 162–162coverage = report_index_coverage(db_path, root)lines 164–164assert coverage.substantive_files == 177lines 165–165assert coverage.barren_files == 7lines 166–166assert round(coverage.barren_ratio, 3) == 0.04lines 167–167assert not coverage.alarminglines 168–170assert not [r for r in caplog.records if r.levelno >= logging.WARNING], ( "entropic's inapplicable platform files are not a defect and must not warn" )

test_total_absence_reports_once_not_twice

None test_coverage.test_total_absence_reports_once_not_twice(Path tmp_path, caplog)

A zero-body index warns once, via the more actionable term.

tests/test_coverage.py:396

Show on the map →

Called by none

Calls _coverage_db, report_index_coverage

Checks

  • assert len(warnings) == 1, warnings
  • assert "NOT ONE yielded a function body" in warnings[0]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-001measuredtest_total_absence_reports_once_not_twice → report_index_coverage → warn_if_no_function_bodies
REQ-DDB-INDEX-002measuredtest_total_absence_reports_once_not_twice → report_index_coverage → measure_index_coverage → _file_yields → memoized
REQ-DDB-INDEX-003measuredtest_total_absence_reports_once_not_twice → report_index_coverage
REQ-DDB-INDEX-004measured
Source · 18 lines
def test_total_absence_reports_once_not_twice(tmp_path: Path, caplog) -> None:
    """The two terms COMPOSE rather than compete. A build that extracted literally
    nothing satisfies both the total-absence check and the barren-ratio check, and
    must produce ONE precise message — the one that names PREDEFINED — instead of
    two overlapping ones that train the reader to skim.

    @brief A zero-body index warns once, via the more actionable term.
    @version 1
    """
    files = [(f"src/mod_{n}.c", BIG, 0) for n in range(MIN_SUBSTANTIVE_FILES + 5)]
    db_path, root = _coverage_db(tmp_path, files)

    with caplog.at_level(logging.WARNING):
        report_index_coverage(db_path, root)

    warnings = [r.getMessage() for r in caplog.records if r.levelno >= logging.WARNING]
    assert len(warnings) == 1, warnings
    assert "NOT ONE yielded a function body" in warnings[0]

1 more lines, not shown

Activity · 7 steps
lines 405–405files = [(f"src/mod_{n}.c", BIG, 0) for n in range(MIN_SUBSTANTIVE_FILES + 5)]lines 406–406db_path, root = _coverage_db(tmp_path, files)lines 408–408with caplog.at_level(logging.WARNING)lines 409–409report_index_coverage(db_path, root)lines 411–411warnings = [r.getMessage() for r in caplog.records if r.levelno >= logging.WARNING]lines 412–412assert len(warnings) == 1, warningslines 413–413assert "NOT ONE yielded a function body" in warnings[0]