Files
repoctl/tests-universal/test_describe_discover.py
Alexander Baranov 86dd79c8ae test: add spec-driven universal CLI suite; fix context strict + path confinement bugs
- tests-universal/ drives repoctl only as a subprocess CLI, asserting
  directly against docs/specification.md (envelope, exit codes 0-5,
  validation rules MVP, security invariants) so the same suite can judge
  any conforming implementation, including the sibling codex/repoctl-l1
  branch built independently from the same baseline.
- Running it surfaced two real bugs, both fixed:
  - `context --strict` only checked budget truncation, never stale or
    missing referenced documents, despite specification.md 19.2 defining
    exit 4 as "stale or incomplete context" (not just truncation).
  - `paths.confined_path` crashed with an unhandled WinError2 when a
    referenced path's parent directory also didn't exist, because it
    resolved a single non-existent parent with strict=True instead of
    walking up to the nearest existing ancestor.
2026-08-24 15:38:49 +03:00

70 lines
3.3 KiB
Python

"""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)