85 lines
2.4 KiB
Python
85 lines
2.4 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from engine.devops_agent import cli
|
|
|
|
|
|
class FakeProvider:
|
|
def __init__(self, *, base_url: str, token: str) -> None:
|
|
self.base_url = base_url
|
|
self.token = token
|
|
|
|
def parse_issue_comment_event(self, payload: dict[str, object]) -> dict[str, object]:
|
|
repository = payload["repository"]
|
|
issue = payload["issue"]
|
|
comment = payload["comment"]
|
|
return {
|
|
"repo": repository["full_name"],
|
|
"issue_number": issue["number"],
|
|
"comment_body": comment["body"],
|
|
}
|
|
|
|
def get_issue(self, repo: str, issue_number: int) -> dict[str, object]:
|
|
return {
|
|
"number": issue_number,
|
|
"title": "Fix issue delivery flow",
|
|
"body": "The agent should post evidence back to the issue.",
|
|
"state": "open",
|
|
"repo": repo,
|
|
}
|
|
|
|
def post_issue_comment(self, repo: str, issue_number: int, body: str) -> dict[str, object]:
|
|
return {"id": 1, "repo": repo, "issue_number": issue_number, "body": body}
|
|
|
|
|
|
def test_compile_command_writes_lock_file() -> None:
|
|
output_path = Path(".tmp/cli-tests/gitea-issue-delivery.lock.json")
|
|
output_path.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
exit_code = cli.main(
|
|
[
|
|
"compile",
|
|
"workflows/gitea-issue-delivery.md",
|
|
"--output",
|
|
str(output_path),
|
|
]
|
|
)
|
|
|
|
assert exit_code == 0
|
|
assert output_path.exists()
|
|
|
|
|
|
def test_validate_command_returns_success() -> None:
|
|
exit_code = cli.main(["validate", "workflows/gitea-issue-delivery.md"])
|
|
|
|
assert exit_code == 0
|
|
|
|
|
|
def test_run_command_writes_runtime_artifact(monkeypatch) -> None:
|
|
output_dir = Path(".tmp/cli-tests/runtime-run")
|
|
output_dir.mkdir(parents=True, exist_ok=True)
|
|
monkeypatch.setattr(cli, "GiteaProvider", FakeProvider)
|
|
|
|
exit_code = cli.main(
|
|
[
|
|
"run",
|
|
"workflows/gitea-issue-delivery.md",
|
|
"--event-payload",
|
|
"tests/fixtures/gitea/comment_event.json",
|
|
"--output-dir",
|
|
str(output_dir),
|
|
"--base-url",
|
|
"https://fun-md.com",
|
|
"--token",
|
|
"fake-token",
|
|
]
|
|
)
|
|
|
|
artifact_path = output_dir / "run-artifact.json"
|
|
artifact = json.loads(artifact_path.read_text(encoding="utf-8"))
|
|
|
|
assert exit_code == 0
|
|
assert artifact["result"] == "success"
|