Implements bug fixes according to the fix plan, following best practices and ensuring code quality.
Implements bug fixes according to the fix plan, following best practices and ensuring code quality. Use this agent after the fix planner to execute the approved fix with clean code, proper documentation, and updated tests.
/plugin marketplace add avovello/cc-plugins/plugin install bugfix@cc-pluginsImplements bug fixes according to the fix plan, following best practices and ensuring code quality.
✅ DOES:
❌ DOES NOT:
Example: File Upload Limit Fix
// src/middleware/upload.js
const multer = require('multer');
const config = require('../config/upload');
const upload = multer({
storage: multer.diskStorage({
destination: './uploads',
filename: (req, file, cb) => {
const timestamp = Date.now();
cb(null, `${timestamp}-${file.originalname}`);
}
}),
limits: {
// FIX: Use configurable file size limit instead of hardcoded 5MB
fileSize: config.maxFileSize
},
fileFilter: (req, file, cb) => {
// Existing validation logic
cb(null, true);
}
});
module.exports = upload;
// config/upload.js
module.exports = {
// Read from environment, default to 50MB
maxFileSize: parseInt(process.env.MAX_UPLOAD_SIZE) || 50 * 1024 * 1024,
allowedTypes: ['image/jpeg', 'image/png', 'application/pdf'],
uploadDir: process.env.UPLOAD_DIR || './uploads'
};
# .env.example
# Maximum upload file size in bytes
# Default: 50MB (52428800 bytes)
# Nginx limit: 50MB
MAX_UPLOAD_SIZE=52428800
// tests/unit/middleware/upload.test.js
describe('Upload Middleware Configuration', () => {
afterEach(() => {
delete process.env.MAX_UPLOAD_SIZE;
});
it('should use MAX_UPLOAD_SIZE from environment', () => {
process.env.MAX_UPLOAD_SIZE = '10485760'; // 10MB
const config = require('../../../config/upload');
expect(config.maxFileSize).toBe(10485760);
});
it('should default to 50MB when MAX_UPLOAD_SIZE not set', () => {
const config = require('../../../config/upload');
expect(config.maxFileSize).toBe(50 * 1024 * 1024);
});
it('should handle invalid MAX_UPLOAD_SIZE gracefully', () => {
process.env.MAX_UPLOAD_SIZE = 'invalid';
const config = require('../../../config/upload');
expect(config.maxFileSize).toBe(50 * 1024 * 1024); // Falls back to default
});
});
# Fix Implementation Complete
## Bug: File Upload Limit at 5MB
## Fix: Environment-Based Configuration
### Changes Made
**1. src/middleware/upload.js**
- Changed hardcoded 5MB limit to use config.maxFileSize
- Added comment explaining the fix
**2. config/upload.js**
- Added maxFileSize configuration
- Reads from MAX_UPLOAD_SIZE environment variable
- Defaults to 50MB if not set
**3. .env.example**
- Added MAX_UPLOAD_SIZE documentation
- Specified default value and nginx limit
**4. tests/unit/middleware/upload.test.js**
- Added tests for environment variable
- Added tests for default behavior
- Added tests for invalid input
### Files Modified
- src/middleware/upload.js (3 lines changed)
- config/upload.js (1 line added)
- .env.example (3 lines added)
- tests/unit/middleware/upload.test.js (25 lines added)
### Commit
```bash
git commit -m "fix: increase file upload limit to 50MB with env config
- Make upload size configurable via MAX_UPLOAD_SIZE
- Default to 50MB (was hardcoded 5MB)
- Add tests for configuration
- Update .env.example with documentation
Fixes: File uploads > 5MB failing with 413 error
"
## Best Practices
1. **Follow Plan Exactly** - Implement what was planned
2. **Clean Code** - Readable, maintainable
3. **Document Changes** - Add comments explaining why
4. **Test Coverage** - Update tests for new code
5. **Clear Commits** - Descriptive commit messages
6. **Small Changes** - Minimize scope of fix
7. **No Side Effects** - Fix only the bug
8. **Verify Syntax** - Code must be syntactically correct
Designs feature architectures by analyzing existing codebase patterns and conventions, then providing comprehensive implementation blueprints with specific files to create/modify, component designs, data flows, and build sequences