Fix bugs that span several files
Send Claude Sonnet 4.5 the error, the failing test and the related files, and ask it to explain the cause before proposing the smallest fix. Review the diff and run the full suite before merging.
Example: Why is the last row missing from the CSV export?
Material
- Test output
- expected 3 rows in report.csv, got 2
- export.ts
- for (let i = 0; i < rows.length - 1; i++) writer.write(toCsv(rows[i]));
- rows.ts
- export const loadRows = () => db.query('SELECT * FROM orders WHERE paid = 1');
PromptUsing the test output and the two file excerpts, find the cause and give the smallest fix.
Sample answer · written by hand to show the reasoning
The bug is in export.ts: the loop runs while i < rows.length - 1, so the last row is never written. Change it to i < rows.length; the query in rows.ts is fine. Add a test with a single row so this off-by-one can’t come back.