test_first_party_walk.py

tests/test_first_party_walk.py

A first-party refresh walks first-party code, and walks it once.

test_a_first_party_refresh_never_walks_inside_a_vendored_tree

None test_first_party_walk.test_a_first_party_refresh_never_walks_inside_a_vendored_tree(Path tmp_path, pytest.MonkeyPatch monkeypatch)

A first-party build walks no vendored tree, derives no full split, and walks root once.

tests/test_first_party_walk.py:119

Show on the map →

Called by none

Calls _nested_split_repo, build_server, derive_sub_indexes

Checks

  • assert outcome.get("ok"), outcome
  • assert vendored == [], f"a first-party refresh walked vendored trees: {vendored}"
  • assert derives == [], f"a first-party refresh derived the full split {len(derives)} time(s)"
  • assert walked.count(root) == 1, f"the root was walked {walked.count(root)} times, not once"

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CLI-001measured
REQ-DDB-CONFIG-001measuredtest_a_first_party_refresh_never_walks_inside_a_vendored_tree → derive_sub_indexes → whole_repo_scope
REQ-DDB-CONFIG-004measured
REQ-DDB-CONFIG-005measured
REQ-DDB-CONFIG-006measured
REQ-DDB-CONFIG-007measured
REQ-DDB-CONFIG-008measured
REQ-DDB-CONFIG-009measured
REQ-DDB-INDEX-001measured
REQ-DDB-INDEX-002measuredtest_a_first_party_refresh_never_walks_inside_a_vendored_tree → derive_sub_indexes
REQ-DDB-INDEX-003measured
REQ-DDB-INDEX-004measured
REQ-DDB-INDEX-005measured
REQ-DDB-INDEX-006measured
REQ-DDB-INDEX-007measured
REQ-DDB-INDEX-008measured
REQ-DDB-INDEX-009measured
REQ-DDB-INDEX-010measured
REQ-DDB-INDEX-011measured
REQ-DDB-MCP-001measuredtest_a_first_party_refresh_never_walks_inside_a_vendored_tree → build_server
REQ-DDB-MCP-003measured
REQ-DDB-MCP-004measuredtest_a_first_party_refresh_never_walks_inside_a_vendored_tree → build_server → _refusal_as_tool_error
REQ-DDB-PIPE-001measured
REQ-DDB-PIPE-003measured
REQ-DDB-PIPE-004measured
REQ-DDB-PIPE-005measured
REQ-DDB-PIPE-006measured
REQ-DDB-PIPE-007measured
REQ-DDB-PIPE-008measured
REQ-DDB-PIPE-009measured
REQ-DDB-PIPE-010measured
REQ-DDB-PIPE-011measured
REQ-DDB-PIPE-012measured
REQ-DDB-PIPE-013measured
REQ-DDB-PIPE-014measured
REQ-DDB-PIPE-015measured
REQ-DDB-QUERY-003measured
REQ-DDB-QUERY-011measured
REQ-DDB-SCHEMA-001measured
REQ-DDB-SCHEMA-002measured
REQ-DDB-SCHEMA-003measured
REQ-DDB-SCHEMA-004measured
REQ-DDB-SCHEMA-005measured
REQ-DDB-SCHEMA-006measured
REQ-DDB-SCHEMA-007measured
REQ-DDB-SCHEMA-009measured
REQ-DDB-SCHEMA-011measured
REQ-DDB-SCHEMA-012measured
REQ-DDB-SCHEMA-013measured
REQ-DDB-SCHEMA-014measured
REQ-DDB-SCHEMA-015measured
REQ-DDB-WIKI-034measuredtest_a_first_party_refresh_never_walks_inside_a_vendored_tree → build_server → _register_prompts
REQ-DDB-WIKI-054measured
Source · 39 lines
def test_a_first_party_refresh_never_walks_inside_a_vendored_tree(
    tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
    """THE COST, PINNED STRUCTURALLY. Timing a small fixture proves nothing about boost, but the
    walk roots do: a first-party refresh that lists a directory under `deps/` as a walk root has
    paid for a vendored tree's size. Also asserted: the repository root is walked once per
    refresh, not once per question asked of it.

    @brief A first-party build walks no vendored tree, derives no full split, and walks root once.
    @version 1
    """
    root = _nested_split_repo(tmp_path)
    registry = st.TargetRegistry(tmp_path / "state")
    _mcp, state = build_server(registry)
    first_party = registry.register(root, FIRST_PARTY_INDEX)
    registry.note_derived(str(root), tuple(s.name for s in derive_sub_indexes(root)))

    walked: list[Path] = []
    derives: list[Path] = []
    real_walk, real_derive = scope._nested_repos_under, scope.derive_sub_indexes

    def _walk(input_root: Path) -> list[Path]:
        walked.append(Path(input_root))
        return real_walk(input_root)

    def _derive(repo_root: Path) -> list[scope.SubIndex]:
        derives.append(Path(repo_root))
        return real_derive(repo_root)

    monkeypatch.setattr(scope, "_nested_repos_under", _walk)
    monkeypatch.setattr(scope, "derive_sub_indexes", _derive)

    outcome = state._run_build(first_party, None, "from-guard", None, None, False)

    assert outcome.get("ok"), outcome
    vendored = [p for p in walked if p != root and (root / "deps") in (p, *p.parents)]
    assert vendored == [], f"a first-party refresh walked vendored trees: {vendored}"
    assert derives == [], f"a first-party refresh derived the full split {len(derives)} time(s)"
    assert walked.count(root) == 1, f"the root was walked {walked.count(root)} times, not once"

1 more lines, not shown

Activity · 18 steps
lines 130–130root = _nested_split_repo(tmp_path)lines 131–131registry = st.TargetRegistry(tmp_path / "state")lines 132–132_mcp, state = build_server(registry)lines 133–133first_party = registry.register(root, FIRST_PARTY_INDEX)lines 134–134registry.note_derived(str(root), tuple(s.name for s in derive_sub_indexes(root)))lines 136–136walked: list[Path] = []lines 137–137derives: list[Path] = []lines 138–138real_walk, real_derive = scope._nested_repos_under, scope.derive_sub_indexeslines 140–142def _walk(input_root: Path) -> list[Path]: walked.append(Path(input_root)) return real_walk(input_root)lines 144–146def _derive(repo_root: Path) -> list[scope.SubIndex]: derives.append(Path(repo_root)) return real_derive(repo_root)lines 148–148monkeypatch.setattr(scope, "_nested_repos_under", _walk)lines 149–149monkeypatch.setattr(scope, "derive_sub_indexes", _derive)lines 151–151outcome = state._run_build(first_party, None, "from-guard", None, None, False)lines 153–153assert outcome.get("ok"), outcomelines 154–154vendored = [p for p in walked if p != root and (root / "deps") in (p, *p.parents)]lines 155–155assert vendored == [], f"a first-party refresh walked vendored trees: {vendored}"lines 156–156assert derives == [], f"a first-party refresh derived the full split {len(derives)} time(s)"lines 157–157assert walked.count(root) == 1, f"the root was walked {walked.count(root)} times, not once"

test_the_cheap_first_party_split_equals_the_derived_one

None test_first_party_walk.test_the_cheap_first_party_split_equals_the_derived_one(Path tmp_path)

first_party_sub_index matches derive_sub_indexes' first-party entry exactly.

tests/test_first_party_walk.py:94

Show on the map →

Called by none

Calls _commit, _nested_split_repo, derive_sub_indexes, first_party_sub_index

Checks

  • assert [s.name for s in derived][0] == FIRST_PARTY_INDEX
  • assert scope.first_party_sub_index(root) == derived[0]
  • assert scope.first_party_sub_index(plain) is None, ("an unsplit repository has no first-party part" )

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-CONFIG-001measuredtest_the_cheap_first_party_split_equals_the_derived_one → derive_sub_indexes → whole_repo_scope
REQ-DDB-INDEX-002measuredtest_the_cheap_first_party_split_equals_the_derived_one → derive_sub_indexes
Source · 25 lines
def test_the_cheap_first_party_split_equals_the_derived_one(tmp_path: Path) -> None:
    """THE EQUIVALENCE THE SHORTCUT RESTS ON. If `first_party_sub_index` and
    `derive_sub_indexes(...)[0]` ever disagree, a refresh indexes a different first-party scope
    from the one the full split names. That is a wrong index, not a slow one.

    @brief first_party_sub_index matches derive_sub_indexes' first-party entry exactly.
    @version 1
    """
    root = _nested_split_repo(tmp_path)

    derived = derive_sub_indexes(root)
    assert [s.name for s in derived][0] == FIRST_PARTY_INDEX
    assert scope.first_party_sub_index(root) == derived[0]

    plain = tmp_path / "plain"
    plain.mkdir()
    (plain / "a.c").write_text("int a(void) { return 0; }\n")
    _commit(plain)
    assert scope.first_party_sub_index(plain) is None, (
        "an unsplit repository has no first-party part"
    )


@needs_git
@pytest.mark.skipif(shutil.which("doxygen") is None, reason="asserted against a real build")