Files
gitea-codex/tests/test_review_format.py
2026-05-22 22:37:53 +02:00

83 lines
2.6 KiB
Python
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from __future__ import annotations
from gitea_codex_bot.services.review_format import format_result_comment
def test_format_result_comment_uses_markdown_comment_verbatim_with_marker() -> None:
body = format_result_comment(
"abc1234",
{
"verdict": "correct",
"confidence": 0.9,
"summary": "ignored when markdown_comment exists",
"findings": [],
"markdown_comment": "## Codex Review\n\nAll good.\n\nNo issues found.",
},
)
assert body.startswith("<!-- codex-review:head_sha=abc1234 -->\n## Codex Review")
assert "All good.\n\nNo issues found." in body
def test_format_result_comment_replaces_existing_marker() -> None:
body = format_result_comment(
"def5678",
{
"markdown_comment": "<!-- codex-review:head_sha=old -->\n## Codex Review\n\nText.",
},
)
assert body.startswith("<!-- codex-review:head_sha=def5678 -->")
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_does_not_append_missing_config_note_to_agent_markdown() -> None:
body = format_result_comment(
"ff0011",
{
"markdown_comment": "## Codex Review\n\nLooks fine.",
},
repo_configured=False,
)
assert ".codex-review.yml is not configured" not in body