Implemented three-layer defense mechanism to prevent AI-generated code from breaking the codebase: - Layer 1: AGENTS.md with universal AI agent instructions - Layer 2: Husky pre-commit hooks with test file checking - Layer 3: GitHub Actions CI with TypeScript, ESLint, tests, and coverage Includes design document, test infrastructure, and coverage thresholds. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2.9 KiB
AI Agent Guidelines for Multica
This document provides guidelines for AI coding agents working on this repository. Following these guidelines helps maintain code quality and prevents regressions.
Testing Requirements
When modifying code in this repository, you MUST:
-
Write tests for all new functionality - Every new function, class, or module must have corresponding unit tests
-
Update tests when modifying existing code - If you change behavior, update the related tests to reflect the new behavior
-
Run tests before committing - Execute
pnpm test:runand ensure all tests pass -
Maintain coverage - New code should have at least 80% test coverage. The CI enforces a minimum of 50% overall coverage.
Test File Conventions
Follow these conventions for test file locations:
| Source File | Test File Location |
|---|---|
src/main/**/*.ts |
tests/unit/main/**/*.test.ts |
src/shared/**/*.ts |
tests/unit/shared/**/*.test.ts |
| Integration tests | tests/integration/**/*.test.ts |
Example
If you modify src/main/conductor/Conductor.ts, ensure tests exist at tests/unit/main/conductor/Conductor.test.ts or create them if they don't exist.
Before Committing
Run these commands to verify your changes:
# TypeScript must compile without errors
pnpm typecheck
# No ESLint errors
pnpm lint
# Code must be properly formatted
pnpm format:check
# All tests must pass
pnpm test:run
# (Optional) Check coverage
pnpm test:coverage
CI Pipeline
The following checks run automatically on every pull request:
- TypeScript - Code must compile without errors
- ESLint - No linting errors allowed
- Prettier - Code must be properly formatted
- Tests - All tests must pass
- Coverage - Minimum 50% code coverage required
- Build - Application must build successfully
PRs that fail any of these checks should not be merged.
Writing Good Tests
Unit Tests
- Test one thing per test case
- Use descriptive test names that explain the expected behavior
- Mock external dependencies (Electron APIs, file system, network)
- Test both success and error cases
Example Test Structure
import { describe, it, expect, vi, beforeEach } from 'vitest'
describe('MyModule', () => {
beforeEach(() => {
vi.clearAllMocks()
})
describe('myFunction', () => {
it('should return expected result when given valid input', () => {
const result = myFunction('valid input')
expect(result).toBe('expected output')
})
it('should throw error when given invalid input', () => {
expect(() => myFunction('')).toThrow('Invalid input')
})
})
})
Common Mocks
The test setup provides mocks for:
- Electron APIs (
app,ipcMain,BrowserWindow, etc.) - ACP SDK (
@agentclientprotocol/sdk) - File system operations
See tests/setup/mocks/ for available mocks.