test_sub_index_refusal.py

tests/test_sub_index_refusal.py

gh#35 — a `sub_index` name that matches nothing built the WHOLE repository.

test_a_legitimate_sub_index_still_registers

None test_sub_index_refusal.test_a_legitimate_sub_index_still_registers(Path tmp_path)

A derived name registers and allocates as before.

tests/test_sub_index_refusal.py:326

Show on the map →

Called by none

Calls _split_repo

Checks

  • assert resolved is not None and resolved.name == "deps-tinyfsm"
  • assert [t.name for t in registry.targets()] == ["deps-tinyfsm"]
  • assert Path(resolved.db_path).parent.is_dir(), "the build still needs somewhere to write"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-INDEX-002measured
REQ-DDB-MCP-001measured
Source · 22 lines
def test_a_legitimate_sub_index_still_registers(tmp_path: Path) -> None:
    """THE CONTROL. The check runs before registration, so getting it wrong would make every
    sub-index unbuildable rather than merely leaving litter behind.

    @brief A derived name registers and allocates as before.
    @return None.
    @version 1
    """
    from clew.mcp_server import server as srv
    from clew.mcp_server import state as st

    repo = _split_repo(tmp_path / "repo")
    registry = st.TargetRegistry(tmp_path / "state")
    instance = srv.DocsDbServer.__new__(srv.DocsDbServer)
    instance.registry = registry

    resolved = asyncio.run(instance._build_subject(None, str(repo), "deps-tinyfsm"))
    assert resolved is not None and resolved.name == "deps-tinyfsm"
    assert [t.name for t in registry.targets()] == ["deps-tinyfsm"]
    assert Path(resolved.db_path).parent.is_dir(), "the build still needs somewhere to write"

Activity · 10 steps
lines 334–334from clew.mcp_server import server as srvlines 335–335from clew.mcp_server import state as stlines 337–337repo = _split_repo(tmp_path / "repo")lines 338–338registry = st.TargetRegistry(tmp_path / "state")lines 339–339instance = srv.DocsDbServer.__new__(srv.DocsDbServer)lines 340–340instance.registry = registrylines 342–342resolved = asyncio.run(instance._build_subject(None, str(repo), "deps-tinyfsm"))lines 343–343assert resolved is not None and resolved.name == "deps-tinyfsm"lines 344–344assert [t.name for t in registry.targets()] == ["deps-tinyfsm"]lines 345–345assert Path(resolved.db_path).parent.is_dir(), "the build still needs somewhere to write"

test_a_refused_sub_index_registers_nothing

None test_sub_index_refusal.test_a_refused_sub_index_registers_nothing(Path tmp_path)

A refused name allocates no slug, no directory, no registry entry.

tests/test_sub_index_refusal.py:295

Show on the map →

Called by none

Calls _split_repo

Checks

  • assert registry.targets() == [], "a refused sub_index must leave the registry untouched"
  • assert stray == [], f"a refused sub_index must allocate no directory, found {stray}"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-INDEX-002measured
REQ-DDB-MCP-001measured
Source · 31 lines
def test_a_refused_sub_index_registers_nothing(tmp_path: Path) -> None:
    """gh#40. THE REFUSAL LANDED AFTER REGISTRATION, so a mistyped name still created
    `~/.local/state/clew/targets/<repo>.<bogus>/` and a four-line `targets.json` entry — and
    `index(action='targets')` then listed a slug that had never been built and never would be.
    A refusal that leaves a trace is a refusal the operator has to clean up by hand, which is
    what the reporter did.

    `_build_subject` registers because a build needs somewhere to write. Nothing needs
    somewhere to write when there is nothing to build, so the name is checked first.

    @brief A refused name allocates no slug, no directory, no registry entry.
    @return None.
    @version 1
    """
    from clew.mcp_server import server as srv
    from clew.mcp_server import state as st

    repo = _split_repo(tmp_path / "repo")
    state = tmp_path / "state"
    registry = st.TargetRegistry(state)
    instance = srv.DocsDbServer.__new__(srv.DocsDbServer)
    instance.registry = registry

    with pytest.raises(RuntimeError, match="no-such-tree"):
        asyncio.run(instance._build_subject(None, str(repo), "no-such-tree"))

    assert registry.targets() == [], "a refused sub_index must leave the registry untouched"
    stray = [p.name for p in state.glob("targets/*") if "no-such-tree" in p.name]
    assert stray == [], f"a refused sub_index must allocate no directory, found {stray}"

