Files
Charon/CONTRIBUTING.md
GitHub Actions 73aad74699 test: improve backend test coverage to 85.4%
Add 38 new test cases across 6 backend files to address Codecov gaps:
- log_watcher.go: 56.25% → 98.2% (+41.95%)
- crowdsec_handler.go: 62.62% → 80.0% (+17.38%)
- routes.go: 69.23% → 82.1% (+12.87%)
- console_enroll.go: 79.59% → 83.3% (+3.71%)
- crowdsec_startup.go: 94.73% → 94.5% (maintained)
- crowdsec_exec.go: 92.85% → 81.0% (edge cases)

Test coverage improvements include:
- Security event detection (WAF, CrowdSec, ACL, rate limiting)
- LAPI decision management and health checking
- Console enrollment validation and error handling
- CrowdSec startup reconciliation edge cases
- Command execution error paths
- Configuration file operations

All quality gates passed:
- 261 backend tests passing (100% success rate)
- Pre-commit hooks passing
- Zero security vulnerabilities (Trivy)
- Clean builds (backend + frontend)
- Updated documentation and Codecov targets

Closes #N/A (addresses Codecov report coverage gaps)
2025-12-16 14:10:32 +00:00

8.7 KiB

Contributing to Charon

Thank you for your interest in contributing to CaddyProxyManager+! This document provides guidelines and instructions for contributing to the project.

Table of Contents

Code of Conduct

This project follows a Code of Conduct that all contributors are expected to adhere to:

  • Be respectful and inclusive
  • Welcome newcomers and help them get started
  • Focus on what's best for the community
  • Show empathy towards other community members

Getting Started

-### Prerequisites

  • Go 1.24+ for backend development
  • Node.js 20+ and npm for frontend development
  • Git for version control
  • A GitHub account

Fork and Clone

  1. Fork the repository on GitHub
  2. Clone your fork locally:
git clone https://github.com/YOUR_USERNAME/charon.git
cd charon
  1. Add the upstream remote:
git remote add upstream https://github.com/Wikid82/charon.git

Set Up Development Environment

Backend:

cd backend
go mod download
go run ./cmd/seed/main.go  # Seed test data
go run ./cmd/api/main.go   # Start backend

Frontend:

cd frontend
npm install
npm run dev  # Start frontend dev server

Development Workflow

Branching Strategy

  • main - Production-ready code
  • development - Main development branch (default)
  • feature/ - Feature branches (e.g., feature/add-ssl-support)
  • bugfix/ - Bug fix branches (e.g., bugfix/fix-import-crash)
  • hotfix/ - Urgent production fixes

Creating a Feature Branch

Always branch from development:

git checkout development
git pull upstream development
git checkout -b feature/your-feature-name

Commit Message Guidelines

Follow the Conventional Commits specification:

<type>(<scope>): <subject>

<body>

<footer>

Types:

  • feat: New feature
  • fix: Bug fix
  • docs: Documentation only
  • style: Code style changes (formatting, etc.)
  • refactor: Code refactoring
  • test: Adding or updating tests
  • chore: Maintenance tasks

Examples:

feat(proxy-hosts): add SSL certificate upload

- Implement certificate upload endpoint
- Add UI for certificate management
- Update database schema

Closes #123
fix(import): resolve conflict detection bug

When importing Caddyfiles with multiple domains, conflicts
were not being detected properly.

Fixes #456

Keeping Your Fork Updated

git checkout development
git fetch upstream
git merge upstream/development
git push origin development

Coding Standards

Go Backend

  • Follow standard Go formatting (gofmt)
  • Use meaningful variable and function names
  • Write godoc comments for exported functions
  • Keep functions small and focused
  • Handle errors explicitly

Example:

// GetProxyHost retrieves a proxy host by UUID.
// Returns an error if the host is not found.
func GetProxyHost(uuid string) (*models.ProxyHost, error) {
    var host models.ProxyHost
    if err := db.First(&host, "uuid = ?", uuid).Error; err != nil {
        return nil, fmt.Errorf("proxy host not found: %w", err)
    }
    return &host, nil
}

TypeScript Frontend

  • Use TypeScript for type safety
  • Follow React best practices and hooks patterns
  • Use functional components
  • Destructure props at function signature
  • Extract reusable logic into custom hooks

Example:

interface ProxyHostFormProps {
  host?: ProxyHost
  onSubmit: (data: ProxyHostData) => Promise<void>
  onCancel: () => void
}

