playbook/tests/test_sync_templates_placeho...

102 lines
3.0 KiB
Python

import subprocess
import sys
import tempfile
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
SCRIPT = ROOT / "scripts" / "playbook.py"
def run_cli(*args):
return subprocess.run(
[sys.executable, str(SCRIPT), *args],
capture_output=True,
text=True,
)
def run_script(script_path: Path, *args, cwd: Path | None = None):
return subprocess.run(
[sys.executable, str(script_path), *args],
capture_output=True,
text=True,
cwd=str(cwd) if cwd else None,
)
class SyncTemplatesPlaceholdersTests(unittest.TestCase):
def test_main_language_placeholder_replaced(self):
with tempfile.TemporaryDirectory() as tmp_dir:
config_body = f"""
[playbook]
project_root = \"{tmp_dir}\"
[sync_rules]
[sync_standards]
langs = [\"cpp\", \"tsl\"]
"""
config_path = Path(tmp_dir) / "playbook.toml"
config_path.write_text(config_body, encoding="utf-8")
result = run_cli("-config", str(config_path))
self.assertEqual(result.returncode, 0, msg=result.stderr)
agents_md = Path(tmp_dir) / "AGENTS.md"
text = agents_md.read_text(encoding="utf-8")
self.assertIn(".agents/cpp/index.md", text)
self.assertNotIn("{{MAIN_LANGUAGE}}", text)
rules_md = Path(tmp_dir) / "AGENT_RULES.md"
rules_text = rules_md.read_text(encoding="utf-8")
self.assertIn("docs/standards/playbook/scripts/plan_progress.py", rules_text)
self.assertNotIn("{{PLAYBOOK_SCRIPTS}}", rules_text)
def test_sync_standards_rewrites_typescript_docs_prefix_for_vendored_playbook(self):
with tempfile.TemporaryDirectory() as tmp_dir:
root = Path(tmp_dir)
vendor_config = root / "vendor.toml"
vendor_config.write_text(
f"""
[playbook]
project_root = "{tmp_dir}"
[vendor]
langs = ["typescript"]
""",
encoding="utf-8",
)
vendor_result = run_cli("-config", str(vendor_config))
self.assertEqual(vendor_result.returncode, 0, msg=vendor_result.stderr)
sync_config = root / "sync.toml"
sync_config.write_text(
f"""
[playbook]
project_root = "{tmp_dir}"
[sync_standards]
langs = ["typescript"]
""",
encoding="utf-8",
)
vendored_script = (
root / "docs" / "standards" / "playbook" / "scripts" / "playbook.py"
)
sync_result = run_script(
vendored_script, "-config", str(sync_config), cwd=root
)
self.assertEqual(sync_result.returncode, 0, msg=sync_result.stderr)
agents_index = root / ".agents" / "typescript" / "index.md"
text = agents_index.read_text(encoding="utf-8")
self.assertIn("`docs/standards/playbook/docs/typescript/", text)
self.assertNotIn("`docs/typescript/", text)
if __name__ == "__main__":
unittest.main()