test_diagnostics.py

tests/test_diagnostics.py

A STRUCTURED ZERO IS EVIDENCE — gh#320.

test_a_capped_list_still_reports_the_true_count

None test_diagnostics.test_a_capped_list_still_reports_the_true_count(Path tmp_path)

The named list is capped while the count stays exact.

tests/test_diagnostics.py:309

Show on the map →

Called by none

Calls _corpus, collect

Checks

  • assert meta["accessor_families_count"] == str(dg.MAX_NAMED + 3)
  • assert meta["accessor_families"].count("keys)") == dg.MAX_NAMED

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measuredtest_a_capped_list_still_reports_the_true_count → collect → resolve_shared_key_patterns
REQ-DDB-CONFIG-007measuredtest_a_capped_list_still_reports_the_true_count → collect
REQ-DDB-QUERY-011measured
REQ-DDB-SCHEMA-001measuredtest_a_capped_list_still_reports_the_true_count → collect → load_thread_patterns
REQ-DDB-SCHEMA-005measuredtest_a_capped_list_still_reports_the_true_count → collect → resolve_shared_key_patterns
REQ-DDB-SCHEMA-011measuredtest_a_capped_list_still_reports_the_true_count → collect → load_lock_patterns
REQ-DDB-SCHEMA-012measuredtest_a_capped_list_still_reports_the_true_count → collect → load_lock_patterns → declaration_origin
Source · 21 lines
def test_a_capped_list_still_reports_the_true_count(tmp_path: Path) -> None:
    """A cap that cannot be seen is how a bounded answer comes to read as a complete one.
    The count is the claim and stays exact, so `count > len(named)` makes the truncation
    visible without a second field.

    @brief Truncation is visible through the exact count.
    @version 1
    """
    rows = [
        ("function", f"Fam{fam}_Set_{key}")
        for fam in range(dg.MAX_NAMED + 3)
        for key in ("A", "B", "C", "D")
    ]
    db = _corpus(tmp_path / "clew.db", rows)

    meta = dg.collect(db, tmp_path / "absent.Doxyfile", None, None, None).as_meta()

    assert meta["accessor_families_count"] == str(dg.MAX_NAMED + 3)
    assert meta["accessor_families"].count("keys)") == dg.MAX_NAMED

Activity · 5 steps
lines 317–321rows = [ ("function", f"Fam{fam}_Set_{key}") for fam in range(dg.MAX_NAMED + 3) for key in ("A", "B", "C", "D") ]lines 322–322db = _corpus(tmp_path / "clew.db", rows)lines 324–324meta = dg.collect(db, tmp_path / "absent.Doxyfile", None, None, None).as_meta()lines 326–326assert meta["accessor_families_count"] == str(dg.MAX_NAMED + 3)lines 327–327assert meta["accessor_families"].count("keys)") == dg.MAX_NAMED

test_a_clean_target_still_reports_its_zeros

None test_diagnostics.test_a_clean_target_still_reports_its_zeros(Path tmp_path)

A target with no undeclared families and no stray aliases reports zeros, not silence.

tests/test_diagnostics.py:194

Show on the map →

Called by none

Calls _corpus, collect

Checks

  • assert meta["accessor_families_count"] == "0"
  • assert meta["unclaimed_event_aliases_count"] == "0"
  • assert meta["accessor_names_examined"] == "2", "a zero needs the corpus it was measured over"
  • assert meta["event_vocabulary_source"] == dg.SOURCE_BUILT_IN

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measuredtest_a_clean_target_still_reports_its_zeros → collect → resolve_shared_key_patterns
REQ-DDB-CONFIG-007measuredtest_a_clean_target_still_reports_its_zeros → collect
REQ-DDB-QUERY-011measured
REQ-DDB-SCHEMA-001measuredtest_a_clean_target_still_reports_its_zeros → collect → load_thread_patterns
REQ-DDB-SCHEMA-005measuredtest_a_clean_target_still_reports_its_zeros → collect → resolve_shared_key_patterns
REQ-DDB-SCHEMA-011measuredtest_a_clean_target_still_reports_its_zeros → collect → load_lock_patterns
REQ-DDB-SCHEMA-012measuredtest_a_clean_target_still_reports_its_zeros → collect → load_lock_patterns → declaration_origin
Source · 23 lines
def test_a_clean_target_still_reports_its_zeros(tmp_path: Path) -> None:
    """THE LOAD-BEARING TEST. A silent zero is indistinguishable from a diagnostic that
    never ran, from an index built before the diagnostic existed, and from a detector that
    is structurally blind to the target — and this repo has made the third mistake and
    written it down as a correct negative, on a target whose real accessors were macros
    with 1,093 call sites and no `kind='function'` rows.

    So both counts must be PRESENT and `"0"`, and the corpus size must be present and
    non-zero: "searched N names, matched none" is a measurement, while an absent key is not.

    @brief Zero is reported, with the corpus it was measured over.
    @version 1
    """
    db = _corpus(tmp_path / "clew.db", [("function", "run"), ("function", "main")])

    meta = dg.collect(db, tmp_path / "absent.Doxyfile", None, None, None).as_meta()

    assert meta["accessor_families_count"] == "0"
    assert meta["unclaimed_event_aliases_count"] == "0"
    assert meta["accessor_names_examined"] == "2", "a zero needs the corpus it was measured over"
    assert meta["event_vocabulary_source"] == dg.SOURCE_BUILT_IN

