test_sub_index_build.py

tests/integration/test_sub_index_build.py

Building a split repository, and refreshing one part of it without touching the rest.

test_a_first_party_refresh_leaves_the_vendored_index_alone

None test_sub_index_build.test_a_first_party_refresh_leaves_the_vendored_index_alone(Path tmp_path)

Refreshing first-party does not rebuild the vendored index.

tests/integration/test_sub_index_build.py:108

Show on the map →

Called by none

Calls _meta, _split_repo, build_sub_indexes, captured_output

Checks

  • assert before is not None, "the vendored index recorded no build time; this test is vacuous"
  • assert [t.name for t in again] == [FIRST_PARTY_INDEX], (f"a targeted refresh built {[t.name for t in again]}" )
  • assert _meta(vendored_db, "refresh.at_epoch") == before, ("the vendored index was rebuilt by a first-party edit — the split saves nothing if a " "pinned tree is re-read on every refresh" )
  • assert "app_added" in names, "the first-party refresh did not pick up the edit"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measured
REQ-DDB-CONFIG-001measuredtest_a_first_party_refresh_leaves_the_vendored_index_alone → build_sub_indexes → 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_a_first_party_refresh_leaves_the_vendored_index_alone → build_sub_indexes → 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 · 44 lines
def test_a_first_party_refresh_leaves_the_vendored_index_alone(tmp_path: Path) -> None:
    """THE ASSERTION THE WHOLE FEATURE EXISTS FOR. A vendored tree is pinned, so its index is
    immutable and must be built once; if an ordinary edit re-reads it, the split has bought
    nothing and merely added machinery.

    Asserted against the vendored index's recorded `refresh.at_epoch` — its own statement of when
    it was last built — rather than against elapsed time. A duration assertion would be flaky on
    a loaded machine and, worse, would pass for a rebuild that merely happened to be quick.

    @brief A targeted refresh rebuilds only what was named.
    @version 1
    """
    repo = _split_repo(tmp_path / "repo")
    state = tmp_path / "state"
    with captured_output():
        built = build_sub_indexes(repo, home=state)
    by_name = {t.name: t for t in built}
    vendored_db = by_name["extern-dep"].db_path
    before = _meta(vendored_db, "refresh.at_epoch")
    assert before is not None, "the vendored index recorded no build time; this test is vacuous"

    (repo / "app" / "main.c").write_text(
        "int app_entry(void) { return 0; }\nint app_added(void) { return 2; }\n",
        encoding="utf-8",
    )
    with captured_output():
        again = build_sub_indexes(repo, home=state, only=FIRST_PARTY_INDEX)

    assert [t.name for t in again] == [FIRST_PARTY_INDEX], (
        f"a targeted refresh built {[t.name for t in again]}"
    )
    assert _meta(vendored_db, "refresh.at_epoch") == before, (
        "the vendored index was rebuilt by a first-party edit — the split saves nothing if a "
        "pinned tree is re-read on every refresh"
    )
    ## And the edit really did land, so the refresh was not a no-op that trivially satisfies it.
    conn = sqlite3.connect(f"file:{by_name[FIRST_PARTY_INDEX].db_path}?mode=ro", uri=True)
    try:
        names = {r[0] for r in conn.execute("SELECT name FROM memberdef WHERE kind='function'")}
    finally:
        conn.close()
    assert "app_added" in names, "the first-party refresh did not pick up the edit"

Activity · 17 steps
lines 120–120repo = _split_repo(tmp_path / "repo")lines 121–121state = tmp_path / "state"lines 122–122with captured_output()lines 123–123built = build_sub_indexes(repo, home=state)lines 124–124by_name = {t.name: t for t in built}lines 125–125vendored_db = by_name["extern-dep"].db_pathlines 126–126before = _meta(vendored_db, "refresh.at_epoch")lines 127–127assert before is not None, "the vendored index recorded no build time; this test is vacuous"lines 129–132(repo / "app" / "main.c").write_text( "int app_entry(void) { return 0; }\nint app_added(void) { return 2; }\n", encoding="utf-8", )lines 133–133with captured_output()lines 134–134again = build_sub_indexes(repo, home=state, only=FIRST_PARTY_INDEX)lines 136–138assert [t.name for t in again] == [FIRST_PARTY_INDEX], ( f"a targeted refresh built {[t.name for t in again]}" )lines 139–142assert _meta(vendored_db, "refresh.at_epoch") == before, ( "the vendored index was rebuilt by a first-party edit — the split saves nothing if a " "pinned tree is re-read on every refresh" )lines 144–144conn = sqlite3.connect(f"file:{by_name[FIRST_PARTY_INDEX].db_path}?mode=ro", uri=True)lines 145–145trylines 146–146names = {r[0] for r in conn.execute("SELECT name FROM memberdef WHERE kind='function'")}lines 149–149assert "app_added" in names, "the first-party refresh did not pick up the edit"