Activity · 12 steps
lines 309–309from clew.mcp_server import server as srvlines 310–310from clew.mcp_server import state as stlines 312–312repo = _split_repo(tmp_path / "repo")lines 313–313state = tmp_path / "state"lines 314–314registry = st.TargetRegistry(state)lines 315–315instance = srv.DocsDbServer.__new__(srv.DocsDbServer)lines 316–316instance.registry = registrylines 318–318with pytest.raises(RuntimeError, match="no-such-tree")lines 319–319asyncio.run(instance._build_subject(None, str(repo), "no-such-tree"))lines 321–321assert registry.targets() == [], "a refused sub_index must leave the registry untouched"lines 322–322stray = [p.name for p in state.glob("targets/*") if "no-such-tree" in p.name]lines 323–323assert stray == [], f"a refused sub_index must allocate no directory, found {stray}"

test_a_registered_sub_index_whose_tree_vanished_refuses_and_names_the_route

None test_sub_index_refusal.test_a_registered_sub_index_whose_tree_vanished_refuses_and_names_the_route(Path tmp_path)

A vanished tree is refused with the cull route named.

tests/test_sub_index_refusal.py:195

Show on the map →

Called by none

Calls _split_repo, _sub_index_rejection, target_for

Checks

  • assert rejection is not None, "a vanished tree must not build the whole repository"
  • assert "clew cull" in rejection, f"name the route that clears the leftover, got: {rejection}"
  • assert "action='cull'" not in rejection
  • assert "deps-removed" in rejection

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_registered_sub_index_whose_tree_vanished_refuses_and_names_the_route → _sub_index_rejection → first_party_sub_index → nested_repo_roots
REQ-DDB-INDEX-002measuredtest_a_registered_sub_index_whose_tree_vanished_refuses_and_names_the_route → _sub_index_rejection → first_party_sub_index
REQ-DDB-MCP-001measuredtest_a_registered_sub_index_whose_tree_vanished_refuses_and_names_the_route → target_for
Source · 32 lines
def test_a_registered_sub_index_whose_tree_vanished_refuses_and_names_the_route(
    tmp_path: Path,
) -> None:
    """THE CASE THE WIDENING BRANCH WAS WRITTEN FOR, and it still must not widen. A submodule
    removed since its sub-index was built leaves a database describing code that is no longer
    in the tree. Building it whole would turn that sub-index into a second copy of the
    repository; building it narrow is impossible, because there is no tree to narrow to.

    So it refuses — and says which route clears the leftover, because a caller told only "no"
    about an index they legitimately built once has nowhere to go.

    @brief A vanished tree is refused with the cull route named.
    @return None.
    @version 1
    """
    from clew.mcp_server.server import _sub_index_rejection
    from clew.mcp_server.state import target_for

    repo = _split_repo(tmp_path / "repo")
    gone = target_for(repo, tmp_path / "state", name="deps-removed")
    db = Path(gone.db_path)
    db.parent.mkdir(parents=True, exist_ok=True)
    db.write_bytes(b"")

    rejection = _sub_index_rejection(gone, repo)
    assert rejection is not None, "a vanished tree must not build the whole repository"
    ## 2.0.0: the route is the `clew cull` CLI; `index(action='cull')` was retired and would 404.
    assert "clew cull" in rejection, f"name the route that clears the leftover, got: {rejection}"
    assert "action='cull'" not in rejection
    assert "deps-removed" in rejection

