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>
36 lines
1.4 KiB
Python
36 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
from stewardship.context import build_context
|
|
|
|
|
|
def test_context_selects_only_matching_topic(make_repo):
|
|
repo = make_repo("positive/infra-lxd")
|
|
result = build_context(repo, "container.deploy")
|
|
bundle = result.bundle
|
|
assert bundle["spec"]["intent"] == "container.deploy"
|
|
assert bundle["spec"]["topics"] == ["topic:infra-lxd/container-deployment"]
|
|
assert bundle["spec"]["documents"] == ["container-deployment-howto"]
|
|
assert "operation:infra-lxd/container.inspect" in bundle["spec"]["operations"]
|
|
|
|
|
|
def test_context_unrelated_intent_returns_empty_topics(make_repo):
|
|
repo = make_repo("positive/infra-lxd")
|
|
result = build_context(repo, "backup.restore")
|
|
bundle = result.bundle
|
|
assert bundle["spec"]["topics"] == []
|
|
assert bundle["spec"]["documents"] == []
|
|
|
|
|
|
def test_context_materialize_respects_budget_and_warns(make_repo):
|
|
repo = make_repo("positive/infra-lxd")
|
|
result = build_context(repo, "container.deploy", materialize=True, budget_bytes=5)
|
|
assert result.truncated is True
|
|
assert any("CONTEXT_BUDGET_TRUNCATED" in w for w in result.bundle["spec"]["warnings"])
|
|
assert result.materialized[0].bytes_used <= 5
|
|
|
|
|
|
def test_context_strict_mode_signaled_via_truncation_flag(make_repo):
|
|
repo = make_repo("positive/infra-lxd")
|
|
result = build_context(repo, "container.deploy", materialize=True, budget_bytes=0, strict=True)
|
|
assert result.truncated is True
|