test_a_split_build_separates_first_party_from_vendored

None test_sub_index_build.test_a_split_build_separates_first_party_from_vendored(Path tmp_path)

A split build produces one index per part, each holding only its own code.

tests/integration/test_sub_index_build.py:75

Show on the map →

Called by none

Calls _split_repo, build_sub_indexes, captured_output

Checks

  • assert set(by_name) == {FIRST_PARTY_INDEX, "extern-dep"}, f"unexpected split: {sorted(by_name)}"
  • assert "app_entry" in first, "the first-party index is missing first-party code"
  • assert "dep_helper" not in first, ("the first-party index still contains the vendored tree, so the split saved nothing" )
  • assert "dep_helper" in vendored, "the vendored index is missing the vendored code"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measured
REQ-DDB-CONFIG-001measuredtest_a_split_build_separates_first_party_from_vendored → build_sub_indexes → 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_a_split_build_separates_first_party_from_vendored → build_sub_indexes → 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 · 31 lines
def test_a_split_build_separates_first_party_from_vendored(tmp_path: Path) -> None:
    """Asserts on SYMBOL MEMBERSHIP rather than counts: each index must hold its own function and
    not the other's. Counts would be satisfied by two indexes that both covered everything.

    @brief Each sub-index contains its own code and not the other's.
    @version 1
    """
    repo = _split_repo(tmp_path / "repo")
    with captured_output():
        built = build_sub_indexes(repo, home=tmp_path / "state")

    by_name = {t.name: t for t in built}
    assert set(by_name) == {FIRST_PARTY_INDEX, "extern-dep"}, f"unexpected split: {sorted(by_name)}"

    def _functions(db: str) -> set[str]:
        conn = sqlite3.connect(f"file:{db}?mode=ro", uri=True)
        try:
            return {r[0] for r in conn.execute("SELECT name FROM memberdef WHERE kind='function'")}
        finally:
            conn.close()

    first = _functions(by_name[FIRST_PARTY_INDEX].db_path)
    vendored = _functions(by_name["extern-dep"].db_path)

    assert "app_entry" in first, "the first-party index is missing first-party code"
    assert "dep_helper" not in first, (
        "the first-party index still contains the vendored tree, so the split saved nothing"
    )
    assert "dep_helper" in vendored, "the vendored index is missing the vendored code"

Activity · 11 steps
lines 82–82repo = _split_repo(tmp_path / "repo")lines 83–83with captured_output()lines 84–84built = build_sub_indexes(repo, home=tmp_path / "state")lines 86–86by_name = {t.name: t for t in built}lines 87–87assert set(by_name) == {FIRST_PARTY_INDEX, "extern-dep"}, f"unexpected split: {sorted(by_name)}"lines 89–94def _functions(db: str) -> set[str]: conn = sqlite3.connect(f"file:{db}?mode=ro", uri=True) try: return {r[0] for r in conn.execute("SELECT name FROM memberdef WHERE kind='function'")} finally: conn.close()lines 96–96first = _functions(by_name[FIRST_PARTY_INDEX].db_path)lines 97–97vendored = _functions(by_name["extern-dep"].db_path)lines 99–99assert "app_entry" in first, "the first-party index is missing first-party code"lines 100–102assert "dep_helper" not in first, ( "the first-party index still contains the vendored tree, so the split saved nothing" )lines 103–103assert "dep_helper" in vendored, "the vendored index is missing the vendored code"

test_a_vendored_sub_indexs_own_stated_exclude_replays

None test_sub_index_build.test_a_vendored_sub_indexs_own_stated_exclude_replays(Path tmp_path)

A caller-stated extra exclude for a vendored sub-index replays on later refresh.

tests/integration/test_sub_index_build.py:284