Activity · 12 steps
lines 210–210from clew.mcp_server.server import _sub_index_rejectionlines 211–211from clew.mcp_server.state import target_forlines 213–213repo = _split_repo(tmp_path / "repo")lines 214–214gone = target_for(repo, tmp_path / "state", name="deps-removed")lines 215–215db = Path(gone.db_path)lines 216–216db.parent.mkdir(parents=True, exist_ok=True)lines 217–217db.write_bytes(b"")lines 219–219rejection = _sub_index_rejection(gone, repo)lines 220–220assert rejection is not None, "a vanished tree must not build the whole repository"lines 222–222assert "clew cull" in rejection, f"name the route that clears the leftover, got: {rejection}"lines 223–223assert "action='cull'" not in rejectionlines 224–224assert "deps-removed" in rejection

test_a_sub_index_name_that_matches_nothing_is_refused

None test_sub_index_refusal.test_a_sub_index_name_that_matches_nothing_is_refused(Path tmp_path)

An unmatched name is rejected, and the message lists what is buildable.

tests/test_sub_index_refusal.py:62

Show on the map →

Called by none

Calls _split_repo, _sub_index_rejection, target_for

Checks

  • assert rejection is not None, "a name matching no nested tree must be refused"
  • assert "no-such-tree" in rejection, "the refusal must quote the name that failed"
  • assert buildable in rejection, f"the refusal must name {buildable!r} as an alternative"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_sub_index_name_that_matches_nothing_is_refused → _sub_index_rejection → first_party_sub_index → nested_repo_roots
REQ-DDB-INDEX-002measuredtest_a_sub_index_name_that_matches_nothing_is_refused → _sub_index_rejection → first_party_sub_index
REQ-DDB-MCP-001measuredtest_a_sub_index_name_that_matches_nothing_is_refused → target_for
Source · 22 lines
def test_a_sub_index_name_that_matches_nothing_is_refused(tmp_path: Path) -> None:
    """THE REFUSAL NAMES THE ALTERNATIVES, because a caller who mistyped a name cannot
    discover the right one from anywhere else — gh#38 is the same gap seen from `targets`.
    A bare "unknown sub_index" would cost the round trip that the fifteen-minute build cost.

    @brief An unmatched name is rejected, and the message lists what is buildable.
    @return None.
    @version 1
    """
    from clew.mcp_server.server import _sub_index_rejection
    from clew.mcp_server.state import target_for

    repo = _split_repo(tmp_path / "repo")
    bogus = target_for(repo, tmp_path / "state", name="no-such-tree")

    rejection = _sub_index_rejection(bogus, repo)
    assert rejection is not None, "a name matching no nested tree must be refused"
    assert "no-such-tree" in rejection, "the refusal must quote the name that failed"
    for buildable in (FIRST_PARTY_INDEX, "deps-tinyfsm", "deps-libIoT"):
        assert buildable in rejection, f"the refusal must name {buildable!r} as an alternative"

Activity · 9 steps
lines 71–71from clew.mcp_server.server import _sub_index_rejectionlines 72–72from clew.mcp_server.state import target_forlines 74–74repo = _split_repo(tmp_path / "repo")lines 75–75bogus = target_for(repo, tmp_path / "state", name="no-such-tree")lines 77–77rejection = _sub_index_rejection(bogus, repo)lines 78–78assert rejection is not None, "a name matching no nested tree must be refused"lines 79–79assert "no-such-tree" in rejection, "the refusal must quote the name that failed"lines 80–80◇ for buildable in (FIRST_PARTY_INDEX, "deps-tinyfsm", "deps-libIoT")lines 81–81assert buildable in rejection, f"the refusal must name {buildable!r} as an alternative"

test_a_whole_repo_target_is_never_refused

None test_sub_index_refusal.test_a_whole_repo_target_is_never_refused(Path tmp_path)

An unnamed target passes without consulting the split at all.

tests/test_sub_index_refusal.py:102

Show on the map →

Called by none

Calls _split_repo, _sub_index_rejection, target_for

