Files
repoctl/tests/test_cli.py
Alexander BaranovandClaude Sonnet 5 96d4d08230 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>
2026-08-24 14:57:34 +03:00

42 lines
1.1 KiB
Python

from __future__ import annotations
from stewardship.cli import main
def test_validate_exit_codes(make_repo, negative_repo):
good = make_repo("positive/infra-lxd")
assert main(["validate", "--repo", str(good), "--output", "json"]) == 0
bad = negative_repo("secret-field")
assert main(["validate", "--repo", str(bad), "--output", "json"]) == 1
def test_missing_repository_returns_exit_3(tmp_path):
missing = tmp_path / "does-not-exist"
assert main(["validate", "--repo", str(missing), "--output", "json"]) == 3
def test_context_strict_truncation_returns_exit_4(make_repo):
repo = make_repo("positive/infra-lxd")
code = main(
[
"context",
"--repo",
str(repo),
"--intent",
"container.deploy",
"--materialize",
"--budget-bytes",
"1",
"--strict",
"--output",
"json",
]
)
assert code == 4
def test_init_apply_without_hash_returns_exit_2(tmp_path):
code = main(["init", "--repo", str(tmp_path), "--apply", "--output", "json"])
assert code == 2