test_scope.py

tests/test_scope.py

Tests for declaration-driven index scope derivation (`clew.scope`).

test_a_declared_exclude_outside_the_repository_is_dropped

None test_scope.test_a_declared_exclude_outside_the_repository_is_dropped(Path tmp_path)

An escaping declared exclude is dropped too, rather than silently matching nothing.

tests/test_scope.py:634

Checks

  • assert derived.source == sc.SOURCE_DECLARED
  • assert derived.excludes == (), (f"an exclude outside the repository must be dropped, not resolved; got {derived.excludes}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_declared_exclude_outside_the_repository_is_dropped → derive_scope
REQ-DDB-GUARD-012inferredtest_a_declared_exclude_outside_the_repository_is_dropped → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-014catalog
REQ-DDB-WIKI-054inferredtest_a_declared_exclude_outside_the_repository_is_dropped → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 24 lines
def test_a_declared_exclude_outside_the_repository_is_dropped(tmp_path: Path) -> None:
    """The same resolution bug on the quieter half. An exclude cannot leak a tree, but one
    pointing outside the repo silently excludes NOTHING while reading as honoured — the
    accepted-but-unread failure this module fixes everywhere else.

    @brief An escaping exclude does not reach the derived scope.
    @return None.
    @version 1
    """
    root = tmp_path / "repo"
    (root / "src").mkdir(parents=True)
    (tmp_path / "outside").mkdir()
    (root / ".clew.yaml").write_text(
        "index_scope:\n  roots: [src]\n  excludes:\n    - ../outside\n", encoding="utf-8"
    )

    derived = sc.derive_scope(root)

    assert derived.source == sc.SOURCE_DECLARED
    assert derived.excludes == (), (
        f"an exclude outside the repository must be dropped, not resolved; got {derived.excludes}"
    )

Activity · 7 steps
lines 643–643root = tmp_path / "repo"lines 644–644(root / "src").mkdir(parents=True)lines 645–645(tmp_path / "outside").mkdir()lines 646–648(root / ".clew.yaml").write_text( "index_scope:\n roots: [src]\n excludes:\n - ../outside\n", encoding="utf-8" )lines 650–650derived = sc.derive_scope(root)lines 652–652assert derived.source == sc.SOURCE_DECLAREDlines 653–655assert derived.excludes == (), ( f"an exclude outside the repository must be dropped, not resolved; got {derived.excludes}" )

test_a_declared_root_outside_the_repository_is_refused

None test_scope.test_a_declared_root_outside_the_repository_is_refused(Path tmp_path)

A declared root that escapes the repository is dropped, not indexed.

tests/test_scope.py:585

Checks

  • assert rejection is not None, f"{entry!r} escapes the repository and must be rejected"
  • assert all(sc._is_within(got, root.resolve()) for got in derived.roots), (f"{entry!r} put {derived.roots} outside {root} — the index would carry a tree " f"this repository never offered" )
  • assert sc.declared_scope_rejection(root, stated) is not None, (f"a STATED root of {entry!r} must be rejected exactly as a declared one is" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_declared_root_outside_the_repository_is_refused → declared_scope_rejection
REQ-DDB-CONFIG-005measured
REQ-DDB-GUARD-012inferredtest_a_declared_root_outside_the_repository_is_refused → declared_scope_rejection → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-007catalog
REQ-DDB-PIPE-014measured
REQ-DDB-QUERY-006catalog
REQ-DDB-WIKI-054inferredtest_a_declared_root_outside_the_repository_is_refused → all
Source · 45 lines
def test_a_declared_root_outside_the_repository_is_refused(tmp_path: Path) -> None:
    """H5, 1.1.0 SECURITY AUDIT. `roots:` is repo-relative by contract, but the derivation
    resolved each entry with `(root / entry).resolve()` and asked only whether it EXISTS. An
    absolute entry discards `root` entirely (`Path('/a') / '/etc'` is `/etc`), and `../` walks
    out, so a repository — or an MCP caller stating a scope for a repository it merely names —
    chose any readable directory on the machine as the indexed tree. The index is then served
    as that repository's content, with the paths of a tree the owner never offered.

    Dropped-and-reported rather than raised: `_existing_paths` already drops a root that does
    not exist, and an empty `roots` is the rejection the caller above already handles.

    @brief An absolute or parent-escaping declared root never reaches the scope.
    @return None.
    @version 1
    """
    root = tmp_path / "repo"
    (root / "src").mkdir(parents=True)
    outside = tmp_path / "outside"
    (outside / "secrets").mkdir(parents=True)

    for entry in (str(outside), "../outside", "src/../../outside"):
        (root / ".clew.yaml").write_text(
            f"index_scope:\n  roots:\n    - {entry}\n", encoding="utf-8"
        )

        rejection = sc.declared_scope_rejection(root)
        derived = sc.derive_scope(root)

        assert rejection is not None, f"{entry!r} escapes the repository and must be rejected"
        assert all(sc._is_within(got, root.resolve()) for got in derived.roots), (
            f"{entry!r} put {derived.roots} outside {root} — the index would carry a tree "
            f"this repository never offered"
        )

        ## AND THE TIER-1 STATED FORM, which is the reachable half: an MCP caller states a
        ## scope for a repository it merely NAMES, so this entry never passed an owner's hands
        ## at all. Both tiers go through one derivation, which is why one fix covers both —
        ## asserted rather than assumed, since the replay path (`_replay_manifest_statements`)
        ## re-enters the same function on every later build.
        stated = {"roots": [entry]}
        assert sc.declared_scope_rejection(root, stated) is not None, (
            f"a STATED root of {entry!r} must be rejected exactly as a declared one is"
        )

Activity · 12 steps
lines 600–600root = tmp_path / "repo"lines 601–601(root / "src").mkdir(parents=True)lines 602–602outside = tmp_path / "outside"lines 603–603(outside / "secrets").mkdir(parents=True)lines 605–605◇ for entry in (str(outside), "../outside", "src/../../outside")lines 606–608(root / ".clew.yaml").write_text( f"index_scope:\n roots:\n - {entry}\n", encoding="utf-8" )lines 610–610rejection = sc.declared_scope_rejection(root)lines 611–611derived = sc.derive_scope(root)lines 613–613assert rejection is not None, f"{entry!r} escapes the repository and must be rejected"lines 614–617assert all(sc._is_within(got, root.resolve()) for got in derived.roots), ( f"{entry!r} put {derived.roots} outside {root} — the index would carry a tree " f"this repository never offered" )lines 624–624stated = {"roots": [entry]}lines 625–627assert sc.declared_scope_rejection(root, stated) is not None, ( f"a STATED root of {entry!r} must be rejected exactly as a declared one is" )

test_a_gate_pattern_alone_derives_no_index_scope

None test_scope.test_a_gate_pattern_alone_derives_no_index_scope(Path tmp_path)

The gate's files: pattern must NOT supply index roots.

tests/test_scope.py:99

Show on the map →

Called by none

Calls _repo, _write, derive_scope

Checks

  • assert derived.source == sc.SOURCE_WHOLE_REPO
  • assert not derived.is_derived(), "the gate is not a declaration"
  • assert derived.roots == (root.resolve(),), "the gate's boundary is not an index boundary"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_gate_pattern_alone_derives_no_index_scope → derive_scope
REQ-DDB-GUARD-012inferredtest_a_gate_pattern_alone_derives_no_index_scope → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-014catalog
REQ-DDB-WIKI-054inferredtest_a_gate_pattern_alone_derives_no_index_scope → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 29 lines
def test_a_gate_pattern_alone_derives_no_index_scope(tmp_path: Path) -> None:
    """THE POINT OF THE THREE-TIER CHAIN. A `files:` regex answers what must be
    DOCUMENTED. Standing in for the index decision it narrowed the index to the
    quality bar — and, sitting above the whole-repo tier, it shadowed the fallback
    that would have covered the rest.

    So a repo whose only declaration is the gate derives NOTHING, and the resolution
    drops to the whole repository (gh#333 removed the Doxyfile tier in between). The
    `.c` file the gate exempts is the measurable consequence: it is out of the
    mandate and squarely inside the repo, so it must be inside the scope.

    `is_derived()` stays FALSE, and that is not a contradiction with the whole-repo
    tier having roots: it asks whether the repo DECLARED a boundary, which is what
    the callers gating on it (`propose`, `init`) actually want to know.

    @brief A doxygen-guard hook contributes no index roots.
    @version 2
    """
    root = _repo(tmp_path / "repo", _SIMPLE_CONFIG)
    _write(root / "src" / "a.c")
    _write(root / "vendor" / "huge" / "d.c")

    derived = sc.derive_scope(root)

    assert derived.source == sc.SOURCE_WHOLE_REPO
    assert not derived.is_derived(), "the gate is not a declaration"
    assert derived.roots == (root.resolve(),), "the gate's boundary is not an index boundary"

Activity · 7 steps
lines 117–117root = _repo(tmp_path / "repo", _SIMPLE_CONFIG)lines 118–118_write(root / "src" / "a.c")lines 119–119_write(root / "vendor" / "huge" / "d.c")lines 121–121derived = sc.derive_scope(root)lines 123–123assert derived.source == sc.SOURCE_WHOLE_REPOlines 124–124assert not derived.is_derived(), "the gate is not a declaration"lines 125–125assert derived.roots == (root.resolve(),), "the gate's boundary is not an index boundary"

test_a_repo_declaring_nothing_still_reports_absence

None test_scope.test_a_repo_declaring_nothing_still_reports_absence(Path tmp_path)

A genuinely absent declaration keeps its original wording.

tests/test_scope.py:495

Checks

  • assert derived.source == sc.SOURCE_WHOLE_REPO
  • assert "no index_scope is declared" in derived.reason, (f"a repo that declares nothing must still report absence; got: {derived.reason}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_repo_declaring_nothing_still_reports_absence → derive_scope
REQ-DDB-GUARD-012inferredtest_a_repo_declaring_nothing_still_reports_absence → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-014catalog
REQ-DDB-WIKI-054inferredtest_a_repo_declaring_nothing_still_reports_absence → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 21 lines
def test_a_repo_declaring_nothing_still_reports_absence(tmp_path: Path) -> None:
    """THE CONTROL. Every message above is a REPLACEMENT for the absence clause, so a check that
    only looked for the new wording would pass a version that had deleted the old one — and a
    repo that declares nothing genuinely has no index_scope, which is the common case and must
    keep saying so.

    @brief With no declaration at all, the reason still says none is declared.
    @return None.
    @version 1
    """
    root = tmp_path / "repo"
    (root / "src").mkdir(parents=True)

    derived = sc.derive_scope(root)

    assert derived.source == sc.SOURCE_WHOLE_REPO
    assert "no index_scope is declared" in derived.reason, (
        f"a repo that declares nothing must still report absence; got: {derived.reason}"
    )

Activity · 5 steps
lines 505–505root = tmp_path / "repo"lines 506–506(root / "src").mkdir(parents=True)lines 508–508derived = sc.derive_scope(root)lines 510–510assert derived.source == sc.SOURCE_WHOLE_REPOlines 511–513assert "no index_scope is declared" in derived.reason, ( f"a repo that declares nothing must still report absence; got: {derived.reason}" )

test_a_scope_that_could_not_ask_git_does_not_claim_it_excluded_ignores

None test_scope.test_a_scope_that_could_not_ask_git_does_not_claim_it_excluded_ignores(Path tmp_path)

A scope that could not ask git must not claim it excluded what git ignores.

tests/test_scope.py:662

Checks

  • assert "less the paths git ignores" not in scope.reason, (f"claims an exclusion that never happened: {scope.reason}" )
  • assert "not a git repository" in lowered or "could not" in lowered, (f"the reason must say the ignore list was unobtainable: {scope.reason}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_a_scope_that_could_not_ask_git_does_not_claim_it_excluded_ignores → whole_repo_scope
REQ-DDB-PIPE-014catalog
Source · 43 lines
def test_a_scope_that_could_not_ask_git_does_not_claim_it_excluded_ignores(
    tmp_path: Path,
) -> None:
    """`_gitignored_paths` returns `[]` on BOTH "git said nothing is ignored" and "git could not
    be asked at all" — a missing binary, or a tree that is not a repository. The second case
    excludes nothing, and the only signal is a WARNING nobody reads after a build reports
    success.

    MEANWHILE `DerivedScope.reason` STATES THE OPPOSITE. It is built unconditionally and says
    the scope is the whole repository "less the paths git ignores and the dot/cache
    directories". When git was never successfully asked, that sentence is FALSE: nothing
    ignored was excluded, and the build log asserts that something was.

    This is the module's own rule turned on itself. `_gitignored_paths`'s docstring already
    concedes "a silently wider index is the outcome this project keeps paying for" — so the
    author knew, and the reason string still claims the exclusion happened.

    AN EMPTY IGNORE LIST AND AN UNASKABLE ONE ARE DIFFERENT FACTS. A reporter whose index is
    mysteriously wide needs to know which one they have, and the reason string is where they
    will look.

    @brief An unaskable ignore list is disclosed, not asserted away.
    @return None.
    @version 1
    """
    ## A DIRECTORY THAT IS NOT A GIT REPOSITORY, which is the reachable half of the fallback:
    ## `git ls-files` exits non-zero and the function returns `[]`. The missing-binary half
    ## takes the same branch and needs no second fixture.
    root = tmp_path / "notarepo"
    (root / "src").mkdir(parents=True)
    (root / "src" / "a.c").write_text("int main(void){return 0;}\n", encoding="utf-8")

    scope = sc.whole_repo_scope(root)

    assert "less the paths git ignores" not in scope.reason, (
        f"claims an exclusion that never happened: {scope.reason}"
    )
    lowered = scope.reason.lower()
    assert "not a git repository" in lowered or "could not" in lowered, (
        f"the reason must say the ignore list was unobtainable: {scope.reason}"
    )

Activity · 7 steps
lines 690–690root = tmp_path / "notarepo"lines 691–691(root / "src").mkdir(parents=True)lines 692–692(root / "src" / "a.c").write_text("int main(void){return 0;}\n", encoding="utf-8")lines 694–694scope = sc.whole_repo_scope(root)lines 696–698assert "less the paths git ignores" not in scope.reason, ( f"claims an exclusion that never happened: {scope.reason}" )lines 699–699lowered = scope.reason.lower()lines 700–702assert "not a git repository" in lowered or "could not" in lowered, ( f"the reason must say the ignore list was unobtainable: {scope.reason}" )

test_an_index_scope_declaration_is_what_yields_roots

None test_scope.test_an_index_scope_declaration_is_what_yields_roots(Path tmp_path)

A declaration is the only tier that yields index roots.

tests/test_scope.py:340

Show on the map →

Called by none

Calls _repo_gating_only_src, derive_scope

Checks

  • assert sc.derive_scope(root).roots == (root.resolve(),), "the gate declares no boundary"
  • assert declared.source == sc.SOURCE_DECLARED
  • assert sorted(p.name for p in declared.roots) == ["src", "tests", "vendor"]
  • assert declared.is_derived() is True, "a declared scope is the only tier that narrows"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_an_index_scope_declaration_is_what_yields_roots → derive_scope
REQ-DDB-GUARD-012inferredtest_an_index_scope_declaration_is_what_yields_roots → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-014catalog
REQ-DDB-WIKI-054inferredtest_an_index_scope_declaration_is_what_yields_roots → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 27 lines
def test_an_index_scope_declaration_is_what_yields_roots(tmp_path: Path) -> None:
    """#57: index scope used to be identical to GATE scope, but they answer different
    questions — the gate says what MUST be documented, the index says what should be
    reasonable-about. Coupling them forced a repo to loosen its quality bar to widen
    its graph. Here the gate covers `src/` alone while `vendor/` and `tests/` are the
    trees a reader wants; the declaration is what lets them differ.

    @brief Declared roots override, and the gate alone yields none.
    @version 2
    """
    root = tmp_path / "repo"
    root.mkdir()
    _repo_gating_only_src(root)

    ## The gate alone yields the WHOLE REPO (gh#333), not nothing — so the thing that
    ## distinguishes a declaration is that it NARROWS, which is the assertion below.
    assert sc.derive_scope(root).roots == (root.resolve(),), "the gate declares no boundary"

    (root / ".clew.yaml").write_text(
        "index_scope:\n  roots: [src, vendor, tests]\n", encoding="utf-8"
    )
    declared = sc.derive_scope(root)
    assert declared.source == sc.SOURCE_DECLARED
    assert sorted(p.name for p in declared.roots) == ["src", "tests", "vendor"]
    assert declared.is_derived() is True, "a declared scope is the only tier that narrows"

Activity · 9 steps
lines 350–350root = tmp_path / "repo"lines 351–351root.mkdir()lines 352–352_repo_gating_only_src(root)lines 356–356assert sc.derive_scope(root).roots == (root.resolve(),), "the gate declares no boundary"lines 358–360(root / ".clew.yaml").write_text( "index_scope:\n roots: [src, vendor, tests]\n", encoding="utf-8" )lines 361–361declared = sc.derive_scope(root)lines 362–362assert declared.source == sc.SOURCE_DECLAREDlines 363–363assert sorted(p.name for p in declared.roots) == ["src", "tests", "vendor"]lines 364–364assert declared.is_derived() is True, "a declared scope is the only tier that narrows"

test_an_index_scope_with_no_roots_says_so_rather_than_claiming_none_is_declared

None test_scope.test_an_index_scope_with_no_roots_says_so_rather_than_claiming_none_is_declared(Path tmp_path)

A present-but-unusable index_scope must not report as an ABSENT one.

tests/test_scope.py:416

Checks

  • assert derived.source == sc.SOURCE_WHOLE_REPO, "a rootless scope must still fall back"
  • assert "no index_scope is declared" not in derived.reason, (f"the reason still claims the declaration is ABSENT while the loader logged that it was " f"read — that is the contradiction this test exists for. Got: {derived.reason}" )
  • assert "roots" in derived.reason and "REPLACES" in derived.reason, (f"the reason must say WHY it was unusable and that `roots` replaces the scope, which is " f"the sharp edge; got: {derived.reason}" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_an_index_scope_with_no_roots_says_so_rather_than_claiming_none_is_declared → derive_scope
REQ-DDB-GUARD-012inferredtest_an_index_scope_with_no_roots_says_so_rather_than_claiming_none_is_declared → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-014catalog
REQ-DDB-WIKI-054inferredtest_an_index_scope_with_no_roots_says_so_rather_than_claiming_none_is_declared → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 39 lines
def test_an_index_scope_with_no_roots_says_so_rather_than_claiming_none_is_declared(
    tmp_path: Path,
) -> None:
    """gh#5, AND THE DEFECT IS A CONTRADICTION RATHER THAN A WRONG SCOPE. The reporter wrote an
    `index_scope:` block, and one build told them both things at once:

        INFO    declaration: <file> declares index_scope
        WARNING scope: indexing the WHOLE repository — no index_scope is declared for this repo

    The behaviour was right — `roots` REPLACES the scope and is required, so a block carrying
    only exclusions is not a usable scope — but nothing distinguished found-but-rejected from
    absent. They spent a round trip deciding whether to fix their YAML or file a bug, and only
    `propose_declaration` settled it: a tool nobody reaches for after a build reports success.

    ASSERTS THE ABSENCE CLAUSE IS GONE, not merely that a reason exists. Appending the real cause
    while still saying "no index_scope is declared" would leave the contradiction in place, which
    is why `rejected` REPLACES that clause instead of adding to it.

    @brief A rootless index_scope is reported as rejected, not as absent.
    @return None.
    @version 1
    """
    root = tmp_path / "repo"
    (root / "src").mkdir(parents=True)
    (root / ".clew.yaml").write_text("index_scope:\n  excludes:\n    - src\n", encoding="utf-8")

    derived = sc.derive_scope(root)

    assert derived.source == sc.SOURCE_WHOLE_REPO, "a rootless scope must still fall back"
    assert "no index_scope is declared" not in derived.reason, (
        f"the reason still claims the declaration is ABSENT while the loader logged that it was "
        f"read — that is the contradiction this test exists for. Got: {derived.reason}"
    )
    assert "roots" in derived.reason and "REPLACES" in derived.reason, (
        f"the reason must say WHY it was unusable and that `roots` replaces the scope, which is "
        f"the sharp edge; got: {derived.reason}"
    )

Activity · 7 steps
lines 438–438root = tmp_path / "repo"lines 439–439(root / "src").mkdir(parents=True)lines 440–440(root / ".clew.yaml").write_text("index_scope:\n excludes:\n - src\n", encoding="utf-8")lines 442–442derived = sc.derive_scope(root)lines 444–444assert derived.source == sc.SOURCE_WHOLE_REPO, "a rootless scope must still fall back"lines 445–448assert "no index_scope is declared" not in derived.reason, ( f"the reason still claims the declaration is ABSENT while the loader logged that it was " f"read — that is the contradiction this test exists for. Got: {derived.reason}" )lines 449–452assert "roots" in derived.reason and "REPLACES" in derived.reason, ( f"the reason must say WHY it was unusable and that `roots` replaces the scope, which is " f"the sharp edge; got: {derived.reason}" )

test_an_indexed_tree_that_looks_vendored_is_named_with_the_remedy

None test_scope.test_an_indexed_tree_that_looks_vendored_is_named_with_the_remedy(Path tmp_path)

A tree that looks vendored and IS indexed is named, with the remedy.

tests/test_scope.py:723

Show on the map →

Called by none

Calls _src, whole_repo_scope

Checks

  • assert "third_party" in reason, f"the vendored-looking tree is not named: {reason}"
  • assert "index_scope" in reason, f"no remedy is given: {reason}"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_an_indexed_tree_that_looks_vendored_is_named_with_the_remedy → whole_repo_scope
REQ-DDB-PIPE-014catalog
Source · 26 lines
def test_an_indexed_tree_that_looks_vendored_is_named_with_the_remedy(tmp_path: Path) -> None:
    """A COMMITTED DEPENDENCY TREE IS EXCLUDED BY NO IGNORE RULE. `_gitignored_paths` asks git
    for `--others`, i.e. UNTRACKED files only, so a vendored library someone checked in is
    indexed in full and nothing says so — the index is silently dominated by somebody else's
    code.

    DISCLOSED, NOT EXCLUDED, by owner ruling. clew cannot tell a vendored tree from
    first-party code sharing a conventional name, and excluding by name would silently remove
    real source — absence reported as emptiness, the failure this whole patch addresses. The
    repository can already narrow its own scope with `index_scope`; what was missing is being
    TOLD to.

    @brief A vendored-looking indexed tree is named and the fix is given.
    @return None.
    @version 1
    """
    root = tmp_path / "repo"
    _src(root, "src/main.c")
    _src(root, "third_party/zlib/inflate.c")

    reason = sc.whole_repo_scope(root).reason

    assert "third_party" in reason, f"the vendored-looking tree is not named: {reason}"
    assert "index_scope" in reason, f"no remedy is given: {reason}"

Activity · 6 steps
lines 739–739root = tmp_path / "repo"lines 740–740_src(root, "src/main.c")lines 741–741_src(root, "third_party/zlib/inflate.c")lines 743–743reason = sc.whole_repo_scope(root).reasonlines 745–745assert "third_party" in reason, f"the vendored-looking tree is not named: {reason}"lines 746–746assert "index_scope" in reason, f"no remedy is given: {reason}"

test_an_unknown_key_inside_index_scope_refuses_by_name

None test_scope.test_an_unknown_key_inside_index_scope_refuses_by_name(Path tmp_path)

A misspelled key INSIDE index_scope must refuse by name, not be silently ignored.

tests/test_scope.py:459

Checks

  • assert derived.source == sc.SOURCE_WHOLE_REPO, ("a declaration carrying an unread key must NOT be applied as though it were understood — " "silently honouring `roots` while dropping `exclude` is the half-applied scope change " "that reads as success" )
  • assert "exclude" in derived.reason, "the reason must name the offending key"
  • assert "excludes" in derived.reason, "and the accepted spelling, so the fix is one edit"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_an_unknown_key_inside_index_scope_refuses_by_name → derive_scope
REQ-DDB-GUARD-012inferredtest_an_unknown_key_inside_index_scope_refuses_by_name → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-014catalog
REQ-DDB-WIKI-054inferredtest_an_unknown_key_inside_index_scope_refuses_by_name → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 32 lines
def test_an_unknown_key_inside_index_scope_refuses_by_name(tmp_path: Path) -> None:
    """FOUND WHILE FIXING gh#5 AND IT IS THE WORSE HALF. Section NAMES were validated against
    KNOWN_SECTIONS; the keys inside a section were not. So `exclude:` for `excludes:` parsed to a
    valid mapping that no consumer ever read — the reporter's own YAML used the singular, and
    even with `roots` supplied it would have excluded nothing while reporting success.

    That is precisely the shape this project has shipped most often: an accepted-but-unread key.
    `key_arg_idx` for `key_arg_index` silently keyed dataflow off argument 0; a `--declare`'d
    `preprocessor:` section validated, logged as applied, and resolved as though nobody had
    stated it. Fail closed at the ENTRY level, and name the accepted keys so the fix is one edit.

    @brief An unknown inner key is refused and both it and the accepted set are named.
    @return None.
    @version 1
    """
    root = tmp_path / "repo"
    (root / "src").mkdir(parents=True)
    (root / ".clew.yaml").write_text(
        "index_scope:\n  roots:\n    - src\n  exclude:\n    - src/gen\n", encoding="utf-8"
    )

    derived = sc.derive_scope(root)

    assert derived.source == sc.SOURCE_WHOLE_REPO, (
        "a declaration carrying an unread key must NOT be applied as though it were understood — "
        "silently honouring `roots` while dropping `exclude` is the half-applied scope change "
        "that reads as success"
    )
    assert "exclude" in derived.reason, "the reason must name the offending key"
    assert "excludes" in derived.reason, "and the accepted spelling, so the fix is one edit"

Activity · 7 steps
lines 474–474root = tmp_path / "repo"lines 475–475(root / "src").mkdir(parents=True)lines 476–478(root / ".clew.yaml").write_text( "index_scope:\n roots:\n - src\n exclude:\n - src/gen\n", encoding="utf-8" )lines 480–480derived = sc.derive_scope(root)lines 482–486assert derived.source == sc.SOURCE_WHOLE_REPO, ( "a declaration carrying an unread key must NOT be applied as though it were understood — " "silently honouring `roots` while dropping `exclude` is the half-applied scope change " "that reads as success" )lines 487–487assert "exclude" in derived.reason, "the reason must name the offending key"lines 488–488assert "excludes" in derived.reason, "and the accepted spelling, so the fix is one edit"

test_cli_apply_scope_default_replaces_the_doxyfile_input

None test_scope.test_cli_apply_scope_default_replaces_the_doxyfile_input(Path tmp_path)

The parser default is from-guard, so a bare invocation indexes the whole repo.

tests/test_scope.py:242

Show on the map →

Called by none

Calls _apply_scope, _args, _repo, _write

Checks

  • assert args.scope == sc.SCOPE_FROM_GUARD, ("gh#333 flipped the default, and the 22->6 collapse must not have moved it: the " "parser default is the ONLY declaration of it left in the tool" )
  • assert args.replace_input is True
  • assert args.extra_input == [str(root.resolve())]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_cli_apply_scope_default_replaces_the_doxyfile_input → _apply_scope → declared_scope_rejection
REQ-DDB-GUARD-012inferredtest_cli_apply_scope_default_replaces_the_doxyfile_input → _apply_scope → declared_scope_rejection → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-014catalog
REQ-DDB-WIKI-054inferredtest_cli_apply_scope_default_replaces_the_doxyfile_input → _apply_scope → declared_scope_rejection → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 29 lines
def test_cli_apply_scope_default_replaces_the_doxyfile_input(tmp_path: Path) -> None:
    """THE INVERSION gh#333 FIXES, asserted from the CLI surface. A repo that ships a
    Doxyfile and declares no index scope used to keep the Doxyfile's INPUT — its
    published-API subset — while an otherwise identical repo WITHOUT a Doxyfile got
    its whole tree. The default now replaces INPUT in both cases.

    `replace_input` is the load-bearing assertion, not `extra_input`: it is what
    tells the Doxyfile writer to discard the target's own INPUT rather than prepend
    to it, so a test that checked only the root list would pass against a build that
    indexed the union of both.

    @brief The default scope replaces a shipped Doxyfile's INPUT with the repo root.
    @version 1
    """
    from clew.cli import _apply_scope

    root = _repo(tmp_path / "repo", _SIMPLE_CONFIG)
    _write(root / "src" / "a.c")
    args = _args(tmp_path / "clew.db", doxyfile=str(root / "Doxyfile"))
    _apply_scope(args, root)

    assert args.scope == sc.SCOPE_FROM_GUARD, (
        "gh#333 flipped the default, and the 22->6 collapse must not have moved it: the "
        "parser default is the ONLY declaration of it left in the tool"
    )
    assert args.replace_input is True
    assert args.extra_input == [str(root.resolve())]

Activity · 8 steps
lines 256–256from clew.cli import _apply_scopelines 258–258root = _repo(tmp_path / "repo", _SIMPLE_CONFIG)lines 259–259_write(root / "src" / "a.c")lines 260–260args = _args(tmp_path / "clew.db", doxyfile=str(root / "Doxyfile"))lines 261–261_apply_scope(args, root)lines 263–266assert args.scope == sc.SCOPE_FROM_GUARD, ( "gh#333 flipped the default, and the 22->6 collapse must not have moved it: the " "parser default is the ONLY declaration of it left in the tool" )lines 267–267assert args.replace_input is Truelines 268–268assert args.extra_input == [str(root.resolve())]

test_cli_apply_scope_doxyfile_is_inert

None test_scope.test_cli_apply_scope_doxyfile_is_inert(Path tmp_path)

A stated doxyfile scope is an EXPLICIT opt-out and leaves the build args untouched.

tests/test_scope.py:206

Show on the map →

Called by none

Calls _apply_scope, _args, _repo, _write

Checks

  • assert args.scope == sc.SCOPE_DOXYFILE
  • assert args.replace_input is False
  • assert args.extra_input is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001inferredtest_cli_apply_scope_doxyfile_is_inert → _apply_scope → declared_scope_rejection
REQ-DDB-GUARD-012inferredtest_cli_apply_scope_doxyfile_is_inert → _apply_scope → declared_scope_rejection → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-014catalog
REQ-DDB-WIKI-054inferredtest_cli_apply_scope_doxyfile_is_inert → _apply_scope → declared_scope_rejection → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 34 lines
def test_cli_apply_scope_doxyfile_is_inert(tmp_path: Path) -> None:
    """gh#333 flipped the DEFAULT to `from-guard`, and this is the surviving narrow
    path: an operator who passes `--scope doxyfile` gets the Doxyfile's own INPUT and
    no derivation at all.

    Stated EXPLICITLY here rather than relying on the parser default, which is the
    whole point of the flip — a test that took the default would have silently
    started asserting the new behaviour under the old name.

    THE FLAG IS GONE AND THE VALUE IS NOT (22->6 collapse). `doxyfile` scope is build
    MECHANICS, not a declaration, so it has no section and never should; it stays reachable
    on the typed surface (`build_index(scope=…)`, `index(action='refresh', scope=…)`) and is
    stated here on the dest those go through. Deleting the value with the flag would have
    removed the only opt-out from gh#333's whole-repo default.

    @brief An explicit doxyfile scope applies no derived roots.
    @version 3
    """
    from clew.cli import _apply_scope

    root = _repo(tmp_path / "repo", _SIMPLE_CONFIG)
    _write(root / "src" / "a.c")
    args = _args(
        tmp_path / "clew.db",
        doxyfile=str(root / "Doxyfile"),
        scope=sc.SCOPE_DOXYFILE,
    )
    _apply_scope(args, root)

    assert args.scope == sc.SCOPE_DOXYFILE
    assert args.replace_input is False
    assert args.extra_input is None

Activity · 8 steps
lines 224–224from clew.cli import _apply_scopelines 226–226root = _repo(tmp_path / "repo", _SIMPLE_CONFIG)lines 227–227_write(root / "src" / "a.c")lines 228–232args = _args( tmp_path / "clew.db", doxyfile=str(root / "Doxyfile"), scope=sc.SCOPE_DOXYFILE, )lines 233–233_apply_scope(args, root)lines 235–235assert args.scope == sc.SCOPE_DOXYFILElines 236–236assert args.replace_input is Falselines 237–237assert args.extra_input is None

test_cli_apply_scope_indexes_the_whole_repo_without_a_declaration

None test_scope.test_cli_apply_scope_indexes_the_whole_repo_without_a_declaration(Path tmp_path)

A repo with no declaration gets the whole repo under from-guard.

tests/test_scope.py:273

Show on the map →

Called by none

Calls _apply_scope, _args, _write

Checks

  • assert args.replace_input is True
  • assert args.extra_input == [str(root.resolve())]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_cli_apply_scope_indexes_the_whole_repo_without_a_declaration → _apply_scope → declared_scope_rejection
REQ-DDB-GUARD-012inferredtest_cli_apply_scope_indexes_the_whole_repo_without_a_declaration → _apply_scope → declared_scope_rejection → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-014catalog
REQ-DDB-WIKI-054inferredtest_cli_apply_scope_indexes_the_whole_repo_without_a_declaration → _apply_scope → declared_scope_rejection → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 24 lines
def test_cli_apply_scope_indexes_the_whole_repo_without_a_declaration(tmp_path: Path) -> None:
    """The undeclared branch must not half-apply. It used to `return` before
    replacing anything, handing INPUT back to the Doxyfile; gh#333 makes it fold a
    real whole-repo scope, so `replace_input` is True and the repo root is the root
    list.

    @brief An undeclared repo folds the whole-repo scope into the build args.
    @version 2
    """
    from clew.cli import _apply_scope

    root = tmp_path / "repo"
    _write(root / "src" / "a.c")
    args = _args(
        tmp_path / "clew.db",
        doxyfile=str(root / "Doxyfile"),
        scope=sc.SCOPE_FROM_GUARD,
    )
    _apply_scope(args, root)

    assert args.replace_input is True
    assert args.extra_input == [str(root.resolve())]

Activity · 7 steps
lines 282–282from clew.cli import _apply_scopelines 284–284root = tmp_path / "repo"lines 285–285_write(root / "src" / "a.c")lines 286–290args = _args( tmp_path / "clew.db", doxyfile=str(root / "Doxyfile"), scope=sc.SCOPE_FROM_GUARD, )lines 291–291_apply_scope(args, root)lines 293–293assert args.replace_input is Truelines 294–294assert args.extra_input == [str(root.resolve())]

test_cli_apply_scope_refuses_a_rejected_declaration

None test_scope.test_cli_apply_scope_refuses_a_rejected_declaration(Path tmp_path)

A rejected declaration refuses the build rather than silently widening it.

tests/test_scope.py:555

Show on the map →

Called by none

Calls _apply_scope, _args, _write

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_cli_apply_scope_refuses_a_rejected_declaration → _apply_scope → declared_scope_rejection
REQ-DDB-GUARD-012inferredtest_cli_apply_scope_refuses_a_rejected_declaration → _apply_scope → declared_scope_rejection → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-014catalog
REQ-DDB-WIKI-054inferredtest_cli_apply_scope_refuses_a_rejected_declaration → _apply_scope → declared_scope_rejection → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 26 lines
def test_cli_apply_scope_refuses_a_rejected_declaration(tmp_path: Path) -> None:
    """FIELD-REPORTED: an excludes-only `.clew.yaml` — written by an operator trying to
    keep a 1.2GB vendored tree out of the index — was silently absorbed into the
    whole-repo tier (a buildlog WARNING, then the widest possible scope anyway), and cost
    a real build a 900s doxygen timeout under exactly the tree the declaration was trying
    to exclude. `_apply_scope` must now refuse instead, before doxygen ever runs.

    @brief An excludes-only declaration makes `_apply_scope` exit rather than fold.
    @return None.
    @version 1
    """
    from clew.cli import _apply_scope

    root = tmp_path / "repo"
    _write(root / "src" / "a.c")
    (root / ".clew.yaml").write_text("index_scope:\n  excludes:\n    - src\n", encoding="utf-8")
    args = _args(
        tmp_path / "clew.db",
        doxyfile=str(root / "Doxyfile"),
        scope=sc.SCOPE_FROM_GUARD,
    )

    with pytest.raises(SystemExit):
        _apply_scope(args, root)

Activity · 7 steps
lines 566–566from clew.cli import _apply_scopelines 568–568root = tmp_path / "repo"lines 569–569_write(root / "src" / "a.c")lines 570–570(root / ".clew.yaml").write_text("index_scope:\n excludes:\n - src\n", encoding="utf-8")lines 571–575args = _args( tmp_path / "clew.db", doxyfile=str(root / "Doxyfile"), scope=sc.SCOPE_FROM_GUARD, )lines 577–577with pytest.raises(SystemExit)lines 578–578_apply_scope(args, root)

test_cli_apply_scope_replaces_input

None test_scope.test_cli_apply_scope_replaces_input(Path tmp_path)

--scope from-guard folds the declared roots into the build arguments.

tests/test_scope.py:179

Show on the map →

Called by none

Calls _apply_scope, _args, _repo, _write

Checks

  • assert args.replace_input is True
  • assert args.extra_input == [str(root.resolve() / "src"), "/elsewhere"]

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_cli_apply_scope_replaces_input → _apply_scope → declared_scope_rejection
REQ-DDB-GUARD-012inferredtest_cli_apply_scope_replaces_input → _apply_scope → declared_scope_rejection → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-014catalog
REQ-DDB-WIKI-054inferredtest_cli_apply_scope_replaces_input → _apply_scope → declared_scope_rejection → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 25 lines
def test_cli_apply_scope_replaces_input(tmp_path: Path) -> None:
    """The declared roots become the INPUT list (replace_input), with any
    explicit --extra-input appended on top rather than discarded.

    @brief A declared index scope becomes the build's INPUT.
    @version 2
    """
    from clew.cli import _apply_scope

    root = _repo(tmp_path / "repo", _SIMPLE_CONFIG)
    _write(root / "src" / "a.c")
    (root / ".clew.yaml").write_text("index_scope:\n  roots: [src]\n", encoding="utf-8")

    args = _args(
        tmp_path / "clew.db",
        doxyfile=str(root / "Doxyfile"),
        scope=sc.SCOPE_FROM_GUARD,
        extra_input=["/elsewhere"],
    )
    _apply_scope(args, root)

    assert args.replace_input is True
    assert args.extra_input == [str(root.resolve() / "src"), "/elsewhere"]

Activity · 8 steps
lines 186–186from clew.cli import _apply_scopelines 188–188root = _repo(tmp_path / "repo", _SIMPLE_CONFIG)lines 189–189_write(root / "src" / "a.c")lines 190–190(root / ".clew.yaml").write_text("index_scope:\n roots: [src]\n", encoding="utf-8")lines 192–197args = _args( tmp_path / "clew.db", doxyfile=str(root / "Doxyfile"), scope=sc.SCOPE_FROM_GUARD, extra_input=["/elsewhere"], )lines 198–198_apply_scope(args, root)lines 200–200assert args.replace_input is Truelines 201–201assert args.extra_input == [str(root.resolve() / "src"), "/elsewhere"]

test_declared_index_scope_drops_paths_that_do_not_exist

None test_scope.test_declared_index_scope_drops_paths_that_do_not_exist(Path tmp_path)

A stale declared root is dropped rather than passed to doxygen.

tests/test_scope.py:369

Show on the map →

Called by none

Calls _repo_gating_only_src, derive_scope

Checks

  • assert [p.name for p in scope.roots] == ["src"]
  • assert scope.excludes == ()

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_declared_index_scope_drops_paths_that_do_not_exist → derive_scope
REQ-DDB-GUARD-012inferredtest_declared_index_scope_drops_paths_that_do_not_exist → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-014catalog
REQ-DDB-WIKI-054inferredtest_declared_index_scope_drops_paths_that_do_not_exist → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 18 lines
def test_declared_index_scope_drops_paths_that_do_not_exist(tmp_path: Path) -> None:
    """A stale entry must not reach doxygen, which would report a confusing
    'input not found'. It is dropped with a warning instead.

    @brief Non-existent declared roots and excludes are dropped.
    @version 2
    """
    root = tmp_path / "repo"
    root.mkdir()
    _repo_gating_only_src(root)
    (root / ".clew.yaml").write_text(
        "index_scope:\n  roots: [src, gone]\n  excludes: [also_gone]\n", encoding="utf-8"
    )
    scope = sc.derive_scope(root)
    assert [p.name for p in scope.roots] == ["src"]
    assert scope.excludes == ()

Activity · 7 steps
lines 376–376root = tmp_path / "repo"lines 377–377root.mkdir()lines 378–378_repo_gating_only_src(root)lines 379–381(root / ".clew.yaml").write_text( "index_scope:\n roots: [src, gone]\n excludes: [also_gone]\n", encoding="utf-8" )lines 382–382scope = sc.derive_scope(root)lines 383–383assert [p.name for p in scope.roots] == ["src"]lines 384–384assert scope.excludes == ()

test_declared_scope_rejection_reports_without_falling_back

None test_scope.test_declared_scope_rejection_reports_without_falling_back(Path tmp_path)

declared_scope_rejection reports the reason without derive_scope's fallback.

tests/test_scope.py:520

Checks

  • assert rejection is not None
  • assert "roots" in rejection and "REPLACES" in rejection
  • assert sc.declared_scope_rejection(plain) is None
  • assert sc.declared_scope_rejection(usable) is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_declared_scope_rejection_reports_without_falling_back → declared_scope_rejection
REQ-DDB-GUARD-012inferredtest_declared_scope_rejection_reports_without_falling_back → declared_scope_rejection → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-014catalog
REQ-DDB-WIKI-054inferredtest_declared_scope_rejection_reports_without_falling_back → declared_scope_rejection → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 31 lines
def test_declared_scope_rejection_reports_without_falling_back(tmp_path: Path) -> None:
    """THE SEPARATE, BUILD-TIME CHECK a caller who can still refuse uses — `derive_scope`
    itself keeps absorbing a rejected declaration into the whole-repo tier for every other
    caller (the test right above this one asserts exactly that, unchanged). This one is
    for the NEW build-time guard, `_apply_scope`, to consult before committing to a scope.

    @brief An excludes-only declaration is reported as rejected by name.
    @return None.
    @version 1
    """
    root = tmp_path / "repo"
    (root / "src").mkdir(parents=True)
    (root / ".clew.yaml").write_text("index_scope:\n  excludes:\n    - src\n", encoding="utf-8")

    rejection = sc.declared_scope_rejection(root)

    assert rejection is not None
    assert "roots" in rejection and "REPLACES" in rejection

    ## AND THE CONTROL: a repo with no declaration at all, or a usable one, is None —
    ## not "rejected", which would make every ordinary repo refuse to build.
    plain = tmp_path / "plain"
    (plain / "src").mkdir(parents=True)
    assert sc.declared_scope_rejection(plain) is None

    usable = tmp_path / "usable"
    (usable / "src").mkdir(parents=True)
    (usable / ".clew.yaml").write_text("index_scope:\n  roots: [src]\n", encoding="utf-8")
    assert sc.declared_scope_rejection(usable) is None

Activity · 13 steps
lines 530–530root = tmp_path / "repo"lines 531–531(root / "src").mkdir(parents=True)lines 532–532(root / ".clew.yaml").write_text("index_scope:\n excludes:\n - src\n", encoding="utf-8")lines 534–534rejection = sc.declared_scope_rejection(root)lines 536–536assert rejection is not Nonelines 537–537assert "roots" in rejection and "REPLACES" in rejectionlines 541–541plain = tmp_path / "plain"lines 542–542(plain / "src").mkdir(parents=True)lines 543–543assert sc.declared_scope_rejection(plain) is Nonelines 545–545usable = tmp_path / "usable"lines 546–546(usable / "src").mkdir(parents=True)lines 547–547(usable / ".clew.yaml").write_text("index_scope:\n roots: [src]\n", encoding="utf-8")lines 548–548assert sc.declared_scope_rejection(usable) is None

test_dot_directories_are_excluded_from_the_whole_repo_scope

None test_scope.test_dot_directories_are_excluded_from_the_whole_repo_scope(Path tmp_path)

Dot-directories are excluded from the whole-repo scope, not indexed.

tests/test_scope.py:157

Show on the map →

Called by none

Calls _rel_excludes, _rel_roots, _write, whole_repo_scope

Checks

  • assert scope.source == sc.SOURCE_WHOLE_REPO
  • assert _rel_roots(scope, root) == ["."], "the repo itself is the one INPUT root"
  • assert ".venv" in _rel_excludes(scope, root)
  • assert "src" not in _rel_excludes(scope, root)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_dot_directories_are_excluded_from_the_whole_repo_scope → whole_repo_scope
REQ-DDB-PIPE-014catalog
Source · 20 lines
def test_dot_directories_are_excluded_from_the_whole_repo_scope(tmp_path: Path) -> None:
    """Virtualenvs and tool caches live in dot-directories, and the whole-repo root
    is handed to doxygen unwalked — so the rule that prunes them has to travel as an
    EXCLUDE entry or it does not apply at all.

    @brief A dot-directory under the whole-repo root is excluded.
    @version 1
    """
    root = tmp_path / "repo"
    _write(root / "src" / "a.c")
    _write(root / ".venv" / "lib" / "vendor.c")

    scope = sc.whole_repo_scope(root)

    assert scope.source == sc.SOURCE_WHOLE_REPO
    assert _rel_roots(scope, root) == ["."], "the repo itself is the one INPUT root"
    assert ".venv" in _rel_excludes(scope, root)
    assert "src" not in _rel_excludes(scope, root)

Activity · 8 steps
lines 165–165root = tmp_path / "repo"lines 166–166_write(root / "src" / "a.c")lines 167–167_write(root / ".venv" / "lib" / "vendor.c")lines 169–169scope = sc.whole_repo_scope(root)lines 171–171assert scope.source == sc.SOURCE_WHOLE_REPOlines 172–172assert _rel_roots(scope, root) == ["."], "the repo itself is the one INPUT root"lines 173–173assert ".venv" in _rel_excludes(scope, root)lines 174–174assert "src" not in _rel_excludes(scope, root)

test_empty_or_absent_index_scope_falls_back_to_the_whole_repo

None test_scope.test_empty_or_absent_index_scope_falls_back_to_the_whole_repo(Path tmp_path)

An empty or absent index_scope falls through to the whole-repo tier.

tests/test_scope.py:389

Show on the map →

Called by none

Calls _repo_gating_only_src, derive_scope

Checks

  • assert sc.derive_scope(root).source == sc.SOURCE_WHOLE_REPO
  • assert sc.derive_scope(root).roots == (root.resolve(),)
  • assert sc.derive_scope(root).source == sc.SOURCE_WHOLE_REPO
  • assert sc.derive_scope(root).roots == (root.resolve(),)

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_empty_or_absent_index_scope_falls_back_to_the_whole_repo → derive_scope
REQ-DDB-GUARD-012inferredtest_empty_or_absent_index_scope_falls_back_to_the_whole_repo → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-014catalog
REQ-DDB-WIKI-054inferredtest_empty_or_absent_index_scope_falls_back_to_the_whole_repo → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 23 lines
def test_empty_or_absent_index_scope_falls_back_to_the_whole_repo(tmp_path: Path) -> None:
    """An unusable section must read as "nothing was declared" and drop to the next
    tier, never as a declared-and-empty scope — which would blank the index. Since
    gh#333 the next tier is the whole repository rather than the Doxyfile, so the
    consequence of getting this wrong got LOUDER, not quieter: an empty declared
    scope would now be the one way to reach an empty index.

    @brief An unusable index_scope section yields the whole repo, not empty roots.
    @version 3
    """
    root = tmp_path / "repo"
    root.mkdir()
    _repo_gating_only_src(root)

    (root / ".clew.yaml").write_text("shared_key_patterns:\n  writers: []\n", encoding="utf-8")
    assert sc.derive_scope(root).source == sc.SOURCE_WHOLE_REPO
    assert sc.derive_scope(root).roots == (root.resolve(),)

    (root / ".clew.yaml").write_text("index_scope:\n  roots: []\n", encoding="utf-8")
    assert sc.derive_scope(root).source == sc.SOURCE_WHOLE_REPO
    assert sc.derive_scope(root).roots == (root.resolve(),)

Activity · 9 steps
lines 399–399root = tmp_path / "repo"lines 400–400root.mkdir()lines 401–401_repo_gating_only_src(root)lines 403–403(root / ".clew.yaml").write_text("shared_key_patterns:\n writers: []\n", encoding="utf-8")lines 404–404assert sc.derive_scope(root).source == sc.SOURCE_WHOLE_REPOlines 405–405assert sc.derive_scope(root).roots == (root.resolve(),)lines 407–407(root / ".clew.yaml").write_text("index_scope:\n roots: []\n", encoding="utf-8")lines 408–408assert sc.derive_scope(root).source == sc.SOURCE_WHOLE_REPOlines 409–409assert sc.derive_scope(root).roots == (root.resolve(),)

test_first_party_platform_directories_are_not_reported_as_vendored

None test_scope.test_first_party_platform_directories_are_not_reported_as_vendored(Path tmp_path)

First-party platform source is never reported as vendored.

tests/test_scope.py:753

Show on the map →

Called by none

Calls _src, whole_repo_scope

Checks

  • assert "vendored" not in reason.lower(), f"first-party platform code was flagged: {reason}"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_first_party_platform_directories_are_not_reported_as_vendored → whole_repo_scope
REQ-DDB-PIPE-014catalog
Source · 24 lines
def test_first_party_platform_directories_are_not_reported_as_vendored(tmp_path: Path) -> None:
    """THE REASON DISCLOSURE WAS CHOSEN OVER EXCLUSION. A React Native app keeps its own native
    source under `ios/` and `android/` — committed, first-party, and exactly what an index of
    that app should contain. Its native DEPENDENCIES live under `ios/Pods` and build outputs,
    which a well-kept repository gitignores and clew already excludes.

    So the platform directories must not trip the vendored check. A rule broad enough to flag
    them would teach every mobile-app user to ignore the disclosure, which is how a real one
    stops being read.

    @brief ios/ and android/ are not called vendored.
    @return None.
    @version 1
    """
    root = tmp_path / "app"
    _src(root, "src/App.c")
    _src(root, "ios/Mattermost/AppDelegate.c")
    _src(root, "android/app/src/main/Main.c")

    reason = sc.whole_repo_scope(root).reason

    assert "vendored" not in reason.lower(), f"first-party platform code was flagged: {reason}"

Activity · 6 steps
lines 767–767root = tmp_path / "app"lines 768–768_src(root, "src/App.c")lines 769–769_src(root, "ios/Mattermost/AppDelegate.c")lines 770–770_src(root, "android/app/src/main/Main.c")lines 772–772reason = sc.whole_repo_scope(root).reasonlines 774–774assert "vendored" not in reason.lower(), f"first-party platform code was flagged: {reason}"

test_no_declaration_yields_the_whole_repo

None test_scope.test_no_declaration_yields_the_whole_repo(Path tmp_path)

No declaration at all yields the whole repo, and says why.

tests/test_scope.py:130

Show on the map →

Called by none

Calls _write, derive_scope

Checks

  • assert derived.source == sc.SOURCE_WHOLE_REPO
  • assert not derived.is_derived()
  • assert derived.roots == (root.resolve(),)
  • assert sc.INDEX_SCOPE_SECTION in derived.reason
  • assert ".clew.yaml" in derived.reason

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_no_declaration_yields_the_whole_repo → derive_scope
REQ-DDB-GUARD-012inferredtest_no_declaration_yields_the_whole_repo → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-014catalog
REQ-DDB-WIKI-054inferredtest_no_declaration_yields_the_whole_repo → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 25 lines
def test_no_declaration_yields_the_whole_repo(tmp_path: Path) -> None:
    """Fail safe and loud: the tier is explicit in both the source and the reason,
    never a silent guess, and the reason names where a declaration was looked for so
    "declares nothing" is distinguishable from "we looked in the wrong place".

    THE REASON MUST STILL CARRY THE SEARCH (gh#333). Folding the Doxyfile tier away
    deleted the function that phrased that clause, and the clause is gh#16's whole
    substance — without it a repo whose config we failed to FIND and a repo that
    declares nothing produce the same sentence.

    @brief An undeclared repo takes the whole-repo tier with a reason naming the search.
    @version 3
    """
    root = tmp_path / "repo"
    _write(root / "src" / "a.c")

    derived = sc.derive_scope(root)

    assert derived.source == sc.SOURCE_WHOLE_REPO
    assert not derived.is_derived()
    assert derived.roots == (root.resolve(),)
    assert sc.INDEX_SCOPE_SECTION in derived.reason
    assert ".clew.yaml" in derived.reason

Activity · 8 steps
lines 143–143root = tmp_path / "repo"lines 144–144_write(root / "src" / "a.c")lines 146–146derived = sc.derive_scope(root)lines 148–148assert derived.source == sc.SOURCE_WHOLE_REPOlines 149–149assert not derived.is_derived()lines 150–150assert derived.roots == (root.resolve(),)lines 151–151assert sc.INDEX_SCOPE_SECTION in derived.reasonlines 152–152assert ".clew.yaml" in derived.reason

test_the_vendored_disclosure_is_bounded

None test_scope.test_the_vendored_disclosure_is_bounded(Path tmp_path)

The vendored disclosure is bounded however many trees match.

tests/test_scope.py:781

Show on the map →

Called by none

Calls _src, whole_repo_scope

Checks

  • assert "look vendored" in reason, f"precondition: nothing was disclosed: {reason}"
  • assert "12 trees" in reason, f"the true count was lost when summarising: {reason}"
  • assert reason.count("/vendor") <= 5, f"the disclosure was not bounded: {reason}"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_the_vendored_disclosure_is_bounded → whole_repo_scope
REQ-DDB-PIPE-014catalog
Source · 22 lines
def test_the_vendored_disclosure_is_bounded(tmp_path: Path) -> None:
    """gh#37: an EXCLUDE list grew to ~390 entries and overflowed a client's reply limit. A
    disclosure that names every matching tree repeats that on a repository vendoring many
    libraries. Name a few, COUNT the rest, so the reader still learns the true size.

    @brief Many vendored trees are summarised, not enumerated.
    @return None.
    @version 1
    """
    root = tmp_path / "mono"
    for i in range(12):
        _src(root, f"pkg{i}/vendor/lib.c")

    reason = sc.whole_repo_scope(root).reason

    ## THE FIRST DRAFT OF THIS TEST PASSED BEFORE THE FEATURE EXISTED, and is kept honest by
    ## these anchors. `reason.count("vendor") <= 8` is trivially true when nothing is
    ## disclosed, and a bare `"12" in reason` matched `git exit 128` in the not-a-repository
    ## clause — so both assertions held over a reason that disclosed nothing at all.
    assert "look vendored" in reason, f"precondition: nothing was disclosed: {reason}"
    assert "12 trees" in reason, f"the true count was lost when summarising: {reason}"
    assert reason.count("/vendor") <= 5, f"the disclosure was not bounded: {reason}"

1 more lines, not shown

Activity · 7 steps
lines 790–790root = tmp_path / "mono"lines 791–791◇ for i in range(12)lines 792–792_src(root, f"pkg{i}/vendor/lib.c")lines 794–794reason = sc.whole_repo_scope(root).reasonlines 800–800assert "look vendored" in reason, f"precondition: nothing was disclosed: {reason}"lines 801–801assert "12 trees" in reason, f"the true count was lost when summarising: {reason}"lines 802–802assert reason.count("/vendor") <= 5, f"the disclosure was not bounded: {reason}"

test_unparseable_config_falls_back_to_the_whole_repo

None test_scope.test_unparseable_config_falls_back_to_the_whole_repo(Path tmp_path)

An unparseable pre-commit config falls back to the whole-repo tier.

tests/test_scope.py:299

Checks

  • assert sc.derive_scope(root).source == sc.SOURCE_WHOLE_REPO

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_unparseable_config_falls_back_to_the_whole_repo → derive_scope
REQ-DDB-GUARD-012inferredtest_unparseable_config_falls_back_to_the_whole_repo → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_requirements → _validate_node
REQ-DDB-PIPE-014catalog
REQ-DDB-WIKI-054inferredtest_unparseable_config_falls_back_to_the_whole_repo → derive_scope → _declared_index_scope → load_declaration_located → _checked_sections → _checked_section → _checked_list_section → all
Source · 17 lines
def test_unparseable_config_falls_back_to_the_whole_repo(tmp_path: Path) -> None:
    """A malformed config is never guessed at — scope derivation drops to the
    whole-repo tier instead of half-reading it. FAILING OPEN is deliberate here and
    is the opposite of the fail-closed rule elsewhere: a scope that cannot be read
    yields a WIDER index, never a narrower one, because a silently narrow index is
    the failure this project keeps paying for.

    @brief A malformed pre-commit config leaves scope on the whole-repo tier.
    @version 3
    """
    root = tmp_path / "repo"
    root.mkdir()
    (root / ".pre-commit-config.yaml").write_text("repos: [ unbalanced\n", encoding="utf-8")

    assert sc.derive_scope(root).source == sc.SOURCE_WHOLE_REPO

Activity · 4 steps
lines 309–309root = tmp_path / "repo"lines 310–310root.mkdir()lines 311–311(root / ".pre-commit-config.yaml").write_text("repos: [ unbalanced\n", encoding="utf-8")lines 313–313assert sc.derive_scope(root).source == sc.SOURCE_WHOLE_REPO