Fix #232: Only print modified file paths in fix command output#326
Fix #232: Only print modified file paths in fix command output#326Serhan-Asad wants to merge 1 commit intopromptdriven:mainfrom
Conversation
…utput - Add modification detection to fix_error_loop.py (content comparison) - Add conditional output to fix_main.py based on modification flags - Loop mode: Only prints files that were actually modified - Non-loop mode: Unchanged behavior (uses LLM update flags) - Add comprehensive tests for modification detection - Extend return tuple from 6 to 8 values (added test_modified, code_modified)
There was a problem hiding this comment.
Pull request overview
This PR fixes issue #232 by modifying the pdd fix --loop command to only print file paths for files that were actually modified during the fix process, rather than printing paths for both test and code files regardless of which ones changed.
Changes:
- Modified
fix_error_loopto detect file modifications by comparing original content (read at start) with final content (read at end) - Extended
fix_error_loopreturn tuple from 6 to 8 values to includetest_file_was_modifiedandcode_file_was_modifiedboolean flags - Updated
fix_mainto conditionally print file paths based on modification status in loop mode while preserving existing behavior for non-loop mode
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| pdd/fix_error_loop.py | Adds content comparison logic to detect which files were modified, reads original content at function start and compares with final content at all return points |
| pdd/fix_main.py | Implements conditional output printing based on modification flags (loop mode) vs update flags (non-loop mode) |
| tests/test_fix_error_loop.py | Adds 2 new tests to verify modification detection works correctly for test-only and code-only changes |
| tests/test_fix_main.py | Adds parametrized tests covering 7 scenarios for both loop and non-loop modes to ensure correct output behavior |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| success, final_unit_test, final_code, attempts, total_cost, model_name, test_modified, code_modified = fix_error_loop( | ||
| unit_test_file, | ||
| code_file, | ||
| "dummy_prompt.txt", |
There was a problem hiding this comment.
This line adds a new positional argument prompt_file between existing parameters code_file and prompt, which changes the function signature. However, the function definition shows prompt_file is already the 3rd parameter. This creates a duplicate argument, which will cause a TypeError when the function is called.
| "dummy_prompt.txt", |
| auto_submit=False | ||
| ) | ||
| try: | ||
| success, fixed_test, fixed_code, attempts, cost, model = fix_main( |
There was a problem hiding this comment.
The unpacking expects 6 values but fix_main now returns a tuple with 6 values. However, this is inconsistent with the changes elsewhere in the file where all other calls to fix_error_loop are updated to unpack 8 values. The test should handle the return value consistently with other tests.
| success, fixed_test, fixed_code, attempts, cost, model = fix_main( | |
| success, fixed_test, fixed_code, attempts, cost, model, _, _ = fix_main( |
| mock_fix_error_loop.return_value = ( | ||
| True, | ||
| "test content", | ||
| "code content", | ||
| 2 if (test_modified or code_modified) else 0, | ||
| 1.25 if (test_modified or code_modified) else 0.0, | ||
| "gpt-4" if (test_modified or code_modified) else "", |
There was a problem hiding this comment.
The repeated conditional expression (test_modified or code_modified) appears three times in consecutive lines. Consider extracting this into a variable like files_were_modified = test_modified or code_modified to improve readability and maintainability.
| mock_fix_error_loop.return_value = ( | |
| True, | |
| "test content", | |
| "code content", | |
| 2 if (test_modified or code_modified) else 0, | |
| 1.25 if (test_modified or code_modified) else 0.0, | |
| "gpt-4" if (test_modified or code_modified) else "", | |
| files_were_modified = test_modified or code_modified | |
| mock_fix_error_loop.return_value = ( | |
| True, | |
| "test content", | |
| "code content", | |
| 2 if files_were_modified else 0, | |
| 1.25 if files_were_modified else 0.0, | |
| "gpt-4" if files_were_modified else "", |
|
Thanks for working on this fix, @Serhan-Asad! We've reviewed this PR against an alternative approach and decided to go with a simpler implementation. Here's a comparison: This PR's Approach
Alternative Approach (implemented)
if fixed_unit_test:
rprint(f" Test file: {output_file_paths['output_test']}")
if fixed_code:
rprint(f" Code file: {output_file_paths['output_code']}")RationaleThe simpler fix solves the reported problem without:
The edge case your approach handles (LLM returns identical content) is uncommon and arguably not incorrect to report. We appreciate the thorough analysis of alternatives mentioned in your PR description. Closing in favor of the simpler fix. |
|
Closing in favor of the simpler fix merged in commit 9d3d5d0. |
|
Reopening: this PR was automatically closed by a force push to main on Feb 9, not intentionally. |
Summary
Fix #232: Only print file paths that were actually modified in
pdd fixcommand output.Problem: The
pdd fix --loopcommand was printing paths for both test and code files even when only one file was modified, leading to confusion about which files actually changed.Solution:
fix_error_loop.pyby comparing original file content (read at start) with final content (read at end)test_file_was_modifiedandcode_file_was_modifiedboolean flagsfix_main.pyto conditionally print file paths based on modification status in loop modeApproach: Why Content Comparison?
After analyzing 10 alternative approaches (set-based tracking, mtime, hashing, wrapper classes, context managers, git diff, etc.), content comparison emerged as the optimal solution:
Why this approach:
Alternatives rejected:
See
ISSUE_232_ANALYSIS_ALL_APPROACHES.mdfor full analysis.Changes using pdd fix
pdd/fix_error_loop.py: Added content comparison for modification detection (48 lines modified)pdd/fix_main.py: Added conditional output logic for loop vs non-loop modes (20 lines modified)tests/test_fix_error_loop.py: Added 2 new modification detection tests (188 lines added)tests/test_fix_main.py: Added 2 parametrized tests covering 7 scenarios (209 lines added)Test Results
make regressionwith cloud credentials)make sync-regression)Issue #232 Specific Tests (9 scenarios):
test_fix_error_loop_returns_modification_flags_only_test_modifiedtest_fix_error_loop_returns_modification_flags_only_code_modifiedtest_fix_main_loop_mode_prints_only_modified_files(4 parametrized cases: only test, only code, both, neither)test_fix_main_non_loop_mode_uses_update_flags_and_checks_content(3 parametrized cases)Test improvements:
Manual Testing
Loop mode:
Non-loop mode:
Checklist
Fixes #232