Repository navigation
test(file-io): cover the Python syntax gate and drop dead mocks - #6960
Conversation
The guard that stops broken Python reaching a source file had no test behind it: the fixtures mocked _validate_python_syntax and _parse_python_code, two helpers the code no longer calls, so the tests passed without touching the real gate. Add tests for write_python_file, edit_python_file and replace_function covering valid Python writing through, invalid Python being refused with the file left untouched, and validate=False bypassing the gate on write_python_file. Remove the dead mocks from all three fixtures that set them. Fixes amd#3955
|
Verdict: Approve with suggestions The checks that stop broken Python reaching a source file now have real tests behind them. Before this PR, the test setup faked two helper functions the code no longer calls, so deleting those checks would have left CI green. The new tests run the real checks for all three Python editing tools, and I found no correctness problems. The one suggestion is optional: trim a test docstring that tells the story of the fix. Real-world evidenceN/A: this PR only changes tests, so there is nothing a user can run. The verdict rests on static review. pytest isn't installed on this runner, so I couldn't run the new tests. The author reports 271 passed, 4 skipped, and that the new invalid-Python tests fail when the check is removed. 🔍 Technical detailsVerified
Issues 🟢 History narration in a test docstring ( Strengths
|
Removing the Python syntax check entirely would have kept CI green: the fixtures mocked _validate_python_syntax and _parse_python_code, two helpers the code no longer calls, so no test touched the real gate.
This adds tests for the three tools that enforce the gate, write_python_file, edit_python_file and replace_function. Valid Python writes through, invalid Python is refused with the file left untouched, and validate=False bypasses the gate on write_python_file. It also removes the dead mocks from all three fixtures that set them.
Note: the issue names write_file, edit_file and replace_lines, but the gate now lives in the Python-specific tools. write_file and edit_file write first and only report a syntax problem afterwards, which test_write_reports_syntax.py already covers.
Fixes #3955
Test plan: pytest on the four affected test files, 271 passed, 4 skipped. Temporarily removing the gate makes the new invalid-Python tests fail, so they genuinely exercise it.