test_doxygen_splice.py¶
tests/integration/test_doxygen_splice.py
The incremental splice must produce what a full rebuild produces.
test_incremental_splice_matches_a_full_rebuild
None test_doxygen_splice.test_incremental_splice_matches_a_full_rebuild(Path tmp_path)
A spliced database must equal a full rebuild of the same tree.
tests/integration/test_doxygen_splice.py:292
Called by none
Calls _doxyfile, _make_edit, _run, _snapshot, in_doxygen_scope, include_expansion, list, splice_doxygen, xref_closure
Checks
assert changed <= set(subset), "the closure must contain the changed set itself"assert len(subset) < len(list(root.rglob("*.c"))) + len(list(root.rglob("*.h"))), ("the closure expanded to the whole tree, so this test would pass without " "exercising any subsetting at all" )assert not report.skipped, f"splice skipped files: {report.skipped}"assert report.files_replaced >= 2assert report.members_inserted > 0, "no members inserted — the splice did nothing"assert report.relations_dropped == 0, ("a relation endpoint was missing from the working copy, which means the closure did " "not bring in a compound the subset needed" )assert report.compounds_inserted > 0, ("no compounddefs inserted while some were deleted — every class, struct and " "file-compound in the changed file would be silently lost" )assert want[layer], (f"the rebuild produced NO {layer} rows, so comparing that table is vacuous and " f"the splice could drop it undetected — the fixture needs to populate it" )assert any("Extra" in ref for row in want[layer] for ref in row), (f"no {layer} row involves the class the edit added, so that table is compared but " f"never exercised by the splice's delete path — two mutation controls passed " f"against exactly that shape" )assert added, "the edit's new function is absent from the spliced database"assert not any("vendor/" in f for f in want["indexed"]), (f"the full rebuild indexed the excluded vendor/ tree, so EXCLUDE_PATTERNS is not " f"taking effect and this test cannot see a scope widening: " f"{sorted(f for f in want['indexed'] if 'vendor' in f)}" )assert probe in want["named_edges"], (f"the rebuild produced no {probe[0]} -> {probe[1]} edge, so this test cannot see " f"whether the splice preserves a NEWLY-ADDED cross-file call at all" )assert probe in got["named_edges"], (f"the splice lost the new cross-file edge {probe[0]} -> {probe[1]}. The outbound " f"closure is computed from the PRE-EDIT master, where this call did not exist, so " f"{probe[1]}'s file never joined the subset and doxygen could not resolve the name" )assert not missing and not extra, (f"{layer}: splice and rebuild disagree.\n" f" missing from splice ({len(missing)}): {sorted(missing)[:8]}\n" f" only in splice ({len(extra)}): {sorted(extra)[:8]}" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CLI-002 | inferred | test_incremental_splice_matches_a_full_rebuild → _run → run_doxygen → doxygen_supports_sqlite3 |
| REQ-DDB-CONFIG-001 | measured | test_incremental_splice_matches_a_full_rebuild → in_doxygen_scope → effective_file_patterns |
| REQ-DDB-INDEX-001 | measured | test_incremental_splice_matches_a_full_rebuild → in_doxygen_scope → effective_file_patterns |
| REQ-DDB-INDEX-002 | measured | test_incremental_splice_matches_a_full_rebuild → in_doxygen_scope |
| REQ-DDB-PIPE-003 | measured | test_incremental_splice_matches_a_full_rebuild → _run → run_doxygen → _build_doxyfile_content → extra_input_clears_exclude |
| REQ-DDB-PIPE-006 | measured | test_incremental_splice_matches_a_full_rebuild → _run → run_doxygen → clean_subprocess_env |
Source · 120 lines
def test_incremental_splice_matches_a_full_rebuild(tmp_path: Path) -> None:
"""THE LOAD-BEARING CONTROL for task #483.
@brief Splice output equals rebuild output.
@return None.
@version 1
"""
root = tmp_path / "repo"
shutil.copytree(FIXTURE, root)
## THE C FIXTURE HOLDS ZERO `reimplements` AND `compoundref` ROWS, so an invariance over
## those tables would pass vacuously on it — 0 == 0. A base/derived pair with a virtual
## override is the smallest thing that populates both, and without it the review's
## least-measured finding stays unmeasured.
(root / "src" / "shapes.cpp").write_text(
"struct Base { virtual int area() const; virtual ~Base() {} };\n"
"struct Derived : Base { int area() const override; };\n"
"int Base::area() const { return 0; }\n"
"int Derived::area() const { return 1; }\n",
encoding="utf-8",
)
## A real C file inside a directory the Doxyfile EXCLUDES by glob. A full rebuild must
## never index it; the splice must not either.
(root / "vendor").mkdir(parents=True, exist_ok=True)
(root / "vendor" / "third_party.c").write_text(
"int vendored_helper(void) { return 7; }\n", encoding="utf-8"
)
doxyfile = _doxyfile(root, tmp_path / "Doxyfile")
master = _run(doxyfile, tmp_path / "master", root)
master_kept = tmp_path / "master-kept.db"
shutil.copy2(master, master_kept)
## THE SAME SCOPE FILTER THE PIPELINE APPLIES. `_make_edit` also touches a file the
## Doxyfile excludes by glob, because the tree scan cannot see that exclusion — narrowing
## here is what keeps the splice from indexing a file no full rebuild produces.
changed = set(in_doxygen_scope(sorted(_make_edit(root)), doxyfile, True))
truth = _run(doxyfile, tmp_path / "truth", root)
truth_kept = tmp_path / "truth-kept.db"
shutil.copy2(truth, truth_kept)
subset = sorted(xref_closure(master_kept, changed, root))
assert changed <= set(subset), "the closure must contain the changed set itself"
assert len(subset) < len(list(root.rglob("*.c"))) + len(list(root.rglob("*.h"))), (
"the closure expanded to the whole tree, so this test would pass without "
"exercising any subsetting at all"
)
subset_db = _run(doxyfile, tmp_path / "subset", root, subset=subset)
## SECOND PASS. The first subset is built from the PRE-EDIT xref table, so it cannot know
## about a callee the edit newly calls. `include_expansion` reads the first pass's include
## graph — doxygen's own resolution, not a regex — and names the files that graph implies.
extra = include_expansion(subset_db, master_kept, changed, set(subset), root)
if extra:
subset = sorted(set(subset) | extra)
subset_db = _run(doxyfile, tmp_path / "subset2", root, subset=subset)
spliced = tmp_path / "spliced.db"
report = splice_doxygen(master_kept, subset_db, changed, spliced, root)
assert not report.skipped, f"splice skipped files: {report.skipped}"
assert report.files_replaced >= 2
assert report.members_inserted > 0, "no members inserted — the splice did nothing"
assert report.relations_dropped == 0, (
"a relation endpoint was missing from the working copy, which means the closure did "
"not bring in a compound the subset needed"
)
assert report.compounds_inserted > 0, (
"no compounddefs inserted while some were deleted — every class, struct and "
"file-compound in the changed file would be silently lost"
)
got = _snapshot(spliced, root)
want = _snapshot(truth_kept, root)
## NON-VACUITY GATE. An invariance over an EMPTY table passes as 0 == 0 and proves nothing.
## The C fixture holds no inheritance at all, which is why `shapes.cpp` is written into the
## copy — and this asserts that it worked. Without this gate, deleting the reimplements and
## compoundref restoration would leave the comparison green.
for layer in ("params", "reimplements", "compoundref", "includes"):
assert want[layer], (
f"the rebuild produced NO {layer} rows, so comparing that table is vacuous and "
f"the splice could drop it undetected — the fixture needs to populate it"
)
## AND THE CHANGED SET MUST CONTRIBUTE TO THEM. Global non-emptiness is not enough: with
## only `main.c` edited, reimplements and compoundref were non-empty yet came entirely from
## an UNCHANGED file, so their rows were never deleted and deleting their restoration was
## invisible. Two mutation controls passed against that shape.
## `Extra` is the class the edit ADDS to shapes.cpp, and doxygen keys a class member's
## refid to the CLASS compound (`structExtra_...`), never to the file — so keying this gate
## on the file name silently found nothing. Its compounddef's `file_id` IS shapes.cpp, so
## the splice deletes it and must put it back.
for layer in ("reimplements", "compoundref"):
assert any("Extra" in ref for row in want[layer] for ref in row), (
f"no {layer} row involves the class the edit added, so that table is compared but "
f"never exercised by the splice's delete path — two mutation controls passed "
f"against exactly that shape"
)
added = [m for m in got["members"] if m[1] == "splice_probe_added"]
assert added, "the edit's new function is absent from the spliced database"
## THE NEW CROSS-FILE EDGE, PINNED BY NAME. The set comparison below would catch its
## absence too, but only as one line among many — and this exact edge is what the closure
## exists to preserve, so it gets its own assertion with its own message.
## SCOPE NON-VACUITY. If the rebuild indexed the vendored file too, the exclusion is not
## in force and the scope comparison below proves nothing.
assert not any("vendor/" in f for f in want["indexed"]), (
f"the full rebuild indexed the excluded vendor/ tree, so EXCLUDE_PATTERNS is not "
f"taking effect and this test cannot see a scope widening: "
f"{sorted(f for f in want['indexed'] if 'vendor' in f)}"
)
probe = ("splice_probe_added", "sound_play_findme")
assert probe in want["named_edges"], (
f"the rebuild produced no {probe[0]} -> {probe[1]} edge, so this test cannot see "
f"whether the splice preserves a NEWLY-ADDED cross-file call at all"
)
assert probe in got["named_edges"], (
f"the splice lost the new cross-file edge {probe[0]} -> {probe[1]}. The outbound "24 more lines, not shown