Runbook 11.1 and 11.2 are decision tables, and nothing tied them to branches: the two existing antivirus-legacy tests asserted only that kdb/kdb.yaml was preserved, which stayed true while the surrounding behaviour was wrong. These cases are parametrized over the table rows so prose and code cannot drift apart again without a failure. Writing them found two defects that no existing test could see. splice_managed_block validated the file it patched but never the block being inserted, so a hand-edited plan carrying unbalanced markers would have been written in and only failed on a later run. And the adoption output schemas were validated nowhere, which had let the richer content roots from the previous commit silently stop conforming to AdoptionAssessment. - table-driven coverage of the knowledge and agent-entrypoint rows - path escape, forbidden path, dirty gate, rollback and preserve-tampering cases - schema conformance for assessment, plan, report and the generated contract - widen proposedContentRoots for writePolicy/generatedFrom, and constrain authority to the enum it always should have used - add a synthetic_repo fixture instead of a fourth copy of git init Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
73 lines
2.2 KiB
Python
73 lines
2.2 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 synthetic_repo(tmp_path):
|
|
"""Build a repository from an explicit path -> content mapping.
|
|
|
|
The checked-in fixtures cover two concrete legacy layouts; the adoption
|
|
compatibility tables need many small permutations of knowledge files and
|
|
agent entrypoints, which are clearer written inline than as dozens of
|
|
near-identical fixture trees.
|
|
"""
|
|
|
|
def _make(files: dict[str, str], *, name: str = "repo", git: bool = True) -> Path:
|
|
dest = tmp_path / name
|
|
dest.mkdir(parents=True, exist_ok=True)
|
|
for relative, content in files.items():
|
|
target = dest / relative
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
target.write_text(content, encoding="utf-8")
|
|
if git:
|
|
_git_init(dest)
|
|
return dest
|
|
|
|
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
|