from __future__ import annotations from gitea_codex_bot.services.review_format import format_result_comment def test_format_result_comment_appends_structured_details_to_markdown_comment() -> None: body = format_result_comment( "abc1234", { "verdict": "has_issues", "confidence": 0.9, "summary": "2 issues detected.", "findings": [ { "severity": "high", "file": "src/app.py", "line_start": 20, "line_end": 22, "title": "Unsafe command execution", "body": "User input is passed directly into shell=True.", "suggestion": "Use a fixed argument list and avoid shell=True.", } ], "markdown_comment": "## Codex Review\n\nShort agent message only.", }, ) assert body.startswith("\n## Codex Review") assert "Short agent message only." in body assert "### Structured Findings" in body assert "2 issues detected." in body assert "`src/app.py:20-22` (high)" in body assert "Unsafe command execution" in body def test_format_result_comment_replaces_existing_marker() -> None: body = format_result_comment( "def5678", { "markdown_comment": "\n## Codex Review\n\nText.", }, ) assert body.startswith("") assert "old" not in body.splitlines()[0] def test_format_result_comment_appends_usage_note_for_markdown_comment() -> None: body = format_result_comment( "ff0011", { "markdown_comment": "## Codex Review\n\nLooks fine.", "_meta": { "model": "gpt-5.3-codex", "usage": {"input_tokens": 120, "output_tokens": 45, "total_tokens": 165}, }, }, ) assert "_Note: model `gpt-5.3-codex`, input `120`, output `45`, total `165` tokens used._" in body def test_format_result_comment_appends_usage_note_for_fallback_layout() -> None: body = format_result_comment( "ff0011", { "verdict": "correct", "confidence": 0.8, "summary": "No issues.", "findings": [], "_meta": {"model": "gpt-5.3-codex", "usage": {"total_tokens": 88}}, }, ) assert body.endswith("_Note: model `gpt-5.3-codex`, total `88` tokens used._") def test_format_result_comment_appends_missing_config_note_for_system_layout() -> None: body = format_result_comment( "ff0011", { "verdict": "correct", "confidence": 0.8, "summary": "No issues.", "findings": [], }, repo_configured=False, ) assert body.endswith("> ℹ️.codex-review.yml is not configured") def test_format_result_comment_appends_missing_config_note_to_agent_markdown() -> None: body = format_result_comment( "ff0011", { "markdown_comment": "## Codex Review\n\nLooks fine.", }, repo_configured=False, ) assert body.endswith("> ℹ️.codex-review.yml is not configured")