Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pdd/fix_error_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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)
# ---------------------------------------------------------------------
Expand Down Expand Up @@ -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]")
Expand Down Expand Up @@ -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]")
Expand Down Expand Up @@ -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]")
Expand Down Expand Up @@ -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:
Expand Down
20 changes: 20 additions & 0 deletions tests/test_fix_error_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
run_pytest_on_file,
format_log_for_output,
_normalize_agentic_result,
_safe_run_agentic_fix,
escape_brackets
)

Expand Down Expand Up @@ -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
# ============================================================================
Expand Down
Loading