Private
Public Access
0
0
Files
manual_slop/tests/test_aggregate_directives.py
T

94 lines
3.1 KiB
Python

"""Tests for scripts/aggregate_directives.py.
These tests exercise the script via subprocess to verify the contract:
- reads v1.md files only (never meta.md)
- emits clean bodies separated by '====' header
- exits 1 on missing files
- emits to stdout by default; -o writes to file
"""
from __future__ import annotations
import subprocess
import sys
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent
SCRIPT = REPO_ROOT / "scripts" / "aggregate_directives.py"
PRESET = REPO_ROOT / "conductor" / "directives" / "presets" / "current_baseline.md"
def _run(args: list[str], cwd: Path | None = None) -> subprocess.CompletedProcess:
return subprocess.run(
[sys.executable, str(SCRIPT), *args],
capture_output=True,
text=True,
encoding="utf-8",
cwd=cwd or REPO_ROOT,
)
def test_runs_against_current_baseline() -> None:
result = _run([str(PRESET)])
assert result.returncode == 0, "script should succeed; stderr=" + result.stderr
body = result.stdout
assert "atomic_per_task_commits" in body
assert "ban_dict_any" in body
assert "knowledge_harvest_pattern" in body
assert body.count("========================================") >= 51 * 2
def test_meta_md_pollution_fix() -> None:
result = _run([str(PRESET)])
body = result.stdout
assert "**Why this iteration:**" not in body
assert "**Lifted:**" not in body
def test_missing_file_exits_nonzero(tmp_path: Path) -> None:
bad = tmp_path / "bad_preset.md"
bad.write_text("- missing_thing: conductor/directives/missing_thing/v1.md\n", encoding="utf-8")
result = _run([str(bad)])
assert result.returncode != 0
assert "missing_thing" in result.stderr
def test_output_flag_writes_to_file(tmp_path: Path) -> None:
out = tmp_path / "out.md"
result = _run([str(PRESET), "-o", str(out)])
assert result.returncode == 0
assert out.exists()
content = out.read_text(encoding="utf-8")
assert "ban_dict_any" in content
assert content.count("========================================") >= 51 * 2
def test_no_meta_md_reads() -> None:
result = _run([str(PRESET)])
body = result.stdout
assert "Provenance" not in body
assert "## v1" not in body
assert "# ban_dict_any" not in body
DIRECTIVES_DIR = REPO_ROOT / "conductor" / "directives"
def _iter_v1_files() -> list[Path]:
return sorted(DIRECTIVES_DIR.glob("*/v1.md"))
def test_every_v1_has_top_level_heading() -> None:
v1_files = _iter_v1_files()
assert len(v1_files) >= 66, "expected at least 66 directive v1.md files; found " + str(len(v1_files))
missing: list[str] = []
for path in v1_files:
first_line = path.read_text(encoding="utf-8").splitlines()[0] if path.read_text(encoding="utf-8") else ""
if not first_line.startswith("# "):
missing.append(path.parent.name)
assert not missing, "v1.md files missing a top-level '# ' rule-statement heading: " + ", ".join(missing)
def test_v1_heading_is_not_meta_provenance_format() -> None:
for path in _iter_v1_files():
first_line = path.read_text(encoding="utf-8").splitlines()[0]
assert not first_line.strip().endswith("- v1"), path.parent.name + " uses the meta.md provenance heading format in v1.md body"