- Add TSF file naming constraint to syntax/02_core_model.md - Clarify semicolon rules: syntax facts vs style preferences - Separate control flow end semicolon rules (syntax allows both) - Add function body semicolon requirements to syntax/05_functions_and_calls.md - Move style preferences to code_style.md (control flow end semicolons) - Remove cross-references from syntax docs to maintain independence - Enhance Gitea workflow emoji for better CI output readability - Fix CI test path from tests/ to test/ - Organize agent test results under test/agent/result/ directory - Add complete Chinese translation of test cases (test_cases_zh.md) - Clean up .gitignore to use unified test/agent/result/ directory - Remove obsolete agent test artifacts (REPORTS_LOCATION.md, old results) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
67 lines
1.9 KiB
Python
67 lines
1.9 KiB
Python
import os
|
|
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, env=None):
|
|
return subprocess.run(
|
|
[sys.executable, str(SCRIPT), *args],
|
|
capture_output=True,
|
|
text=True,
|
|
env=env,
|
|
)
|
|
|
|
|
|
class FormatMdActionTests(unittest.TestCase):
|
|
def test_format_md_invokes_prettier_from_path(self):
|
|
with tempfile.TemporaryDirectory() as tmp_dir:
|
|
root = Path(tmp_dir)
|
|
(root / "README.md").write_text("# Title\n", encoding="utf-8")
|
|
|
|
bin_dir = root / "bin"
|
|
bin_dir.mkdir()
|
|
if os.name == "nt":
|
|
prettier = bin_dir / "prettier.cmd"
|
|
prettier.write_text(
|
|
"@echo off\r\n"
|
|
"echo ok> .prettier_called\r\n",
|
|
encoding="utf-8",
|
|
)
|
|
else:
|
|
prettier = bin_dir / "prettier"
|
|
prettier.write_text(
|
|
"#!/usr/bin/env python3\n"
|
|
"from pathlib import Path\n"
|
|
"Path(\".prettier_called\").write_text(\"ok\")\n",
|
|
encoding="utf-8",
|
|
)
|
|
prettier.chmod(0o755)
|
|
|
|
config_body = f"""
|
|
[playbook]
|
|
project_root = \"{tmp_dir}\"
|
|
|
|
[format_md]
|
|
# tool defaults to prettier
|
|
# keep default globs
|
|
"""
|
|
config_path = root / "playbook.toml"
|
|
config_path.write_text(config_body, encoding="utf-8")
|
|
|
|
env = os.environ.copy()
|
|
env["PATH"] = f"{bin_dir}{os.pathsep}{env.get('PATH', '')}"
|
|
|
|
result = run_cli("-config", str(config_path), env=env)
|
|
self.assertEqual(result.returncode, 0, msg=result.stderr)
|
|
self.assertTrue((root / ".prettier_called").exists())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|