test_sub_index_declaration.py

tests/test_sub_index_declaration.py

gh#39 route 2b — the parent declares scope for its NAMED sub-indexes.

test_a_declaration_applies_only_to_the_sub_index_it_names

None test_sub_index_declaration.test_a_declaration_applies_only_to_the_sub_index_it_names(Path tmp_path)

A sibling sub-index is unaffected.

tests/test_sub_index_declaration.py:98

Show on the map →

Called by none

Calls _declare, _repo, _sub_index_scope, target_for

Checks

  • assert "deps/slam/third_party" not in (options["index_scope"].get("excludes") or [])

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_declaration_applies_only_to_the_sub_index_it_names → _sub_index_scope → declared_sub_index_excludes
REQ-DDB-GUARD-012inferredtest_a_declaration_applies_only_to_the_sub_index_it_names → _sub_index_scope → declared_sub_index_excludes → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-002measuredtest_a_declaration_applies_only_to_the_sub_index_it_names → _sub_index_scope → derive_sub_indexes
REQ-DDB-MCP-001measuredtest_a_declaration_applies_only_to_the_sub_index_it_names → target_for
REQ-DDB-WIKI-054inferredtest_a_declaration_applies_only_to_the_sub_index_it_names → _sub_index_scope → declared_sub_index_excludes → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 18 lines
def test_a_declaration_applies_only_to_the_sub_index_it_names(tmp_path: Path) -> None:
    """THE CONTROL. A block keyed by name must not leak onto a sibling — otherwise one heavy
    tree's trim would silently narrow every other vendored index in the repository.

    @brief A sibling sub-index is unaffected.
    @version 1
    """
    from clew.mcp_server.server import _sub_index_scope
    from clew.mcp_server.state import target_for

    repo = _repo(tmp_path / "repo")
    _declare(repo, "  deps-slam:\n    excludes: [deps/slam/third_party]\n")
    sibling = target_for(repo, tmp_path / "state", name="deps-tinyfsm")

    _exclude, options = _sub_index_scope(sibling, repo, None, None)
    assert "deps/slam/third_party" not in (options["index_scope"].get("excludes") or [])

Activity · 7 steps
lines 105–105from clew.mcp_server.server import _sub_index_scopelines 106–106from clew.mcp_server.state import target_forlines 108–108repo = _repo(tmp_path / "repo")lines 109–109_declare(repo, " deps-slam:\n excludes: [deps/slam/third_party]\n")lines 110–110sibling = target_for(repo, tmp_path / "state", name="deps-tinyfsm")lines 112–112_exclude, options = _sub_index_scope(sibling, repo, None, None)lines 113–113assert "deps/slam/third_party" not in (options["index_scope"].get("excludes") or [])

test_a_declared_exclude_reaches_the_named_sub_index

None test_sub_index_declaration.test_a_declared_exclude_reaches_the_named_sub_index(Path tmp_path)

A declared exclude joins the derived ones for that sub-index.

tests/test_sub_index_declaration.py:74

Show on the map →

Called by none

Calls _declare, _repo, _sub_index_scope, target_for

