fix(discover): a contract inside another repository is not a repository
`tests/fixtures/positive/` holds four valid contracts. Running `discover` over the machine's Git directory returned six repositories: two real ones and those four, with nothing in the output to tell them apart. Any catalog-wide question -- which repositories lack an owner, which are behind the template version -- was answered over a set that included this project's own test material. A repository is the root of a git repository. A directory holding ops/contract.yaml somewhere inside another repository's working tree is that repository's content: a fixture, an example, a vendored copy. Skip it, and say so with CATALOG_NESTED_CONTRACT_SKIPPED rather than silently, so a genuinely misplaced contract is still visible. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
d7a506a5d9
commit
c21ffceef3
@@ -1,7 +1,11 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from stewardship.discovery import build_catalog_index
|
||||
|
||||
FIXTURES = Path(__file__).parent / "fixtures"
|
||||
|
||||
|
||||
def test_catalog_finds_all_positive_fixtures_and_is_deterministic(tmp_path, make_repo):
|
||||
make_repo("positive/infra-lxd")
|
||||
@@ -62,3 +66,28 @@ def test_catalog_detects_duplicate_repository_name(tmp_path, make_repo):
|
||||
|
||||
_, findings = build_catalog_index([tmp_path])
|
||||
assert any(f.code == "CATALOG_DUPLICATE_REPOSITORY_NAME" for f in findings)
|
||||
|
||||
|
||||
def test_a_contract_inside_another_repository_is_not_a_repository(tmp_path, make_repo) -> None:
|
||||
"""A fixture, example or vendored copy is content, not a peer.
|
||||
|
||||
This project's own `tests/fixtures/positive/` holds four valid contracts.
|
||||
They appeared in the catalog beside production repositories and were
|
||||
indistinguishable from them, which corrupts every catalog-wide question.
|
||||
"""
|
||||
outer = make_repo("positive/project-example")
|
||||
nested = outer / "examples" / "vendored"
|
||||
(nested / "ops").mkdir(parents=True)
|
||||
(nested / "ops" / "contract.yaml").write_text(
|
||||
(FIXTURES / "positive" / "software-example" / "ops" / "contract.yaml").read_text(
|
||||
encoding="utf-8"
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
index, findings = build_catalog_index([outer])
|
||||
refs = {entry["ref"] for entry in index["spec"]["repositories"]}
|
||||
assert refs == {"repo:example-project"}
|
||||
skipped = [f for f in findings if f.code == "CATALOG_NESTED_CONTRACT_SKIPPED"]
|
||||
assert len(skipped) == 1
|
||||
assert "vendored" in skipped[0].path
|
||||
|
||||
Reference in New Issue
Block a user