"""specification.md 11 (CatalogIndex) and PLAN.md: describe never loads KDB.""" from __future__ import annotations from pathlib import Path from conftest import git_init, minimal_contract, run_repoctl, write_yaml def test_describe_succeeds_even_with_broken_kdb(tmp_path: Path) -> None: root = tmp_path / "repo" write_yaml(root / "ops" / "contract.yaml", minimal_contract()) # KDB is present but deliberately invalid; describe must not touch it. (root / "kdb").mkdir(parents=True) (root / "kdb" / "kdb.yaml").write_text("{{{ not valid yaml", encoding="utf-8") git_init(root) result = run_repoctl("describe", "--repo", str(root), "--output", "json") assert result.returncode == 0, (result.returncode, result.stdout, result.stderr) envelope = result.envelope() assert envelope["data"]["metadata"]["name"] == "sample-repo" def test_discover_finds_repository_under_root(tmp_path: Path) -> None: root_dir = tmp_path / "roots" repo = root_dir / "sample-repo" write_yaml(repo / "ops" / "contract.yaml", minimal_contract()) write_yaml(repo / "kdb" / "kdb.yaml", "apiVersion: stewardship.corsus.ru/v1alpha1\nkind: KnowledgeBase\nmetadata:\n name: sample-repo-kdb\nspec:\n repository: repo:sample-repo\n defaultLanguage: en\n topics: []\n documents: []\n") git_init(repo) result = run_repoctl("discover", "--root", str(root_dir), "--output", "json") assert result.returncode == 0, (result.returncode, result.stdout, result.stderr) envelope = result.envelope() refs = [r["ref"] for r in envelope["data"]["spec"]["repositories"]] assert "repo:sample-repo" in refs def test_discover_detects_duplicate_repository_names(tmp_path: Path) -> None: root_dir = tmp_path / "roots" for sub in ("first", "second"): repo = root_dir / sub write_yaml(repo / "ops" / "contract.yaml", minimal_contract(name="duplicate-name")) write_yaml( repo / "kdb" / "kdb.yaml", "apiVersion: stewardship.corsus.ru/v1alpha1\nkind: KnowledgeBase\nmetadata:\n name: k\nspec:\n repository: repo:duplicate-name\n defaultLanguage: en\n topics: []\n documents: []\n", ) git_init(repo) result = run_repoctl("discover", "--root", str(root_dir), "--output", "json") envelope = result.envelope() assert any("DUPLICATE" in f["code"] for f in envelope["findings"]) def test_discover_output_is_deterministically_sorted(tmp_path: Path) -> None: root_dir = tmp_path / "roots" for name in ("zzz-repo", "aaa-repo", "mmm-repo"): repo = root_dir / name write_yaml(repo / "ops" / "contract.yaml", minimal_contract(name=name)) write_yaml( repo / "kdb" / "kdb.yaml", f"apiVersion: stewardship.corsus.ru/v1alpha1\nkind: KnowledgeBase\nmetadata:\n name: k\nspec:\n repository: repo:{name}\n defaultLanguage: en\n topics: []\n documents: []\n", ) git_init(repo) first = run_repoctl("discover", "--root", str(root_dir), "--output", "json").envelope() second = run_repoctl("discover", "--root", str(root_dir), "--output", "json").envelope() refs_first = [r["ref"] for r in first["data"]["spec"]["repositories"]] refs_second = [r["ref"] for r in second["data"]["spec"]["repositories"]] assert refs_first == refs_second == sorted(refs_first)