test_filedocs.py

tests/test_filedocs.py

gh#10 — file-level documentation as an indexed, searchable unit.

test_a_plain_comment_header_is_not_documentation

None test_filedocs.test_a_plain_comment_header_is_not_documentation()

A license-only header never becomes searchable documentation.

tests/test_filedocs.py:130

Checks

  • assert extract_file_doc("src/thing.c", C_LICENSE_ONLY) == ""
  • assert "Copyright" not in extract_file_doc("src/mutex_order.c", C_SOURCE)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-008measuredtest_a_plain_comment_header_is_not_documentation → extract_file_doc
REQ-DDB-SCHEMA-014catalog
Source · 19 lines
def test_a_plain_comment_header_is_not_documentation() -> None:
    """THE CONTROL ON THE WHOLE CORPUS. A bare `/*` block is excluded by construction
    — only `/**`, `/*!`, `///` and `//!` count — because if a copyright notice entered
    the corpus then `search("copyright")` would return every file in the repository and
    the new surface would be pure noise on its first query. Deciding by CONTENT would
    need a heuristic about what a license looks like; the marker the author already
    wrote answers it exactly.

    TWO mechanisms enforce this and the test covers the pair, which a mutation control
    is what proved: `_PLAIN_BLOCK` SKIPS a bare block as preamble, and `_CXX_BLOCK_DOC`
    would not accept one anyway. Loosening either alone leaves the other holding, so a
    single-edit mutation could not break this and the assertion looked stronger than it
    was until both were mutated together."""
    assert extract_file_doc("src/thing.c", C_LICENSE_ONLY) == ""
    ## And the copyright text must not arrive via the license block sitting ABOVE a
    ## real doc block, which is the common real-world layout.
    assert "Copyright" not in extract_file_doc("src/mutex_order.c", C_SOURCE)

Activity · 2 steps
lines 143–143assert extract_file_doc("src/thing.c", C_LICENSE_ONLY) == ""lines 146–146assert "Copyright" not in extract_file_doc("src/mutex_order.c", C_SOURCE)

test_a_synthetic_path_row_produces_no_warning

None test_filedocs.test_a_synthetic_path_row_produces_no_warning(tuple[Path, Path] indexed, pytest.LogCaptureFixture caplog)

A synthetic path row is filtered before anything tries to open it.

tests/test_filedocs.py:247

