9d3222ddc0
Aggregates v1.md bodies from a preset markdown into a single output stream. NEVER reads meta.md (pollution fix). Stdlib-only; supports stdout and -o. 5 tests in tests/test_aggregate_directives.py cover: success path, no-meta-md pollution, missing-file error, -o flag, no provenance leakage.
70 lines
2.1 KiB
Python
70 lines
2.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 |