feat: implement repoctl L1 core (models, schemas, validate, discover, context, init, adopt)

Adds the repository-stewardship Python package (src/stewardship) with:
- JSON Schemas (Draft 2020-12) for RepositoryContract, KnowledgeBase, CatalogIndex,
  ContextBundle, BootstrapPlan, AdoptionAssessment/Plan/Report, user config and the
  repoctl-result envelope.
- Safe YAML I/O, path confinement, deterministic clock and canonical-JSON hashing.
- validate: schema, ID uniqueness, path safety, KDB references, freshness, secret-shaped
  fields, shell-string detection, and Markdown frontmatter/fence/link checks.
- discover/CatalogIndex with deterministic sorting and duplicate-name detection.
- describe (contract-only) and context (intent-scoped ContextBundle with budgeted
  materialization and --strict truncation).
- init: plan-then-apply bootstrap with SHA-256 plan-hash approval, no fake domain
  artifacts, bundled Claude skills.
- adopt: assess/plan/apply/verify overlay workflow per docs/adoption-runbook.md,
  preserving legacy content roots and KDB, with baseline-hash re-check and rollback.
- argparse-based `repoctl` CLI with human/yaml/json output and spec exit codes.
- pytest suite (39 tests) covering positive/negative fixtures, discovery, context,
  bootstrap and adoption (including LXD- and Antivirus-shaped legacy layouts).

Managed with uv (.venv), ruff clean, mypy --strict clean.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Alexander Baranov
2026-08-24 14:57:34 +03:00
co-authored by Claude Sonnet 5
parent 9a39b8a941
commit 96d4d08230
75 changed files with 4259 additions and 0 deletions
+64
View File
@@ -0,0 +1,64 @@
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)