AI coding assistants scaffold functions and tests rapidly, but merging generated diffs unread introduces subtle edge-case bugs. Always verify generated patches with targeted regression tests.
1. Toy Bug, Weak AI Patch, and Catching Regression Test
Consider a simple discount function that must reject negative prices:
# Buggy / weak AI patch: silently returns 0.0 instead of raising ValueError
def apply_discount(price: float, pct: float) -> float:
if price < 0:
return 0.0 # Masks invalid upstream data!
return round(price * (1 - pct / 100), 2)
# Regression test that catches silent error swallowing
import pytest
def test_negative_price_raises():
with pytest.raises(ValueError):
apply_discount(-50.0, 10)2. Pre-Merge Review Checklist
- Ask for unit tests covering empty inputs, negative values, and timeouts before accepting implementation code.
- Run the full test suite and linter locally after every edit.
- Audit every new dependency added to
package.jsonorrequirements.txt. - Reuse existing repository helpers instead of accepting duplicated utility functions.