test_derived_target_listing.py

tests/test_derived_target_listing.py

gh#38 — the derived sub-index names a caller may build are listed nowhere.

test_a_derived_name_is_listed_once_even_when_built

None test_derived_target_listing.test_a_derived_name_is_listed_once_even_when_built(Path tmp_path, Path rich_db)

The built sub-index appears exactly once.

tests/test_derived_target_listing.py:83

Show on the map →

Called by none

Calls _partly_built, build_server

Checks

  • assert names.count(FIRST_PARTY_INDEX) == 1, (f"first-party listed {names.count(FIRST_PARTY_INDEX)}x" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-003measured
REQ-DDB-MCP-001measuredtest_a_derived_name_is_listed_once_even_when_built → build_server
REQ-DDB-MCP-002measured
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_a_derived_name_is_listed_once_even_when_built → build_server → _refusal_as_tool_error
REQ-DDB-PIPE-005measured
REQ-DDB-WIKI-034measuredtest_a_derived_name_is_listed_once_even_when_built → build_server → _register_prompts
REQ-DDB-WIKI-054measured
Source · 20 lines
def test_a_derived_name_is_listed_once_even_when_built(tmp_path: Path, rich_db: Path) -> None:
    """A DUPLICATE ROW IS WORSE THAN A MISSING ONE, because a caller counting indexes would
    double-count every built sub-index the moment the derived set started being reported. The
    registered row wins: it is the one carrying the real staleness measurement.

    @brief The built sub-index appears exactly once.
    @return None.
    @version 1
    """
    from clew.mcp_server.server import build_server

    reg, _repo, _built = _partly_built(tmp_path, rich_db)
    _mcp, server = build_server(reg)

    names = [row.get("sub_index") for row in server.list_targets()]
    assert names.count(FIRST_PARTY_INDEX) == 1, (
        f"first-party listed {names.count(FIRST_PARTY_INDEX)}x"
    )

Activity · 5 steps
lines 92–92from clew.mcp_server.server import build_serverlines 94–94reg, _repo, _built = _partly_built(tmp_path, rich_db)lines 95–95_mcp, server = build_server(reg)lines 97–97names = [row.get("sub_index") for row in server.list_targets()]lines 98–100assert names.count(FIRST_PARTY_INDEX) == 1, ( f"first-party listed {names.count(FIRST_PARTY_INDEX)}x" )

test_a_repository_with_no_recorded_split_invents_nothing

None test_derived_target_listing.test_a_repository_with_no_recorded_split_invents_nothing(Path tmp_path, Path rich_db)

An unrecorded repository lists only what is registered.

tests/test_derived_target_listing.py:103

Checks

  • assert len(rows) == 1, f"nothing may be invented for an unrecorded repo, got {rows}"
  • assert rows[0].get("sub_index") is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-003measured
REQ-DDB-MCP-001measuredtest_a_repository_with_no_recorded_split_invents_nothing → build_server
REQ-DDB-MCP-002measured
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_a_repository_with_no_recorded_split_invents_nothing → build_server → _refusal_as_tool_error
REQ-DDB-PIPE-005measured
REQ-DDB-WIKI-034measuredtest_a_repository_with_no_recorded_split_invents_nothing → build_server → _register_prompts
REQ-DDB-WIKI-054measured
Source · 24 lines
def test_a_repository_with_no_recorded_split_invents_nothing(tmp_path: Path, rich_db: Path) -> None:
    """NO WALK ON A LISTING, which is the cost this design refuses to pay. A repository whose
    split has never been derived lists exactly its registered entries — the same answer as
    before this change — rather than paying a whole-tree walk on the cheapest call in the
    surface to discover names nobody asked for.

    @brief An unrecorded repository lists only what is registered.
    @return None.
    @version 1
    """
    from clew.mcp_server.server import build_server

    repo = tmp_path / "plain"
    repo.mkdir()
    reg = st.TargetRegistry(tmp_path / "state")
    target = reg.register(repo.resolve())
    Path(target.db_path).write_bytes(rich_db.read_bytes())
    _mcp, server = build_server(reg)

    rows = server.list_targets()
    assert len(rows) == 1, f"nothing may be invented for an unrecorded repo, got {rows}"
    assert rows[0].get("sub_index") is None

Activity · 10 steps
lines 113–113from clew.mcp_server.server import build_serverlines 115–115repo = tmp_path / "plain"lines 116–116repo.mkdir()lines 117–117reg = st.TargetRegistry(tmp_path / "state")lines 118–118target = reg.register(repo.resolve())lines 119–119Path(target.db_path).write_bytes(rich_db.read_bytes())lines 120–120_mcp, server = build_server(reg)lines 122–122rows = server.list_targets()lines 123–123assert len(rows) == 1, f"nothing may be invented for an unrecorded repo, got {rows}"lines 124–124assert rows[0].get("sub_index") is None

test_an_unbuilt_row_carries_no_staleness_block

None test_derived_target_listing.test_an_unbuilt_row_carries_no_staleness_block(Path tmp_path, Path rich_db)

An unbuilt derived row is minimal.

tests/test_derived_target_listing.py:189

Checks

  • assert unbuilt["exists"] is False
  • assert "staleness" not in unbuilt, "a database that was never built has no staleness"
  • assert "age_days" not in unbuilt, "nor an age"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-003measured
REQ-DDB-MCP-001measuredtest_an_unbuilt_row_carries_no_staleness_block → build_server
REQ-DDB-MCP-002measured
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_an_unbuilt_row_carries_no_staleness_block → build_server → _refusal_as_tool_error
REQ-DDB-PIPE-005measured
REQ-DDB-WIKI-034measuredtest_an_unbuilt_row_carries_no_staleness_block → build_server → _register_prompts
REQ-DDB-WIKI-054measured
Source · 29 lines
def test_an_unbuilt_row_carries_no_staleness_block(tmp_path: Path, rich_db: Path) -> None:
    """WHAT MADE THE REPLY 127,867 CHARACTERS. Each unbuilt row carried the full `db_status`
    projection including a staleness block — a paragraph explaining that a database which was
    never built is not current. Three hundred of those is the whole overflow.

    An unbuilt sub-index has exactly two facts: its name, and that it is not built. Reporting a
    staleness measurement for a database that does not exist is measuring something that was
    never measurable, which this repository has a standing rule against.

    @brief An unbuilt derived row is minimal.
    @return None.
    @version 1
    """
    from clew.mcp_server.server import build_server

    repo = tmp_path / "repo"
    repo.mkdir()
    reg = st.TargetRegistry(tmp_path / "state")
    built = reg.register(repo.resolve(), name=FIRST_PARTY_INDEX)
    Path(built.db_path).write_bytes(rich_db.read_bytes())
    reg.note_derived(built.repo_path, (FIRST_PARTY_INDEX, "deps-tinyfsm"))
    _mcp, server = build_server(reg)

    unbuilt = next(r for r in server.list_targets() if r.get("sub_index") == "deps-tinyfsm")
    assert unbuilt["exists"] is False
    assert "staleness" not in unbuilt, "a database that was never built has no staleness"
    assert "age_days" not in unbuilt, "nor an age"

Activity · 12 steps
lines 202–202from clew.mcp_server.server import build_serverlines 204–204repo = tmp_path / "repo"lines 205–205repo.mkdir()lines 206–206reg = st.TargetRegistry(tmp_path / "state")lines 207–207built = reg.register(repo.resolve(), name=FIRST_PARTY_INDEX)lines 208–208Path(built.db_path).write_bytes(rich_db.read_bytes())lines 209–209reg.note_derived(built.repo_path, (FIRST_PARTY_INDEX, "deps-tinyfsm"))lines 210–210_mcp, server = build_server(reg)lines 212–212unbuilt = next(r for r in server.list_targets() if r.get("sub_index") == "deps-tinyfsm")lines 213–213assert unbuilt["exists"] is Falselines 214–214assert "staleness" not in unbuilt, "a database that was never built has no staleness"lines 215–215assert "age_days" not in unbuilt, "nor an age"

test_the_listing_names_the_sub_indexes_that_are_not_built_yet

None test_derived_target_listing.test_the_listing_names_the_sub_indexes_that_are_not_built_yet(Path tmp_path, Path rich_db)

Unbuilt derived names appear with exists false.

tests/test_derived_target_listing.py:59

Show on the map →

Called by none

Calls _partly_built, build_server

Checks

  • assert by_name[FIRST_PARTY_INDEX]["exists"] is True, "the built index must still be built"
  • assert unbuilt in by_name, f"{unbuilt!r} is buildable and was not listed"
  • assert by_name[unbuilt]["exists"] is False, f"{unbuilt!r} is not built and must say so"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-003measured
REQ-DDB-MCP-001measuredtest_the_listing_names_the_sub_indexes_that_are_not_built_yet → build_server
REQ-DDB-MCP-002measured
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_the_listing_names_the_sub_indexes_that_are_not_built_yet → build_server → _refusal_as_tool_error
REQ-DDB-PIPE-005measured
REQ-DDB-WIKI-034measuredtest_the_listing_names_the_sub_indexes_that_are_not_built_yet → build_server → _register_prompts
REQ-DDB-WIKI-054measured
Source · 24 lines
def test_the_listing_names_the_sub_indexes_that_are_not_built_yet(
    tmp_path: Path, rich_db: Path
) -> None:
    """THE ON-DEMAND BUILD MODEL NEEDS A NAME TO BUILD. "Build a vendored sub-index only when a
    query needs it" is only usable if the name is obtainable without guessing, and guessing was
    what cost fifteen minutes of a shared build lock.

    @brief Unbuilt derived names appear with exists false.
    @return None.
    @version 1
    """
    from clew.mcp_server.server import build_server

    reg, _repo, _built = _partly_built(tmp_path, rich_db)
    _mcp, server = build_server(reg)

    rows = server.list_targets()
    by_name = {row.get("sub_index"): row for row in rows}
    assert by_name[FIRST_PARTY_INDEX]["exists"] is True, "the built index must still be built"
    for unbuilt in ("deps-tinyfsm", "deps-libIoT"):
        assert unbuilt in by_name, f"{unbuilt!r} is buildable and was not listed"
        assert by_name[unbuilt]["exists"] is False, f"{unbuilt!r} is not built and must say so"

Activity · 9 steps
lines 70–70from clew.mcp_server.server import build_serverlines 72–72reg, _repo, _built = _partly_built(tmp_path, rich_db)lines 73–73_mcp, server = build_server(reg)lines 75–75rows = server.list_targets()lines 76–76by_name = {row.get("sub_index"): row for row in rows}lines 77–77assert by_name[FIRST_PARTY_INDEX]["exists"] is True, "the built index must still be built"lines 78–78◇ for unbuilt in ("deps-tinyfsm", "deps-libIoT")lines 79–79assert unbuilt in by_name, f"{unbuilt!r} is buildable and was not listed"lines 80–80assert by_name[unbuilt]["exists"] is False, f"{unbuilt!r} is not built and must say so"

test_the_listing_names_top_level_derived_trees_only

None test_derived_target_listing.test_the_listing_names_top_level_derived_trees_only(Path tmp_path, Path rich_db)

Nested derived names are counted, not listed.

tests/test_derived_target_listing.py:145

Checks

  • assert {FIRST_PARTY_INDEX, "deps-slam", "deps-tinyfsm"} <= listed
  • assert nested not in listed, f"{nested!r} is nested and must be counted, not listed"
  • assert slam.get("nested_sub_indexes") == 3, slam

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-003measured
REQ-DDB-MCP-001measuredtest_the_listing_names_top_level_derived_trees_only → build_server
REQ-DDB-MCP-002measured
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_the_listing_names_top_level_derived_trees_only → build_server → _refusal_as_tool_error
REQ-DDB-PIPE-005measured
REQ-DDB-WIKI-034measuredtest_the_listing_names_top_level_derived_trees_only → build_server → _register_prompts
REQ-DDB-WIKI-054measured
Source · 44 lines
def test_the_listing_names_top_level_derived_trees_only(tmp_path: Path, rich_db: Path) -> None:
    """gh#44's adjacent finding, and a regression I shipped in 1.0.33. gh#38 made every derived
    name discoverable through `targets`; on a repository whose recursive split reaches ~300
    names that turned the ORIENTATION call into **127,867 characters** — past the client's
    result cap, so the call was unusable.

    THE SAME ARGUMENT AS gh#41, one surface over. There the refusal listed 300 names and a
    caller could not find the one they mistyped; here the listing does it and a caller cannot
    read it at all. Top-level names, a count of what is nested under them, and the spelling rule
    — every name stays BUILDABLE, only the enumeration narrows.

    @brief Nested derived names are counted, not listed.
    @return None.
    @version 1
    """
    from clew.mcp_server.server import build_server

    repo = tmp_path / "repo"
    repo.mkdir()
    reg = st.TargetRegistry(tmp_path / "state")
    built = reg.register(repo.resolve(), name=FIRST_PARTY_INDEX)
    Path(built.db_path).write_bytes(rich_db.read_bytes())
    reg.note_derived(
        built.repo_path,
        (
            FIRST_PARTY_INDEX,
            "deps-slam",
            "deps-slam-deps-boost",
            "deps-slam-deps-opencv",
            "deps-slam-deps-pcl",
            "deps-tinyfsm",
        ),
    )
    _mcp, server = build_server(reg)

    rows = server.list_targets()
    listed = {row.get("sub_index") for row in rows}
    assert {FIRST_PARTY_INDEX, "deps-slam", "deps-tinyfsm"} <= listed
    for nested in ("deps-slam-deps-boost", "deps-slam-deps-opencv", "deps-slam-deps-pcl"):
        assert nested not in listed, f"{nested!r} is nested and must be counted, not listed"
    slam = next(row for row in rows if row.get("sub_index") == "deps-slam")
    assert slam.get("nested_sub_indexes") == 3, slam

Activity · 15 steps
lines 160–160from clew.mcp_server.server import build_serverlines 162–162repo = tmp_path / "repo"lines 163–163repo.mkdir()lines 164–164reg = st.TargetRegistry(tmp_path / "state")lines 165–165built = reg.register(repo.resolve(), name=FIRST_PARTY_INDEX)lines 166–166Path(built.db_path).write_bytes(rich_db.read_bytes())lines 167–177reg.note_derived( built.repo_path, ( FIRST_PARTY_INDEX, "deps-slam", "deps-slam-deps-boost", "deps-slam-deps-opencv", "deps-slam-deps-pcl", "deps-tinyfsm", ), )lines 178–178_mcp, server = build_server(reg)lines 180–180rows = server.list_targets()lines 181–181listed = {row.get("sub_index") for row in rows}lines 182–182assert {FIRST_PARTY_INDEX, "deps-slam", "deps-tinyfsm"} <= listedlines 183–183◇ for nested in ("deps-slam-deps-boost", "deps-slam-deps-opencv", "deps-slam-deps-pcl")lines 184–184assert nested not in listed, f"{nested!r} is nested and must be counted, not listed"lines 185–185slam = next(row for row in rows if row.get("sub_index") == "deps-slam")lines 186–186assert slam.get("nested_sub_indexes") == 3, slam

test_the_recorded_split_survives_a_reload

None test_derived_target_listing.test_the_recorded_split_survives_a_reload(Path tmp_path, Path rich_db)

A second registry over the same state root reads the split back.

tests/test_derived_target_listing.py:127

Show on the map →

Called by none

Calls _partly_built

Checks

  • assert reloaded.derived_names(built.repo_path) == (FIRST_PARTY_INDEX, "deps-tinyfsm", "deps-libIoT", )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-MCP-001measured
Source · 18 lines
def test_the_recorded_split_survives_a_reload(tmp_path: Path, rich_db: Path) -> None:
    """IT IS PERSISTED, not held in the process. The listing is most useful to a session that
    did not do the build — another session, or this one after a restart — and a note kept in
    memory would be exactly backwards: available only where it is least needed.

    @brief A second registry over the same state root reads the split back.
    @return None.
    @version 1
    """
    reg, _repo, built = _partly_built(tmp_path, rich_db)
    reloaded = st.TargetRegistry(tmp_path / "state")
    assert reloaded.derived_names(built.repo_path) == (
        FIRST_PARTY_INDEX,
        "deps-tinyfsm",
        "deps-libIoT",
    )

Activity · 3 steps
lines 136–136reg, _repo, built = _partly_built(tmp_path, rich_db)lines 137–137reloaded = st.TargetRegistry(tmp_path / "state")lines 138–142assert reloaded.derived_names(built.repo_path) == ( FIRST_PARTY_INDEX, "deps-tinyfsm", "deps-libIoT", )

test_the_whole_listing_is_bounded

None test_derived_target_listing.test_the_whole_listing_is_bounded(Path tmp_path, Path rich_db)

A listing over many targets stays inside the cap.

tests/test_derived_target_listing.py:218

Checks

  • assert len(rows) <= TARGETS_CAP + 1, f"{len(rows)} rows is not a bound"
  • assert len(rendered) < 100_000, f"{len(rendered)} characters still overflows a client"
  • assert any("more" in str(row) for row in rows), "the omission must be disclosed"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-003measured
REQ-DDB-MCP-001measuredtest_the_whole_listing_is_bounded → build_server
REQ-DDB-MCP-002measured
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_the_whole_listing_is_bounded → build_server → _refusal_as_tool_error
REQ-DDB-PIPE-005measured
REQ-DDB-WIKI-034measuredtest_the_whole_listing_is_bounded → build_server → _register_prompts
REQ-DDB-WIKI-054measured
Source · 27 lines
def test_the_whole_listing_is_bounded(tmp_path: Path, rich_db: Path) -> None:
    """THE ONE REPLY WITH NO BOUND, which `list_targets`' own docstring already called out when
    it trimmed the per-target payload: "this multiplied an unbounded per-target payload by an
    unbounded target count". The payload got its bound then and the COUNT did not, so gh#38's
    extra rows walked straight through the gap.

    @brief A listing over many targets stays inside the cap.
    @return None.
    @version 1
    """
    import json

    from clew.mcp_server.server import TARGETS_CAP, build_server

    reg = st.TargetRegistry(tmp_path / "state")
    for i in range(TARGETS_CAP + 20):
        repo = tmp_path / f"repo{i}"
        repo.mkdir()
        target = reg.register(repo.resolve())
        Path(target.db_path).write_bytes(rich_db.read_bytes())
    _mcp, server = build_server(reg)

    rows = server.list_targets()
    assert len(rows) <= TARGETS_CAP + 1, f"{len(rows)} rows is not a bound"
    rendered = json.dumps(rows)
    assert len(rendered) < 100_000, f"{len(rendered)} characters still overflows a client"
    assert any("more" in str(row) for row in rows), "the omission must be disclosed"

1 more lines, not shown

Activity · 14 steps
lines 228–228import jsonlines 230–230from clew.mcp_server.server import TARGETS_CAP, build_serverlines 232–232reg = st.TargetRegistry(tmp_path / "state")lines 233–233◇ for i in range(TARGETS_CAP + 20)lines 234–234repo = tmp_path / f"repo{i}"lines 235–235repo.mkdir()lines 236–236target = reg.register(repo.resolve())lines 237–237Path(target.db_path).write_bytes(rich_db.read_bytes())lines 238–238_mcp, server = build_server(reg)lines 240–240rows = server.list_targets()lines 241–241assert len(rows) <= TARGETS_CAP + 1, f"{len(rows)} rows is not a bound"lines 242–242rendered = json.dumps(rows)lines 243–243assert len(rendered) < 100_000, f"{len(rendered)} characters still overflows a client"lines 244–244assert any("more" in str(row) for row in rows), "the omission must be disclosed"