Running a full assess -> plan -> apply -> verify against Infra/LXD and Infra/Docker in throwaway worktrees, and a bootstrap into a scratch directory, surfaced the same two mistakes repeated across both commands: a shape was read where evidence was available, and a missing answer became a silent default rather than a refusal. adopt: - classify secret-shaped paths by content, not by filename. A live credential blocks; a file tracked against the repository's own ignore rules and a name-only match are warnings; findings name keys, never values. In Infra/Docker this turned 14 false blockers into 2 true ones and surfaced 14 files committed despite `**/.env`. - carry assess findings into the plan and refuse while an error-severity finding is unresolved. An owner may accept one through `acknowledgedFindings` with a reason; the acknowledgement enters the plan and therefore planHash, so approval covers it. - derive metadata.name from the git remote instead of the clone directory, and refuse to plan without a confirmed owner (runbook section 9). - propose content roots from the whole content vocabulary rather than the winning type's markers, and recognise N sibling directories sharing a marker file as one file-set root with a selector, as runbook 7.2 already specified. Authority defaulted rather than derived now asks. init: apply the guards adopt already had. Answers are validated against the vocabularies that already existed in constants (name, type, lifecycle, access) so init can no longer create a repository that fails its own validate; owners are required; a directory that already holds the planned paths is refused at plan time and pointed at adopt; and every path from a plan is confined before the first byte is written -- init wrote outside the repository from an edited plan. validate: mask fenced blocks and inline code spans before scanning for Markdown links. A PowerShell snippet in Infra/Docker's CLAUDE.md parsed as a link and kept validate red for a reason unrelated to the repository. paths: allow "." as a whole content-root path, never as a segment, so the file-set root runbook 7.2 describes can be declared. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
92 lines
4.1 KiB
Python
92 lines
4.1 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from stewardship import adoption
|
|
|
|
|
|
def test_assess_lxd_legacy_preserves_layout(make_repo):
|
|
repo = make_repo("adoption/lxd-legacy")
|
|
result = adoption.assess(repo)
|
|
assert result["repository"]["dirty"] is False
|
|
assert result["classification"]["proposedType"] == "infrastructure-config"
|
|
kdb_actions = {(entry["path"], entry["action"]) for entry in result["knowledge"]}
|
|
assert ("kdb.yaml", "wrap") in kdb_actions
|
|
root_paths = {cr["path"] for cr in result["proposedContentRoots"]}
|
|
assert "profiles-source" in root_paths
|
|
|
|
|
|
def test_plan_lxd_legacy_creates_contract_and_kdb_adapter_without_moving_profiles(make_repo):
|
|
repo = make_repo("adoption/lxd-legacy")
|
|
assessment = adoption.assess(repo)
|
|
plan = adoption.build_plan(
|
|
repo, assessment, confirmed_name="infra-lxd", confirmed_owners=["infrastructure"], confirmed_lifecycle="production"
|
|
)
|
|
changes_by_path = {c["path"]: c for c in plan["changes"]}
|
|
assert changes_by_path["ops/contract.yaml"]["action"] == "create"
|
|
assert changes_by_path["kdb/kdb.yaml"]["action"] == "create"
|
|
assert changes_by_path["kdb.yaml"]["action"] == "preserve"
|
|
assert "profiles-source/**" in plan["forbiddenChanges"]
|
|
assert "profiles/**" in plan["forbiddenChanges"]
|
|
assert plan["planHash"].startswith("sha256:")
|
|
|
|
|
|
def test_apply_does_not_touch_working_tree_before_approval(make_repo):
|
|
repo = make_repo("adoption/lxd-legacy")
|
|
before = sorted(p.relative_to(repo).as_posix() for p in repo.rglob("*") if p.is_file())
|
|
assessment = adoption.assess(repo)
|
|
adoption.build_plan(repo, assessment, confirmed_name="infra-lxd", confirmed_owners=["infrastructure"])
|
|
after = sorted(p.relative_to(repo).as_posix() for p in repo.rglob("*") if p.is_file())
|
|
assert before == after
|
|
|
|
|
|
def test_apply_rejects_stale_baseline(make_repo):
|
|
repo = make_repo("adoption/lxd-legacy")
|
|
assessment = adoption.assess(repo)
|
|
plan = adoption.build_plan(repo, assessment, confirmed_name="infra-lxd", confirmed_owners=["infrastructure"])
|
|
plan["baselineRevision"] = "0" * 40
|
|
with pytest.raises(ValueError):
|
|
adoption.apply_plan(repo, plan, plan["planHash"])
|
|
assert not (repo / "ops" / "contract.yaml").exists()
|
|
|
|
|
|
def test_apply_and_verify_lxd_legacy(make_repo):
|
|
repo = make_repo("adoption/lxd-legacy")
|
|
assessment = adoption.assess(repo)
|
|
plan = adoption.build_plan(
|
|
repo, assessment, confirmed_name="infra-lxd", confirmed_owners=["infrastructure"], confirmed_lifecycle="production"
|
|
)
|
|
written = adoption.apply_plan(repo, plan, plan["planHash"])
|
|
assert "ops/contract.yaml" in written
|
|
assert (repo / "profiles-source" / "default.yaml").exists()
|
|
assert (repo / "profiles" / "default.yaml").exists()
|
|
assert (repo / "kdb.yaml").exists()
|
|
|
|
report = adoption.verify(repo, plan)
|
|
assert "profiles-source" in report["preservedPaths"] or "kdb.yaml" in report["preservedPaths"]
|
|
assert report["outcome"] in {"pass", "pass-with-warnings"}
|
|
|
|
|
|
def test_assess_antivirus_legacy_detects_occupied_kdb_path(make_repo):
|
|
repo = make_repo("adoption/antivirus-legacy")
|
|
result = adoption.assess(repo)
|
|
kdb_paths = {entry["path"] for entry in result["knowledge"]}
|
|
assert "kdb/kdb.yaml" in kdb_paths
|
|
|
|
|
|
def test_plan_antivirus_legacy_does_not_overwrite_existing_kdb(make_repo):
|
|
repo = make_repo("adoption/antivirus-legacy")
|
|
assessment = adoption.assess(repo)
|
|
plan = adoption.build_plan(repo, assessment, confirmed_name="services-antivirus", confirmed_owners=["security"])
|
|
changes_by_path = {c["path"]: c for c in plan["changes"]}
|
|
assert changes_by_path["kdb/kdb.yaml"]["action"] == "preserve"
|
|
|
|
|
|
def test_apply_preserves_existing_antivirus_kdb_bytes(make_repo):
|
|
repo = make_repo("adoption/antivirus-legacy")
|
|
original = (repo / "kdb" / "kdb.yaml").read_bytes()
|
|
assessment = adoption.assess(repo)
|
|
plan = adoption.build_plan(repo, assessment, confirmed_name="services-antivirus", confirmed_owners=["security"])
|
|
adoption.apply_plan(repo, plan, plan["planHash"])
|
|
assert (repo / "kdb" / "kdb.yaml").read_bytes() == original
|