test_nested_tree_cache.py¶
tests/test_nested_tree_cache.py
gh#24 — the nested-tree walk ran repeatedly inside one build.
test_nesting_the_cache_is_a_no_op_and_the_outermost_owns_it
None test_nested_tree_cache.test_nesting_the_cache_is_a_no_op_and_the_outermost_owns_it(Path tmp_path)
`build_index` opens one, and a caller that already opened its own must not have the inner exit clear it out from under the rest of the build. The outermost owns the lifetime; an inner activation is inert.
tests/test_nested_tree_cache.py:92
Checks
assert scope._NESTED_CACHE is not None, "the inner exit cleared the outer cache"assert scope._NESTED_CACHE is None, "the outermost exit must clear it"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_nesting_the_cache_is_a_no_op_and_the_outermost_owns_it → nested_repo_roots |
Source · 11 lines
def test_nesting_the_cache_is_a_no_op_and_the_outermost_owns_it(tmp_path: Path) -> None:
"""`build_index` opens one, and a caller that already opened its own must not have the
inner exit clear it out from under the rest of the build. The outermost owns the
lifetime; an inner activation is inert."""
root = _nested(tmp_path)
with scope.nested_tree_cache():
scope.nested_repo_roots(root)
with scope.nested_tree_cache():
scope.nested_repo_roots(root)
assert scope._NESTED_CACHE is not None, "the inner exit cleared the outer cache"
assert scope._NESTED_CACHE is None, "the outermost exit must clear it"1 more lines, not shown
Activity · 7 steps
test_outside_the_cache_every_call_walks
None test_nested_tree_cache.test_outside_the_cache_every_call_walks(Path tmp_path, monkeypatch)
THE STALENESS GUARD, asserted rather than assumed. The cache must not outlive the build that opened it: `nested_repo_roots` answers filesystem state, and a submodule added while a long-lived server runs would otherwise serve a stale SCOPE — which decides what is indexed at all, so the cost of being wrong is not a slow build but a wrong one.
tests/test_nested_tree_cache.py:58
Checks
assert len(calls) == 2, "outside a build the walk must not be memoised"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_outside_the_cache_every_call_walks → nested_repo_roots |
Source · 17 lines
def test_outside_the_cache_every_call_walks(tmp_path: Path, monkeypatch) -> None:
"""THE STALENESS GUARD, asserted rather than assumed. The cache must not outlive the
build that opened it: `nested_repo_roots` answers filesystem state, and a submodule
added while a long-lived server runs would otherwise serve a stale SCOPE — which
decides what is indexed at all, so the cost of being wrong is not a slow build but a
wrong one.
"""
root = _nested(tmp_path)
calls: list[Path] = []
real = scope._nested_repos_under
monkeypatch.setattr(scope, "_nested_repos_under", lambda r: calls.append(r) or real(r))
scope.nested_repo_roots(root)
scope.nested_repo_roots(root)
assert len(calls) == 2, "outside a build the walk must not be memoised"
Activity · 7 steps
test_the_cache_sees_a_tree_added_between_builds
None test_nested_tree_cache.test_the_cache_sees_a_tree_added_between_builds(Path tmp_path)
The behavioural form of the guard above: two builds, a nested tree appearing between them, and the second build must see it. A process-lifetime cache passes the call-count test and fails this one.
tests/test_nested_tree_cache.py:75
Checks
assert {p.name for p in before} == {"dep"}assert {p.name for p in after} == {"dep", "extra"}, ("the second build did not see a tree added after the first — the cache outlived its build" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_the_cache_sees_a_tree_added_between_builds → nested_repo_roots |
Source · 17 lines
def test_the_cache_sees_a_tree_added_between_builds(tmp_path: Path) -> None:
"""The behavioural form of the guard above: two builds, a nested tree appearing
between them, and the second build must see it. A process-lifetime cache passes the
call-count test and fails this one."""
root = _nested(tmp_path)
with scope.nested_tree_cache():
before = scope.nested_repo_roots(root)
(root / "vendor" / "extra" / ".git").mkdir(parents=True)
with scope.nested_tree_cache():
after = scope.nested_repo_roots(root)
assert {p.name for p in before} == {"dep"}
assert {p.name for p in after} == {"dep", "extra"}, (
"the second build did not see a tree added after the first — the cache outlived its build"
)
Activity · 8 steps
test_the_walk_runs_once_per_root_inside_the_cache
None test_nested_tree_cache.test_the_walk_runs_once_per_root_inside_the_cache(Path tmp_path, monkeypatch)
Four callers, one walk. The cache is keyed by RESOLVED root, so two callers naming the same tree differently still share the answer.
tests/test_nested_tree_cache.py:41
Checks
assert len(calls) == 1, f"the walk ran {len(calls)} times inside one build"assert [p.name for p in first] == ["dep"]
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_the_walk_runs_once_per_root_inside_the_cache → nested_repo_roots |
Source · 17 lines
def test_the_walk_runs_once_per_root_inside_the_cache(tmp_path: Path, monkeypatch) -> None:
"""Four callers, one walk. The cache is keyed by RESOLVED root, so two callers naming
the same tree differently still share the answer."""
root = _nested(tmp_path)
calls: list[Path] = []
real = scope._nested_repos_under
monkeypatch.setattr(scope, "_nested_repos_under", lambda r: calls.append(r) or real(r))
with scope.nested_tree_cache():
first = scope.nested_repo_roots(root)
scope.nested_repo_roots(root)
scope.nested_repo_roots(Path(str(root) + "/."))
assert len(calls) == 1, f"the walk ran {len(calls)} times inside one build"
assert [p.name for p in first] == ["dep"]