Checks

  • assert first.get("ok") is True, first
  • assert second.get("ok") is True, second
  • assert after_first == {"dep_helper"}, (f"the stated exclude must apply on its own (first) build: {after_first}" )
  • assert after_second == {"dep_helper"}, (f"the stated exclude must REPLAY on a refresh that names no exclude at all — a " f"generated_fn reappearing here means the omitted argument silently discarded a " f"previously-stated operator decision: {after_second}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measured
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-004measured
REQ-DDB-CONFIG-005measured
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-CONFIG-008measured
REQ-DDB-CONFIG-009measured
REQ-DDB-INDEX-001measured
REQ-DDB-INDEX-002measured
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-001measuredtest_a_vendored_sub_indexs_own_stated_exclude_replays → build_server
REQ-DDB-MCP-002measured
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_a_vendored_sub_indexs_own_stated_exclude_replays → build_server → _refusal_as_tool_error
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
REQ-DDB-WIKI-034measuredtest_a_vendored_sub_indexs_own_stated_exclude_replays → build_server → _register_prompts
REQ-DDB-WIKI-054measured
Source · 80 lines
def test_a_vendored_sub_indexs_own_stated_exclude_replays(tmp_path: Path) -> None:
    """MECHANISM (a), owner-requested: a caller names an EXTRA exclude for one vendored
    sub-index — something recursion cannot discover on its own, like a plain (non-git)
    generated-output directory sitting inside a vendored tree — on that sub-index's first
    build, and it must still apply on a LATER refresh that passes no `exclude` argument at
    all. `_operator_excludes` already replays per-TARGET (`output=target.db_path` is
    specific to this sub-index), so this only works if `_sub_index_scope` leaves the
    caller's own `exclude` argument alone rather than folding its own auto-derived
    children-exclude into it — which would collapse an omitted argument into a concrete
    list and silently defeat the replay on every single call.

    @brief An extra exclude stated once for a vendored sub-index survives an unstated refresh.
    @version 1
    """
    import sys

    import anyio

    from clew.mcp_server.server import build_server
    from clew.mcp_server.state import TargetRegistry

    sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
    from test_mcp_server import _FakeCtx  # noqa: PLC0415 -- reused test helper, deliberately

    repo = tmp_path / "repo"
    (repo / "app").mkdir(parents=True)
    (repo / "app" / "main.c").write_text("int app_entry(void) { return 0; }\n", encoding="utf-8")
    vendor = repo / "extern" / "dep"
    vendor.mkdir(parents=True)
    (vendor / "dep.c").write_text("int dep_helper(void) { return 1; }\n", encoding="utf-8")
    (vendor / ".git").write_text("gitdir: ../../.git/modules/dep\n", encoding="utf-8")
    ## A plain, non-git generated-output directory recursion cannot see -- exactly Finding
    ## C's shape (deps/libBissellIoT/build/), the case this mechanism exists for.
    generated = vendor / "build"
    generated.mkdir()
    (generated / "gen.c").write_text("int generated_fn(void) { return 9; }\n", encoding="utf-8")
    (repo / "Doxyfile").write_text("PROJECT_NAME = replay\nINPUT = .\n", encoding="utf-8")

    reg = TargetRegistry(tmp_path / "state")
    _mcp, state = build_server(reg)

    def _functions(db_path: str) -> set[str]:
        conn = sqlite3.connect(f"file:{db_path}?mode=ro", uri=True)
        try:
            return {r[0] for r in conn.execute("SELECT name FROM memberdef WHERE kind='function'")}
        finally:
            conn.close()

    async def _run() -> tuple[set[str], set[str]]:
        with captured_output():
            first = await state.build_or_refresh(
                _FakeCtx(),
                target=str(repo),
                sub_index="extern-dep",
                exclude=["extern/dep/build"],
                force=True,
            )
        assert first.get("ok") is True, first
        target = state.registry.register(repo, "extern-dep")
        after_first = _functions(target.db_path)

        ## THE REPLAY: no `exclude` argument at all on this call.
        with captured_output():
            second = await state.build_or_refresh(
                _FakeCtx(), target=str(repo), sub_index="extern-dep", force=True
            )
        assert second.get("ok") is True, second
        after_second = _functions(target.db_path)
        return after_first, after_second

    after_first, after_second = anyio.run(_run)

    assert after_first == {"dep_helper"}, (
        f"the stated exclude must apply on its own (first) build: {after_first}"
    )
    assert after_second == {"dep_helper"}, (
        f"the stated exclude must REPLAY on a refresh that names no exclude at all — a "
        f"generated_fn reappearing here means the omitted argument silently discarded a "
        f"previously-stated operator decision: {after_second}"
    )

1 more lines, not shown

Activity · 24 steps
lines 298–298import syslines 300–300import anyiolines 302–302from clew.mcp_server.server import build_serverlines 303–303from clew.mcp_server.state import TargetRegistrylines 305–305sys.path.insert(0, str(Path(__file__).resolve().parents[1]))lines 306–306from test_mcp_server import _FakeCtxlines 308–308repo = tmp_path / "repo"lines 309–309(repo / "app").mkdir(parents=True)lines 310–310(repo / "app" / "main.c").write_text("int app_entry(void) { return 0; }\n", encoding="utf-8")lines 311–311vendor = repo / "extern" / "dep"lines 312–312vendor.mkdir(parents=True)lines 313–313(vendor / "dep.c").write_text("int dep_helper(void) { return 1; }\n", encoding="utf-8")lines 314–314(vendor / ".git").write_text("gitdir: ../../.git/modules/dep\n", encoding="utf-8")lines 317–317generated = vendor / "build"lines 318–318generated.mkdir()lines 319–319(generated / "gen.c").write_text("int generated_fn(void) { return 9; }\n", encoding="utf-8")lines 320–320(repo / "Doxyfile").write_text("PROJECT_NAME = replay\nINPUT = .\n", encoding="utf-8")lines 322–322reg = TargetRegistry(tmp_path / "state")lines 323–323_mcp, state = build_server(reg)lines 325–330def _functions(db_path: str) -> set[str]: conn = sqlite3.connect(f"file:{db_path}?mode=ro", uri=True) try: return {r[0] for r in conn.execute("SELECT name FROM memberdef WHERE kind='function'")} finally: conn.close()lines 332–352async def _run() -> tuple[set[str], set[str]]: with captured_output(): first = await state.build_or_refresh( _FakeCtx(), target=str(repo), sub_index="extern-dep", exclude=["extern/dep/build"], force=True, ) assert first.get("ok") is True, first target = state.registry.register(repo, "extern-dep") after_first = _functions(target.db_path) ## THE REPLAY: no `exclude` argument at all on this call. with captured_output(): second = await state.build_or_refresh( _FakeCtx(), target=str(repo), sub_index="extern-dep", force=True ) assert second.get("ok") is True, second after_second = _functions(target.db_path) return after_first, after_secondlines 354–354after_first, after_second = anyio.run(_run)lines 356–358assert after_first == {"dep_helper"}, ( f"the stated exclude must apply on its own (first) build: {after_first}" )lines 359–363assert after_second == {"dep_helper"}, ( f"the stated exclude must REPLAY on a refresh that names no exclude at all — a " f"generated_fn reappearing here means the omitted argument silently discarded a " f"previously-stated operator decision: {after_second}" )

test_a_vendored_trees_own_vendored_tree_is_not_swallowed

None test_sub_index_build.test_a_vendored_trees_own_vendored_tree_is_not_swallowed(Path tmp_path)

A vendored tree's own vendored tree gets its own index, real doxygen included.

tests/integration/test_sub_index_build.py:199

Show on the map →

Called by none

Calls _deeply_nested_repo, build_sub_indexes, captured_output

Checks

  • assert set(by_name) == {FIRST_PARTY_INDEX, "deps-vendor", "deps-vendor-subdep"}, sorted(by_name)
  • assert first == {"app_entry"}, f"first-party must hold only its own code: {first}"
  • assert vendor == {"vendor_fn"}, (f"vendor's own sub-index must hold only ITS code, not subdep's too — the swallowing " f"this fix closes: {vendor}" )
  • assert subdep == {"subdep_fn"}, f"subdep must be indexed as its own tree: {subdep}"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measured
REQ-DDB-CONFIG-001measuredtest_a_vendored_trees_own_vendored_tree_is_not_swallowed → build_sub_indexes → 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_a_vendored_trees_own_vendored_tree_is_not_swallowed → build_sub_indexes → 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 · 38 lines
def test_a_vendored_trees_own_vendored_tree_is_not_swallowed(tmp_path: Path) -> None:
    """FIELD-REPORTED: `sub_index='deps-vendor'` built OK, but its 23,893 files in scope were
    almost entirely `subdep`'s own code, none of which belongs to `vendor` itself — a nested
    tree's own nested tree was indexed as PART of it rather than getting its own identity.
    `test_sub_index_split.py` already proves `derive_sub_indexes` computes the right split and
    the right excludes; this proves the BUILD actually applies them — `_sub_index_scope`'s
    vendored branch used to construct `options.index_scope.roots` and drop `SubIndex.excludes`
    entirely, so even a correct derivation changed nothing about what got indexed.

    @brief Building the middle sub-index alone excludes its own child's code, real doxygen run.
    @version 1
    """
    repo = _deeply_nested_repo(tmp_path / "repo")
    with captured_output():
        built = build_sub_indexes(repo, home=tmp_path / "state")

    by_name = {t.name: t for t in built}
    assert set(by_name) == {FIRST_PARTY_INDEX, "deps-vendor", "deps-vendor-subdep"}, sorted(by_name)

    def _functions(db: str) -> set[str]:
        conn = sqlite3.connect(f"file:{db}?mode=ro", uri=True)
        try:
            return {r[0] for r in conn.execute("SELECT name FROM memberdef WHERE kind='function'")}
        finally:
            conn.close()

    first = _functions(by_name[FIRST_PARTY_INDEX].db_path)
    vendor = _functions(by_name["deps-vendor"].db_path)
    subdep = _functions(by_name["deps-vendor-subdep"].db_path)

    assert first == {"app_entry"}, f"first-party must hold only its own code: {first}"
    assert vendor == {"vendor_fn"}, (
        f"vendor's own sub-index must hold only ITS code, not subdep's too — the swallowing "
        f"this fix closes: {vendor}"
    )
    assert subdep == {"subdep_fn"}, f"subdep must be indexed as its own tree: {subdep}"

Activity · 12 steps
lines 211–211repo = _deeply_nested_repo(tmp_path / "repo")lines 212–212with captured_output()lines 213–213built = build_sub_indexes(repo, home=tmp_path / "state")lines 215–215by_name = {t.name: t for t in built}lines 216–216assert set(by_name) == {FIRST_PARTY_INDEX, "deps-vendor", "deps-vendor-subdep"}, sorted(by_name)lines 218–223def _functions(db: str) -> set[str]: conn = sqlite3.connect(f"file:{db}?mode=ro", uri=True) try: return {r[0] for r in conn.execute("SELECT name FROM memberdef WHERE kind='function'")} finally: conn.close()lines 225–225first = _functions(by_name[FIRST_PARTY_INDEX].db_path)lines 226–226vendor = _functions(by_name["deps-vendor"].db_path)lines 227–227subdep = _functions(by_name["deps-vendor-subdep"].db_path)lines 229–229assert first == {"app_entry"}, f"first-party must hold only its own code: {first}"lines 230–233assert vendor == {"vendor_fn"}, ( f"vendor's own sub-index must hold only ITS code, not subdep's too — the swallowing " f"this fix closes: {vendor}" )lines 234–234assert subdep == {"subdep_fn"}, f"subdep must be indexed as its own tree: {subdep}"

test_an_unvendored_repo_is_not_split

None test_sub_index_build.test_an_unvendored_repo_is_not_split(Path tmp_path)

A repository with nothing vendored is not split.

tests/integration/test_sub_index_build.py:154

Show on the map →

Called by none

Calls build_sub_indexes, captured_output

Checks

  • assert build_sub_indexes(repo, home=tmp_path / "state") == []

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_an_unvendored_repo_is_not_split → build_sub_indexes → derive_sub_indexes → whole_repo_scope
REQ-DDB-INDEX-002measuredtest_an_unvendored_repo_is_not_split → build_sub_indexes → derive_sub_indexes
Source · 16 lines
def test_an_unvendored_repo_is_not_split(tmp_path: Path) -> None:
    """THE COMPATIBILITY CASE. Every existing target must keep its slug and its database; a
    driver that split unconditionally would strand them all.

    @brief No nested trees means no sub-index build.
    @version 1
    """
    repo = tmp_path / "plain"
    (repo / "src").mkdir(parents=True)
    (repo / "src" / "main.c").write_text("int main(void){return 0;}\n", encoding="utf-8")
    (repo / "Doxyfile").write_text("PROJECT_NAME = plain\nINPUT = .\n", encoding="utf-8")

    with captured_output():
        assert build_sub_indexes(repo, home=tmp_path / "state") == []

Activity · 6 steps
lines 161–161repo = tmp_path / "plain"lines 162–162(repo / "src").mkdir(parents=True)lines 163–163(repo / "src" / "main.c").write_text("int main(void){return 0;}\n", encoding="utf-8")lines 164–164(repo / "Doxyfile").write_text("PROJECT_NAME = plain\nINPUT = .\n", encoding="utf-8")lines 166–166with captured_output()lines 167–167assert build_sub_indexes(repo, home=tmp_path / "state") == []

test_mcp_refresh_of_a_vendored_sub_index_excludes_its_own_children

None test_sub_index_build.test_mcp_refresh_of_a_vendored_sub_index_excludes_its_own_children(Path tmp_path)

The MCP refresh path also excludes a vendored tree's own nested children.

tests/integration/test_sub_index_build.py:239

Show on the map →

Called by none

Calls _deeply_nested_repo, build_server, captured_output

Checks

  • assert result.get("ok") is True, result
  • assert functions == {"vendor_fn"}, (f"the MCP refresh path must also exclude a vendored sub-index's own children: {functions}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measured
REQ-DDB-CONFIG-001measured
REQ-DDB-CONFIG-004measured
REQ-DDB-CONFIG-005measured
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-CONFIG-008measured
REQ-DDB-CONFIG-009measured
REQ-DDB-INDEX-001measured
REQ-DDB-INDEX-002measured
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-001measuredtest_mcp_refresh_of_a_vendored_sub_index_excludes_its_own_children → build_server
REQ-DDB-MCP-002measured
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_mcp_refresh_of_a_vendored_sub_index_excludes_its_own_children → build_server → _refusal_as_tool_error
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
REQ-DDB-WIKI-032measured
REQ-DDB-WIKI-033measured
REQ-DDB-WIKI-034measuredtest_mcp_refresh_of_a_vendored_sub_index_excludes_its_own_children → build_server → _register_prompts
REQ-DDB-WIKI-035measured
REQ-DDB-WIKI-054measured
Source · 43 lines
def test_mcp_refresh_of_a_vendored_sub_index_excludes_its_own_children(tmp_path: Path) -> None:
    """THE ACTUAL PATH A REAL SESSION USES. `build_sub_indexes` (above) and `_sub_index_scope`
    (server.py, driving `index(action='refresh', sub_index=...)`) are two SEPARATE
    implementations of the same idea — this project's own history already has one instance of
    fixing a bug in one and not the other. Real doxygen, through `build_or_refresh` exactly as
    a client calls it, not the CLI helper.

    @brief index(action='refresh', sub_index='deps-vendor') excludes deps/vendor/subdep too.
    @version 1
    """
    import sys

    import anyio

    from clew.mcp_server.server import build_server
    from clew.mcp_server.state import TargetRegistry

    sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
    from test_mcp_server import _FakeCtx  # noqa: PLC0415 -- reused test helper, deliberately

    repo = _deeply_nested_repo(tmp_path / "repo")
    reg = TargetRegistry(tmp_path / "state")
    _mcp, state = build_server(reg)

    async def _run() -> str:
        with captured_output():
            result = await state.build_or_refresh(
                _FakeCtx(), target=str(repo), sub_index="deps-vendor", force=True
            )
        assert result.get("ok") is True, result
        target = state.registry.register(repo, "deps-vendor")
        conn = sqlite3.connect(f"file:{target.db_path}?mode=ro", uri=True)
        try:
            return {r[0] for r in conn.execute("SELECT name FROM memberdef WHERE kind='function'")}
        finally:
            conn.close()

    functions = anyio.run(_run)
    assert functions == {"vendor_fn"}, (
        f"the MCP refresh path must also exclude a vendored sub-index's own children: {functions}"
    )

Activity · 12 steps
lines 249–249import syslines 251–251import anyiolines 253–253from clew.mcp_server.server import build_serverlines 254–254from clew.mcp_server.state import TargetRegistrylines 256–256sys.path.insert(0, str(Path(__file__).resolve().parents[1]))lines 257–257from test_mcp_server import _FakeCtxlines 259–259repo = _deeply_nested_repo(tmp_path / "repo")lines 260–260reg = TargetRegistry(tmp_path / "state")lines 261–261_mcp, state = build_server(reg)lines 263–274async def _run() -> str: with captured_output(): result = await state.build_or_refresh( _FakeCtx(), target=str(repo), sub_index="deps-vendor", force=True ) assert result.get("ok") is True, result target = state.registry.register(repo, "deps-vendor") conn = sqlite3.connect(f"file:{target.db_path}?mode=ro", uri=True) try: return {r[0] for r in conn.execute("SELECT name FROM memberdef WHERE kind='function'")} finally: conn.close()lines 276–276functions = anyio.run(_run)lines 277–279assert functions == {"vendor_fn"}, ( f"the MCP refresh path must also exclude a vendored sub-index's own children: {functions}" )