repo-manager/tests/test_scaffold.py
tegwick 35e86d7b85 feat: advance repository records and provenance
Assistant: codex
Assistant-Model: gpt-5.6-sol
Assistant-Session: 01a023c0-a0a3-7c03-b395-5a0d2757214d
2026-08-21 22:07:48 +02:00

77 lines
2.7 KiB
Python

from pathlib import Path
from repo_manager.cli import main
from repo_manager.commands.scaffold import scaffold_repository
from repo_manager.standards import check_repository
def test_prj_scaffold_requires_prefix(tmp_path: Path):
dest = tmp_path / "prj-example"
result = scaffold_repository(dest, flavor="project", commit=False)
assert result.status == "rejected"
assert "wp-prefix" in (result.error or {}).get("message", "").lower() or "PRJ" in str(
result.error
)
def test_prj_scaffold_refuses_flavor_prefix(tmp_path: Path):
dest = tmp_path / "prj-example"
result = scaffold_repository(dest, flavor="project", wp_prefix="PRJ-WP", commit=False)
assert result.status == "rejected"
def test_prj_scaffold_writes_goal_not_intent(tmp_path: Path):
dest = tmp_path / "prj-example-cutover"
result = scaffold_repository(
dest, flavor="project", wp_prefix="EXCO-WP", commit=False
)
assert result.status == "applied"
assert (dest / "GOAL.md").is_file()
assert not (dest / "INTENT.md").exists()
goal = (dest / "GOAL.md").read_text()
for heading in ("Outcome", "Invariants", "Success gates", "Project retirement"):
assert heading in goal
assert not list((dest / "workplans").glob("*-0001-*.md"))
report = check_repository(dest)
assert report.ok, report.to_dict()
def test_durable_scaffold_writes_intent(tmp_path: Path):
dest = tmp_path / "some-tool"
result = scaffold_repository(dest, flavor="tooling", commit=False)
assert result.status == "applied"
assert (dest / "INTENT.md").is_file()
assert not (dest / "GOAL.md").exists()
assert (dest / "workplans" / "SOMETOOL-WP-0001-foundation.md").is_file()
report = check_repository(dest)
assert report.ok, report.to_dict()
def test_scaffold_rerun_is_an_applied_noop(tmp_path: Path):
dest = tmp_path / "stable-tool"
first = scaffold_repository(dest, flavor="tooling", commit=False)
before = {path.relative_to(dest): path.read_bytes() for path in dest.rglob("*") if path.is_file()}
second = scaffold_repository(dest, flavor="tooling", commit=False)
after = {path.relative_to(dest): path.read_bytes() for path in dest.rglob("*") if path.is_file()}
assert first.status == second.status == "applied"
assert second.evidence["noop"] is True
assert second.evidence["written"] == []
assert after == before
def test_cli_scaffold(tmp_path: Path):
dest = tmp_path / "cli-tool"
assert (
main(
[
"scaffold",
"--path",
str(dest),
"--flavor",
"tooling",
"--no-commit",
]
)
== 0
)
assert (dest / "INTENT.md").is_file()