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
Checks
assert "deps/slam/third_party" not in (options["index_scope"].get("excludes") or [])
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_a_declaration_applies_only_to_the_sub_index_it_names → _sub_index_scope → declared_sub_index_excludes |
| REQ-DDB-GUARD-012 | inferred | test_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-002 | measured | test_a_declaration_applies_only_to_the_sub_index_it_names → _sub_index_scope → derive_sub_indexes |
| REQ-DDB-MCP-001 | measured | test_a_declaration_applies_only_to_the_sub_index_it_names → target_for |
| REQ-DDB-WIKI-054 | inferred | test_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
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
Checks
assert scope["roots"] == ["deps/slam"]assert "deps/slam/third_party" in scope["excludes"], scopeassert "deps/slam/deps/boost" in scope["excludes"], ("the derived child-tree excludes must survive the declared ones" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_a_declared_exclude_reaches_the_named_sub_index → _sub_index_scope → declared_sub_index_excludes |
| REQ-DDB-GUARD-012 | inferred | test_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-002 | measured | test_a_declared_exclude_reaches_the_named_sub_index → _sub_index_scope → derive_sub_indexes |
| REQ-DDB-MCP-001 | measured | test_a_declared_exclude_reaches_the_named_sub_index → target_for |
| REQ-DDB-WIKI-054 | inferred | test_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
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
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_a_declared_name_that_is_not_a_sub_index_is_refused → _sub_index_scope → declared_sub_index_excludes |
| REQ-DDB-GUARD-012 | inferred | test_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-002 | measured | test_a_declared_name_that_is_not_a_sub_index_is_refused → _sub_index_scope → derive_sub_indexes |
| REQ-DDB-MCP-001 | measured | test_a_declared_name_that_is_not_a_sub_index_is_refused → target_for |
| REQ-DDB-WIKI-054 | inferred | test_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
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
Checks
assert "deps/slam/from_call" in excludes, excludesassert "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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_a_stated_block_wins_over_the_declared_one → _sub_index_scope → declared_sub_index_excludes |
| REQ-DDB-GUARD-012 | inferred | test_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-002 | measured | test_a_stated_block_wins_over_the_declared_one → _sub_index_scope → derive_sub_indexes |
| REQ-DDB-MCP-001 | measured | test_a_stated_block_wins_over_the_declared_one → target_for |
| REQ-DDB-WIKI-054 | inferred | test_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
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
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_a_stated_sub_index_scope_reaches_the_build → _sub_index_scope → declared_sub_index_excludes |
| REQ-DDB-GUARD-012 | inferred | test_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-002 | measured | test_a_stated_sub_index_scope_reaches_the_build → _sub_index_scope → derive_sub_indexes |
| REQ-DDB-MCP-001 | measured | test_a_stated_sub_index_scope_reaches_the_build → target_for |
| REQ-DDB-WIKI-054 | inferred | test_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
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
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_an_unknown_key_inside_a_block_is_refused_by_name → _sub_index_scope → declared_sub_index_excludes |
| REQ-DDB-GUARD-012 | inferred | test_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-002 | measured | test_an_unknown_key_inside_a_block_is_refused_by_name → _sub_index_scope → derive_sub_indexes |
| REQ-DDB-MCP-001 | measured | test_an_unknown_key_inside_a_block_is_refused_by_name → target_for |
| REQ-DDB-WIKI-054 | inferred | test_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
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
Checks
assert "app/generated" in exclude, excludeassert "build" in exclude, "the caller's own exclusions are still added to, never replaced"
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-CONFIG-001 | measured | test_first_party_honours_its_own_declared_excludes → _sub_index_scope → declared_sub_index_excludes |
| REQ-DDB-GUARD-012 | inferred | test_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-002 | measured | test_first_party_honours_its_own_declared_excludes → _sub_index_scope → derive_sub_indexes |
| REQ-DDB-MCP-001 | measured | test_first_party_honours_its_own_declared_excludes → target_for |
| REQ-DDB-WIKI-054 | inferred | test_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"