Checks

  • assert _sub_index_rejection(target_for(repo, tmp_path / "state"), repo) is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001inferredtest_a_whole_repo_target_is_never_refused → _sub_index_rejection → first_party_sub_index → nested_repo_roots
REQ-DDB-INDEX-002inferredtest_a_whole_repo_target_is_never_refused → _sub_index_rejection → first_party_sub_index
REQ-DDB-MCP-001measuredtest_a_whole_repo_target_is_never_refused → target_for
Source · 16 lines
def test_a_whole_repo_target_is_never_refused(tmp_path: Path) -> None:
    """`name is None` is the unnamed target, which every repository has and which this check
    must not touch — it is also the only shape that existed before sub-indexes, so refusing it
    would strand every index on disk.

    @brief An unnamed target passes without consulting the split at all.
    @return None.
    @version 1
    """
    from clew.mcp_server.server import _sub_index_rejection
    from clew.mcp_server.state import target_for

    repo = _split_repo(tmp_path / "repo")
    assert _sub_index_rejection(target_for(repo, tmp_path / "state"), repo) is None

Activity · 4 steps
lines 111–111from clew.mcp_server.server import _sub_index_rejectionlines 112–112from clew.mcp_server.state import target_forlines 114–114repo = _split_repo(tmp_path / "repo")lines 115–115assert _sub_index_rejection(target_for(repo, tmp_path / "state"), repo) is None

test_an_unsplit_repository_refuses_any_sub_index_by_saying_so

None test_sub_index_refusal.test_an_unsplit_repository_refuses_any_sub_index_by_saying_so(Path tmp_path)

The refusal for an unsplit repo says the repo is unsplit.

tests/test_sub_index_refusal.py:118

Checks

  • assert rejection is not None
  • assert "not split" in rejection.lower(), f"say the repo is unsplit, got: {rejection}"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_an_unsplit_repository_refuses_any_sub_index_by_saying_so → _sub_index_rejection → first_party_sub_index → nested_repo_roots
REQ-DDB-INDEX-002measuredtest_an_unsplit_repository_refuses_any_sub_index_by_saying_so → _sub_index_rejection → first_party_sub_index
REQ-DDB-MCP-001measuredtest_an_unsplit_repository_refuses_any_sub_index_by_saying_so → target_for
Source · 22 lines
def test_an_unsplit_repository_refuses_any_sub_index_by_saying_so(tmp_path: Path) -> None:
    """A REPOSITORY WITH NOTHING VENDORED HAS NO SUB-INDEXES AT ALL — `derive_sub_indexes`
    returns [] to mean "do not split" — so every name is wrong and the honest message is that
    this repository is not split, not a list of zero alternatives.

    @brief The refusal for an unsplit repo says the repo is unsplit.
    @return None.
    @version 1
    """
    from clew.mcp_server.server import _sub_index_rejection
    from clew.mcp_server.state import target_for

    repo = tmp_path / "plain"
    (repo / "src").mkdir(parents=True)
    (repo / "src" / "a.c").write_text("int a(void){return 0;}\n", encoding="utf-8")
    target = target_for(repo.resolve(), tmp_path / "state", name="anything")

    rejection = _sub_index_rejection(target, repo.resolve())
    assert rejection is not None
    assert "not split" in rejection.lower(), f"say the repo is unsplit, got: {rejection}"

Activity · 9 steps
lines 127–127from clew.mcp_server.server import _sub_index_rejectionlines 128–128from clew.mcp_server.state import target_forlines 130–130repo = tmp_path / "plain"lines 131–131(repo / "src").mkdir(parents=True)lines 132–132(repo / "src" / "a.c").write_text("int a(void){return 0;}\n", encoding="utf-8")lines 133–133target = target_for(repo.resolve(), tmp_path / "state", name="anything")lines 135–135rejection = _sub_index_rejection(target, repo.resolve())lines 136–136assert rejection is not Nonelines 137–137assert "not split" in rejection.lower(), f"say the repo is unsplit, got: {rejection}"

test_culling_one_dead_sub_index_leaves_its_healthy_siblings_alone

