test_treescan_pruning.py

tests/test_treescan_pruning.py

Tests for the index-cache tree scan: pruning must not change what is scanned.

test_editing_a_scanned_file_invalidates_the_tree_hash

None test_treescan_pruning.test_editing_a_scanned_file_invalidates_the_tree_hash(Path tmp_path, str name)

Editing any scanned file — source or not — moves the doxygen cache key.

tests/test_treescan_pruning.py:204

Show on the map →

Called by none

Calls _make_scan_tree, _tree_sha

Checks

  • assert _tree_sha(repo, cache_path) != before

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_editing_a_scanned_file_invalidates_the_tree_hash → _tree_sha → enumerate_tree
REQ-DDB-PIPE-003measuredtest_editing_a_scanned_file_invalidates_the_tree_hash → _tree_sha → enumerate_tree → rel_key
Source · 18 lines
def test_editing_a_scanned_file_invalidates_the_tree_hash(tmp_path: Path, name: str) -> None:
    """A faster scan that misses an invalidation is worse than a slow one. The
    non-source cases are the ones an extension filter would break: the tree hash
    gates whether doxygen is re-run at all, so a missed change ships a database
    describing content that no longer exists.

    @brief Tree hash responds to every scanned file.
    @version 1
    """
    repo = tmp_path / "repo"
    repo.mkdir()
    _make_scan_tree(repo)
    cache_path = tmp_path / "c.idxcache"
    before = _tree_sha(repo, cache_path)
    (repo / name).write_text("CHANGED CONTENT\n", encoding="utf-8")
    assert _tree_sha(repo, cache_path) != before

Activity · 7 steps
lines 213–213repo = tmp_path / "repo"lines 214–214repo.mkdir()lines 215–215_make_scan_tree(repo)lines 216–216cache_path = tmp_path / "c.idxcache"lines 217–217before = _tree_sha(repo, cache_path)lines 218–218(repo / name).write_text("CHANGED CONTENT\n", encoding="utf-8")lines 219–219assert _tree_sha(repo, cache_path) != before

test_exclude_naming_a_file_is_honoured

None test_treescan_pruning.test_exclude_naming_a_file_is_honoured(Path tmp_path)

An exclude naming a single FILE drops just that file.

tests/test_treescan_pruning.py:178

Show on the map →

Called by none

Calls _write_scan_file, enumerate_tree

Checks

  • assert "src/engine.c" in found
  • assert "src/generated.c" not in found

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_exclude_naming_a_file_is_honoured → enumerate_tree
REQ-DDB-PIPE-003measuredtest_exclude_naming_a_file_is_honoured → enumerate_tree → rel_key
Source · 9 lines
def test_exclude_naming_a_file_is_honoured(tmp_path: Path) -> None:
    """@brief A file-valued EXCLUDE entry is matched exactly."""
    _write_scan_file(tmp_path / "src" / "engine.c")
    _write_scan_file(tmp_path / "src" / "generated.c")
    found = ts.enumerate_tree([tmp_path], [tmp_path / "src" / "generated.c"], tmp_path)
    assert "src/engine.c" in found
    assert "src/generated.c" not in found

Activity · 5 steps
lines 180–180_write_scan_file(tmp_path / "src" / "engine.c")lines 181–181_write_scan_file(tmp_path / "src" / "generated.c")lines 182–182found = ts.enumerate_tree([tmp_path], [tmp_path / "src" / "generated.c"], tmp_path)lines 183–183assert "src/engine.c" in foundlines 184–184assert "src/generated.c" not in found

test_excluded_file_does_not_move_the_hash

None test_treescan_pruning.test_excluded_file_does_not_move_the_hash(Path tmp_path)

A file appearing inside an excluded subtree does not move the hash.

tests/test_treescan_pruning.py:240

Show on the map →

Called by none

Calls _make_scan_tree, _tree_sha, _write_scan_file

Checks

  • assert _tree_sha(repo, cache_path) == before

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_excluded_file_does_not_move_the_hash → _tree_sha → enumerate_tree
REQ-DDB-PIPE-003measuredtest_excluded_file_does_not_move_the_hash → _tree_sha → enumerate_tree → rel_key
Source · 9 lines
def test_excluded_file_does_not_move_the_hash(tmp_path: Path) -> None:
    """@brief Excluded content stays out of the cache key."""
    repo = tmp_path / "repo"
    repo.mkdir()
    _make_scan_tree(repo)
    cache_path = tmp_path / "c.idxcache"
    before = _tree_sha(repo, cache_path)
    _write_scan_file(repo / "vendored" / "late.c", "int late;\n")
    assert _tree_sha(repo, cache_path) == before