Checks

  • assert scope["roots"] == ["deps/slam"]
  • assert "deps/slam/third_party" in scope["excludes"], scope
  • assert "deps/slam/deps/boost" in scope["excludes"], ("the derived child-tree excludes must survive the declared ones" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_declared_exclude_reaches_the_named_sub_index → _sub_index_scope → declared_sub_index_excludes
REQ-DDB-GUARD-012inferredtest_a_declared_exclude_reaches_the_named_sub_index → _sub_index_scope → declared_sub_index_excludes → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-002measuredtest_a_declared_exclude_reaches_the_named_sub_index → _sub_index_scope → derive_sub_indexes
REQ-DDB-MCP-001measuredtest_a_declared_exclude_reaches_the_named_sub_index → target_for
REQ-DDB-WIKI-054inferredtest_a_declared_exclude_reaches_the_named_sub_index → _sub_index_scope → declared_sub_index_excludes → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 24 lines
def test_a_declared_exclude_reaches_the_named_sub_index(tmp_path: Path) -> None:
    """THE MOTIVATING CASE. The parent trims a vendored tree it does not own, and the trim
    lands on top of the derived nested-tree excludes rather than replacing them — the child
    trees still belong to their own sub-indexes.

    @brief A declared exclude joins the derived ones for that sub-index.
    @version 1
    """
    from clew.mcp_server.server import _sub_index_scope
    from clew.mcp_server.state import target_for

    repo = _repo(tmp_path / "repo")
    _declare(repo, "  deps-slam:\n    excludes: [deps/slam/third_party]\n")
    target = target_for(repo, tmp_path / "state", name="deps-slam")

    _exclude, options = _sub_index_scope(target, repo, None, None)
    scope = options["index_scope"]
    assert scope["roots"] == ["deps/slam"]
    assert "deps/slam/third_party" in scope["excludes"], scope
    assert "deps/slam/deps/boost" in scope["excludes"], (
        "the derived child-tree excludes must survive the declared ones"
    )

Activity · 10 steps
lines 82–82from clew.mcp_server.server import _sub_index_scopelines 83–83from clew.mcp_server.state import target_forlines 85–85repo = _repo(tmp_path / "repo")lines 86–86_declare(repo, " deps-slam:\n excludes: [deps/slam/third_party]\n")lines 87–87target = target_for(repo, tmp_path / "state", name="deps-slam")lines 89–89_exclude, options = _sub_index_scope(target, repo, None, None)lines 90–90scope = options["index_scope"]lines 91–91assert scope["roots"] == ["deps/slam"]lines 92–92assert "deps/slam/third_party" in scope["excludes"], scopelines 93–95assert "deps/slam/deps/boost" in scope["excludes"], ( "the derived child-tree excludes must survive the declared ones" )

test_a_declared_name_that_is_not_a_sub_index_is_refused

None test_sub_index_declaration.test_a_declared_name_that_is_not_a_sub_index_is_refused(Path tmp_path)

An unknown sub-index name is refused, naming what is buildable.

tests/test_sub_index_declaration.py:136

Show on the map →

Called by none

Calls _declare, _repo, _sub_index_scope, target_for

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_declared_name_that_is_not_a_sub_index_is_refused → _sub_index_scope → declared_sub_index_excludes
REQ-DDB-GUARD-012inferredtest_a_declared_name_that_is_not_a_sub_index_is_refused → _sub_index_scope → declared_sub_index_excludes → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-002measuredtest_a_declared_name_that_is_not_a_sub_index_is_refused → _sub_index_scope → derive_sub_indexes
REQ-DDB-MCP-001measuredtest_a_declared_name_that_is_not_a_sub_index_is_refused → target_for
REQ-DDB-WIKI-054inferredtest_a_declared_name_that_is_not_a_sub_index_is_refused → _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_a_declared_name_that_is_not_a_sub_index_is_refused(tmp_path: Path) -> None:
    """AN ACCEPTED-BUT-UNREAD KEY IS THIS PROJECT'S MOST REPEATED DEFECT. A block naming a tree
    this repository does not vendor would sit in the file doing nothing while its author
    believed it was trimming a build — the same failure `_INDEX_SCOPE_KEYS` closes one level
    down, and the same one gh#5's reporter hit with `exclude:` for `excludes:`.

    @brief An unknown sub-index name is refused, naming what is buildable.
    @version 1
    """
    from clew.mcp_server.server import _sub_index_scope
    from clew.mcp_server.state import target_for

    repo = _repo(tmp_path / "repo")
    _declare(repo, "  deps-nosuchtree:\n    excludes: [x]\n")
    target = target_for(repo, tmp_path / "state", name="deps-slam")

    with pytest.raises(ValueError, match="deps-nosuchtree"):
        _sub_index_scope(target, repo, None, None)

Activity · 7 steps
lines 145–145from clew.mcp_server.server import _sub_index_scopelines 146–146from clew.mcp_server.state import target_forlines 148–148repo = _repo(tmp_path / "repo")lines 149–149_declare(repo, " deps-nosuchtree:\n excludes: [x]\n")lines 150–150target = target_for(repo, tmp_path / "state", name="deps-slam")lines 152–152with pytest.raises(ValueError, match="deps-nosuchtree")lines 153–153_sub_index_scope(target, repo, None, None)

test_a_stated_block_wins_over_the_declared_one

None test_sub_index_declaration.test_a_stated_block_wins_over_the_declared_one(Path tmp_path)

The stated block replaces the file's for that sub-index.

tests/test_sub_index_declaration.py:196

Show on the map →

Called by none

Calls _declare, _repo, _sub_index_scope, target_for

Checks

  • assert "deps/slam/from_call" in excludes, excludes
  • assert "deps/slam/from_file" not in excludes, ("a stated block must replace the declared one, or a declared exclude could never be " "withdrawn from the call" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_stated_block_wins_over_the_declared_one → _sub_index_scope → declared_sub_index_excludes
REQ-DDB-GUARD-012inferredtest_a_stated_block_wins_over_the_declared_one → _sub_index_scope → declared_sub_index_excludes → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-002measuredtest_a_stated_block_wins_over_the_declared_one → _sub_index_scope → derive_sub_indexes
REQ-DDB-MCP-001measuredtest_a_stated_block_wins_over_the_declared_one → target_for
REQ-DDB-WIKI-054inferredtest_a_stated_block_wins_over_the_declared_one → _sub_index_scope → declared_sub_index_excludes → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 23 lines
def test_a_stated_block_wins_over_the_declared_one(tmp_path: Path) -> None:
    """TIER 1 OVER TIER 2, which is what every other option does — and stating it has to mean
    REPLACING rather than adding, or an operator could never withdraw a declared exclude they
    disagree with.

    @brief The stated block replaces the file's for that sub-index.
    @version 1
    """
    from clew.mcp_server.server import _sub_index_scope
    from clew.mcp_server.state import target_for

    repo = _repo(tmp_path / "repo")
    _declare(repo, "  deps-slam:\n    excludes: [deps/slam/from_file]\n")
    target = target_for(repo, tmp_path / "state", name="deps-slam")
    options = {"sub_indexes": {"deps-slam": {"excludes": ["deps/slam/from_call"]}}}

    _exclude, merged = _sub_index_scope(target, repo, None, options)
    excludes = merged["index_scope"]["excludes"]
    assert "deps/slam/from_call" in excludes, excludes
    assert "deps/slam/from_file" not in excludes, (
        "a stated block must replace the declared one, or a declared exclude could never be "
        "withdrawn from the call"
    )

1 more lines, not shown

Activity · 10 steps
lines 204–204from clew.mcp_server.server import _sub_index_scopelines 205–205from clew.mcp_server.state import target_forlines 207–207repo = _repo(tmp_path / "repo")lines 208–208_declare(repo, " deps-slam:\n excludes: [deps/slam/from_file]\n")lines 209–209target = target_for(repo, tmp_path / "state", name="deps-slam")lines 210–210options = {"sub_indexes": {"deps-slam": {"excludes": ["deps/slam/from_call"]}}}lines 212–212_exclude, merged = _sub_index_scope(target, repo, None, options)lines 213–213excludes = merged["index_scope"]["excludes"]lines 214–214assert "deps/slam/from_call" in excludes, excludeslines 215–218assert "deps/slam/from_file" not in excludes, ( "a stated block must replace the declared one, or a declared exclude could never be " "withdrawn from the call" )

test_a_stated_sub_index_scope_reaches_the_build

None test_sub_index_declaration.test_a_stated_sub_index_scope_reaches_the_build(Path tmp_path)

A tier-1 stated block trims the sub-index it names.

tests/test_sub_index_declaration.py:175

Checks

  • assert "deps/slam/vendor" in merged["index_scope"]["excludes"], merged

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_stated_sub_index_scope_reaches_the_build → _sub_index_scope → declared_sub_index_excludes
REQ-DDB-GUARD-012inferredtest_a_stated_sub_index_scope_reaches_the_build → _sub_index_scope → declared_sub_index_excludes → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-002measuredtest_a_stated_sub_index_scope_reaches_the_build → _sub_index_scope → derive_sub_indexes
REQ-DDB-MCP-001measuredtest_a_stated_sub_index_scope_reaches_the_build → target_for
REQ-DDB-WIKI-054inferredtest_a_stated_sub_index_scope_reaches_the_build → _sub_index_scope → declared_sub_index_excludes → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 21 lines
def test_a_stated_sub_index_scope_reaches_the_build(tmp_path: Path) -> None:
    """REGISTERED IS NOT THE SAME AS READ. `sub_indexes` is an accepted build option because
    every declaration section must be reachable from the MCP surface — a tier-2-only section is
    unreachable for an operator who cannot edit the target's tree. An option that is accepted
    and then ignored is this project's most repeated defect, so the acceptance is pinned to the
    effect rather than to the registration.

    @brief A tier-1 stated block trims the sub-index it names.
    @version 1
    """
    from clew.mcp_server.server import _sub_index_scope
    from clew.mcp_server.state import target_for

    repo = _repo(tmp_path / "repo")
    target = target_for(repo, tmp_path / "state", name="deps-slam")
    options = {"sub_indexes": {"deps-slam": {"excludes": ["deps/slam/vendor"]}}}

    _exclude, merged = _sub_index_scope(target, repo, None, options)
    assert "deps/slam/vendor" in merged["index_scope"]["excludes"], merged

Activity · 7 steps
lines 185–185from clew.mcp_server.server import _sub_index_scopelines 186–186from clew.mcp_server.state import target_forlines 188–188repo = _repo(tmp_path / "repo")lines 189–189target = target_for(repo, tmp_path / "state", name="deps-slam")lines 190–190options = {"sub_indexes": {"deps-slam": {"excludes": ["deps/slam/vendor"]}}}lines 192–192_exclude, merged = _sub_index_scope(target, repo, None, options)lines 193–193assert "deps/slam/vendor" in merged["index_scope"]["excludes"], merged

test_an_unknown_key_inside_a_block_is_refused_by_name

None test_sub_index_declaration.test_an_unknown_key_inside_a_block_is_refused_by_name(Path tmp_path)

A misspelled key inside a sub-index block is refused.

tests/test_sub_index_declaration.py:156

Show on the map →

Called by none

Calls _declare, _repo, _sub_index_scope, target_for

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_an_unknown_key_inside_a_block_is_refused_by_name → _sub_index_scope → declared_sub_index_excludes
REQ-DDB-GUARD-012inferredtest_an_unknown_key_inside_a_block_is_refused_by_name → _sub_index_scope → declared_sub_index_excludes → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-002measuredtest_an_unknown_key_inside_a_block_is_refused_by_name → _sub_index_scope → derive_sub_indexes
REQ-DDB-MCP-001measuredtest_an_unknown_key_inside_a_block_is_refused_by_name → target_for
REQ-DDB-WIKI-054inferredtest_an_unknown_key_inside_a_block_is_refused_by_name → _sub_index_scope → declared_sub_index_excludes → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 19 lines
def test_an_unknown_key_inside_a_block_is_refused_by_name(tmp_path: Path) -> None:
    """THE ENTRY-LEVEL RULE `index_scope` ALREADY KEEPS, one section over: the section name is
    validated and the keys inside it must be too, or `exclude:` for `excludes:` parses to a
    perfectly valid mapping no consumer reads.

    @brief A misspelled key inside a sub-index block is refused.
    @version 1
    """
    from clew.mcp_server.server import _sub_index_scope
    from clew.mcp_server.state import target_for

    repo = _repo(tmp_path / "repo")
    _declare(repo, "  deps-slam:\n    exclude: [deps/slam/third_party]\n")
    target = target_for(repo, tmp_path / "state", name="deps-slam")

    with pytest.raises(ValueError, match="exclude"):
        _sub_index_scope(target, repo, None, None)

Activity · 7 steps
lines 164–164from clew.mcp_server.server import _sub_index_scopelines 165–165from clew.mcp_server.state import target_forlines 167–167repo = _repo(tmp_path / "repo")lines 168–168_declare(repo, " deps-slam:\n exclude: [deps/slam/third_party]\n")lines 169–169target = target_for(repo, tmp_path / "state", name="deps-slam")lines 171–171with pytest.raises(ValueError, match="exclude")lines 172–172_sub_index_scope(target, repo, None, None)

test_first_party_honours_its_own_declared_excludes

None test_sub_index_declaration.test_first_party_honours_its_own_declared_excludes(Path tmp_path)

A declared first-party exclude reaches the build.

tests/test_sub_index_declaration.py:116

Show on the map →

Called by none

Calls _declare, _repo, _sub_index_scope, target_for

Checks

  • assert "app/generated" in exclude, exclude
  • assert "build" in exclude, "the caller's own exclusions are still added to, never replaced"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_first_party_honours_its_own_declared_excludes → _sub_index_scope → declared_sub_index_excludes
REQ-DDB-GUARD-012inferredtest_first_party_honours_its_own_declared_excludes → _sub_index_scope → declared_sub_index_excludes → load_declaration → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-INDEX-002measuredtest_first_party_honours_its_own_declared_excludes → _sub_index_scope → derive_sub_indexes
REQ-DDB-MCP-001measuredtest_first_party_honours_its_own_declared_excludes → target_for
REQ-DDB-WIKI-054inferredtest_first_party_honours_its_own_declared_excludes → _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_first_party_honours_its_own_declared_excludes(tmp_path: Path) -> None:
    """FIRST-PARTY IS A SUB-INDEX LIKE ANY OTHER here, so the same block trims it. Its excludes
    join the caller's list rather than an `index_scope`, because that is how the first-party
    branch has always passed them.

    @brief A declared first-party exclude reaches the build.
    @version 1
    """
    from clew.mcp_server.server import _sub_index_scope
    from clew.mcp_server.state import target_for

    repo = _repo(tmp_path / "repo")
    _declare(repo, f"  {FIRST_PARTY_INDEX}:\n    excludes: [app/generated]\n")
    target = target_for(repo, tmp_path / "state", name=FIRST_PARTY_INDEX)

    exclude, _options = _sub_index_scope(target, repo, ["build"], None)
    assert "app/generated" in exclude, exclude
    assert "build" in exclude, "the caller's own exclusions are still added to, never replaced"

Activity · 8 steps
lines 124–124from clew.mcp_server.server import _sub_index_scopelines 125–125from clew.mcp_server.state import target_forlines 127–127repo = _repo(tmp_path / "repo")lines 128–128_declare(repo, f" {FIRST_PARTY_INDEX}:\n excludes: [app/generated]\n")lines 129–129target = target_for(repo, tmp_path / "state", name=FIRST_PARTY_INDEX)lines 131–131exclude, _options = _sub_index_scope(target, repo, ["build"], None)lines 132–132assert "app/generated" in exclude, excludelines 133–133assert "build" in exclude, "the caller's own exclusions are still added to, never replaced"