None test_sub_index_refusal.test_culling_one_dead_sub_index_leaves_its_healthy_siblings_alone(Path tmp_path, Path rich_db)

A cull removes only the target it judged, not its siblings.

tests/test_sub_index_refusal.py:227

Show on the map →

Called by none

Calls cull

Checks

  • assert [c["repo_path"] for c in culled], "the never-built sub-index must be culled"
  • assert FIRST_PARTY_INDEX in names, "culling a dead sibling dropped the healthy index"
  • assert "deps-abandoned" not in names, "the dead sub-index is still registered"
  • assert Path(healthy.db_path).exists(), "the healthy database was deleted from disk"
  • assert not leftovers.exists(), "the killed build's leftover directory was not reclaimed"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measuredtest_culling_one_dead_sub_index_leaves_its_healthy_siblings_alone → cull → db_status
REQ-DDB-CONFIG-007measuredtest_culling_one_dead_sub_index_leaves_its_healthy_siblings_alone → cull → db_status
REQ-DDB-INDEX-003measuredtest_culling_one_dead_sub_index_leaves_its_healthy_siblings_alone → cull → db_status → _coverage_meta
REQ-DDB-MCP-001measuredtest_culling_one_dead_sub_index_leaves_its_healthy_siblings_alone → cull
REQ-DDB-MCP-004measuredtest_culling_one_dead_sub_index_leaves_its_healthy_siblings_alone → cull → db_status
REQ-DDB-PIPE-005measuredtest_culling_one_dead_sub_index_leaves_its_healthy_siblings_alone → cull → db_status → read_build_signature
Source · 42 lines
def test_culling_one_dead_sub_index_leaves_its_healthy_siblings_alone(
    tmp_path: Path, rich_db: Path
) -> None:
    """FOUND WHILE FIXING gh#35's LEFTOVER, and worse than the leftover. `cull` evaluates each
    target individually and then calls `registry.drop(target.repo_path)`, which drops EVERY
    entry sharing that repo path AND `rmtree`s each one's database directory. So culling the
    dead slug the bogus build left behind also deletes the repository's first-party index and
    every vendored sub-index beside it — a sweep meant to reclaim one abandoned directory takes
    out the working indexes it was called to preserve.

    `drop`'s breadth is right for `drop`: a caller passing a repo root means "forget this repo".
    It is wrong as the implementation of a per-target decision, and it is the loop above it that
    makes it wrong.

    @brief A cull removes only the target it judged, not its siblings.
    @return None.
    @version 1
    """
    from clew.mcp_server import state as st

    reg = st.TargetRegistry(tmp_path / "state")
    repo = tmp_path / "repo"
    repo.mkdir()
    healthy = reg.register(repo, name=FIRST_PARTY_INDEX)
    dead = reg.register(repo, name="deps-abandoned")
    Path(healthy.db_path).write_bytes(rich_db.read_bytes())
    ## `dead` gets the leftovers of a killed build and no database at all.
    leftovers = Path(dead.db_path).parent
    leftovers.mkdir(parents=True, exist_ok=True)
    (leftovers / "clew.db.buildlock").write_text("", encoding="utf-8")
    (leftovers / "clew.db.buildlog").write_text("killed at 900 s\n", encoding="utf-8")

    culled = st.cull(reg, max_age_days=None)

    assert [c["repo_path"] for c in culled], "the never-built sub-index must be culled"
    names = {t.name for t in reg.targets()}
    assert FIRST_PARTY_INDEX in names, "culling a dead sibling dropped the healthy index"
    assert "deps-abandoned" not in names, "the dead sub-index is still registered"
    assert Path(healthy.db_path).exists(), "the healthy database was deleted from disk"
    assert not leftovers.exists(), "the killed build's leftover directory was not reclaimed"

