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>
49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
import shutil
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
FIXTURES = Path(__file__).parent / "fixtures"
|
|
|
|
|
|
def _git_init(repo: Path) -> None:
|
|
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", "fixture baseline"], cwd=repo, check=True)
|
|
|
|
|
|
def materialize_fixture(tmp_path: Path, relative: str, *, git: bool = True) -> Path:
|
|
src = FIXTURES / relative
|
|
dest = tmp_path / Path(relative).name
|
|
shutil.copytree(src, dest)
|
|
if git:
|
|
_git_init(dest)
|
|
return dest
|
|
|
|
|
|
@pytest.fixture
|
|
def make_repo(tmp_path):
|
|
def _make(relative: str, *, git: bool = True) -> Path:
|
|
return materialize_fixture(tmp_path, relative, git=git)
|
|
|
|
return _make
|
|
|
|
|
|
@pytest.fixture
|
|
def negative_repo(tmp_path):
|
|
"""Materialize a negative/<name>/contract.yaml fixture as ops/contract.yaml under a fresh repo."""
|
|
|
|
def _make(name: str) -> Path:
|
|
dest = tmp_path / name
|
|
(dest / "ops").mkdir(parents=True)
|
|
shutil.copy(FIXTURES / "negative" / name / "contract.yaml", dest / "ops" / "contract.yaml")
|
|
_git_init(dest)
|
|
return dest
|
|
|
|
return _make
|