test_sub_index_ignores.py¶
tests/test_sub_index_ignores.py
gh#23 — a derived sub-index scope did not carry the vendored tree's own ignores.
test_a_child_trees_ignores_are_not_repeated_on_the_parent
None test_sub_index_ignores.test_a_child_trees_ignores_are_not_repeated_on_the_parent(Path tmp_path)
The parent already excludes the child tree WHOLE, so listing paths inside it again adds entries that exclude nothing — and this list becomes doxygen's EXCLUDE, where a repository vendoring several large dependencies would otherwise carry every ignored path in the tree on every sub-index.
tests/test_sub_index_ignores.py:104
Checks
assert dep in first.excludes, "the parent must still exclude the vendored tree whole"assert inside == [], f"first-party repeats paths inside an already-excluded tree: {inside}"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_a_child_trees_ignores_are_not_repeated_on_the_parent → derive_sub_indexes → whole_repo_scope |
| REQ-DDB-INDEX-002 | measured | test_a_child_trees_ignores_are_not_repeated_on_the_parent → derive_sub_indexes |
Source · 19 lines
def test_a_child_trees_ignores_are_not_repeated_on_the_parent(tmp_path: Path) -> None:
"""The parent already excludes the child tree WHOLE, so listing paths inside it again
adds entries that exclude nothing — and this list becomes doxygen's EXCLUDE, where a
repository vendoring several large dependencies would otherwise carry every ignored path
in the tree on every sub-index."""
root = _repo(tmp_path)
subs = {s.name: s for s in derive_sub_indexes(root)}
first = subs[FIRST_PARTY_INDEX]
dep = root / "deps" / "vendored"
assert dep in first.excludes, "the parent must still exclude the vendored tree whole"
inside = [p for p in first.excludes if p != dep and dep in p.parents]
assert inside == [], f"first-party repeats paths inside an already-excluded tree: {inside}"
@pytest.mark.skipif(
subprocess.run(["git", "--version"], capture_output=True).returncode != 0,
reason="needs git",
)test_a_vendored_sub_index_excludes_its_own_gitignored_build
None test_sub_index_ignores.test_a_vendored_sub_index_excludes_its_own_gitignored_build(Path tmp_path)
THE REPORTED CASE. `deps/vendored/build/` is ignored by the vendored tree's OWN `.gitignore`, which `git ls-files` in the parent cannot see through — so it has to be asked per tree, which `whole_repo_scope` already does. The sub-index simply was not given the answer.
tests/test_sub_index_ignores.py:66
Checks
assert vendored.roots == (root / "deps" / "vendored",)assert any(p.name == "build" for p in vendored.excludes), (f"the vendored tree's own gitignored build/ is not excluded: {vendored.excludes}" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_a_vendored_sub_index_excludes_its_own_gitignored_build → derive_sub_indexes → whole_repo_scope |
| REQ-DDB-INDEX-002 | measured | test_a_vendored_sub_index_excludes_its_own_gitignored_build → derive_sub_indexes |
Source · 20 lines
def test_a_vendored_sub_index_excludes_its_own_gitignored_build(tmp_path: Path) -> None:
"""THE REPORTED CASE. `deps/vendored/build/` is ignored by the vendored tree's OWN
`.gitignore`, which `git ls-files` in the parent cannot see through — so it has to be
asked per tree, which `whole_repo_scope` already does. The sub-index simply was not
given the answer.
"""
root = _repo(tmp_path)
subs = {s.name: s for s in derive_sub_indexes(root)}
vendored = next(s for name, s in subs.items() if name != FIRST_PARTY_INDEX)
assert vendored.roots == (root / "deps" / "vendored",)
assert any(p.name == "build" for p in vendored.excludes), (
f"the vendored tree's own gitignored build/ is not excluded: {vendored.excludes}"
)
@pytest.mark.skipif(
subprocess.run(["git", "--version"], capture_output=True).returncode != 0,
reason="needs git",
)test_every_derived_sub_index_name_is_discoverable
None test_sub_index_ignores.test_every_derived_sub_index_name_is_discoverable(Path tmp_path)
gh#25. The split already goes N levels deep, so a vendored dependency's own vendored dependency HAS a name — but registering happened inside the build loop, behind the `only` filter, so a caller who built one sub-index never learned the others existed. `index(action='targets')` showed first-party and the tree they had built, and nothing on the tool surface separated "this nested tree is not built yet" from "this nested tree was never given an identity at all".
tests/test_sub_index_ignores.py:123
Checks
assert len(derived) == 3, f"expected first-party plus two nested trees: {sorted(derived)}"assert registered == derived, (f"derived {sorted(derived)} but only {sorted(registered)} are addressable — a caller " f"cannot pass a name the tool surface never showed them" )
Result: passed
Verifies
Source · 41 lines
def test_every_derived_sub_index_name_is_discoverable(tmp_path: Path) -> None:
"""gh#25. The split already goes N levels deep, so a vendored dependency's own vendored
dependency HAS a name — but registering happened inside the build loop, behind the `only`
filter, so a caller who built one sub-index never learned the others existed.
`index(action='targets')` showed first-party and the tree they had built, and nothing on
the tool surface separated "this nested tree is not built yet" from "this nested tree was
never given an identity at all".
REGISTERING IS NOT BUILDING, and that distinction is what makes this the right surface
rather than a new tool: each of these rows reports `exists: false` until someone builds it,
which `targets` already draws for every other unbuilt target.
"""
from clew.cli import build_sub_indexes
from clew.mcp_server.state import TargetRegistry
from clew.scope import derive_sub_indexes
root = _repo(tmp_path)
inner = root / "deps" / "vendored" / "deps" / "inner"
(inner / "src").mkdir(parents=True)
(inner / "src" / "c.c").write_text("void c(void) {}\n", encoding="utf-8")
subprocess.run(["git", "init", "-q", "."], cwd=inner, check=True)
subprocess.run(["git", "add", "-A"], cwd=inner, check=True)
subprocess.run(
["git", "-c", "user.email=t@e", "-c", "user.name=t", "commit", "-qm", "init"],
cwd=inner,
check=True,
)
derived = {s.name for s in derive_sub_indexes(root)}
assert len(derived) == 3, f"expected first-party plus two nested trees: {sorted(derived)}"
home = tmp_path / "state"
## Build ONLY first-party — the case the reporter hit. Every OTHER derived name must still
## become discoverable, or the recursive split looks like it silently stops one level deep.
build_sub_indexes(root, home=home, only=FIRST_PARTY_INDEX)
registered = {t.name for t in TargetRegistry(home).targets() if Path(t.repo_path) == root}
assert registered == derived, (
f"derived {sorted(derived)} but only {sorted(registered)} are addressable — a caller "
f"cannot pass a name the tool surface never showed them"
)1 more lines, not shown
Activity · 16 steps
test_the_tree_itself_is_never_in_its_own_excludes
None test_sub_index_ignores.test_the_tree_itself_is_never_in_its_own_excludes(Path tmp_path)
THE SELF-EXCLUSION TRAP. `_under_any` matches equality as well as containment — by design, because an exclusion names the directory itself — so a tree that git reports as ignored WITHIN ITS PARENT would otherwise exclude its own root and index nothing at all.
tests/test_sub_index_ignores.py:86
Checks
assert tree not in sub.excludes, f"{sub.name} excludes its own root"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_the_tree_itself_is_never_in_its_own_excludes → derive_sub_indexes → whole_repo_scope |
| REQ-DDB-INDEX-002 | measured | test_the_tree_itself_is_never_in_its_own_excludes → derive_sub_indexes |
Source · 18 lines
def test_the_tree_itself_is_never_in_its_own_excludes(tmp_path: Path) -> None:
"""THE SELF-EXCLUSION TRAP. `_under_any` matches equality as well as containment — by
design, because an exclusion names the directory itself — so a tree that git reports as
ignored WITHIN ITS PARENT would otherwise exclude its own root and index nothing at all.
A sub-index whose root is in its own excludes builds an empty database and reports
success, which is the silent-emptiness failure this project keeps finding.
"""
root = _repo(tmp_path)
for sub in derive_sub_indexes(root):
for tree in sub.roots:
assert tree not in sub.excludes, f"{sub.name} excludes its own root"
@pytest.mark.skipif(
subprocess.run(["git", "--version"], capture_output=True).returncode != 0,
reason="needs git",
)