Activity · 6 steps
lines 207–207db = _corpus(tmp_path / "clew.db", [("function", "run"), ("function", "main")])lines 209–209meta = dg.collect(db, tmp_path / "absent.Doxyfile", None, None, None).as_meta()lines 211–211assert meta["accessor_families_count"] == "0"lines 212–212assert meta["unclaimed_event_aliases_count"] == "0"lines 213–213assert meta["accessor_names_examined"] == "2", "a zero needs the corpus it was measured over"lines 214–214assert meta["event_vocabulary_source"] == dg.SOURCE_BUILT_IN

test_a_covered_family_is_not_reported

None test_diagnostics.test_a_covered_family_is_not_reported(Path tmp_path)

A declared pattern covering a family removes it from the diagnostic.

tests/test_diagnostics.py:334

Checks

  • assert bare.as_meta()["accessor_families_count"] == "1", "control: undeclared, so reported"
  • assert detect_undeclared_accessor_families(conn, [covering]) == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measuredtest_a_covered_family_is_not_reported → collect → resolve_shared_key_patterns
REQ-DDB-CONFIG-007measuredtest_a_covered_family_is_not_reported → collect
REQ-DDB-QUERY-011measured
REQ-DDB-SCHEMA-001measuredtest_a_covered_family_is_not_reported → collect → load_thread_patterns
REQ-DDB-SCHEMA-005measuredtest_a_covered_family_is_not_reported → detect_undeclared_accessor_families
REQ-DDB-SCHEMA-011measuredtest_a_covered_family_is_not_reported → collect → load_lock_patterns
REQ-DDB-SCHEMA-012measuredtest_a_covered_family_is_not_reported → collect → load_lock_patterns → declaration_origin
Source · 32 lines
def test_a_covered_family_is_not_reported(tmp_path: Path) -> None:
    """The diagnostic names what is NOT covered, so declaring the prefix must silence it.
    Without this the payload would be a list of every accessor family in the repo, which
    would say nothing about what is missing — and would keep saying it after an operator
    fixed the thing it complained about.

    @brief Declaring the prefix silences the finding.
    @version 1
    """
    from clew.shared_key_edges import NamePrefixPattern

    db = _corpus(
        tmp_path / "clew.db",
        [("macro definition", f"Store_Set_{key}") for key in ("A", "B", "C", "D", "E")],
    )
    covering = NamePrefixPattern("Store_Set_")

    bare = dg.collect(db, tmp_path / "absent.Doxyfile", None, None, None)
    assert bare.as_meta()["accessor_families_count"] == "1", "control: undeclared, so reported"

    conn = sqlite3.connect(f"file:{db}?mode=ro", uri=True)
    try:
        from clew.shared_key_edges import detect_undeclared_accessor_families

        assert detect_undeclared_accessor_families(conn, [covering]) == []
    finally:
        conn.close()


# ─── persistence ─────────────────────────────────────────────────────────────

Activity · 9 steps
lines 343–343from clew.shared_key_edges import NamePrefixPatternlines 345–348db = _corpus( tmp_path / "clew.db", [("macro definition", f"Store_Set_{key}") for key in ("A", "B", "C", "D", "E")], )lines 349–349covering = NamePrefixPattern("Store_Set_")lines 351–351bare = dg.collect(db, tmp_path / "absent.Doxyfile", None, None, None)lines 352–352assert bare.as_meta()["accessor_families_count"] == "1", "control: undeclared, so reported"lines 354–354conn = sqlite3.connect(f"file:{db}?mode=ro", uri=True)lines 355–355trylines 356–356from clew.shared_key_edges import detect_undeclared_accessor_familieslines 358–358assert detect_undeclared_accessor_families(conn, [covering]) == []

test_a_declared_vocabulary_is_reported_and_reclassifies

None test_diagnostics.test_a_declared_vocabulary_is_reported_and_reclassifies(Path tmp_path)

A declared vocabulary is reported as declared, and changes what counts as unclaimed.

tests/test_diagnostics.py:281

Show on the map →

Called by none

Calls _corpus, collect

Checks

  • assert meta["event_vocabulary_source"] == dg.SOURCE_DECLARED
  • assert meta["event_vocabulary_size"] == "1"
  • assert "broadcasts" not in result.unclaimed_aliases, "the declared verb is claimed"
  • assert "emits" in result.unclaimed_aliases, "a declaration REPLACES the built-in verbs"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measuredtest_a_declared_vocabulary_is_reported_and_reclassifies → collect → resolve_shared_key_patterns
REQ-DDB-CONFIG-007measuredtest_a_declared_vocabulary_is_reported_and_reclassifies → collect
REQ-DDB-QUERY-011measured
REQ-DDB-SCHEMA-001measuredtest_a_declared_vocabulary_is_reported_and_reclassifies → collect → load_thread_patterns
REQ-DDB-SCHEMA-005measuredtest_a_declared_vocabulary_is_reported_and_reclassifies → collect → resolve_shared_key_patterns
REQ-DDB-SCHEMA-011measuredtest_a_declared_vocabulary_is_reported_and_reclassifies → collect → load_lock_patterns
REQ-DDB-SCHEMA-012measuredtest_a_declared_vocabulary_is_reported_and_reclassifies → collect → load_lock_patterns → declaration_origin
Source · 24 lines
def test_a_declared_vocabulary_is_reported_and_reclassifies(tmp_path: Path) -> None:
    """The loop gh#332 closes: an operator declares `event_tags`, and the reply has to say
    whether the declaration ARRIVED. A count alone cannot — it moves for several reasons.

    Declaring `broadcasts` must both claim it and UNCLAIM `emits`, because a declared
    vocabulary REPLACES the built-in verbs rather than extending them. Asserting only the
    first half would pass against an extend-semantics implementation.

    @brief A declaration is reported as the source and replaces the defaults.
    @version 1
    """
    doxyfile = tmp_path / "Doxyfile"
    doxyfile.write_text(ALIASES_TEXT, encoding="utf-8")
    db = _corpus(tmp_path / "clew.db", [("function", "run")])

    result = dg.collect(db, doxyfile, None, None, {"broadcasts": "producer"})
    meta = result.as_meta()

    assert meta["event_vocabulary_source"] == dg.SOURCE_DECLARED
    assert meta["event_vocabulary_size"] == "1"
    assert "broadcasts" not in result.unclaimed_aliases, "the declared verb is claimed"
    assert "emits" in result.unclaimed_aliases, "a declaration REPLACES the built-in verbs"

