72 lines
2.2 KiB
Python
72 lines
2.2 KiB
Python
from pathlib import Path
|
|
|
|
import textwrap
|
|
|
|
import pytest
|
|
|
|
from automation.config import RulesConfig
|
|
from automation.ai_config import DEFAULT_SENTINEL
|
|
from automation.patcher import ModelConfig
|
|
from automation.runner import process
|
|
|
|
from tests.test_patcher import run as run_git
|
|
|
|
|
|
@pytest.fixture()
|
|
def repo(tmp_path: Path) -> Path:
|
|
repo = tmp_path / "repo"
|
|
repo.mkdir()
|
|
run_git(["git", "init"], cwd=repo)
|
|
run_git(["git", "config", "user.email", "dev@example.com"], cwd=repo)
|
|
run_git(["git", "config", "user.name", "Dev"], cwd=repo)
|
|
|
|
(repo / "Docs/features/FR_1/discussions").mkdir(parents=True, exist_ok=True)
|
|
(repo / "Docs/features/FR_1/discussions/example.discussion.md").write_text("- Note\n", encoding="utf-8")
|
|
run_git(["git", "add", "Docs/features/FR_1/discussions/example.discussion.md"], cwd=repo)
|
|
|
|
(repo / ".ai-rules.yml").write_text(
|
|
textwrap.dedent(
|
|
"""
|
|
file_associations:
|
|
example.discussion.md: discussion_rule
|
|
rules:
|
|
discussion_rule:
|
|
outputs:
|
|
summary:
|
|
path: "Docs/features/FR_1/discussions/example.discussion.sum.md"
|
|
instruction: "Create summary"
|
|
"""
|
|
).strip()
|
|
+ "\n",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
return repo
|
|
|
|
|
|
def test_process_generates_output(repo: Path, tmp_path: Path) -> None:
|
|
patch_text = """<<<AI_DIFF_START>>>
|
|
diff --git a/Docs/features/FR_1/discussions/example.discussion.sum.md b/Docs/features/FR_1/discussions/example.discussion.sum.md
|
|
--- /dev/null
|
|
+++ b/Docs/features/FR_1/discussions/example.discussion.sum.md
|
|
@@ -0,0 +1,2 @@
|
|
+Summary line
|
|
+Another line
|
|
<<<AI_DIFF_END>>>
|
|
"""
|
|
patch_file = tmp_path / "patch.txt"
|
|
patch_file.write_text(patch_text, encoding="utf-8")
|
|
|
|
rules = RulesConfig.load(repo)
|
|
model = ModelConfig(
|
|
commands=[f"bash -lc 'cat {patch_file.as_posix()}'"],
|
|
sentinel=DEFAULT_SENTINEL,
|
|
)
|
|
|
|
rc = process(repo, rules, model)
|
|
assert rc == 0
|
|
|
|
output_file = repo / "Docs/features/FR_1/discussions/example.discussion.sum.md"
|
|
assert output_file.exists()
|
|
assert output_file.read_text(encoding="utf-8") == "Summary line\nAnother line\n"
|