diff --git a/pdd/fix_error_loop.py b/pdd/fix_error_loop.py index e719f068e..551dccf3f 100644 --- a/pdd/fix_error_loop.py +++ b/pdd/fix_error_loop.py @@ -195,7 +195,7 @@ def _normalize_agentic_result(result): # Fallback (shouldn't happen) return False, "Invalid agentic result shape", 0.0, "agentic-cli", [] -def _safe_run_agentic_fix(*, prompt_file, code_file, unit_test_file, error_log_file, cwd=None): +def _safe_run_agentic_fix(*, prompt_file, code_file, unit_test_file, error_log_file, cwd=None, protect_tests: bool = False): """ Call (possibly monkeypatched) run_agentic_fix and normalize its return. """ @@ -205,6 +205,7 @@ def _safe_run_agentic_fix(*, prompt_file, code_file, unit_test_file, error_log_f unit_test_file=unit_test_file, error_log_file=error_log_file, cwd=cwd, + protect_tests=protect_tests, ) return _normalize_agentic_result(res) # --------------------------------------------------------------------- @@ -424,6 +425,7 @@ def fix_error_loop(unit_test_file: str, unit_test_file=unit_test_file, error_log_file=error_log_file, cwd=None, # Use project root (cwd), not prompt file's parent + protect_tests=protect_tests, ) if not success: rprint(f"[bold red]Agentic fix fallback failed: {agent_msg}[/bold red]") @@ -481,6 +483,7 @@ def fix_error_loop(unit_test_file: str, unit_test_file=unit_test_file, error_log_file=error_log_file, cwd=None, + protect_tests=protect_tests, ) if not success: rprint(f"[bold red]Agentic fix fallback failed: {agent_msg}[/bold red]") @@ -521,6 +524,7 @@ def fix_error_loop(unit_test_file: str, unit_test_file=unit_test_file, error_log_file=error_log_file, cwd=None, # Use project root (cwd), not prompt file's parent + protect_tests=protect_tests, ) if not success: rprint(f"[bold red]Agentic fix fallback failed: {agent_msg}[/bold red]") @@ -998,6 +1002,7 @@ def fix_error_loop(unit_test_file: str, unit_test_file=unit_test_file, error_log_file=error_log_file, cwd=None, # Use project root (cwd), not prompt file's parent + protect_tests=protect_tests, ) total_cost += agent_cost if not agent_success: diff --git a/tests/test_fix_error_loop.py b/tests/test_fix_error_loop.py index d5c94e50d..aa2da980a 100644 --- a/tests/test_fix_error_loop.py +++ b/tests/test_fix_error_loop.py @@ -13,6 +13,7 @@ run_pytest_on_file, format_log_for_output, _normalize_agentic_result, + _safe_run_agentic_fix, escape_brackets ) @@ -1744,6 +1745,25 @@ def test_protect_tests_prevents_unit_test_write(mock_subprocess, mock_fix, mock_ "Test file should NOT be modified when protect_tests=True" +@patch("pdd.fix_error_loop.run_agentic_fix") +def test_safe_run_agentic_fix_preserves_protect_tests_flag(mock_run_agentic_fix): + """Regression test: agentic fallback must receive protect_tests from fix_error_loop.""" + mock_run_agentic_fix.return_value = (True, "ok", 0.0, "agentic-cli", []) + + _safe_run_agentic_fix( + prompt_file="prompt.txt", + code_file="code.py", + unit_test_file="test.py", + error_log_file="error.log", + cwd=".", + protect_tests=True, + ) + + mock_run_agentic_fix.assert_called_once() + _, kwargs = mock_run_agentic_fix.call_args + assert kwargs["protect_tests"] is True, "protect_tests should be forwarded to run_agentic_fix" + + # ============================================================================ # Bug Fix Tests - Issue #485: Warnings block success gate # ============================================================================