test_split_repo_routing.py

tests/test_split_repo_routing.py

gh#48 — a split repository refused every query while six of its indexes sat built on disk.

test_a_bare_call_on_a_split_repo_answers_from_first_party

None test_split_repo_routing.test_a_bare_call_on_a_split_repo_answers_from_first_party(Path tmp_path, Path rich_db)

An absent whole-repo index routes a bare call to first-party, disclosed.

tests/test_split_repo_routing.py:76

Show on the map →

Called by none

Calls _built_on_disk, _split_repo, build_server

Checks

  • assert "found" not in reply, f"first-party knows sensor_poll; got {reply}"
  • assert reply.get("sub_index") == FIRST_PARTY_INDEX, (f"a defaulted reply must name the index that answered it, got {reply.get('sub_index')!r}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-003measured
REQ-DDB-INDEX-004measured
REQ-DDB-MCP-001measuredtest_a_bare_call_on_a_split_repo_answers_from_first_party → build_server
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_a_bare_call_on_a_split_repo_answers_from_first_party → build_server → _refusal_as_tool_error
REQ-DDB-PIPE-005measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-002measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-006measured
REQ-DDB-QUERY-009measured
REQ-DDB-QUERY-010measured
REQ-DDB-QUERY-012measured
REQ-DDB-QUERY-014measured
REQ-DDB-SCHEMA-011measured
REQ-DDB-WIKI-034measuredtest_a_bare_call_on_a_split_repo_answers_from_first_party → build_server → _register_prompts
REQ-DDB-WIKI-054measured
Source · 23 lines
def test_a_bare_call_on_a_split_repo_answers_from_first_party(
    tmp_path: Path, rich_db: Path
) -> None:
    """ASK 1. The whole-repo database is absent and first-party is built, so a call that names
    no sub_index answers from first-party — and SAYS so, because a reply that read one index and
    stamped another's identity is this module's most expensive recorded defect.

    @brief An absent whole-repo index routes a bare call to first-party, disclosed.
    @version 1
    """
    home = tmp_path / "state"
    repo = _split_repo(tmp_path / "repo")
    _built_on_disk(home, repo, FIRST_PARTY_INDEX, rich_db)
    _mcp, state = build_server(st.TargetRegistry(home))

    reply = state.tools.dossier("sensor_poll", target=str(repo))

    assert "found" not in reply, f"first-party knows sensor_poll; got {reply}"
    assert reply.get("sub_index") == FIRST_PARTY_INDEX, (
        f"a defaulted reply must name the index that answered it, got {reply.get('sub_index')!r}"
    )

Activity · 7 steps
lines 86–86home = tmp_path / "state"lines 87–87repo = _split_repo(tmp_path / "repo")lines 88–88_built_on_disk(home, repo, FIRST_PARTY_INDEX, rich_db)lines 89–89_mcp, state = build_server(st.TargetRegistry(home))lines 91–91reply = state.tools.dossier("sensor_poll", target=str(repo))lines 93–93assert "found" not in reply, f"first-party knows sensor_poll; got {reply}"lines 94–96assert reply.get("sub_index") == FIRST_PARTY_INDEX, ( f"a defaulted reply must name the index that answered it, got {reply.get('sub_index')!r}" )

test_a_built_first_party_outranks_a_registered_but_unbuilt_whole_index

None test_split_repo_routing.test_a_built_first_party_outranks_a_registered_but_unbuilt_whole_index(Path tmp_path, Path rich_db)

A built index beats a registered-only one when choosing the default.

tests/test_split_repo_routing.py:285

Show on the map →

Called by none

Calls _built_on_disk, _split_repo, build_server

Checks

  • assert "found" not in reply, reply
  • assert reply.get("sub_index") == FIRST_PARTY_INDEX

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-003measured
REQ-DDB-INDEX-004measured
REQ-DDB-MCP-001measuredtest_a_built_first_party_outranks_a_registered_but_unbuilt_whole_index → build_server
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_a_built_first_party_outranks_a_registered_but_unbuilt_whole_index → build_server → _refusal_as_tool_error
REQ-DDB-PIPE-005measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-002measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-006measured
REQ-DDB-QUERY-009measured
REQ-DDB-QUERY-010measured
REQ-DDB-QUERY-012measured
REQ-DDB-QUERY-014measured
REQ-DDB-SCHEMA-011measured
REQ-DDB-WIKI-034measuredtest_a_built_first_party_outranks_a_registered_but_unbuilt_whole_index → build_server → _register_prompts
REQ-DDB-WIKI-054measured
Source · 24 lines
def test_a_built_first_party_outranks_a_registered_but_unbuilt_whole_index(
    tmp_path: Path, rich_db: Path
) -> None:
    """THE STATE FOLLOWING THE OLD ADVICE LEAVES BEHIND. `index(action='refresh', target=repo)`
    registers the whole-repository target before it builds, so B12's killed 900 s build left a
    whole-repo RECORD with no database — and the default preferred any whole-repo record, built or
    not, over a first-party index that worked. Every later bare call refused.

    @brief A built index beats a registered-only one when choosing the default.
    @version 1
    """
    home = tmp_path / "state"
    repo = _split_repo(tmp_path / "repo")
    registry = st.TargetRegistry(home)
    registry.register(repo)
    _built_on_disk(home, repo, FIRST_PARTY_INDEX, rich_db)
    _mcp, state = build_server(registry)

    reply = state.tools.dossier("sensor_poll", target=str(repo))

    assert "found" not in reply, reply
    assert reply.get("sub_index") == FIRST_PARTY_INDEX

Activity · 9 steps
lines 296–296home = tmp_path / "state"lines 297–297repo = _split_repo(tmp_path / "repo")lines 298–298registry = st.TargetRegistry(home)lines 299–299registry.register(repo)lines 300–300_built_on_disk(home, repo, FIRST_PARTY_INDEX, rich_db)lines 301–301_mcp, state = build_server(registry)lines 303–303reply = state.tools.dossier("sensor_poll", target=str(repo))lines 305–305assert "found" not in reply, replylines 306–306assert reply.get("sub_index") == FIRST_PARTY_INDEX

test_a_call_naming_no_target_answers_from_first_party_and_says_so

None test_split_repo_routing.test_a_call_naming_no_target_answers_from_first_party_and_says_so(Path tmp_path, Path rich_db)

The default target follows an on-disk first-party index and the reply names it.

tests/test_split_repo_routing.py:309

Show on the map →

Called by none

Calls _built_on_disk, _split_repo, build_server

Checks

  • assert state.active is not None and state.active.name is None, "premise: nothing built yet"
  • assert "found" not in reply, reply
  • assert reply.get("sub_index") == FIRST_PARTY_INDEX, reply.get("sub_index")

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-003measured
REQ-DDB-INDEX-004measured
REQ-DDB-MCP-001measuredtest_a_call_naming_no_target_answers_from_first_party_and_says_so → build_server
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_a_call_naming_no_target_answers_from_first_party_and_says_so → build_server → _refusal_as_tool_error
REQ-DDB-PIPE-005measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-002measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-006measured
REQ-DDB-QUERY-009measured
REQ-DDB-QUERY-010measured
REQ-DDB-QUERY-012measured
REQ-DDB-QUERY-014measured
REQ-DDB-SCHEMA-011measured
REQ-DDB-WIKI-034measuredtest_a_call_naming_no_target_answers_from_first_party_and_says_so → build_server → _register_prompts
REQ-DDB-WIKI-054measured
Source · 27 lines
def test_a_call_naming_no_target_answers_from_first_party_and_says_so(
    tmp_path: Path, rich_db: Path
) -> None:
    """MODES 2 AND 3 OF THE REPORT: `--repo` or `$CLAUDE_PROJECT_DIR` supplies the default and the
    call names no target. Two defects stacked there. `adopt` saw only registered siblings, and
    `self.active` is resolved ONCE, so a first-party index built after the session connected — by
    another session, the CLI, or a background first build — never became the default.

    And the default path stamped only the repository, so an answer from first-party read as an
    answer from the whole repository.

    @brief The default target follows an on-disk first-party index and the reply names it.
    @version 1
    """
    home = tmp_path / "state"
    repo = _split_repo(tmp_path / "repo")
    _mcp, state = build_server(st.TargetRegistry(home))
    state.adopt(str(repo), st.TARGET_SOURCE_FLAG)
    assert state.active is not None and state.active.name is None, "premise: nothing built yet"

    _built_on_disk(home, repo, FIRST_PARTY_INDEX, rich_db)
    reply = state.tools.dossier("sensor_poll")

    assert "found" not in reply, reply
    assert reply.get("sub_index") == FIRST_PARTY_INDEX, reply.get("sub_index")

Activity · 9 steps
lines 323–323home = tmp_path / "state"lines 324–324repo = _split_repo(tmp_path / "repo")lines 325–325_mcp, state = build_server(st.TargetRegistry(home))lines 326–326state.adopt(str(repo), st.TARGET_SOURCE_FLAG)lines 327–327assert state.active is not None and state.active.name is None, "premise: nothing built yet"lines 329–329_built_on_disk(home, repo, FIRST_PARTY_INDEX, rich_db)lines 330–330reply = state.tools.dossier("sensor_poll")lines 332–332assert "found" not in reply, replylines 333–333assert reply.get("sub_index") == FIRST_PARTY_INDEX, reply.get("sub_index")

test_a_comment_only_declaration_is_not_reported_as_malformed

None test_split_repo_routing.test_a_comment_only_declaration_is_not_reported_as_malformed(Path tmp_path, pytest.LogCaptureFixture caplog)

Comment-only declarations log as stating nothing; non-mappings still warn.

tests/test_split_repo_routing.py:336

Checks

  • assert load_declaration(repo) == {}
  • assert not [r for r in caplog.records if r.levelno >= logging.WARNING], caplog.text
  • assert "states nothing" in caplog.text
  • assert load_declaration(repo) == {}
  • assert any(r.levelno == logging.WARNING and "not a mapping" in r.getMessage() for r in caplog.records )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_comment_only_declaration_is_not_reported_as_malformed → load_declaration
REQ-DDB-GUARD-012inferredtest_a_comment_only_declaration_is_not_reported_as_malformed → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-WIKI-054inferredtest_a_comment_only_declaration_is_not_reported_as_malformed → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 30 lines
def test_a_comment_only_declaration_is_not_reported_as_malformed(
    tmp_path: Path, caplog: pytest.LogCaptureFixture
) -> None:
    """ASK 4's other half. A `.clew.yaml` holding only comments is what `propose_declaration`
    hands an owner, and it was logged at WARNING as "does not contain a mapping — ignoring it",
    which reads as a broken file. It states nothing; that is said at INFO, in those words. A file
    that holds something other than a mapping is still a WARNING.

    @brief Comment-only declarations log as stating nothing; non-mappings still warn.
    @version 1
    """
    import logging

    from clew.declaration import load_declaration

    repo = tmp_path / "repo"
    repo.mkdir()
    (repo / ".clew.yaml").write_text("# locks:\n#   primitives: []\n", encoding="utf-8")
    with caplog.at_level(logging.INFO):
        assert load_declaration(repo) == {}
    assert not [r for r in caplog.records if r.levelno >= logging.WARNING], caplog.text
    assert "states nothing" in caplog.text

    caplog.clear()
    (repo / ".clew.yaml").write_text("- a\n- b\n", encoding="utf-8")
    with caplog.at_level(logging.INFO):
        assert load_declaration(repo) == {}
    assert any(
        r.levelno == logging.WARNING and "not a mapping" in r.getMessage() for r in caplog.records
    )

1 more lines, not shown

Activity · 14 steps
lines 347–347import logginglines 349–349from clew.declaration import load_declarationlines 351–351repo = tmp_path / "repo"lines 352–352repo.mkdir()lines 353–353(repo / ".clew.yaml").write_text("# locks:\n# primitives: []\n", encoding="utf-8")lines 354–354with caplog.at_level(logging.INFO)lines 355–355assert load_declaration(repo) == {}lines 356–356assert not [r for r in caplog.records if r.levelno >= logging.WARNING], caplog.textlines 357–357assert "states nothing" in caplog.textlines 359–359caplog.clear()lines 360–360(repo / ".clew.yaml").write_text("- a\n- b\n", encoding="utf-8")lines 361–361with caplog.at_level(logging.INFO)lines 362–362assert load_declaration(repo) == {}lines 363–365assert any( r.levelno == logging.WARNING and "not a mapping" in r.getMessage() for r in caplog.records )

test_a_first_party_miss_is_scoped_even_when_no_other_part_is_built

None test_split_repo_routing.test_a_first_party_miss_is_scoped_even_when_no_other_part_is_built(Path tmp_path, Path rich_db)

Recorded-but-unbuilt parts are listed as not searched, and the negative is scoped.

tests/test_split_repo_routing.py:129

Show on the map →

Called by none

Calls _built_on_disk, _split_repo, build_server

Checks

  • assert reply.get("not_searched") == ["deps-libIoT", "deps-tinyfsm"], reply.get("not_searched")
  • assert "definitive negative" not in reply["note"], reply["note"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-003measured
REQ-DDB-MCP-001measuredtest_a_first_party_miss_is_scoped_even_when_no_other_part_is_built → build_server
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_a_first_party_miss_is_scoped_even_when_no_other_part_is_built → build_server → _refusal_as_tool_error
REQ-DDB-PIPE-005measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-010measured
REQ-DDB-QUERY-012measured
REQ-DDB-QUERY-013measured
REQ-DDB-QUERY-014measured
REQ-DDB-WIKI-034measuredtest_a_first_party_miss_is_scoped_even_when_no_other_part_is_built → build_server → _register_prompts
REQ-DDB-WIKI-054measured
Source · 26 lines
def test_a_first_party_miss_is_scoped_even_when_no_other_part_is_built(
    tmp_path: Path, rich_db: Path
) -> None:
    """MEASURED END TO END, then pinned. A background first build of a split repository builds
    first-party ONLY, so the state right after it has no vendored part built at all — and a miss
    for a vendored function came back "a definitive negative" because `not_searched` listed only
    BUILT siblings and there were none. The build had recorded the vendored names; an unbuilt part
    makes the answer more partial, not complete.

    @brief Recorded-but-unbuilt parts are listed as not searched, and the negative is scoped.
    @version 1
    """
    home = tmp_path / "state"
    repo = _split_repo(tmp_path / "repo")
    registry = st.TargetRegistry(home)
    registry.register(repo, FIRST_PARTY_INDEX)
    registry.note_derived(str(repo), (FIRST_PARTY_INDEX, "deps-libIoT", "deps-tinyfsm"))
    _built_on_disk(home, repo, FIRST_PARTY_INDEX, rich_db)
    _mcp, state = build_server(registry)

    reply = state.tools.dossier("vendored_only_symbol", target=str(repo))

    assert reply.get("not_searched") == ["deps-libIoT", "deps-tinyfsm"], reply.get("not_searched")
    assert "definitive negative" not in reply["note"], reply["note"]

Activity · 10 steps
lines 141–141home = tmp_path / "state"lines 142–142repo = _split_repo(tmp_path / "repo")lines 143–143registry = st.TargetRegistry(home)lines 144–144registry.register(repo, FIRST_PARTY_INDEX)lines 145–145registry.note_derived(str(repo), (FIRST_PARTY_INDEX, "deps-libIoT", "deps-tinyfsm"))lines 146–146_built_on_disk(home, repo, FIRST_PARTY_INDEX, rich_db)lines 147–147_mcp, state = build_server(registry)lines 149–149reply = state.tools.dossier("vendored_only_symbol", target=str(repo))lines 151–151assert reply.get("not_searched") == ["deps-libIoT", "deps-tinyfsm"], reply.get("not_searched")lines 152–152assert "definitive negative" not in reply["note"], reply["note"]

test_a_hit_whose_callees_are_unresolved_says_which_parts_it_did_not_read

None test_split_repo_routing.test_a_hit_whose_callees_are_unresolved_says_which_parts_it_did_not_read(Path tmp_path, Path rich_db, Path repo_root)

A hit with unresolved call sites names the unread parts beside them.

tests/test_split_repo_routing.py:155

Show on the map →

Called by none

Calls _built_on_disk, _split_repo, build_server, target_for

Checks

  • assert reply.get("found") is not False, reply
  • assert reply.get("external_callees"), "premise: this subject has unresolved call sites"
  • assert reply.get("not_searched") == ["deps-tinyfsm"], reply.get("not_searched")
  • assert "not_searched" in note and FIRST_PARTY_INDEX in note, (f"a hit with unresolved callees must point at the unread parts: {note!r}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-003measured
REQ-DDB-INDEX-004measured
REQ-DDB-MCP-001measuredtest_a_hit_whose_callees_are_unresolved_says_which_parts_it_did_not_read → build_server
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_a_hit_whose_callees_are_unresolved_says_which_parts_it_did_not_read → build_server → _refusal_as_tool_error
REQ-DDB-PIPE-003measured
REQ-DDB-PIPE-005measured
REQ-DDB-PIPE-011measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-002measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-006measured
REQ-DDB-QUERY-009measured
REQ-DDB-QUERY-010measured
REQ-DDB-QUERY-012measured
REQ-DDB-QUERY-014measured
REQ-DDB-SCHEMA-011measured
REQ-DDB-WIKI-034measuredtest_a_hit_whose_callees_are_unresolved_says_which_parts_it_did_not_read → build_server → _register_prompts
REQ-DDB-WIKI-054measured
Source · 49 lines
def test_a_hit_whose_callees_are_unresolved_says_which_parts_it_did_not_read(
    tmp_path: Path, rich_db: Path, repo_root: Path
) -> None:
    """ASK 3 IN THE WORDS THE ISSUE USED: "a dossier answered from first-party whose callees live
    in a vendored sub-index should say so, rather than presenting an apparently complete
    neighbour list." A HIT is the dangerous case, because the reply looks complete.
    `external_callees` already names the call sites that resolve to no indexed function; what was
    missing is the connection to the parts of the repository this answer never read.

    THE UNRESOLVED CALL IS MANUFACTURED by dropping one callee's rows from a copy of the fixture
    index — which is exactly the shape a split repository produces: the caller is first-party,
    the callee is indexed somewhere this database is not.

    @brief A hit with unresolved call sites names the unread parts beside them.
    @version 1
    """
    import shutil
    import sqlite3

    home = tmp_path / "state"
    repo = _split_repo(tmp_path / "repo")
    ## The fixture index records paths relative to the csample tree, and `external_callees`
    ## PARSES THE BODY off disk — so the split repository has to hold those sources for the call
    ## sites to be found at all.
    shutil.copytree(repo_root, repo, dirs_exist_ok=True)
    registry = st.TargetRegistry(home)
    ## `note_derived` records the split onto this repository's existing records, which is what a
    ## build leaves behind — so the first-party record has to exist, as it would after one.
    registry.register(repo, FIRST_PARTY_INDEX)
    registry.note_derived(str(repo), (FIRST_PARTY_INDEX, "deps-tinyfsm"))
    _built_on_disk(home, repo, FIRST_PARTY_INDEX, rich_db)
    first_party = st.target_for(repo, home, FIRST_PARTY_INDEX)
    conn = sqlite3.connect(first_party.db_path)
    conn.execute("DELETE FROM memberdef WHERE name = 'DataModel_Set_DEMOBOT_POWER_BATTERY_MV'")
    conn.commit()
    conn.close()
    _mcp, state = build_server(registry)

    reply = state.tools.dossier("sensor_poll", target=str(repo))

    assert reply.get("found") is not False, reply
    assert reply.get("external_callees"), "premise: this subject has unresolved call sites"
    assert reply.get("not_searched") == ["deps-tinyfsm"], reply.get("not_searched")
    note = str(reply.get("scope_note"))
    assert "not_searched" in note and FIRST_PARTY_INDEX in note, (
        f"a hit with unresolved callees must point at the unread parts: {note!r}"
    )

Activity · 21 steps
lines 171–171import shutillines 172–172import sqlite3lines 174–174home = tmp_path / "state"lines 175–175repo = _split_repo(tmp_path / "repo")lines 179–179shutil.copytree(repo_root, repo, dirs_exist_ok=True)lines 180–180registry = st.TargetRegistry(home)lines 183–183registry.register(repo, FIRST_PARTY_INDEX)lines 184–184registry.note_derived(str(repo), (FIRST_PARTY_INDEX, "deps-tinyfsm"))lines 185–185_built_on_disk(home, repo, FIRST_PARTY_INDEX, rich_db)lines 186–186first_party = st.target_for(repo, home, FIRST_PARTY_INDEX)lines 187–187conn = sqlite3.connect(first_party.db_path)lines 188–188conn.execute("DELETE FROM memberdef WHERE name = 'DataModel_Set_DEMOBOT_POWER_BATTERY_MV'")lines 189–189conn.commit()lines 190–190conn.close()lines 191–191_mcp, state = build_server(registry)lines 193–193reply = state.tools.dossier("sensor_poll", target=str(repo))lines 195–195assert reply.get("found") is not False, replylines 196–196assert reply.get("external_callees"), "premise: this subject has unresolved call sites"lines 197–197assert reply.get("not_searched") == ["deps-tinyfsm"], reply.get("not_searched")lines 198–198note = str(reply.get("scope_note"))lines 199–201assert "not_searched" in note and FIRST_PARTY_INDEX in note, ( f"a hit with unresolved callees must point at the unread parts: {note!r}" )

test_a_negative_from_first_party_is_scoped_even_with_nothing_else_on_record

None test_split_repo_routing.test_a_negative_from_first_party_is_scoped_even_with_nothing_else_on_record(Path tmp_path, Path rich_db)

A sub-index negative is scoped by declared split evidence, with nothing else recorded.

tests/test_split_repo_routing.py:204

Show on the map →

Called by none

Calls _built_on_disk, _split_repo, build_server

Checks

  • assert reply.get("found") is False
  • assert "definitive negative" not in reply["note"], reply["note"]
  • assert "sub_index" in reply["note"], (f"a scoped negative must route to the parts that were not read: {reply['note']!r}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-INDEX-003measured
REQ-DDB-MCP-001measuredtest_a_negative_from_first_party_is_scoped_even_with_nothing_else_on_record → build_server
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_a_negative_from_first_party_is_scoped_even_with_nothing_else_on_record → build_server → _refusal_as_tool_error
REQ-DDB-PIPE-005measured
REQ-DDB-QUERY-001measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-004measured
REQ-DDB-QUERY-010measured
REQ-DDB-QUERY-012measured
REQ-DDB-QUERY-013measured
REQ-DDB-QUERY-014measured
REQ-DDB-WIKI-034measuredtest_a_negative_from_first_party_is_scoped_even_with_nothing_else_on_record → build_server → _register_prompts
REQ-DDB-WIKI-054measured
Source · 29 lines
def test_a_negative_from_first_party_is_scoped_even_with_nothing_else_on_record(
    tmp_path: Path, rich_db: Path
) -> None:
    """FOUND BY DRIVING A MODEL AT IT (gh#48 ask 5). A repository whose first-party index was
    built by the CLI registers no sub-index and records no split, so `not_searched` is empty —
    and a miss for a symbol that lives in a vendored tree came back as "a definitive negative
    from the database". The repository says it is split in its own `.gitmodules`, which costs a
    stat to read, and an answer from ONE part of it is never definitive for the whole.

    @brief A sub-index negative is scoped by declared split evidence, with nothing else recorded.
    @version 1
    """
    home = tmp_path / "state"
    repo = _split_repo(tmp_path / "repo")
    (repo / ".gitmodules").write_text(
        '[submodule "deps/tinyfsm"]\n\tpath = deps/tinyfsm\n', encoding="utf-8"
    )
    _built_on_disk(home, repo, FIRST_PARTY_INDEX, rich_db)
    _mcp, state = build_server(st.TargetRegistry(home))

    reply = state.tools.dossier("vendored_only_symbol", target=str(repo))

    assert reply.get("found") is False
    assert "definitive negative" not in reply["note"], reply["note"]
    assert "sub_index" in reply["note"], (
        f"a scoped negative must route to the parts that were not read: {reply['note']!r}"
    )

Activity · 9 steps
lines 216–216home = tmp_path / "state"lines 217–217repo = _split_repo(tmp_path / "repo")lines 218–220(repo / ".gitmodules").write_text( '[submodule "deps/tinyfsm"]\n\tpath = deps/tinyfsm\n', encoding="utf-8" )lines 221–221_built_on_disk(home, repo, FIRST_PARTY_INDEX, rich_db)lines 222–222_mcp, state = build_server(st.TargetRegistry(home))lines 224–224reply = state.tools.dossier("vendored_only_symbol", target=str(repo))lines 226–226assert reply.get("found") is Falselines 227–227assert "definitive negative" not in reply["note"], reply["note"]lines 228–230assert "sub_index" in reply["note"], ( f"a scoped negative must route to the parts that were not read: {reply['note']!r}" )

test_an_unsplit_repo_keeps_the_original_refusal

None test_split_repo_routing.test_an_unsplit_repo_keeps_the_original_refusal(Path tmp_path)

A plain unbuilt repository is refused with the unscoped remedy, as before.

tests/test_split_repo_routing.py:266

Checks

  • assert "index(action='refresh'" in message and "sub_index" not in message, message

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-MCP-001measuredtest_an_unsplit_repo_keeps_the_original_refusal → build_server
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_an_unsplit_repo_keeps_the_original_refusal → build_server → _refusal_as_tool_error
REQ-DDB-QUERY-010measured
REQ-DDB-WIKI-034measuredtest_an_unsplit_repo_keeps_the_original_refusal → build_server → _register_prompts
REQ-DDB-WIKI-054measured
Source · 19 lines
def test_an_unsplit_repo_keeps_the_original_refusal(tmp_path: Path) -> None:
    """THE CONTROL. A repository with no nested trees is not split, has no sub-indexes to name,
    and an unscoped refresh is exactly the right advice for it.

    @brief A plain unbuilt repository is refused with the unscoped remedy, as before.
    @version 1
    """
    home = tmp_path / "state"
    repo = tmp_path / "plain"
    repo.mkdir()
    _mcp, state = build_server(st.TargetRegistry(home))

    with pytest.raises(RuntimeError) as exc:
        state.tools.dossier("anything", target=str(repo))
    message = str(exc.value)

    assert "index(action='refresh'" in message and "sub_index" not in message, message

Activity · 8 steps
lines 273–273home = tmp_path / "state"lines 274–274repo = tmp_path / "plain"lines 275–275repo.mkdir()lines 276–276_mcp, state = build_server(st.TargetRegistry(home))lines 278–278with pytest.raises(RuntimeError) as exclines 279–279state.tools.dossier("anything", target=str(repo))lines 280–280message = str(exc.value)lines 282–282assert "index(action='refresh'" in message and "sub_index" not in message, message

test_the_refusal_names_what_is_built_and_never_advises_an_unscoped_build

None test_split_repo_routing.test_the_refusal_names_what_is_built_and_never_advises_an_unscoped_build(Path tmp_path, Path rich_db)

The refusal enumerates built sub-indexes and recommends a scoped refresh only.

tests/test_split_repo_routing.py:233

Show on the map →

Called by none

Calls _built_on_disk, _split_repo, build_server

Checks

  • assert "deps-tinyfsm" in message, f"the refusal must name the built sub-index: {message}"
  • assert ".clew.yaml holds only comments" in message, message
  • assert f"sub_index='{FIRST_PARTY_INDEX}'" in message, (f"the remedy must be the SCOPED first-party build: {message}" )
  • assert f"index(action='refresh', target={str(repo)!r})" not in message, (f"an unscoped refresh of a split repository must never be advised: {message}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measured
REQ-DDB-MCP-001measuredtest_the_refusal_names_what_is_built_and_never_advises_an_unscoped_build → build_server
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_the_refusal_names_what_is_built_and_never_advises_an_unscoped_build → build_server → _refusal_as_tool_error
REQ-DDB-QUERY-010measured
REQ-DDB-WIKI-034measuredtest_the_refusal_names_what_is_built_and_never_advises_an_unscoped_build → build_server → _register_prompts
REQ-DDB-WIKI-054measured
Source · 33 lines
def test_the_refusal_names_what_is_built_and_never_advises_an_unscoped_build(
    tmp_path: Path, rich_db: Path
) -> None:
    """ASK 2, and the half of the old message that did damage. With neither the whole-repo nor
    the first-party index built, a query is refused — but the refusal must list the sub-indexes
    that ARE built and name the scoped build that fixes it. It must not recommend
    `index(action='refresh', target=...)` with no sub_index on a split repository: that call is
    the 87,911-file, 900-second build.

    @brief The refusal enumerates built sub-indexes and recommends a scoped refresh only.
    @version 1
    """
    home = tmp_path / "state"
    repo = _split_repo(tmp_path / "repo")
    (repo / ".clew.yaml").write_text("# sub_indexes:\n#   deps-tinyfsm: {}\n", encoding="utf-8")
    _built_on_disk(home, repo, "deps-tinyfsm", rich_db)
    _mcp, state = build_server(st.TargetRegistry(home))

    with pytest.raises(RuntimeError) as exc:
        state.tools.dossier("sensor_poll", target=str(repo))
    message = str(exc.value)

    assert "deps-tinyfsm" in message, f"the refusal must name the built sub-index: {message}"
    ## ASK 4: the repository's own declaration file, and whether a build honours it.
    assert ".clew.yaml holds only comments" in message, message
    assert f"sub_index='{FIRST_PARTY_INDEX}'" in message, (
        f"the remedy must be the SCOPED first-party build: {message}"
    )
    assert f"index(action='refresh', target={str(repo)!r})" not in message, (
        f"an unscoped refresh of a split repository must never be advised: {message}"
    )

Activity · 12 steps
lines 245–245home = tmp_path / "state"lines 246–246repo = _split_repo(tmp_path / "repo")lines 247–247(repo / ".clew.yaml").write_text("# sub_indexes:\n# deps-tinyfsm: {}\n", encoding="utf-8")lines 248–248_built_on_disk(home, repo, "deps-tinyfsm", rich_db)lines 249–249_mcp, state = build_server(st.TargetRegistry(home))lines 251–251with pytest.raises(RuntimeError) as exclines 252–252state.tools.dossier("sensor_poll", target=str(repo))lines 253–253message = str(exc.value)lines 255–255assert "deps-tinyfsm" in message, f"the refusal must name the built sub-index: {message}"lines 257–257assert ".clew.yaml holds only comments" in message, messagelines 258–260assert f"sub_index='{FIRST_PARTY_INDEX}'" in message, ( f"the remedy must be the SCOPED first-party build: {message}" )lines 261–263assert f"index(action='refresh', target={str(repo)!r})" not in message, ( f"an unscoped refresh of a split repository must never be advised: {message}" )