140 lines
4.8 KiB
Python
140 lines
4.8 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"
|
|
DEFAULT_DEPLOY_ROOT = "docs/standards/playbook"
|
|
|
|
|
|
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_templates_no_longer_expose_main_language_placeholder(self):
|
|
example_text = (ROOT / "playbook.toml.example").read_text(encoding="utf-8")
|
|
self.assertNotIn("main_language", example_text)
|
|
|
|
templates_readme = (ROOT / "templates" / "README.md").read_text(
|
|
encoding="utf-8"
|
|
)
|
|
self.assertNotIn("{{MAIN_LANGUAGE}}", templates_readme)
|
|
self.assertNotIn("{{LANGUAGE_1}}", templates_readme)
|
|
|
|
agents_template = (ROOT / "templates" / "AGENTS.template.md").read_text(
|
|
encoding="utf-8"
|
|
)
|
|
self.assertNotIn("{{MAIN_LANGUAGE}}", agents_template)
|
|
|
|
tech_stack_template = (
|
|
ROOT / "templates" / "memory-bank" / "tech-stack.template.md"
|
|
).read_text(encoding="utf-8")
|
|
self.assertNotIn("{{MAIN_LANGUAGE}}", tech_stack_template)
|
|
self.assertNotIn("{{LANGUAGE_1}}", tech_stack_template)
|
|
self.assertNotIn("**主要语言**", tech_stack_template)
|
|
|
|
def test_sync_templates_replaces_playbook_scripts_without_main_language_support(self):
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
config_body = f"""
|
|
[playbook]
|
|
project_root = \"{tmp_dir}\"
|
|
deploy_root = "{DEFAULT_DEPLOY_ROOT}"
|
|
|
|
[sync_rules]
|
|
|
|
[sync_memory_bank]
|
|
|
|
[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)
|
|
|
|
tech_stack = Path(tmp_dir) / "memory-bank" / "tech-stack.md"
|
|
tech_stack_text = tech_stack.read_text(encoding="utf-8")
|
|
self.assertNotIn("{{LANGUAGE_1}}", tech_stack_text)
|
|
self.assertNotIn("{{MAIN_LANGUAGE}}", tech_stack_text)
|
|
self.assertNotIn("**主要语言**", tech_stack_text)
|
|
|
|
rules_md = Path(tmp_dir) / "AGENT_RULES.md"
|
|
rules_text = rules_md.read_text(encoding="utf-8")
|
|
self.assertIn("docs/standards/playbook/scripts/main_loop.py claim", rules_text)
|
|
self.assertNotIn("plan_progress.py", rules_text)
|
|
self.assertIn("不得直接使用 `$executing-plans`", rules_text)
|
|
self.assertIn("不得直接使用 `$subagent-driven-development`", rules_text)
|
|
self.assertNotIn("{{PLAYBOOK_SCRIPTS}}", rules_text)
|
|
self.assertFalse(rules_text.endswith("\n\n"))
|
|
|
|
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}"
|
|
deploy_root = "{DEFAULT_DEPLOY_ROOT}"
|
|
|
|
[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}"
|
|
deploy_root = "{DEFAULT_DEPLOY_ROOT}"
|
|
|
|
[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()
|