from __future__ import annotations from stewardship.discovery import build_catalog_index def test_catalog_finds_all_positive_fixtures_and_is_deterministic(tmp_path, make_repo): make_repo("positive/infra-lxd") make_repo("positive/service-antivirus") make_repo("positive/software-example") make_repo("positive/project-example") catalog1, findings1 = build_catalog_index([tmp_path]) catalog2, _findings2 = build_catalog_index([tmp_path]) names = {r["ref"] for r in catalog1["spec"]["repositories"]} assert names == { "repo:infra-lxd", "repo:services-antivirus", "repo:example-software", "repo:example-project", } assert not any(f.severity == "error" for f in findings1) # Deterministic rebuild ignoring the volatile generatedAt timestamp. repos1 = catalog1["spec"]["repositories"] repos2 = catalog2["spec"]["repositories"] assert repos1 == repos2 assert catalog1["spec"]["relations"] == catalog2["spec"]["relations"] def test_catalog_matches_requirement_to_capability(tmp_path, make_repo): make_repo("positive/infra-lxd") make_repo("positive/service-antivirus") catalog, _ = build_catalog_index([tmp_path]) relations = catalog["spec"]["relations"] matches = [r for r in relations if r["type"] == "matches"] assert any( r["from"] == "requirement:services-antivirus/control-plane-container" and r["to"] == "capability:infra-lxd/container" for r in matches ) def test_catalog_detects_duplicate_repository_name(tmp_path, make_repo): first = make_repo("positive/infra-lxd", git=False) import shutil second_parent = tmp_path / "duplicate-holder" second_parent.mkdir() second = second_parent / "infra-lxd-copy" shutil.copytree(first, second) import subprocess for repo in (first, second): subprocess.run(["git", "init", "-q"], cwd=repo, check=True) subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=repo, check=True) subprocess.run(["git", "config", "user.name", "Test"], cwd=repo, check=True) subprocess.run(["git", "add", "-A"], cwd=repo, check=True) subprocess.run(["git", "commit", "-q", "-m", "baseline"], cwd=repo, check=True) _, findings = build_catalog_index([tmp_path]) assert any(f.code == "CATALOG_DUPLICATE_REPOSITORY_NAME" for f in findings)