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

Show on the map →

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 >= 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" )
  • 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

requirementlinkedpath to the implementer
REQ-DDB-CLI-002inferredtest_incremental_splice_matches_a_full_rebuild → _run → run_doxygen → doxygen_supports_sqlite3
REQ-DDB-CONFIG-001measuredtest_incremental_splice_matches_a_full_rebuild → in_doxygen_scope → effective_file_patterns
REQ-DDB-INDEX-001measuredtest_incremental_splice_matches_a_full_rebuild → in_doxygen_scope → effective_file_patterns
REQ-DDB-INDEX-002measuredtest_incremental_splice_matches_a_full_rebuild → in_doxygen_scope
REQ-DDB-PIPE-003measuredtest_incremental_splice_matches_a_full_rebuild → _run → run_doxygen → _build_doxyfile_content → extra_input_clears_exclude
REQ-DDB-PIPE-006measuredtest_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

Activity · 44 steps
lines 299–299root = tmp_path / "repo"lines 300–300shutil.copytree(FIXTURE, root)lines 305–311(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", )lines 314–314(root / "vendor").mkdir(parents=True, exist_ok=True)lines 315–317(root / "vendor" / "third_party.c").write_text( "int vendored_helper(void) { return 7; }\n", encoding="utf-8" )lines 318–318doxyfile = _doxyfile(root, tmp_path / "Doxyfile")lines 320–320master = _run(doxyfile, tmp_path / "master", root)lines 321–321master_kept = tmp_path / "master-kept.db"lines 322–322shutil.copy2(master, master_kept)lines 327–327changed = set(in_doxygen_scope(sorted(_make_edit(root)), doxyfile, True))lines 329–329truth = _run(doxyfile, tmp_path / "truth", root)lines 330–330truth_kept = tmp_path / "truth-kept.db"lines 331–331shutil.copy2(truth, truth_kept)lines 333–333subset = sorted(xref_closure(master_kept, changed, root))lines 334–334assert changed <= set(subset), "the closure must contain the changed set itself"lines 335–338assert 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" )lines 340–340subset_db = _run(doxyfile, tmp_path / "subset", root, subset=subset)lines 345–345extra = include_expansion(subset_db, master_kept, changed, set(subset), root)lines 346–346◇ if extralines 347–347subset = sorted(set(subset) | extra)lines 348–348subset_db = _run(doxyfile, tmp_path / "subset2", root, subset=subset)lines 349–349spliced = tmp_path / "spliced.db"lines 350–350report = splice_doxygen(master_kept, subset_db, changed, spliced, root)lines 352–352assert not report.skipped, f"splice skipped files: {report.skipped}"lines 353–353assert report.files_replaced >= 2lines 354–354assert report.members_inserted > 0, "no members inserted — the splice did nothing"lines 355–358assert 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" )lines 359–362assert 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" )lines 364–364got = _snapshot(spliced, root)lines 365–365want = _snapshot(truth_kept, root)lines 371–371◇ for layer in ("params", "reimplements", "compoundref", "includes")lines 372–375assert 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" )lines 384–384◇ for layer in ("reimplements", "compoundref")lines 385–389assert 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" )lines 391–391added = [m for m in got["members"] if m[1] == "splice_probe_added"]lines 392–392assert added, "the edit's new function is absent from the spliced database"lines 399–403assert 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)}" )lines 405–405probe = ("splice_probe_added", "sound_play_findme")lines 406–409assert 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" )lines 410–414assert 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" )lines 416–416◇ for layer in (lines 428–428missing = want[layer] - got[layer]lines 429–429extra = got[layer] - want[layer]lines 430–434assert 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]}" )