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

Show on the map →

Called by none

Calls _repo, derive_sub_indexes

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

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_child_trees_ignores_are_not_repeated_on_the_parent → derive_sub_indexes → whole_repo_scope
REQ-DDB-INDEX-002measuredtest_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

Show on the map →

Called by none

Calls _repo, derive_sub_indexes

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

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_vendored_sub_index_excludes_its_own_gitignored_build → derive_sub_indexes → whole_repo_scope
REQ-DDB-INDEX-002measuredtest_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

Show on the map →

Called by none

Calls _repo, build_sub_indexes, derive_sub_indexes

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

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measured
REQ-DDB-CONFIG-001measuredtest_every_derived_sub_index_name_is_discoverable → derive_sub_indexes → whole_repo_scope
REQ-DDB-CONFIG-004measured
REQ-DDB-CONFIG-005measured
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-CONFIG-009measured
REQ-DDB-INDEX-001measured
REQ-DDB-INDEX-002measuredtest_every_derived_sub_index_name_is_discoverable → derive_sub_indexes
REQ-DDB-INDEX-003measured
REQ-DDB-INDEX-004measured
REQ-DDB-INDEX-005measured
REQ-DDB-INDEX-006measured
REQ-DDB-INDEX-007measured
REQ-DDB-INDEX-008measured
REQ-DDB-INDEX-009measured
REQ-DDB-INDEX-010measured
REQ-DDB-INDEX-011measured
REQ-DDB-MCP-001measured
REQ-DDB-MCP-004measured
REQ-DDB-PIPE-001measured
REQ-DDB-PIPE-003measured
REQ-DDB-PIPE-004measured
REQ-DDB-PIPE-005measured
REQ-DDB-PIPE-006measured
REQ-DDB-PIPE-007measured
REQ-DDB-PIPE-008measured
REQ-DDB-PIPE-009measured
REQ-DDB-PIPE-010measured
REQ-DDB-PIPE-011measured
REQ-DDB-PIPE-012measured
REQ-DDB-PIPE-013measured
REQ-DDB-PIPE-014measured
REQ-DDB-PIPE-015measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-011measured
REQ-DDB-SCHEMA-001measured
REQ-DDB-SCHEMA-002measured
REQ-DDB-SCHEMA-003measured
REQ-DDB-SCHEMA-004measured
REQ-DDB-SCHEMA-005measured
REQ-DDB-SCHEMA-006measured
REQ-DDB-SCHEMA-007measured
REQ-DDB-SCHEMA-009measured
REQ-DDB-SCHEMA-011measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measured
REQ-DDB-SCHEMA-014measured
REQ-DDB-SCHEMA-015measured
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
lines 135–135from clew.cli import build_sub_indexeslines 136–136from clew.mcp_server.state import TargetRegistrylines 137–137from clew.scope import derive_sub_indexeslines 139–139root = _repo(tmp_path)lines 140–140inner = root / "deps" / "vendored" / "deps" / "inner"lines 141–141(inner / "src").mkdir(parents=True)lines 142–142(inner / "src" / "c.c").write_text("void c(void) {}\n", encoding="utf-8")lines 143–143subprocess.run(["git", "init", "-q", "."], cwd=inner, check=True)lines 144–144subprocess.run(["git", "add", "-A"], cwd=inner, check=True)lines 145–149subprocess.run( ["git", "-c", "user.email=t@e", "-c", "user.name=t", "commit", "-qm", "init"], cwd=inner, check=True, )lines 151–151derived = {s.name for s in derive_sub_indexes(root)}lines 152–152assert len(derived) == 3, f"expected first-party plus two nested trees: {sorted(derived)}"lines 154–154home = tmp_path / "state"lines 157–157build_sub_indexes(root, home=home, only=FIRST_PARTY_INDEX)lines 159–159registered = {t.name for t in TargetRegistry(home).targets() if Path(t.repo_path) == root}lines 160–163assert 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" )

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

Show on the map →

Called by none

Calls _repo, derive_sub_indexes

Checks

  • assert tree not in sub.excludes, f"{sub.name} excludes its own root"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_the_tree_itself_is_never_in_its_own_excludes → derive_sub_indexes → whole_repo_scope
REQ-DDB-INDEX-002measuredtest_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",
)