Activity · 18 steps
lines 245–245from clew.mcp_server import state as stlines 247–247reg = st.TargetRegistry(tmp_path / "state")lines 248–248repo = tmp_path / "repo"lines 249–249repo.mkdir()lines 250–250healthy = reg.register(repo, name=FIRST_PARTY_INDEX)lines 251–251dead = reg.register(repo, name="deps-abandoned")lines 252–252Path(healthy.db_path).write_bytes(rich_db.read_bytes())lines 254–254leftovers = Path(dead.db_path).parentlines 255–255leftovers.mkdir(parents=True, exist_ok=True)lines 256–256(leftovers / "clew.db.buildlock").write_text("", encoding="utf-8")lines 257–257(leftovers / "clew.db.buildlog").write_text("killed at 900 s\n", encoding="utf-8")lines 259–259culled = st.cull(reg, max_age_days=None)lines 261–261assert [c["repo_path"] for c in culled], "the never-built sub-index must be culled"lines 262–262names = {t.name for t in reg.targets()}lines 263–263assert FIRST_PARTY_INDEX in names, "culling a dead sibling dropped the healthy index"lines 264–264assert "deps-abandoned" not in names, "the dead sub-index is still registered"lines 265–265assert Path(healthy.db_path).exists(), "the healthy database was deleted from disk"lines 266–266assert not leftovers.exists(), "the killed build's leftover directory was not reclaimed"

test_every_derived_name_is_accepted

None test_sub_index_refusal.test_every_derived_name_is_accepted(Path tmp_path)

First-party and each derived vendored name pass.

tests/test_sub_index_refusal.py:84

Show on the map →

Called by none

Calls _split_repo, _sub_index_rejection, target_for

Checks

  • assert _sub_index_rejection(target, repo) is None, f"{name!r} is buildable and was refused"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_every_derived_name_is_accepted → _sub_index_rejection → first_party_sub_index → nested_repo_roots
REQ-DDB-INDEX-002measuredtest_every_derived_name_is_accepted → _sub_index_rejection → first_party_sub_index
REQ-DDB-MCP-001measuredtest_every_derived_name_is_accepted → target_for
Source · 18 lines
def test_every_derived_name_is_accepted(tmp_path: Path) -> None:
    """THE CONTROL, and the half a refusal gets wrong most easily. A check that rejected a
    legitimate vendored name would make the split unbuildable, which is worse than the defect
    it replaced.

    @brief First-party and each derived vendored name pass.
    @return None.
    @version 1
    """
    from clew.mcp_server.server import _sub_index_rejection
    from clew.mcp_server.state import target_for

    repo = _split_repo(tmp_path / "repo")
    for name in (FIRST_PARTY_INDEX, "deps-tinyfsm", "deps-libIoT"):
        target = target_for(repo, tmp_path / "state", name=name)
        assert _sub_index_rejection(target, repo) is None, f"{name!r} is buildable and was refused"

Activity · 6 steps
lines 93–93from clew.mcp_server.server import _sub_index_rejectionlines 94–94from clew.mcp_server.state import target_forlines 96–96repo = _split_repo(tmp_path / "repo")lines 97–97◇ for name in (FIRST_PARTY_INDEX, "deps-tinyfsm", "deps-libIoT")lines 98–98target = target_for(repo, tmp_path / "state", name=name)lines 99–99assert _sub_index_rejection(target, repo) is None, f"{name!r} is buildable and was refused"

test_the_refusal_happens_before_the_build_lock_is_taken

None test_sub_index_refusal.test_the_refusal_happens_before_the_build_lock_is_taken(Path tmp_path)

A refused sub_index never reaches the build lock.

tests/test_sub_index_refusal.py:140

Show on the map →

Called by none

Calls _split_repo, target_for