Checks

  • assert not [r for r in caplog.records if "[STL]" in r.getMessage()], ("a synthetic path row must be filtered, not opened and warned about" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_a_synthetic_path_row_produces_no_warning → ingest_file_docs → _collect_file_docs → memoized
REQ-DDB-PIPE-008measuredtest_a_synthetic_path_row_produces_no_warning → ingest_file_docs
REQ-DDB-PIPE-014measuredtest_a_synthetic_path_row_produces_no_warning → ingest_file_docs → _collect_file_docs → within_repo
REQ-DDB-SCHEMA-014measuredtest_a_synthetic_path_row_produces_no_warning → ingest_file_docs → ensure_file_docs_table
Source · 19 lines
def test_a_synthetic_path_row_produces_no_warning(
    indexed: tuple[Path, Path], caplog: pytest.LogCaptureFixture
) -> None:
    """A MUTATION CONTROL FOUND THIS TEST, by finding that the version before it was
    vacuous. Asserting `[STL]` produces no `file_docs` row passes with the filter
    REMOVED, because doxygen's synthetic row names no openable file and `_read_text`
    drops it anyway — two mechanisms, one observable, so the assertion tested nothing.

    What the filter actually buys is silence: without it every build logs a spurious
    `could not read [STL]` warning, which trains a reader to ignore that warning for
    the files where it means something real. So the log is what gets asserted."""
    db, repo = indexed
    with caplog.at_level("WARNING"):
        ingest_file_docs(db, repo)
    assert not [r for r in caplog.records if "[STL]" in r.getMessage()], (
        "a synthetic path row must be filtered, not opened and warned about"
    )

Activity · 4 steps
lines 258–258db, repo = indexedlines 259–259with caplog.at_level("WARNING")lines 260–260ingest_file_docs(db, repo)lines 261–263assert not [r for r in caplog.records if "[STL]" in r.getMessage()], ( "a synthetic path row must be filtered, not opened and warned about" )

test_absent_corpus_is_reported_as_absent

None test_filedocs.test_absent_corpus_is_reported_as_absent(tuple[Path, Path] indexed)

The corpus's ABSENCE is detectable, so an empty search can say so.

tests/test_filedocs.py:306

Checks

  • assert has_file_docs(db) is False
  • assert file_doc_rows(sqlite3.connect(db), ["anything"]) == []
  • assert has_file_docs(db) is True

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_absent_corpus_is_reported_as_absent → ingest_file_docs → _collect_file_docs → memoized
REQ-DDB-PIPE-008measuredtest_absent_corpus_is_reported_as_absent → ingest_file_docs
REQ-DDB-PIPE-014measuredtest_absent_corpus_is_reported_as_absent → ingest_file_docs → _collect_file_docs → within_repo
REQ-DDB-QUERY-001measuredtest_absent_corpus_is_reported_as_absent → has_file_docs → connect
REQ-DDB-QUERY-003measuredtest_absent_corpus_is_reported_as_absent → file_doc_rows → table_exists
REQ-DDB-QUERY-007measuredtest_absent_corpus_is_reported_as_absent → file_doc_rows
REQ-DDB-SCHEMA-014measuredtest_absent_corpus_is_reported_as_absent → ingest_file_docs → ensure_file_docs_table
Source · 9 lines
def test_absent_corpus_is_reported_as_absent(indexed: tuple[Path, Path]) -> None:
    """An index built before build 23 has no `file_docs` table. A detector that cannot
    look must not report a negative — this repo's most-repeated lesson, applied to its
    newest table."""
    db, repo = indexed
    assert has_file_docs(db) is False
    assert file_doc_rows(sqlite3.connect(db), ["anything"]) == []
    ingest_file_docs(db, repo)
    assert has_file_docs(db) is True

1 more lines, not shown

Activity · 5 steps
lines 310–310db, repo = indexedlines 311–311assert has_file_docs(db) is Falselines 312–312assert file_doc_rows(sqlite3.connect(db), ["anything"]) == []lines 313–313ingest_file_docs(db, repo)lines 314–314assert has_file_docs(db) is True

test_an_unclaimed_suffix_yields_no_documentation

None test_filedocs.test_an_unclaimed_suffix_yields_no_documentation()

A suffix no extractor claims yields nothing, silently and correctly.

tests/test_filedocs.py:152

Checks

  • assert extract_file_doc("tests/data/schema_vocabulary.json", '{"a": 1}') == ""

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-008measuredtest_an_unclaimed_suffix_yields_no_documentation → extract_file_doc
REQ-DDB-SCHEMA-014catalog
Source · 6 lines
def test_an_unclaimed_suffix_yields_no_documentation() -> None:
    """A `.json` fixture has no file-level documentation to find, and inventing one
    would put noise on a search surface."""
    assert extract_file_doc("tests/data/schema_vocabulary.json", '{"a": 1}') == ""

Activity · 1 steps
lines 155–155assert extract_file_doc("tests/data/schema_vocabulary.json", '{"a": 1}') == ""

test_c_family_doxygen_block_is_found_past_a_license_header

None test_filedocs.test_c_family_doxygen_block_is_found_past_a_license_header()

A C file's leading doxygen block is found past a plain license header.

tests/test_filedocs.py:87

Checks

  • assert "deadlock" in doc
  • assert "Copyright" not in doc
  • assert not doc.startswith("*")

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-008measuredtest_c_family_doxygen_block_is_found_past_a_license_header → extract_file_doc
REQ-DDB-SCHEMA-014catalog
Source · 11 lines
def test_c_family_doxygen_block_is_found_past_a_license_header() -> None:
    """The `/* Copyright */` line must be SKIPPED OVER rather than terminating the
    search — the same shape as the `#`-divider trap that used to make doxygen-guard
    read the wrong block."""
    doc = extract_file_doc("src/mutex_order.c", C_SOURCE)
    assert "deadlock" in doc
    assert "Copyright" not in doc
    ## The `*` gutter each continuation line carries is furniture, not content.
    assert not doc.startswith("*")

Activity · 4 steps
lines 91–91doc = extract_file_doc("src/mutex_order.c", C_SOURCE)lines 92–92assert "deadlock" in doclines 93–93assert "Copyright" not in doclines 95–95assert not doc.startswith("*")

test_c_family_line_comment_run_is_extracted

None test_filedocs.test_c_family_line_comment_run_is_extracted()

A run of /// line comments is the file documentation too.

tests/test_filedocs.py:101

Checks

  • assert "lock-free ring buffer" in doc

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-008measuredtest_c_family_line_comment_run_is_extracted → extract_file_doc
REQ-DDB-SCHEMA-014catalog
Source · 7 lines
def test_c_family_line_comment_run_is_extracted() -> None:
    """Doxygen accepts both forms and a repo may use either; supporting only the
    block form would make the corpus silently empty for a codebase using `///`."""
    doc = extract_file_doc("src/ring.h", C_LINE_SOURCE)
    assert "lock-free ring buffer" in doc

Activity · 2 steps
lines 104–104doc = extract_file_doc("src/ring.h", C_LINE_SOURCE)lines 105–105assert "lock-free ring buffer" in doc

test_extractor_suffix_sets_do_not_overlap

None test_filedocs.test_extractor_suffix_sets_do_not_overlap()

The extractors claim disjoint suffix sets.

tests/test_filedocs.py:170

Show on the map →

Called by none

Calls none

Checks

  • assert py & cxx == set()
  • assert py and cxx

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-008catalog
REQ-DDB-SCHEMA-014catalog
Source · 9 lines
def test_extractor_suffix_sets_do_not_overlap() -> None:
    """Dispatch is first-match, so an overlap would make which extractor runs depend
    on declaration order — the sort of thing that works until someone sorts a tuple."""
    py = set(PythonFileDoc.EXTENSIONS)
    cxx = set(CFamilyFileDoc.EXTENSIONS)
    assert py & cxx == set()
    assert py and cxx

Activity · 4 steps
lines 173–173py = set(PythonFileDoc.EXTENSIONS)lines 174–174cxx = set(CFamilyFileDoc.EXTENSIONS)lines 175–175assert py & cxx == set()lines 176–176assert py and cxx

test_ingest_covers_the_indexed_set_and_only_that

None test_filedocs.test_ingest_covers_the_indexed_set_and_only_that(tuple[Path, Path] indexed)

Ingest writes one row per documented indexed file, and no others.

tests/test_filedocs.py:220

Checks

  • assert count == 2
  • assert paths == {"src/cb.py", "src/mutex_order.c"}
  • assert "src/plain.c" not in paths, "a license header is not documentation"
  • assert "src/unindexed.py" not in paths, "the stage must read the INDEX, not the tree"
  • assert any("src/cb.py" in h for h in headings)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_ingest_covers_the_indexed_set_and_only_that → ingest_file_docs → _collect_file_docs → memoized
REQ-DDB-PIPE-008measuredtest_ingest_covers_the_indexed_set_and_only_that → ingest_file_docs
REQ-DDB-PIPE-014measuredtest_ingest_covers_the_indexed_set_and_only_that → ingest_file_docs → _collect_file_docs → within_repo
REQ-DDB-SCHEMA-014measuredtest_ingest_covers_the_indexed_set_and_only_that → ingest_file_docs → ensure_file_docs_table
Source · 22 lines
def test_ingest_covers_the_indexed_set_and_only_that(indexed: tuple[Path, Path]) -> None:
    """Four claims in one pass, because they share a fixture and each is a different way
    the stage could be wrong: the documented files are in, the license-only file is out,
    the synthetic `[STL]` row and the directory row are out, and a file on disk that the
    index does not know about STAYS OUT — the stage must not widen the build's scope
    decision by globbing."""
    db, repo = indexed
    count = ingest_file_docs(db, repo)
    assert count == 2

    conn = sqlite3.connect(db)
    paths = {row[0] for row in conn.execute("SELECT file_path FROM file_docs")}
    headings = {row[0] for row in conn.execute("SELECT heading FROM supplementary_docs")}
    conn.close()

    assert paths == {"src/cb.py", "src/mutex_order.c"}
    assert "src/plain.c" not in paths, "a license header is not documentation"
    assert "src/unindexed.py" not in paths, "the stage must read the INDEX, not the tree"
    ## The FTS5 mirror is what `search_prose` reads; a row per file, headed by its path.
    assert any("src/cb.py" in h for h in headings)

Activity · 11 steps
lines 226–226db, repo = indexedlines 227–227count = ingest_file_docs(db, repo)lines 228–228assert count == 2lines 230–230conn = sqlite3.connect(db)lines 231–231paths = {row[0] for row in conn.execute("SELECT file_path FROM file_docs")}lines 232–232headings = {row[0] for row in conn.execute("SELECT heading FROM supplementary_docs")}lines 233–233conn.close()lines 235–235assert paths == {"src/cb.py", "src/mutex_order.c"}lines 236–236assert "src/plain.c" not in paths, "a license header is not documentation"lines 237–237assert "src/unindexed.py" not in paths, "the stage must read the INDEX, not the tree"lines 239–239assert any("src/cb.py" in h for h in headings)

test_ingest_is_idempotent

None test_filedocs.test_ingest_is_idempotent(tuple[Path, Path] indexed)

Ingest is idempotent across repeated runs.

tests/test_filedocs.py:270

Checks

  • assert total == 2

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_ingest_is_idempotent → ingest_file_docs → _collect_file_docs → memoized
REQ-DDB-PIPE-008measuredtest_ingest_is_idempotent → ingest_file_docs
REQ-DDB-PIPE-014measuredtest_ingest_is_idempotent → ingest_file_docs → _collect_file_docs → within_repo
REQ-DDB-SCHEMA-014measuredtest_ingest_is_idempotent → ingest_file_docs → ensure_file_docs_table
Source · 12 lines
def test_ingest_is_idempotent(indexed: tuple[Path, Path]) -> None:
    """A rebuild of the same database must not double the corpus. `DELETE` then insert,
    the same shape `ingest_supplementary_docs` uses."""
    db, repo = indexed
    ingest_file_docs(db, repo)
    ingest_file_docs(db, repo)
    conn = sqlite3.connect(db)
    total = conn.execute("SELECT COUNT(*) FROM file_docs").fetchone()[0]
    conn.close()
    assert total == 2

Activity · 7 steps
lines 273–273db, repo = indexedlines 274–274ingest_file_docs(db, repo)lines 275–275ingest_file_docs(db, repo)lines 276–276conn = sqlite3.connect(db)lines 277–277total = conn.execute("SELECT COUNT(*) FROM file_docs").fetchone()[0]lines 278–278conn.close()lines 279–279assert total == 2

test_python_module_docstring_is_the_file_documentation

None test_filedocs.test_python_module_docstring_is_the_file_documentation()

A Python module docstring is extracted, its own # header ignored.

tests/test_filedocs.py:72

Checks

  • assert "function-pointer calls" in doc
  • assert "callback assignment" in doc
  • assert "SPDX" not in doc, "a `#` comment is not the module docstring"
  • assert "Do it." not in doc, "a FUNCTION docstring is not the file's documentation"
  • assert "\n" not in doc

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-008measuredtest_python_module_docstring_is_the_file_documentation → extract_file_doc
REQ-DDB-SCHEMA-014catalog
Source · 12 lines
def test_python_module_docstring_is_the_file_documentation() -> None:
    """Uses the AST rather than a regex, so the SPDX comment above the docstring and
    the `from __future__` import below it are both non-events."""
    doc = extract_file_doc("clew/callback_edges.py", PY_SOURCE)
    assert "function-pointer calls" in doc
    assert "callback assignment" in doc
    assert "SPDX" not in doc, "a `#` comment is not the module docstring"
    assert "Do it." not in doc, "a FUNCTION docstring is not the file's documentation"
    ## One line, so a multi-line block is searchable as one string.
    assert "\n" not in doc

Activity · 6 steps
lines 75–75doc = extract_file_doc("clew/callback_edges.py", PY_SOURCE)lines 76–76assert "function-pointer calls" in doclines 77–77assert "callback assignment" in doclines 78–78assert "SPDX" not in doc, "a `#` comment is not the module docstring"lines 79–79assert "Do it." not in doc, "a FUNCTION docstring is not the file's documentation"lines 81–81assert "\n" not in doc

test_rust_module_doc_comment_is_extracted

None test_filedocs.test_rust_module_doc_comment_is_extracted()

A leading //! run is the file documentation for a Rust source too.

tests/test_filedocs.py:111

Checks

  • assert "Efferent" in doc
  • assert "best-effort heuristic" in doc

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-008measuredtest_rust_module_doc_comment_is_extracted → extract_file_doc
REQ-DDB-SCHEMA-014catalog
Source · 16 lines
def test_rust_module_doc_comment_is_extracted() -> None:
    """Rust's `//!` is not a lookalike of doxygen's line-comment marker — it is the
    same syntax, reused by rustc for module docs. `CFamilyFileDoc` needs no
    Rust-specific branch, only `.rs` in its claimed suffixes; this pins that it
    stays claimed."""
    doc = extract_file_doc(
        "src/coupling.rs",
        "//! File-level import coupling: Efferent (Ce) and Afferent (Ca).\n"
        "//!\n"
        "//! Resolution is a best-effort heuristic, not real module resolution.\n"
        "use std::path::Path;\n",
    )
    assert "Efferent" in doc
    assert "best-effort heuristic" in doc

Activity · 3 steps
lines 116–122doc = extract_file_doc( "src/coupling.rs", "//! File-level import coupling: Efferent (Ce) and Afferent (Ca).\n" "//!\n" "//! Resolution is a best-effort heuristic, not real module resolution.\n" "use std::path::Path;\n", )lines 123–123assert "Efferent" in doclines 124–124assert "best-effort heuristic" in doc

test_search_reaches_a_file_by_concept

None test_filedocs.test_search_reaches_a_file_by_concept(tuple[Path, Path] indexed)

A conceptual query reaches the file, as a hit whose kind is 'file'.

tests/test_filedocs.py:286

Checks

  • assert [h.name for h in hits] == ["src/mutex_order.c"]
  • assert hits[0].kind == "file"
  • assert hits[0].provenance == "file_doc"
  • assert search(db, "deadlock nosuchtoken") == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_search_reaches_a_file_by_concept → ingest_file_docs → _collect_file_docs → memoized
REQ-DDB-PIPE-008measuredtest_search_reaches_a_file_by_concept → ingest_file_docs
REQ-DDB-PIPE-014measuredtest_search_reaches_a_file_by_concept → ingest_file_docs → _collect_file_docs → within_repo
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-007measured
REQ-DDB-QUERY-012measured
REQ-DDB-SCHEMA-014measuredtest_search_reaches_a_file_by_concept → ingest_file_docs → ensure_file_docs_table
Source · 16 lines
def test_search_reaches_a_file_by_concept(indexed: tuple[Path, Path]) -> None:
    """gh#10's whole point, at unit scale: 'deadlock' appears in NO function name and
    in no `@brief`, only in a file's own documentation, and `search` must still find it.
    `kind == 'file'` so a consumer can tell a file hit from a symbol hit rather than
    having to infer it."""
    db, repo = indexed
    ingest_file_docs(db, repo)
    hits = search(db, "deadlock")
    assert [h.name for h in hits] == ["src/mutex_order.c"]
    assert hits[0].kind == "file"
    assert hits[0].provenance == "file_doc"

    ## The conjunction still applies across the file corpus.
    assert search(db, "deadlock nosuchtoken") == []

Activity · 7 steps
lines 291–291db, repo = indexedlines 292–292ingest_file_docs(db, repo)lines 293–293hits = search(db, "deadlock")lines 294–294assert [h.name for h in hits] == ["src/mutex_order.c"]lines 295–295assert hits[0].kind == "file"lines 296–296assert hits[0].provenance == "file_doc"lines 299–299assert search(db, "deadlock nosuchtoken") == []

test_unparseable_python_is_skipped_not_fatal

None test_filedocs.test_unparseable_python_is_skipped_not_fatal()

Unparseable Python yields "" rather than failing the build.

tests/test_filedocs.py:161

Checks

  • assert extract_file_doc("broken.py", "def (:\n") == ""

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-PIPE-008measuredtest_unparseable_python_is_skipped_not_fatal → extract_file_doc
REQ-DDB-SCHEMA-014catalog
Source · 6 lines
def test_unparseable_python_is_skipped_not_fatal() -> None:
    """This stage ANNOTATES an index doxygen already built successfully. One file that
    will not parse must not undo that."""
    assert extract_file_doc("broken.py", "def (:\n") == ""

Activity · 1 steps
lines 164–164assert extract_file_doc("broken.py", "def (:\n") == ""