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:
co-authored by
Claude Sonnet 5
parent
9a39b8a941
commit
96d4d08230
@@ -0,0 +1,51 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from stewardship.bootstrap import BootstrapAnswers, apply_bootstrap_plan, build_bootstrap_plan
|
||||
from stewardship.validate import validate_repository
|
||||
|
||||
|
||||
def test_bootstrap_plan_writes_nothing(tmp_path):
|
||||
answers = BootstrapAnswers(name="new-proj", title="New project", owners=["team"], repository_type="project")
|
||||
plan = build_bootstrap_plan(answers)
|
||||
assert list(tmp_path.iterdir()) == []
|
||||
assert plan["planHash"].startswith("sha256:")
|
||||
|
||||
|
||||
def test_bootstrap_apply_requires_matching_approval_hash(tmp_path):
|
||||
answers = BootstrapAnswers(name="new-proj", title="New project", owners=["team"], repository_type="project")
|
||||
plan = build_bootstrap_plan(answers)
|
||||
with pytest.raises(ValueError):
|
||||
apply_bootstrap_plan(tmp_path, plan, "sha256:not-the-real-hash")
|
||||
assert list(tmp_path.iterdir()) == []
|
||||
|
||||
|
||||
def test_bootstrap_apply_writes_and_validates(tmp_path):
|
||||
import subprocess
|
||||
|
||||
subprocess.run(["git", "init", "-q"], cwd=tmp_path, check=True)
|
||||
answers = BootstrapAnswers(
|
||||
name="new-proj", title="New project", owners=["team"], repository_type="project", lifecycle="active"
|
||||
)
|
||||
plan = build_bootstrap_plan(answers)
|
||||
written = apply_bootstrap_plan(tmp_path, plan, plan["planHash"])
|
||||
assert "ops/contract.yaml" in written
|
||||
assert (tmp_path / "AGENTS.md").exists()
|
||||
assert (tmp_path / ".claude/skills/repository-bootstrap/SKILL.md").exists()
|
||||
|
||||
result = validate_repository(tmp_path)
|
||||
errors = [f for f in result.findings if f.severity == "error"]
|
||||
assert errors == []
|
||||
|
||||
|
||||
def test_bootstrap_apply_refuses_to_overwrite(tmp_path):
|
||||
import subprocess
|
||||
|
||||
subprocess.run(["git", "init", "-q"], cwd=tmp_path, check=True)
|
||||
(tmp_path / "AGENTS.md").write_text("existing", encoding="utf-8")
|
||||
answers = BootstrapAnswers(name="new-proj", title="New project", owners=["team"], repository_type="project")
|
||||
plan = build_bootstrap_plan(answers)
|
||||
with pytest.raises(FileExistsError):
|
||||
apply_bootstrap_plan(tmp_path, plan, plan["planHash"])
|
||||
assert (tmp_path / "AGENTS.md").read_text(encoding="utf-8") == "existing"
|
||||
Reference in New Issue
Block a user