Checks

  • assert result["ok"] is False, "a refused build must not report ok"
  • assert result["built"] is False
  • assert "no-such-tree" in result["error"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-008measured
REQ-DDB-INDEX-002measured
REQ-DDB-MCP-001measuredtest_the_refusal_happens_before_the_build_lock_is_taken → target_for
Source · 35 lines
def test_the_refusal_happens_before_the_build_lock_is_taken(tmp_path: Path) -> None:
    """THE WHOLE POINT OF THE ISSUE. The damage was not the wasted build, it was holding a
    shared repository's build lock for fifteen minutes: a legitimate sub-index refresh queued
    behind it, and so did every other session's auto-refresh. A refusal after the lock would
    fix the wasted work and leave the contention exactly as it was.

    `build_lock` is replaced with something that fails if it is ever entered, so the assertion
    is about ORDER rather than about the message.

    @brief A refused sub_index never reaches the build lock.
    @return None.
    @version 1
    """
    from clew.mcp_server import server as srv
    from clew.mcp_server.state import target_for

    repo = _split_repo(tmp_path / "repo")
    bogus = target_for(repo, tmp_path / "state", name="no-such-tree")

    def _explode(_db: Path):  # noqa: ANN202 - a stand-in that must never be called
        raise AssertionError("the build lock was taken for a sub_index that names nothing")

    original = srv.build_lock
    srv.build_lock = _explode
    try:
        instance = srv.DocsDbServer.__new__(srv.DocsDbServer)
        result = instance._run_build(bogus, doxyfile=None)
    finally:
        srv.build_lock = original

    assert result["ok"] is False, "a refused build must not report ok"
    assert result["built"] is False
    assert "no-such-tree" in result["error"]

Activity · 13 steps
lines 153–153from clew.mcp_server import server as srvlines 154–154from clew.mcp_server.state import target_forlines 156–156repo = _split_repo(tmp_path / "repo")lines 157–157bogus = target_for(repo, tmp_path / "state", name="no-such-tree")lines 159–160def _explode(_db: Path): # noqa: ANN202 - a stand-in that must never be called raise AssertionError("the build lock was taken for a sub_index that names nothing")lines 162–162original = srv.build_locklines 163–163srv.build_lock = _explodelines 164–164trylines 165–165instance = srv.DocsDbServer.__new__(srv.DocsDbServer)lines 166–166result = instance._run_build(bogus, doxyfile=None)lines 170–170assert result["ok"] is False, "a refused build must not report ok"lines 171–171assert result["built"] is Falselines 172–172assert "no-such-tree" in result["error"]

test_the_refusal_names_top_level_trees_and_counts_the_rest

None test_sub_index_refusal.test_the_refusal_names_top_level_trees_and_counts_the_rest(Path tmp_path)

The refusal lists top-level names and counts what is under them.

tests/test_sub_index_refusal.py:348

Show on the map →

Called by none

Calls _nested_split_repo, _sub_index_rejection, target_for

Checks

  • assert rejection is not None
  • assert top in rejection, f"the top-level name {top!r} must be offered"
  • assert deep not in rejection, f"{deep!r} is a nested name and must not be enumerated"
  • assert "3" in rejection, "the count of nested names under deps-vendor must be reported"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_the_refusal_names_top_level_trees_and_counts_the_rest → _sub_index_rejection → first_party_sub_index → nested_repo_roots
REQ-DDB-INDEX-002measuredtest_the_refusal_names_top_level_trees_and_counts_the_rest → _sub_index_rejection → first_party_sub_index
REQ-DDB-MCP-001measuredtest_the_refusal_names_top_level_trees_and_counts_the_rest → target_for
Source · 27 lines
def test_the_refusal_names_top_level_trees_and_counts_the_rest(tmp_path: Path) -> None:
    """gh#41. THE LIST WAS CORRECT AND UNREADABLE: ~300 names in one error string on the
    reporting repository, including every boost sub-library from `-accumulators` to `-yap` and
    a libBissellIoT transitive dependency 96 characters long. A caller who mistyped
    `deps-tinyfsm` cannot find it in that.

    THE DEEP NAMES ARE STILL REACHABLE, and the message says how they are spelled rather than
    enumerating them — the same choice `_bounded_output` makes about repeated warning lines:
    one example plus a count beats the full set.

    @brief The refusal lists top-level names and counts what is under them.
    @return None.
    @version 1
    """
    from clew.mcp_server.server import _sub_index_rejection
    from clew.mcp_server.state import target_for

    repo = _nested_split_repo(tmp_path / "repo")
    bogus = target_for(repo, tmp_path / "state", name="typo")

    rejection = _sub_index_rejection(bogus, repo)
    assert rejection is not None
    for top in (FIRST_PARTY_INDEX, "deps-tinyfsm", "deps-vendor"):
        assert top in rejection, f"the top-level name {top!r} must be offered"
    for deep in ("deps-vendor-sub-alpha", "deps-vendor-sub-beta", "deps-vendor-sub-gamma"):
        assert deep not in rejection, f"{deep!r} is a nested name and must not be enumerated"
    assert "3" in rejection, "the count of nested names under deps-vendor must be reported"

1 more lines, not shown

Activity · 11 steps
lines 362–362from clew.mcp_server.server import _sub_index_rejectionlines 363–363from clew.mcp_server.state import target_forlines 365–365repo = _nested_split_repo(tmp_path / "repo")lines 366–366bogus = target_for(repo, tmp_path / "state", name="typo")lines 368–368rejection = _sub_index_rejection(bogus, repo)lines 369–369assert rejection is not Nonelines 370–370◇ for top in (FIRST_PARTY_INDEX, "deps-tinyfsm", "deps-vendor")lines 371–371assert top in rejection, f"the top-level name {top!r} must be offered"lines 372–372◇ for deep in ("deps-vendor-sub-alpha", "deps-vendor-sub-beta", "deps-vendor-sub-gamma")lines 373–373assert deep not in rejection, f"{deep!r} is a nested name and must not be enumerated"lines 374–374assert "3" in rejection, "the count of nested names under deps-vendor must be reported"

test_the_scope_helper_raises_rather_than_widening

None test_sub_index_refusal.test_the_scope_helper_raises_rather_than_widening(Path tmp_path)

The unmatched branch refuses instead of returning a whole-repo scope.

tests/test_sub_index_refusal.py:175

Show on the map →

Called by none

Calls _split_repo, _sub_index_scope, target_for

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_the_scope_helper_raises_rather_than_widening → _sub_index_scope → declared_sub_index_excludes
REQ-DDB-GUARD-012inferredtest_the_scope_helper_raises_rather_than_widening → _sub_index_scope → declared_sub_index_excludes → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-002measuredtest_the_scope_helper_raises_rather_than_widening → _sub_index_scope → derive_sub_indexes
REQ-DDB-MCP-001measuredtest_the_scope_helper_raises_rather_than_widening → target_for
REQ-DDB-WIKI-054inferredtest_the_scope_helper_raises_rather_than_widening → _sub_index_scope → declared_sub_index_excludes → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 20 lines
def test_the_scope_helper_raises_rather_than_widening(tmp_path: Path) -> None:
    """DEFENCE IN DEPTH, and the reason it is not redundant: `_sub_index_scope` is reachable
    from any future caller, and its unmatched branch returned the caller's scope — which for a
    sub-index build is the whole repository. A helper that silently answers "build everything"
    when asked "what is the scope of this part" is wrong regardless of who calls it.

    @brief The unmatched branch refuses instead of returning a whole-repo scope.
    @return None.
    @version 1
    """
    from clew.mcp_server.server import _sub_index_scope
    from clew.mcp_server.state import target_for

    repo = _split_repo(tmp_path / "repo")
    bogus = target_for(repo, tmp_path / "state", name="no-such-tree")

    with pytest.raises(ValueError, match="no-such-tree"):
        _sub_index_scope(bogus, repo, None, None)

Activity · 6 steps
lines 185–185from clew.mcp_server.server import _sub_index_scopelines 186–186from clew.mcp_server.state import target_forlines 188–188repo = _split_repo(tmp_path / "repo")lines 189–189bogus = target_for(repo, tmp_path / "state", name="no-such-tree")lines 191–191with pytest.raises(ValueError, match="no-such-tree")lines 192–192_sub_index_scope(bogus, repo, None, None)