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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-008 | measured | test_a_plain_comment_header_is_not_documentation → extract_file_doc |
| REQ-DDB-SCHEMA-014 | catalog |
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
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.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-002 | measured | test_a_synthetic_path_row_produces_no_warning → ingest_file_docs → _collect_file_docs → memoized |
| REQ-DDB-PIPE-008 | measured | test_a_synthetic_path_row_produces_no_warning → ingest_file_docs |
| REQ-DDB-PIPE-014 | measured | test_a_synthetic_path_row_produces_no_warning → ingest_file_docs → _collect_file_docs → within_repo |
| REQ-DDB-SCHEMA-014 | measured | test_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
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.
Checks
assert has_file_docs(db) is Falseassert file_doc_rows(sqlite3.connect(db), ["anything"]) == []assert has_file_docs(db) is True
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-002 | measured | test_absent_corpus_is_reported_as_absent → ingest_file_docs → _collect_file_docs → memoized |
| REQ-DDB-PIPE-008 | measured | test_absent_corpus_is_reported_as_absent → ingest_file_docs |
| REQ-DDB-PIPE-014 | measured | test_absent_corpus_is_reported_as_absent → ingest_file_docs → _collect_file_docs → within_repo |
| REQ-DDB-QUERY-001 | measured | test_absent_corpus_is_reported_as_absent → has_file_docs → connect |
| REQ-DDB-QUERY-003 | measured | test_absent_corpus_is_reported_as_absent → file_doc_rows → table_exists |
| REQ-DDB-QUERY-007 | measured | test_absent_corpus_is_reported_as_absent → file_doc_rows |
| REQ-DDB-SCHEMA-014 | measured | test_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 True1 more lines, not shown
Activity · 5 steps
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.
Checks
assert extract_file_doc("tests/data/schema_vocabulary.json", '{"a": 1}') == ""
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-008 | measured | test_an_unclaimed_suffix_yields_no_documentation → extract_file_doc |
| REQ-DDB-SCHEMA-014 | catalog |
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
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.
Checks
assert "deadlock" in docassert "Copyright" not in docassert not doc.startswith("*")
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-008 | measured | test_c_family_doxygen_block_is_found_past_a_license_header → extract_file_doc |
| REQ-DDB-SCHEMA-014 | catalog |
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
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.
Checks
assert "lock-free ring buffer" in doc
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-008 | measured | test_c_family_line_comment_run_is_extracted → extract_file_doc |
| REQ-DDB-SCHEMA-014 | catalog |
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
test_extractor_suffix_sets_do_not_overlap
None test_filedocs.test_extractor_suffix_sets_do_not_overlap()
The extractors claim disjoint suffix sets.
Checks
assert py & cxx == set()assert py and cxx
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-008 | catalog | |
| REQ-DDB-SCHEMA-014 | catalog |
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
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.
Checks
assert count == 2assert 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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-002 | measured | test_ingest_covers_the_indexed_set_and_only_that → ingest_file_docs → _collect_file_docs → memoized |
| REQ-DDB-PIPE-008 | measured | test_ingest_covers_the_indexed_set_and_only_that → ingest_file_docs |
| REQ-DDB-PIPE-014 | measured | test_ingest_covers_the_indexed_set_and_only_that → ingest_file_docs → _collect_file_docs → within_repo |
| REQ-DDB-SCHEMA-014 | measured | test_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
test_ingest_is_idempotent
None test_filedocs.test_ingest_is_idempotent(tuple[Path, Path] indexed)
Ingest is idempotent across repeated runs.
Checks
assert total == 2
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-002 | measured | test_ingest_is_idempotent → ingest_file_docs → _collect_file_docs → memoized |
| REQ-DDB-PIPE-008 | measured | test_ingest_is_idempotent → ingest_file_docs |
| REQ-DDB-PIPE-014 | measured | test_ingest_is_idempotent → ingest_file_docs → _collect_file_docs → within_repo |
| REQ-DDB-SCHEMA-014 | measured | test_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
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.
Checks
assert "function-pointer calls" in docassert "callback assignment" in docassert "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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-008 | measured | test_python_module_docstring_is_the_file_documentation → extract_file_doc |
| REQ-DDB-SCHEMA-014 | catalog |
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
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.
Checks
assert "Efferent" in docassert "best-effort heuristic" in doc
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-008 | measured | test_rust_module_doc_comment_is_extracted → extract_file_doc |
| REQ-DDB-SCHEMA-014 | catalog |
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
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'.
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-002 | measured | test_search_reaches_a_file_by_concept → ingest_file_docs → _collect_file_docs → memoized |
| REQ-DDB-PIPE-008 | measured | test_search_reaches_a_file_by_concept → ingest_file_docs |
| REQ-DDB-PIPE-014 | measured | test_search_reaches_a_file_by_concept → ingest_file_docs → _collect_file_docs → within_repo |
| REQ-DDB-QUERY-001 | measured | |
| REQ-DDB-QUERY-003 | measured | |
| REQ-DDB-QUERY-007 | measured | |
| REQ-DDB-QUERY-012 | measured | |
| REQ-DDB-SCHEMA-014 | measured | test_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
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.
Checks
assert extract_file_doc("broken.py", "def (:\n") == ""
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-008 | measured | test_unparseable_python_is_skipped_not_fatal → extract_file_doc |
| REQ-DDB-SCHEMA-014 | catalog |
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") == ""