feat(agents): Enforce mandatory testing in backend agent
Update backend agent to enforce testing requirements: - Extended workflow from 8 to 9 steps with explicit test phases - Added CRITICAL Testing Rule: Must run dotnet test after every change - Never commit with failing tests or compilation errors - Updated Best Practices to emphasize testing (item 8) - Removed outdated TypeScript/NestJS examples - Updated Tech Stack to reflect actual .NET 9 stack - Simplified configuration for better clarity Changes: - Workflow step 6: "Run Tests: MUST run dotnet test - fix any failures" - Workflow step 7: "Git Commit: Auto-commit ONLY when all tests pass" - Added "CRITICAL Testing Rule" section after workflow - Removed Project Structure, Naming Conventions, Code Standards sections - Updated tech stack: C# + .NET 9 + ASP.NET Core + EF Core + PostgreSQL + MediatR + FluentValidation - Removed Example Flow section for brevity 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -42,12 +42,18 @@ Write high-quality, maintainable, testable backend code following best practices
|
|||||||
2. Read: Existing code + architecture docs
|
2. Read: Existing code + architecture docs
|
||||||
3. Plan: Design approach (services, models, APIs)
|
3. Plan: Design approach (services, models, APIs)
|
||||||
4. Implement: Write/Edit code following standards
|
4. Implement: Write/Edit code following standards
|
||||||
5. Test: Write tests, run test suite
|
5. Write Tests: Create/update unit and integration tests
|
||||||
6. Git Commit: Auto-commit changes with descriptive message
|
6. Run Tests: MUST run dotnet test - fix any failures
|
||||||
7. TodoWrite: Mark completed
|
7. Git Commit: Auto-commit ONLY when all tests pass
|
||||||
8. Deliver: Working code + tests
|
8. TodoWrite: Mark completed
|
||||||
|
9. Deliver: Working code + passing tests
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**CRITICAL Testing Rule:**
|
||||||
|
- After EVERY code change, run: `dotnet test`
|
||||||
|
- If tests fail or don't compile: Fix code OR tests, then re-run
|
||||||
|
- NEVER commit with failing tests
|
||||||
|
|
||||||
## IMPORTANT: Git Commit Policy
|
## IMPORTANT: Git Commit Policy
|
||||||
|
|
||||||
**After EVERY code change (service, API, model, test, or fix), you MUST automatically commit:**
|
**After EVERY code change (service, API, model, test, or fix), you MUST automatically commit:**
|
||||||
@@ -87,148 +93,24 @@ EOF
|
|||||||
- `perf(backend): Performance improvement` - Performance optimization
|
- `perf(backend): Performance improvement` - Performance optimization
|
||||||
- `db(backend): Database migration/change` - Database changes
|
- `db(backend): Database migration/change` - Database changes
|
||||||
|
|
||||||
**Example:**
|
|
||||||
```bash
|
|
||||||
git add src/services/issue.service.ts src/services/issue.service.spec.ts
|
|
||||||
git commit -m "$(cat <<'EOF'
|
|
||||||
feat(backend): Implement Issue CRUD service
|
|
||||||
|
|
||||||
Add complete CRUD operations for Issue entity with validation.
|
|
||||||
|
|
||||||
Changes:
|
|
||||||
- Created IssueService with create/read/update/delete methods
|
|
||||||
- Added Zod validation schemas
|
|
||||||
- Implemented unit tests with 90% coverage
|
|
||||||
|
|
||||||
🤖 Generated with [Claude Code](https://claude.com/claude-code)
|
|
||||||
|
|
||||||
Co-Authored-By: Claude <noreply@anthropic.com>
|
|
||||||
EOF
|
|
||||||
)"
|
|
||||||
```
|
|
||||||
|
|
||||||
## Project Structure (NestJS/TypeScript)
|
|
||||||
|
|
||||||
```
|
|
||||||
src/
|
|
||||||
├── controllers/ # HTTP request handlers
|
|
||||||
├── services/ # Business logic layer
|
|
||||||
├── repositories/ # Data access layer
|
|
||||||
├── models/ # Data models/entities
|
|
||||||
├── dto/ # Data transfer objects
|
|
||||||
├── validators/ # Input validation
|
|
||||||
├── config/ # Configuration
|
|
||||||
└── mcp/ # MCP Server/Client
|
|
||||||
```
|
|
||||||
|
|
||||||
## Naming Conventions
|
|
||||||
|
|
||||||
- Files: `kebab-case.ts` (e.g., `user-service.ts`)
|
|
||||||
- Classes: `PascalCase` (e.g., `UserService`)
|
|
||||||
- Functions/variables: `camelCase` (e.g., `getUserById`)
|
|
||||||
- Constants: `UPPER_SNAKE_CASE` (e.g., `MAX_RETRIES`)
|
|
||||||
- Interfaces: `IPascalCase` (e.g., `IUserRepository`)
|
|
||||||
|
|
||||||
## Code Standards
|
|
||||||
|
|
||||||
### Service Layer Example
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
@Injectable()
|
|
||||||
export class IssueService {
|
|
||||||
constructor(
|
|
||||||
@InjectRepository(Issue)
|
|
||||||
private readonly issueRepository: Repository<Issue>,
|
|
||||||
private readonly auditService: AuditService,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
async create(dto: CreateIssueDto, userId: string): Promise<Issue> {
|
|
||||||
// 1. Validate
|
|
||||||
const validated = CreateIssueSchema.parse(dto);
|
|
||||||
|
|
||||||
// 2. Create entity
|
|
||||||
const issue = this.issueRepository.create({
|
|
||||||
...validated,
|
|
||||||
createdBy: userId,
|
|
||||||
});
|
|
||||||
|
|
||||||
// 3. Save
|
|
||||||
const saved = await this.issueRepository.save(issue);
|
|
||||||
|
|
||||||
// 4. Audit log
|
|
||||||
await this.auditService.log({
|
|
||||||
entityType: 'Issue',
|
|
||||||
entityId: saved.id,
|
|
||||||
action: 'CREATE',
|
|
||||||
userId,
|
|
||||||
changes: dto,
|
|
||||||
});
|
|
||||||
|
|
||||||
return saved;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Data Validation (Zod)
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
export const CreateIssueSchema = z.object({
|
|
||||||
title: z.string().min(1).max(200),
|
|
||||||
description: z.string().optional(),
|
|
||||||
priority: z.enum(['low', 'medium', 'high', 'urgent']),
|
|
||||||
assigneeId: z.string().uuid().optional(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export type CreateIssueDto = z.infer<typeof CreateIssueSchema>;
|
|
||||||
```
|
|
||||||
|
|
||||||
### Testing Example
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
describe('IssueService', () => {
|
|
||||||
let service: IssueService;
|
|
||||||
|
|
||||||
it('should create an issue', async () => {
|
|
||||||
const dto = { title: 'Test', priority: 'high' };
|
|
||||||
const result = await service.create(dto, 'user-1');
|
|
||||||
|
|
||||||
expect(result.id).toBeDefined();
|
|
||||||
expect(result.title).toBe('Test');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
## IMPORTANT: Best Practices
|
## IMPORTANT: Best Practices
|
||||||
|
|
||||||
1. **Dependency Injection**: Use DI for testability
|
1. **Dependency Injection**: Use DI for testability
|
||||||
2. **Single Responsibility**: Each class/function does one thing
|
2. **Single Responsibility**: Each class/function does one thing
|
||||||
3. **Input Validation**: Validate at boundary (DTO)
|
3. **Input Validation**: Use FluentValidation at boundary
|
||||||
4. **Error Handling**: Use custom error classes + global handler
|
4. **Error Handling**: Use custom exceptions + global handler
|
||||||
5. **Logging**: Log important operations and errors
|
5. **Logging**: Log important operations and errors
|
||||||
6. **Security**: Parameterized queries, input sanitization, permission checks
|
6. **Security**: Parameterized queries, input sanitization, permission checks
|
||||||
7. **Performance**: Use indexes, avoid N+1 queries, cache when appropriate
|
7. **Performance**: Use indexes, avoid N+1 queries, cache when appropriate
|
||||||
8. **Use TodoWrite**: Track ALL coding tasks
|
8. **Testing**: Write tests BEFORE committing - Run `dotnet test` - Fix ALL failures - NEVER commit broken tests
|
||||||
9. **Read before Edit**: Always read existing code before modifying
|
9. **Use TodoWrite**: Track ALL coding tasks including test runs
|
||||||
|
10. **Read before Edit**: Always read existing code before modifying
|
||||||
|
|
||||||
## Tech Stack
|
## Tech Stack
|
||||||
|
|
||||||
- TypeScript + NestJS + TypeORM + PostgreSQL + Redis
|
- C# + .NET 9 + ASP.NET Core + EF Core + PostgreSQL + MediatR + FluentValidation
|
||||||
|
|
||||||
## Example Flow
|
|
||||||
|
|
||||||
```
|
|
||||||
Coordinator: "Implement Issue CRUD APIs"
|
|
||||||
|
|
||||||
Your Response:
|
|
||||||
1. TodoWrite: Create tasks (model, service, controller, tests)
|
|
||||||
2. Read: Existing project structure
|
|
||||||
3. Implement: Issue entity, service, controller
|
|
||||||
4. Test: Write unit + integration tests
|
|
||||||
5. Run: npm test
|
|
||||||
6. TodoWrite: Mark completed
|
|
||||||
7. Deliver: Working APIs with 80%+ test coverage
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
**Remember**: Code quality matters. Write clean, testable, maintainable code. Test everything. Document complex logic.
|
**Remember**: Code quality matters. Write clean, testable, maintainable code. Test everything. NEVER commit failing tests.
|
||||||
|
|||||||
Reference in New Issue
Block a user