1 more lines, not shown

Activity · 7 steps
lines 242–242repo = tmp_path / "repo"lines 243–243repo.mkdir()lines 244–244_make_scan_tree(repo)lines 245–245cache_path = tmp_path / "c.idxcache"lines 246–246before = _tree_sha(repo, cache_path)lines 247–247_write_scan_file(repo / "vendored" / "late.c", "int late;\n")lines 248–248assert _tree_sha(repo, cache_path) == before

test_excluded_subtree_is_never_visited

None test_treescan_pruning.test_excluded_subtree_is_never_visited(Path tmp_path, monkeypatch)

An excluded directory is never descended into.

tests/test_treescan_pruning.py:123

Show on the map →

Called by none

Calls _make_scan_tree, enumerate_tree

Checks

  • assert str(tmp_path / "src") in visited
  • assert str(tmp_path / "vendored") not in visited
  • assert str(tmp_path / "vendored" / "deep") not in visited
  • assert str(tmp_path / ".cache") not in visited

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_excluded_subtree_is_never_visited → enumerate_tree
REQ-DDB-PIPE-003measuredtest_excluded_subtree_is_never_visited → enumerate_tree → rel_key
Source · 26 lines
def test_excluded_subtree_is_never_visited(tmp_path: Path, monkeypatch) -> None:
    """The STRUCTURAL half. Equal output sets would also hold for
    enumerate-then-filter, so membership alone cannot show the walk got smaller;
    this records every directory the walk actually yielded.

    @brief Assert the walk skips excluded subtrees outright.
    @version 1
    """
    roots, excludes = _make_scan_tree(tmp_path)
    visited: list[str] = []
    real_walk = os.walk

    def spy(top, **kwargs):
        for dirpath, dirnames, filenames in real_walk(top, **kwargs):
            visited.append(dirpath)
            yield dirpath, dirnames, filenames

    monkeypatch.setattr(ts.os, "walk", spy)
    ts.enumerate_tree(roots, excludes, tmp_path)

    assert str(tmp_path / "src") in visited
    assert str(tmp_path / "vendored") not in visited
    assert str(tmp_path / "vendored" / "deep") not in visited
    assert str(tmp_path / ".cache") not in visited

Activity · 10 steps
lines 131–131roots, excludes = _make_scan_tree(tmp_path)lines 132–132visited: list[str] = []lines 133–133real_walk = os.walklines 135–138def spy(top, **kwargs): for dirpath, dirnames, filenames in real_walk(top, **kwargs): visited.append(dirpath) yield dirpath, dirnames, filenameslines 140–140monkeypatch.setattr(ts.os, "walk", spy)lines 141–141ts.enumerate_tree(roots, excludes, tmp_path)lines 143–143assert str(tmp_path / "src") in visitedlines 144–144assert str(tmp_path / "vendored") not in visitedlines 145–145assert str(tmp_path / "vendored" / "deep") not in visitedlines 146–146assert str(tmp_path / ".cache") not in visited

test_non_source_files_are_enumerated

None test_treescan_pruning.test_non_source_files_are_enumerated(Path tmp_path, str name)

A non-source file under INPUT is still enumerated.

tests/test_treescan_pruning.py:152

Show on the map →

Called by none

Calls _make_scan_tree, enumerate_tree

Checks

  • assert name in ts.enumerate_tree(roots, excludes, tmp_path)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_non_source_files_are_enumerated → enumerate_tree
REQ-DDB-PIPE-003measuredtest_non_source_files_are_enumerated → enumerate_tree → rel_key
Source · 11 lines
def test_non_source_files_are_enumerated(tmp_path: Path, name: str) -> None:
    """The scan is deliberately NOT extension-filtered. A filter is the obvious
    way to make this walk cheaper and it would drop exactly these paths.

    @brief Non-source files stay in the scanned set.
    @version 1
    """
    roots, excludes = _make_scan_tree(tmp_path)
    assert name in ts.enumerate_tree(roots, excludes, tmp_path)

