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
Checks
assert _tree_sha(repo, cache_path) != before
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-002 | measured | test_editing_a_scanned_file_invalidates_the_tree_hash → _tree_sha → enumerate_tree |
| REQ-DDB-PIPE-003 | measured | test_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
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
Checks
assert "src/engine.c" in foundassert "src/generated.c" not in found
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-002 | measured | test_exclude_naming_a_file_is_honoured → enumerate_tree |
| REQ-DDB-PIPE-003 | measured | test_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
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
Checks
assert _tree_sha(repo, cache_path) == before
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-002 | measured | test_excluded_file_does_not_move_the_hash → _tree_sha → enumerate_tree |
| REQ-DDB-PIPE-003 | measured | test_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) == before1 more lines, not shown
Activity · 7 steps
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
Checks
assert str(tmp_path / "src") in visitedassert str(tmp_path / "vendored") not in visitedassert str(tmp_path / "vendored" / "deep") not in visitedassert str(tmp_path / ".cache") not in visited
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-002 | measured | test_excluded_subtree_is_never_visited → enumerate_tree |
| REQ-DDB-PIPE-003 | measured | test_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
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
Checks
assert name in ts.enumerate_tree(roots, excludes, tmp_path)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-002 | measured | test_non_source_files_are_enumerated → enumerate_tree |
| REQ-DDB-PIPE-003 | measured | test_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
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
Checks
assert ts.enumerate_tree(roots, excludes, tmp_path) == _reference_enumerate(roots, excludes, tmp_path )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-002 | measured | test_pruned_enumeration_matches_unpruned_reference → enumerate_tree |
| REQ-DDB-PIPE-003 | measured | test_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
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
Checks
assert ts.enumerate_tree([tmp_path / "src"], [tmp_path], tmp_path) == {}
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-002 | measured | test_root_under_an_exclude_contributes_nothing → enumerate_tree |
| REQ-DDB-PIPE-003 | inferred | test_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
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
Checks
assert _tree_sha(repo, cache_path) == _tree_sha(repo, cache_path)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-INDEX-002 | measured | test_unchanged_tree_keeps_its_hash → _tree_sha → enumerate_tree |
| REQ-DDB-PIPE-003 | measured | test_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)