export function ProxyHostForm({ host, onSubmit, onCancel }: ProxyHostFormProps) {
  const [domain, setDomain] = useState(host?.domain ?? '')
  // ... component logic
}

CSS/Styling

  • Use TailwindCSS utility classes
  • Follow the dark theme color palette
  • Keep custom CSS minimal
  • Use semantic color names from the theme

Testing Guidelines

Backend Tests

Write tests for all new functionality:

func TestGetProxyHost(t *testing.T) {
    // Setup
    db := setupTestDB(t)
    host := createTestHost(db)

    // Execute
    result, err := GetProxyHost(host.UUID)

    // Assert
    assert.NoError(t, err)
    assert.Equal(t, host.Domain, result.Domain)
}

Run tests:

go test ./... -v
go test -cover ./...

Frontend Tests

Write component and hook tests using Vitest and React Testing Library:

describe('ProxyHostForm', () => {
  it('renders create form with empty fields', async () => {
    render(
      <ProxyHostForm onSubmit={vi.fn()} onCancel={vi.fn()} />
    )

    await waitFor(() => {
      expect(screen.getByText('Add Proxy Host')).toBeInTheDocument()
    })
  })
})

Run tests:

npm test              # Watch mode
npm run test:coverage # Coverage report

CrowdSec Frontend Test Coverage

The CrowdSec integration has comprehensive frontend test coverage (100%) across all modules:

  • API Clients - All CrowdSec API endpoints tested with error handling
  • React Query Hooks - Complete hook testing with query invalidation
  • Data & Utilities - Preset validation and export functionality
  • 162 tests total - All passing with no flaky tests

See QA Coverage Report for details.

Test Coverage

  • Aim for 85%+ code coverage (current backend: 85.4%)
  • All new features must include tests
  • Bug fixes should include regression tests
  • CrowdSec modules maintain 100% frontend coverage

Pull Request Process

Before Submitting

  1. Ensure tests pass:
# Backend
go test ./...

# Frontend
npm test -- --run
  1. Check code quality:
# Go formatting
go fmt ./...

# Frontend linting
npm run lint
  1. Update documentation if needed
  2. Add tests for new functionality
  3. Rebase on latest development branch

Submitting a Pull Request

  1. Push your branch to your fork:
git push origin feature/your-feature-name
  1. Open a Pull Request on GitHub
  2. Fill out the PR template completely
  3. Link related issues using "Closes #123" or "Fixes #456"
  4. Request review from maintainers

PR Template

## Description
Brief description of changes

## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation update

## Testing
- [ ] Unit tests added/updated
- [ ] Manual testing performed
- [ ] All tests passing

## Screenshots (if applicable)
Add screenshots of UI changes

## Checklist
- [ ] Code follows style guidelines
- [ ] Self-review performed
- [ ] Comments added for complex code
- [ ] Documentation updated
- [ ] No new warnings generated

Review Process

  • Maintainers will review within 2-3 business days
  • Address review feedback promptly
  • Keep discussions focused and professional
  • Be open to suggestions and alternative approaches

Issue Guidelines

Reporting Bugs

Use the bug report template and include:

  • Clear, descriptive title
  • Steps to reproduce
  • Expected vs actual behavior
  • Environment details (OS, browser, Go version, etc.)
  • Screenshots or error logs
  • Potential solutions (if known)

Feature Requests

Use the feature request template and include:

  • Clear description of the feature
  • Use case and motivation
  • Potential implementation approach
  • Mockups or examples (if applicable)

Issue Labels

  • bug - Something isn't working
  • enhancement - New feature or request
  • documentation - Documentation improvements
  • good first issue - Good for newcomers
  • help wanted - Extra attention needed
  • priority: high - Urgent issue
  • wontfix - Will not be fixed

Documentation

Code Documentation

  • Add docstrings to all exported functions
  • Include examples in complex functions
  • Document return types and error conditions
  • Keep comments up-to-date with code changes

Project Documentation

When adding features, update:

  • README.md - User-facing information
  • docs/api.md - API changes
  • docs/import-guide.md - Import feature updates
  • docs/database-schema.md - Schema changes

Recognition

Contributors will be recognized in:

  • CONTRIBUTORS.md file
  • Release notes for significant contributions
  • GitHub contributors page

Questions?

  • Open a Discussion for general questions
  • Join our community chat (coming soon)
  • Tag maintainers in issues for urgent matters

License

By contributing, you agree that your contributions will be licensed under the project's MIT License.


Thank you for contributing to CaddyProxyManager+! 🎉