Activity · 9 steps
lines 292–292doxyfile = tmp_path / "Doxyfile"lines 293–293doxyfile.write_text(ALIASES_TEXT, encoding="utf-8")lines 294–294db = _corpus(tmp_path / "clew.db", [("function", "run")])lines 296–296result = dg.collect(db, doxyfile, None, None, {"broadcasts": "producer"})lines 297–297meta = result.as_meta()lines 299–299assert meta["event_vocabulary_source"] == dg.SOURCE_DECLAREDlines 300–300assert meta["event_vocabulary_size"] == "1"lines 301–301assert "broadcasts" not in result.unclaimed_aliases, "the declared verb is claimed"lines 302–302assert "emits" in result.unclaimed_aliases, "a declaration REPLACES the built-in verbs"

test_a_family_spanning_both_sides_is_first_party

None test_diagnostics.test_a_family_spanning_both_sides_is_first_party(Path tmp_path)

A family with functions on BOTH sides is first party, not external.

tests/test_diagnostics.py:160

Show on the map →

Called by none

Calls _attributed_corpus, collect

Checks

  • assert meta["accessor_families_first_party_count"] == "1"
  • assert meta["accessor_families_external_count"] == "0"
  • assert "Store_Set_* (4 keys)" in meta["accessor_families"], ("all four keys count toward the family; only its ORIGIN is at issue" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measuredtest_a_family_spanning_both_sides_is_first_party → collect → resolve_shared_key_patterns
REQ-DDB-CONFIG-007measuredtest_a_family_spanning_both_sides_is_first_party → collect
REQ-DDB-QUERY-011measured
REQ-DDB-SCHEMA-001measuredtest_a_family_spanning_both_sides_is_first_party → collect → load_thread_patterns
REQ-DDB-SCHEMA-005measuredtest_a_family_spanning_both_sides_is_first_party → collect → resolve_shared_key_patterns
REQ-DDB-SCHEMA-011measuredtest_a_family_spanning_both_sides_is_first_party → collect → load_lock_patterns
REQ-DDB-SCHEMA-012measuredtest_a_family_spanning_both_sides_is_first_party → collect → load_lock_patterns → declaration_origin
Source · 30 lines
def test_a_family_spanning_both_sides_is_first_party(tmp_path: Path) -> None:
    """THE STATED RULE FOR AN EXPRESSIBLE AMBIGUITY. A prefix can collect functions from both
    a repo and its submodule, and then the classification could silently pick either side.
    Fail-closed here means OURS — the same asymmetry `scope._is_dependency_of_parent` and
    `locks._origin_per_mutex` argue: if any part of the family is this repo's, declaring a
    prefix IS an action the operator can take, and calling it external would remove it from the
    list they act on.

    @brief A mixed-origin family is named as actionable.
    @version 1
    """
    db = _attributed_corpus(
        tmp_path / "clew.db",
        [("function", f"Store_Set_{key}", 1) for key in ("A", "B")]
        + [("function", f"Store_Set_{key}", 2) for key in ("C", "D")],
        [(1, "src/store.c", None), (2, "extern/dep/store_extra.c", "extern/dep")],
    )

    meta = dg.collect(db, tmp_path / "absent.Doxyfile", None, None, None).as_meta()

    assert meta["accessor_families_first_party_count"] == "1"
    assert meta["accessor_families_external_count"] == "0"
    assert "Store_Set_* (4 keys)" in meta["accessor_families"], (
        "all four keys count toward the family; only its ORIGIN is at issue"
    )


# ─── the control: nothing to report is still a report ─────────────────────────

Activity · 5 steps
lines 171–176db = _attributed_corpus( tmp_path / "clew.db", [("function", f"Store_Set_{key}", 1) for key in ("A", "B")] + [("function", f"Store_Set_{key}", 2) for key in ("C", "D")], [(1, "src/store.c", None), (2, "extern/dep/store_extra.c", "extern/dep")], )lines 178–178meta = dg.collect(db, tmp_path / "absent.Doxyfile", None, None, None).as_meta()lines 180–180assert meta["accessor_families_first_party_count"] == "1"lines 181–181assert meta["accessor_families_external_count"] == "0"lines 182–184assert "Store_Set_* (4 keys)" in meta["accessor_families"], ( "all four keys count toward the family; only its ORIGIN is at issue" )

test_a_macro_accessor_family_is_named_in_the_payload

None test_diagnostics.test_a_macro_accessor_family_is_named_in_the_payload(Path tmp_path)

An undeclared MACRO accessor family is named, with its key count.

tests/test_diagnostics.py:221

Show on the map →

Called by none

Calls _corpus, collect

Checks

  • assert (result.accessor_families[0].prefix, result.accessor_families[0].keys) == ("Store_Set_", 5, )
  • assert "Store_Set_* (5 keys)" in meta["accessor_families"]
  • assert meta["accessor_families_count"] == "1"
  • assert meta["accessor_names_examined"] == "5"
  • assert meta["accessor_families_first_party_count"] == "1"
  • assert meta["accessor_families_external_count"] == "0"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measuredtest_a_macro_accessor_family_is_named_in_the_payload → collect → resolve_shared_key_patterns
REQ-DDB-CONFIG-007measuredtest_a_macro_accessor_family_is_named_in_the_payload → collect
REQ-DDB-QUERY-011measured
REQ-DDB-SCHEMA-001measuredtest_a_macro_accessor_family_is_named_in_the_payload → collect → load_thread_patterns
REQ-DDB-SCHEMA-005measuredtest_a_macro_accessor_family_is_named_in_the_payload → collect → resolve_shared_key_patterns
REQ-DDB-SCHEMA-011measuredtest_a_macro_accessor_family_is_named_in_the_payload → collect → load_lock_patterns
REQ-DDB-SCHEMA-012measuredtest_a_macro_accessor_family_is_named_in_the_payload → collect → load_lock_patterns → declaration_origin
Source · 29 lines
def test_a_macro_accessor_family_is_named_in_the_payload(tmp_path: Path) -> None:
    """Macros only, deliberately: the case the diagnostic exists for is a repo whose
    accessors produce ZERO function rows, so a fixture with a function in it would pass
    against a functions-only corpus and prove nothing.

    @brief A macro-defined family reaches the payload by name.
    @version 1
    """
    db = _corpus(
        tmp_path / "clew.db",
        [("macro definition", f"Store_Set_{key}") for key in ("A", "B", "C", "D", "E")],
    )

    result = dg.collect(db, tmp_path / "absent.Doxyfile", None, None, None)
    meta = result.as_meta()

    assert (result.accessor_families[0].prefix, result.accessor_families[0].keys) == (
        "Store_Set_",
        5,
    )
    assert "Store_Set_* (5 keys)" in meta["accessor_families"]
    assert meta["accessor_families_count"] == "1"
    assert meta["accessor_names_examined"] == "5"
    ## The fixture's `path` table carries no external tag, so the family is FIRST PARTY and the
    ## three counts reconcile — which is the gh#352 contract at this surface.
    assert meta["accessor_families_first_party_count"] == "1"
    assert meta["accessor_families_external_count"] == "0"

Activity · 9 steps
lines 229–232db = _corpus( tmp_path / "clew.db", [("macro definition", f"Store_Set_{key}") for key in ("A", "B", "C", "D", "E")], )lines 234–234result = dg.collect(db, tmp_path / "absent.Doxyfile", None, None, None)lines 235–235meta = result.as_meta()lines 237–240assert (result.accessor_families[0].prefix, result.accessor_families[0].keys) == ( "Store_Set_", 5, )lines 241–241assert "Store_Set_* (5 keys)" in meta["accessor_families"]lines 242–242assert meta["accessor_families_count"] == "1"lines 243–243assert meta["accessor_names_examined"] == "5"lines 246–246assert meta["accessor_families_first_party_count"] == "1"lines 247–247assert meta["accessor_families_external_count"] == "0"

test_a_real_build_stamps_the_diagnostics_section

None test_diagnostics.test_a_real_build_stamps_the_diagnostics_section(Path tmp_path)

A real build stamps the section, naming a family doxygen itself emitted.

tests/test_diagnostics.py:431

Checks

  • assert section, "a built index must carry the section, not merely be able to"
  • assert section["accessor_families_count"] == "1"
  • assert "Store_Set_* (5 keys)" in section["accessor_families"]
  • assert int(section["accessor_names_examined"]) >= 5
  • assert section["event_vocabulary_source"] == dg.SOURCE_BUILT_IN

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measured
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-004measured
REQ-DDB-CONFIG-005measured
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-CONFIG-009measured
REQ-DDB-INDEX-001measured
REQ-DDB-INDEX-002measured
REQ-DDB-INDEX-003measured
REQ-DDB-INDEX-004measured
REQ-DDB-INDEX-005measured
REQ-DDB-INDEX-006measured
REQ-DDB-INDEX-007measured
REQ-DDB-INDEX-008measured
REQ-DDB-INDEX-009measured
REQ-DDB-INDEX-010measured
REQ-DDB-INDEX-011measured
REQ-DDB-MCP-001measuredtest_a_real_build_stamps_the_diagnostics_section → meta_section
REQ-DDB-MCP-004measured
REQ-DDB-PIPE-001measured
REQ-DDB-PIPE-003measured
REQ-DDB-PIPE-004measured
REQ-DDB-PIPE-005measured
REQ-DDB-PIPE-006measured
REQ-DDB-PIPE-007measured
REQ-DDB-PIPE-008measured
REQ-DDB-PIPE-009measured
REQ-DDB-PIPE-010measured
REQ-DDB-PIPE-011measured
REQ-DDB-PIPE-012measured
REQ-DDB-PIPE-013measured
REQ-DDB-PIPE-014measured
REQ-DDB-PIPE-015measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-011measured
REQ-DDB-SCHEMA-001measured
REQ-DDB-SCHEMA-002measured
REQ-DDB-SCHEMA-003measured
REQ-DDB-SCHEMA-004measured
REQ-DDB-SCHEMA-005measured
REQ-DDB-SCHEMA-006measured
REQ-DDB-SCHEMA-007measured
REQ-DDB-SCHEMA-009measured
REQ-DDB-SCHEMA-011measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measured
REQ-DDB-SCHEMA-014measured
REQ-DDB-SCHEMA-015measured
Source · 45 lines
def test_a_real_build_stamps_the_diagnostics_section(tmp_path: Path) -> None:
    """THE TEST THAT COVERS THE WIRING, and without it the whole feature is green for the
    wrong reason: every test above calls `collect` or `write_build_signature` directly, so
    deleting the `diagnostics=` argument from `cli`'s stamp leaves them all passing while
    no built index carries the section. Mutation-checked, not assumed.

    It asserts a family is NAMED rather than that a zero appears, so it also proves the
    detector works on real doxygen output — a hand-built corpus only ever proves the
    fixture agrees with the code.

    @brief A real build records the diagnostics, detected from doxygen's own rows.
    @version 1
    """
    root = tmp_path / "repo"
    root.mkdir()
    (root / "store.c").write_text(
        "".join(
            f"/** @brief Set {key}. */\nvoid Store_Set_{key}(int v) {{ (void)v; }}\n"
            for key in ("ALPHA", "BETA", "GAMMA", "DELTA", "EPSILON")
        ),
        encoding="utf-8",
    )
    doxyfile = root / "Doxyfile"
    doxyfile.write_text(
        f"INPUT = {root}\nOUTPUT_DIRECTORY = {root}/out\nRECURSIVE = YES\nGENERATE_SQLITE3 = YES\n",
        encoding="utf-8",
    )
    out = tmp_path / "clew.db"

    from clew.cli import build_index

    build_index(output=out, repo_root=root, doxyfile=doxyfile)

    section = meta_section(out, dg.META_PREFIX)
    assert section, "a built index must carry the section, not merely be able to"
    assert section["accessor_families_count"] == "1"
    assert "Store_Set_* (5 keys)" in section["accessor_families"]
    assert int(section["accessor_names_examined"]) >= 5
    assert section["event_vocabulary_source"] == dg.SOURCE_BUILT_IN


@pytest.mark.skipif(
    shutil.which("doxygen") is None,
    reason="precedence is asserted against a real build",
)

test_a_stated_vocabulary_beats_the_repos_declaration

None test_diagnostics.test_a_stated_vocabulary_beats_the_repos_declaration(Path tmp_path)

A STATED vocabulary beats the repo's DECLARED one, through a real build.

tests/test_diagnostics.py:480

Checks

  • assert baseline["event_vocabulary_size"] == "2", "premise: the declaration is read"
  • assert baseline["event_vocabulary_source"] == dg.SOURCE_DECLARED
  • assert section["event_vocabulary_size"] == "1", "a stated vocabulary REPLACES the declared one"
  • assert section["event_vocabulary_source"] == dg.SOURCE_DECLARED

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measured
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-004measured
REQ-DDB-CONFIG-005measured
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-CONFIG-009measured
REQ-DDB-GUARD-012measured
REQ-DDB-INDEX-001measured
REQ-DDB-INDEX-002measured
REQ-DDB-INDEX-003measured
REQ-DDB-INDEX-004measured
REQ-DDB-INDEX-005measured
REQ-DDB-INDEX-006measured
REQ-DDB-INDEX-007measured
REQ-DDB-INDEX-008measured
REQ-DDB-INDEX-009measured
REQ-DDB-INDEX-010measured
REQ-DDB-INDEX-011measured
REQ-DDB-MCP-001measuredtest_a_stated_vocabulary_beats_the_repos_declaration → meta_section
REQ-DDB-MCP-004measured
REQ-DDB-PIPE-001measured
REQ-DDB-PIPE-003measured
REQ-DDB-PIPE-004measured
REQ-DDB-PIPE-005measured
REQ-DDB-PIPE-006measured
REQ-DDB-PIPE-007measured
REQ-DDB-PIPE-008measured
REQ-DDB-PIPE-009measured
REQ-DDB-PIPE-010measured
REQ-DDB-PIPE-011measured
REQ-DDB-PIPE-012measured
REQ-DDB-PIPE-013measured
REQ-DDB-PIPE-014measured
REQ-DDB-PIPE-015measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-011measured
REQ-DDB-SCHEMA-001measured
REQ-DDB-SCHEMA-002measured
REQ-DDB-SCHEMA-003measured
REQ-DDB-SCHEMA-004measured
REQ-DDB-SCHEMA-005measured
REQ-DDB-SCHEMA-006measured
REQ-DDB-SCHEMA-007measured
REQ-DDB-SCHEMA-009measured
REQ-DDB-SCHEMA-011measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measured
REQ-DDB-SCHEMA-014measured
REQ-DDB-SCHEMA-015measured
Source · 51 lines
def test_a_stated_vocabulary_beats_the_repos_declaration(tmp_path: Path) -> None:
    """gh#332's PRECEDENCE, and it needs a real build because the `or` chain that
    implements it lives one line deep inside `_build_stages`. A mutation control found this
    untested: swapping the two sides — so the declaration beats the statement — left the
    entire suite green, which is tier 1 reachable and INERT, the exact shape gh#332 exists
    to fix reintroduced one line lower.

    The observable is the gh#320 diagnostics, which is why the two changes belong together:
    `event_vocabulary_source` and `_size` report WHICH vocabulary was in force, so the
    precedence is checkable from the payload rather than by inspection. The declaration
    carries TWO entries and the statement ONE, so the size alone discriminates.

    @brief A caller's stated event vocabulary wins over the declared one.
    @version 1
    """
    root = tmp_path / "repo"
    root.mkdir()
    (root / "unit.c").write_text("/** @brief A unit. */\nvoid unit(void) {}\n", encoding="utf-8")
    (root / ".clew.yaml").write_text(
        "event_tags:\n  emits: producer\n  handles: consumer\n", encoding="utf-8"
    )
    doxyfile = root / "Doxyfile"
    doxyfile.write_text(
        f"INPUT = {root}\nOUTPUT_DIRECTORY = {root}/out\nRECURSIVE = YES\nGENERATE_SQLITE3 = YES\n",
        encoding="utf-8",
    )

    from clew.cli import build_index

    declared_only = tmp_path / "declared.db"
    build_index(output=declared_only, repo_root=root, doxyfile=doxyfile)
    baseline = meta_section(declared_only, dg.META_PREFIX)
    assert baseline["event_vocabulary_size"] == "2", "premise: the declaration is read"
    assert baseline["event_vocabulary_source"] == dg.SOURCE_DECLARED

    stated = tmp_path / "stated.db"
    build_index(
        output=stated,
        repo_root=root,
        doxyfile=doxyfile,
        options={"event_tags": {"broadcasts": "producer"}},
    )
    section = meta_section(stated, dg.META_PREFIX)

    assert section["event_vocabulary_size"] == "1", "a stated vocabulary REPLACES the declared one"
    ## KNOWN COARSENESS, asserted so it is visible rather than discovered. `source` says
    ## only "not the built-in verbs" — it does NOT separate a STATED vocabulary (tier 1)
    ## from a DECLARED one (tier 2), so both read `declared` and the SIZE is what
    ## discriminates above. Reporting the tier properly means an `options.event_tags.tier`
    ## row, which `options_meta` will only accept from a LayeredResolution.
    assert section["event_vocabulary_source"] == dg.SOURCE_DECLARED

1 more lines, not shown

Activity · 17 steps
lines 495–495root = tmp_path / "repo"lines 496–496root.mkdir()lines 497–497(root / "unit.c").write_text("/** @brief A unit. */\nvoid unit(void) {}\n", encoding="utf-8")lines 498–500(root / ".clew.yaml").write_text( "event_tags:\n emits: producer\n handles: consumer\n", encoding="utf-8" )lines 501–501doxyfile = root / "Doxyfile"lines 502–505doxyfile.write_text( f"INPUT = {root}\nOUTPUT_DIRECTORY = {root}/out\nRECURSIVE = YES\nGENERATE_SQLITE3 = YES\n", encoding="utf-8", )lines 507–507from clew.cli import build_indexlines 509–509declared_only = tmp_path / "declared.db"lines 510–510build_index(output=declared_only, repo_root=root, doxyfile=doxyfile)lines 511–511baseline = meta_section(declared_only, dg.META_PREFIX)lines 512–512assert baseline["event_vocabulary_size"] == "2", "premise: the declaration is read"lines 513–513assert baseline["event_vocabulary_source"] == dg.SOURCE_DECLAREDlines 515–515stated = tmp_path / "stated.db"lines 516–521build_index( output=stated, repo_root=root, doxyfile=doxyfile, options={"event_tags": {"broadcasts": "producer"}}, )lines 522–522section = meta_section(stated, dg.META_PREFIX)lines 524–524assert section["event_vocabulary_size"] == "1", "a stated vocabulary REPLACES the declared one"lines 530–530assert section["event_vocabulary_source"] == dg.SOURCE_DECLARED

test_a_vendored_accessor_family_is_counted_but_not_named

None test_diagnostics.test_a_vendored_accessor_family_is_counted_but_not_named(Path tmp_path)

A vendored accessor family is COUNTED but not NAMED as actionable.

tests/test_diagnostics.py:113

Show on the map →

Called by none

Calls _attributed_corpus, collect

Checks

  • assert meta["accessor_families_count"] == "2", "both families are found"
  • assert meta["accessor_families_first_party_count"] == "1"
  • assert meta["accessor_families_external_count"] == "1"
  • assert int(meta["accessor_families_first_party_count"]) + int(meta["accessor_families_external_count"] ) == int(meta["accessor_families_count"])
  • assert "Store_Set_*" in meta["accessor_families"], "the actionable family is named"
  • assert "ggml_set_" not in meta["accessor_families"], ("a vendored family is not the operator's to declare, so naming it beside the one they " "can act on is what trains a reader to ignore the whole hint" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measuredtest_a_vendored_accessor_family_is_counted_but_not_named → collect → resolve_shared_key_patterns
REQ-DDB-CONFIG-007measuredtest_a_vendored_accessor_family_is_counted_but_not_named → collect
REQ-DDB-QUERY-011measured
REQ-DDB-SCHEMA-001measuredtest_a_vendored_accessor_family_is_counted_but_not_named → collect → load_thread_patterns
REQ-DDB-SCHEMA-005measuredtest_a_vendored_accessor_family_is_counted_but_not_named → collect → resolve_shared_key_patterns
REQ-DDB-SCHEMA-011measuredtest_a_vendored_accessor_family_is_counted_but_not_named → collect → load_lock_patterns
REQ-DDB-SCHEMA-012measuredtest_a_vendored_accessor_family_is_counted_but_not_named → collect → load_lock_patterns → declaration_origin
Source · 43 lines
def test_a_vendored_accessor_family_is_counted_but_not_named(tmp_path: Path) -> None:
    """WHY THIS SPLIT EXISTS, measured rather than argued. Probing this detector against both
    public targets: [tvanfossen/entropic](https://github.com/tvanfossen/entropic) examines
    17,773 distinct names and names NINE families, ALL NINE vendored inside `extern/llama.cpp`
    (`ma_*` from miniaudio, `ggml_set_*`); Mbed-TLS/mbedtls examines 5,967 and names TWO, both
    DES key-schedule setters. Eleven families across two repos, and an operator should declare
    NONE of them.

    A hint whose entries are unactionable teaches its reader to skip the hint, which is the
    same defect as `lock_roster` telling a caller to quote a count that is 57% another
    repository's — and this one costs an operator time before they discover it yielded nothing.

    THE EXTERNAL FAMILIES ARE STILL COUNTED. Dropping them would make "found nothing"
    indistinguishable from "found nine things in somebody else's code", and those call for
    different next steps. So `accessor_families_count` stays the total, and an EMPTY name list
    beside a non-zero count is the honest reading of entropic.

    @brief A vendored family is counted in the total and absent from the named list.
    @version 1
    """
    db = _attributed_corpus(
        tmp_path / "clew.db",
        [("macro definition", f"ggml_set_{key}", 2) for key in ("A", "B", "C", "D", "E")]
        + [("function", f"Store_Set_{key}", 1) for key in ("A", "B", "C", "D")],
        [(1, "src/store.c", None), (2, "extern/llama.cpp/ggml/src/ggml.c", "extern/llama.cpp")],
    )

    meta = dg.collect(db, tmp_path / "absent.Doxyfile", None, None, None).as_meta()

    assert meta["accessor_families_count"] == "2", "both families are found"
    assert meta["accessor_families_first_party_count"] == "1"
    assert meta["accessor_families_external_count"] == "1"
    ## The three counts reconcile, which is the gh#352 contract.
    assert int(meta["accessor_families_first_party_count"]) + int(
        meta["accessor_families_external_count"]
    ) == int(meta["accessor_families_count"])
    assert "Store_Set_*" in meta["accessor_families"], "the actionable family is named"
    assert "ggml_set_" not in meta["accessor_families"], (
        "a vendored family is not the operator's to declare, so naming it beside the one they "
        "can act on is what trains a reader to ignore the whole hint"
    )

Activity · 8 steps
lines 133–138db = _attributed_corpus( tmp_path / "clew.db", [("macro definition", f"ggml_set_{key}", 2) for key in ("A", "B", "C", "D", "E")] + [("function", f"Store_Set_{key}", 1) for key in ("A", "B", "C", "D")], [(1, "src/store.c", None), (2, "extern/llama.cpp/ggml/src/ggml.c", "extern/llama.cpp")], )lines 140–140meta = dg.collect(db, tmp_path / "absent.Doxyfile", None, None, None).as_meta()lines 142–142assert meta["accessor_families_count"] == "2", "both families are found"lines 143–143assert meta["accessor_families_first_party_count"] == "1"lines 144–144assert meta["accessor_families_external_count"] == "1"lines 146–148assert int(meta["accessor_families_first_party_count"]) + int( meta["accessor_families_external_count"] ) == int(meta["accessor_families_count"])lines 149–149assert "Store_Set_*" in meta["accessor_families"], "the actionable family is named"lines 150–153assert "ggml_set_" not in meta["accessor_families"], ( "a vendored family is not the operator's to declare, so naming it beside the one they " "can act on is what trains a reader to ignore the whole hint" )

test_a_zero_count_survives_the_falsy_drop

None test_diagnostics.test_a_zero_count_survives_the_falsy_drop(Path tmp_path)

A zero count survives persistence, where a falsy value would be dropped.

tests/test_diagnostics.py:398

Checks

  • assert read["accessor_families_count"] == "0", "the zero IS the measurement"
  • assert read["unclaimed_event_aliases_count"] == "0"
  • assert "accessor_families" not in read, "an empty name list carries no claim"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measuredtest_a_zero_count_survives_the_falsy_drop → write_build_signature
REQ-DDB-CONFIG-007measuredtest_a_zero_count_survives_the_falsy_drop → write_build_signature
REQ-DDB-MCP-001measuredtest_a_zero_count_survives_the_falsy_drop → meta_section
REQ-DDB-PIPE-005measuredtest_a_zero_count_survives_the_falsy_drop → write_build_signature
REQ-DDB-QUERY-011measured
Source · 29 lines
def test_a_zero_count_survives_the_falsy_drop(tmp_path: Path) -> None:
    """`write_build_signature` DROPS falsy values, so an int `0` would vanish and rebuild
    the silent zero one layer down — in the persistence rather than in the detector. The
    flatten emits `"0"`, which is truthy, and this is the test that says so.

    Its control is the empty NAMED list in the same payload, which is SUPPOSED to be
    dropped: the count is the claim and must always be present, the names are evidence and
    may be absent.

    @brief A measured zero persists; an empty name list does not have to.
    @version 1
    """
    db = tmp_path / "clew.db"

    write_build_signature(db, diagnostics=dg.BuildDiagnostics().as_meta())
    read = meta_section(db, dg.META_PREFIX)

    assert read["accessor_families_count"] == "0", "the zero IS the measurement"
    assert read["unclaimed_event_aliases_count"] == "0"
    assert "accessor_families" not in read, "an empty name list carries no claim"


# ─── the wiring, against a real build ─────────────────────────────────────────


@pytest.mark.skipif(
    shutil.which("doxygen") is None,
    reason="the stamp is asserted against a real build",
)

test_the_stamped_prefix_round_trips

None test_diagnostics.test_the_stamped_prefix_round_trips(Path tmp_path)

The section survives a write/read round trip under the same prefix.

tests/test_diagnostics.py:370

Checks

  • assert read["accessor_families_count"] == "1"
  • assert read["accessor_names_examined"] == "3784"
  • assert read["unclaimed_event_aliases"] == "broadcasts"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measuredtest_the_stamped_prefix_round_trips → write_build_signature
REQ-DDB-CONFIG-007measuredtest_the_stamped_prefix_round_trips → write_build_signature
REQ-DDB-MCP-001measuredtest_the_stamped_prefix_round_trips → meta_section
REQ-DDB-PIPE-005measuredtest_the_stamped_prefix_round_trips → write_build_signature
REQ-DDB-QUERY-011measured
Source · 24 lines
def test_the_stamped_prefix_round_trips(tmp_path: Path) -> None:
    """THREE MODULES SPELL THIS SECTION NAME and only one imports the constant: the
    flatten (`diagnostics.META_PREFIX`), the writer (`signature`, a literal) and the reader
    (`mcp_server.state`, a literal). A shared constant would not have caught a divergence
    in the two literals; writing through one and reading through the other does.

    @brief The diagnostics section persists and reads back.
    @version 1
    """
    db = tmp_path / "clew.db"
    payload = dg.BuildDiagnostics(
        accessor_families=(AccessorFamily(prefix="Store_Set_", keys=5),),
        accessor_names_examined=3784,
        unclaimed_aliases=("broadcasts",),
    )

    write_build_signature(db, diagnostics=payload.as_meta())
    read = meta_section(db, dg.META_PREFIX)

    assert read["accessor_families_count"] == "1"
    assert read["accessor_names_examined"] == "3784"
    assert read["unclaimed_event_aliases"] == "broadcasts"

Activity · 7 steps
lines 379–379db = tmp_path / "clew.db"lines 380–384payload = dg.BuildDiagnostics( accessor_families=(AccessorFamily(prefix="Store_Set_", keys=5),), accessor_names_examined=3784, unclaimed_aliases=("broadcasts",), )lines 386–386write_build_signature(db, diagnostics=payload.as_meta())lines 387–387read = meta_section(db, dg.META_PREFIX)lines 389–389assert read["accessor_families_count"] == "1"lines 390–390assert read["accessor_names_examined"] == "3784"lines 391–391assert read["unclaimed_event_aliases"] == "broadcasts"

test_unclaimed_aliases_are_named_and_claimed_ones_are_not

None test_diagnostics.test_unclaimed_aliases_are_named_and_claimed_ones_are_not(Path tmp_path)

Aliased tags no vocabulary claims are named; a claimed one is not.

tests/test_diagnostics.py:254

Show on the map →

Called by none

Calls _corpus, collect

Checks

  • assert set(result.unclaimed_aliases) == {"broadcasts", "req"}
  • assert "emits" not in result.unclaimed_aliases, "a claimed verb is not a finding"
  • assert result.as_meta()["unclaimed_event_aliases_count"] == "2"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measuredtest_unclaimed_aliases_are_named_and_claimed_ones_are_not → collect → resolve_shared_key_patterns
REQ-DDB-CONFIG-007measuredtest_unclaimed_aliases_are_named_and_claimed_ones_are_not → collect
REQ-DDB-QUERY-011measured
REQ-DDB-SCHEMA-001measuredtest_unclaimed_aliases_are_named_and_claimed_ones_are_not → collect → load_thread_patterns
REQ-DDB-SCHEMA-005measuredtest_unclaimed_aliases_are_named_and_claimed_ones_are_not → collect → resolve_shared_key_patterns
REQ-DDB-SCHEMA-011measuredtest_unclaimed_aliases_are_named_and_claimed_ones_are_not → collect → load_lock_patterns
REQ-DDB-SCHEMA-012measuredtest_unclaimed_aliases_are_named_and_claimed_ones_are_not → collect → load_lock_patterns → declaration_origin
Source · 23 lines
def test_unclaimed_aliases_are_named_and_claimed_ones_are_not(tmp_path: Path) -> None:
    """BOTH HALVES, because a diagnostic that lists every alias would be noise and one that
    lists none would be the silence being fixed. `emits` is a built-in producer verb and
    must NOT appear; `broadcasts` and `req` are unclaimed and must.

    `req` appearing is deliberate rather than sloppy — nothing in an ALIASES line marks a
    tag as belonging to an event bus, so filtering would mean guessing, and guessing wrong
    hides exactly the tag an owner needed to see.

    @brief Unclaimed aliases are surfaced; claimed ones are excluded.
    @version 1
    """
    doxyfile = tmp_path / "Doxyfile"
    doxyfile.write_text(ALIASES_TEXT, encoding="utf-8")
    db = _corpus(tmp_path / "clew.db", [("function", "run")])

    result = dg.collect(db, doxyfile, None, None, None)

    assert set(result.unclaimed_aliases) == {"broadcasts", "req"}
    assert "emits" not in result.unclaimed_aliases, "a claimed verb is not a finding"
    assert result.as_meta()["unclaimed_event_aliases_count"] == "2"

Activity · 7 steps
lines 266–266doxyfile = tmp_path / "Doxyfile"lines 267–267doxyfile.write_text(ALIASES_TEXT, encoding="utf-8")lines 268–268db = _corpus(tmp_path / "clew.db", [("function", "run")])lines 270–270result = dg.collect(db, doxyfile, None, None, None)lines 272–272assert set(result.unclaimed_aliases) == {"broadcasts", "req"}lines 273–273assert "emits" not in result.unclaimed_aliases, "a claimed verb is not a finding"lines 274–274assert result.as_meta()["unclaimed_event_aliases_count"] == "2"