Activity · 2 steps
lines 159–159roots, excludes = _make_scan_tree(tmp_path)lines 160–160assert name in ts.enumerate_tree(roots, excludes, tmp_path)

test_pruned_enumeration_matches_unpruned_reference

None test_treescan_pruning.test_pruned_enumeration_matches_unpruned_reference(Path tmp_path)

The pruned scan returns exactly the unpruned scan's surviving set.

tests/test_treescan_pruning.py:113

Show on the map →

Called by none

Calls _make_scan_tree, _reference_enumerate, enumerate_tree

Checks

  • assert ts.enumerate_tree(roots, excludes, tmp_path) == _reference_enumerate(roots, excludes, tmp_path )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_pruned_enumeration_matches_unpruned_reference → enumerate_tree
REQ-DDB-PIPE-003measuredtest_pruned_enumeration_matches_unpruned_reference → enumerate_tree → rel_key
Source · 8 lines
def test_pruned_enumeration_matches_unpruned_reference(tmp_path: Path) -> None:
    """@brief Pruning changes cost, never membership."""
    roots, excludes = _make_scan_tree(tmp_path)
    assert ts.enumerate_tree(roots, excludes, tmp_path) == _reference_enumerate(
        roots, excludes, tmp_path
    )

Activity · 2 steps
lines 115–115roots, excludes = _make_scan_tree(tmp_path)lines 116–118assert ts.enumerate_tree(roots, excludes, tmp_path) == _reference_enumerate( roots, excludes, tmp_path )

test_root_under_an_exclude_contributes_nothing

None test_treescan_pruning.test_root_under_an_exclude_contributes_nothing(Path tmp_path)

A root whose own ancestor is excluded contributes nothing.

tests/test_treescan_pruning.py:165

Show on the map →

Called by none

Calls _write_scan_file, enumerate_tree

Checks

  • assert ts.enumerate_tree([tmp_path / "src"], [tmp_path], tmp_path) == {}

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_root_under_an_exclude_contributes_nothing → enumerate_tree
REQ-DDB-PIPE-003inferredtest_root_under_an_exclude_contributes_nothing → enumerate_tree → rel_key
Source · 11 lines
def test_root_under_an_exclude_contributes_nothing(tmp_path: Path) -> None:
    """Pruning starts AT the root, so an exclude above the root would be invisible
    to the descent unless the root itself is tested.

    @brief Exclusion above an INPUT root still applies.
    @version 1
    """
    _write_scan_file(tmp_path / "src" / "engine.c")
    assert ts.enumerate_tree([tmp_path / "src"], [tmp_path], tmp_path) == {}

Activity · 2 steps
lines 172–172_write_scan_file(tmp_path / "src" / "engine.c")lines 173–173assert ts.enumerate_tree([tmp_path / "src"], [tmp_path], tmp_path) == {}

test_unchanged_tree_keeps_its_hash

None test_treescan_pruning.test_unchanged_tree_keeps_its_hash(Path tmp_path)

An unchanged tree keeps its hash, so a warm refresh still hits.

tests/test_treescan_pruning.py:224

Show on the map →

Called by none

Calls _make_scan_tree, _tree_sha

Checks

  • assert _tree_sha(repo, cache_path) == _tree_sha(repo, cache_path)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-INDEX-002measuredtest_unchanged_tree_keeps_its_hash → _tree_sha → enumerate_tree
REQ-DDB-PIPE-003measuredtest_unchanged_tree_keeps_its_hash → _tree_sha → enumerate_tree → rel_key
Source · 14 lines
def test_unchanged_tree_keeps_its_hash(tmp_path: Path) -> None:
    """The other half of the invalidation contract — without this, "always
    invalidate" would pass every test above while destroying the cache.

    @brief Stable hash across two scans of identical content.
    @version 1
    """
    repo = tmp_path / "repo"
    repo.mkdir()
    _make_scan_tree(repo)
    cache_path = tmp_path / "c.idxcache"
    assert _tree_sha(repo, cache_path) == _tree_sha(repo, cache_path)

Activity · 5 steps
lines 231–231repo = tmp_path / "repo"lines 232–232repo.mkdir()lines 233–233_make_scan_tree(repo)lines 234–234cache_path = tmp_path / "c.idxcache"lines 235–235assert _tree_sha(repo, cache_path) == _tree_sha(repo, cache_path)