[refactor]. Remove legacy review prompt path
This commit is contained in:
@@ -12,6 +12,7 @@ from gitea_codex_bot.workers.container_runner import (
|
||||
RESULT_END_MARKER,
|
||||
RESULT_START_MARKER,
|
||||
_build_docker_command,
|
||||
_build_exec_review_prompt,
|
||||
_build_install_and_run_command,
|
||||
_extract_result_meta_from_codex_stdout,
|
||||
_load_codex_auth_json_b64,
|
||||
@@ -95,7 +96,7 @@ def test_build_install_command_chatgpt_mode_sets_git_checkout_and_review(monkeyp
|
||||
settings = get_settings()
|
||||
pr = _sample_pr()
|
||||
|
||||
command = _build_install_and_run_command(settings, pr=pr)
|
||||
command = _build_install_and_run_command(settings, pr=pr, review_prompt="review: security --full")
|
||||
|
||||
assert 'printf "%s" "$CODEX_AUTH_JSON_B64" | base64 -d > /root/.codex/auth.json' in command
|
||||
assert "git -c http.extraHeader=" in command
|
||||
@@ -107,7 +108,8 @@ def test_build_install_command_chatgpt_mode_sets_git_checkout_and_review(monkeyp
|
||||
assert f"git checkout --detach {pr.head_sha}" in command
|
||||
assert "resolved_head=\"$(git rev-parse HEAD)\"" in command
|
||||
assert "unset GITEA_TOKEN auth_b64" in command
|
||||
assert f"codex exec review --base {pr.base_sha}" in command
|
||||
assert "codex exec --json --output-schema /tmp/codex-review-schema.json -o /tmp/codex-review-result.json" in command
|
||||
assert "review: security --full" in command
|
||||
assert "--output-schema /tmp/codex-review-schema.json" in command
|
||||
assert "-o /tmp/codex-review-result.json" in command
|
||||
assert "npm install -g @openai/codex@latest" in command
|
||||
@@ -121,7 +123,7 @@ def test_build_install_command_does_not_include_reasoning_effort_flag() -> None:
|
||||
settings = get_settings()
|
||||
pr = _sample_pr()
|
||||
|
||||
command = _build_install_and_run_command(settings, pr=pr)
|
||||
command = _build_install_and_run_command(settings, pr=pr, review_prompt="review: tests")
|
||||
|
||||
assert "--reasoning-effort" not in command
|
||||
|
||||
@@ -130,7 +132,7 @@ def test_build_install_command_uses_upstream_remote_for_fork_pr_base_fetch() ->
|
||||
settings = get_settings()
|
||||
pr = _sample_fork_pr()
|
||||
|
||||
command = _build_install_and_run_command(settings, pr=pr)
|
||||
command = _build_install_and_run_command(settings, pr=pr, review_prompt="review: tests")
|
||||
|
||||
assert "base_remote=upstream" in command
|
||||
assert f"git remote add upstream {pr.base_clone_url}" in command
|
||||
@@ -320,6 +322,18 @@ def test_parse_review_result_from_stdout_artifact_fails_without_markers() -> Non
|
||||
_parse_review_result_from_stdout_artifact("no markers here")
|
||||
|
||||
|
||||
def test_build_exec_review_prompt_strips_mention_and_command() -> None:
|
||||
prompt = _build_exec_review_prompt(
|
||||
ParsedCommand(name="review", raw="@codex review security --full\nfocus session handling")
|
||||
)
|
||||
assert prompt == "review: security --full\nfocus session handling"
|
||||
|
||||
|
||||
def test_build_exec_review_prompt_falls_back_when_no_extra_text() -> None:
|
||||
prompt = _build_exec_review_prompt(ParsedCommand(name="rerun", raw="@codex rerun"))
|
||||
assert prompt == "review: review this pull request and report introduced issues."
|
||||
|
||||
|
||||
def test_extract_result_meta_from_codex_stdout_collects_model_and_usage() -> None:
|
||||
settings = get_settings()
|
||||
stdout = "\n".join(
|
||||
|
||||
@@ -1,107 +0,0 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import httpx
|
||||
|
||||
from gitea_codex_bot.config import get_settings
|
||||
from gitea_codex_bot.services.repo_config import RepoReviewConfig
|
||||
from gitea_codex_bot.services.reviewer import _build_prompt, _fallback_review, prepare_review_prompt, run_review_for_pr
|
||||
from gitea_codex_bot.types import ParsedCommand
|
||||
|
||||
|
||||
def test_fallback_review_surfaces_failure_reason() -> None:
|
||||
result = _fallback_review({"diff": ""}, failure_reason="OpenAI API HTTP 401: invalid_api_key")
|
||||
|
||||
assert result["verdict"] == "has_issues"
|
||||
assert result["summary"] == "OpenAI review failed. Error: OpenAI API HTTP 401: invalid_api_key"
|
||||
assert result["findings"][0]["title"] == "OpenAI review request failed"
|
||||
assert result["findings"][0]["body"] == "OpenAI API HTTP 401: invalid_api_key"
|
||||
|
||||
|
||||
def test_run_review_for_pr_uses_openai_http_error_in_fallback(monkeypatch) -> None:
|
||||
def _fake_prepare(*_args, **_kwargs):
|
||||
return "prompt", {"diff": "TODO: tighten validation"}, RepoReviewConfig()
|
||||
|
||||
def _raise_http_error(*_args, **_kwargs):
|
||||
request = httpx.Request("POST", "https://api.openai.com/v1/responses")
|
||||
response = httpx.Response(429, request=request, text='{"error":{"message":"rate_limited"}}')
|
||||
raise httpx.HTTPStatusError("rate limited", request=request, response=response)
|
||||
|
||||
monkeypatch.setattr("gitea_codex_bot.services.reviewer.prepare_review_prompt", _fake_prepare)
|
||||
monkeypatch.setattr("gitea_codex_bot.services.reviewer._call_openai_review", _raise_http_error)
|
||||
|
||||
settings = get_settings()
|
||||
command = ParsedCommand(name="review", raw="@codex review")
|
||||
result, _repo_cfg = run_review_for_pr(settings, object(), "acme/repo", 9, command)
|
||||
|
||||
assert result["summary"].startswith("OpenAI review failed. Error: OpenAI API HTTP 429:")
|
||||
assert result["findings"][0]["title"] == "OpenAI review request failed"
|
||||
assert "rate_limited" in result["findings"][0]["body"]
|
||||
|
||||
|
||||
def test_build_prompt_includes_trigger_message() -> None:
|
||||
pr = type("PR", (), {"html_url": "https://gitea.example/pr/1"})()
|
||||
command = ParsedCommand(name="review", raw="@codex review security\nPlease focus auth.")
|
||||
diff_context = {"truncated": False, "changed_files": ["app.py"], "diff": "diff --git a/app.py b/app.py"}
|
||||
repo_cfg = RepoReviewConfig()
|
||||
|
||||
prompt = _build_prompt(
|
||||
pr,
|
||||
command,
|
||||
diff_context,
|
||||
repo_cfg,
|
||||
changed_file_contents="",
|
||||
test_output=None,
|
||||
)
|
||||
|
||||
assert "Trigger message: @codex review security\nPlease focus auth." in prompt
|
||||
|
||||
|
||||
def test_build_prompt_uses_empty_placeholders_and_no_network_instruction() -> None:
|
||||
pr = type("PR", (), {"html_url": "https://gitea.example/pr/1"})()
|
||||
command = ParsedCommand(name="review", raw="@codex review")
|
||||
diff_context = {"truncated": False, "changed_files": [], "diff": ""}
|
||||
repo_cfg = RepoReviewConfig()
|
||||
|
||||
prompt = _build_prompt(
|
||||
pr,
|
||||
command,
|
||||
diff_context,
|
||||
repo_cfg,
|
||||
changed_file_contents="",
|
||||
test_output=None,
|
||||
)
|
||||
|
||||
assert "You do not have internet/network access. Do not try to fetch URLs." in prompt
|
||||
assert "Never claim that PR content is inaccessible or missing if these sections are present." in prompt
|
||||
assert "Changed files:\n(none)" in prompt
|
||||
assert "Unified diff:\n(empty)" in prompt
|
||||
|
||||
|
||||
def test_prepare_review_prompt_applies_repo_default_mode_when_command_mode_not_explicit(monkeypatch, tmp_path) -> None:
|
||||
repo_dir = tmp_path / "repo"
|
||||
repo_dir.mkdir(parents=True, exist_ok=True)
|
||||
(repo_dir / ".codex-review.yml").write_text("review:\n default_mode: tests\n", encoding="utf-8")
|
||||
|
||||
pr = type(
|
||||
"PR",
|
||||
(),
|
||||
{
|
||||
"base_sha": "b" * 40,
|
||||
"head_sha": "a" * 40,
|
||||
"html_url": "https://gitea.example/pr/1",
|
||||
},
|
||||
)()
|
||||
|
||||
monkeypatch.setattr("gitea_codex_bot.services.reviewer.checkout_pr", lambda *_args, **_kwargs: repo_dir)
|
||||
monkeypatch.setattr(
|
||||
"gitea_codex_bot.services.reviewer.collect_diff_context",
|
||||
lambda *_args, **_kwargs: {"diff": "", "changed_files": [], "truncated": False},
|
||||
)
|
||||
|
||||
settings = get_settings()
|
||||
gitea = type("GiteaStub", (), {"get_pull_request": lambda *_args, **_kwargs: pr})()
|
||||
command = ParsedCommand(name="review", raw="@codex review")
|
||||
|
||||
prompt, _diff, _cfg = prepare_review_prompt(settings, gitea, "acme/repo", 9, command)
|
||||
|
||||
assert "Mode: tests" in prompt
|
||||
Reference in New Issue
Block a user