* feat: Implement Claude orchestration with session management - Add CLAUDE_WEBHOOK_SECRET for webhook authentication - Fix Docker volume mounting for Claude credentials - Capture Claude's internal session ID from stream-json output - Update entrypoint script to support OUTPUT_FORMAT=stream-json - Fix environment variable naming (REPOSITORY -> REPO_FULL_NAME) - Enable parallel session execution with proper authentication - Successfully tested creating PRs via orchestrated sessions This enables the webhook to create and manage Claude Code sessions that can: - Clone repositories - Create feature branches - Implement code changes - Commit and push changes - Create pull requests All while capturing Claude's internal session ID for potential resumption. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: Update SessionManager tests for new implementation - Update test to expect docker volume create instead of docker create - Add unref() method to mock process objects to fix test environment error - Update spawn expectations to match new docker run implementation - Fix tests for both startSession and queueSession methods Tests now pass in CI environment. * feat: Add Claude API documentation and improve session validation - Add comprehensive Swagger/OpenAPI documentation for Claude webhook API - Add improved validation for session dependencies to handle edge cases - Add hackathon-specific Docker Compose configuration - Update SessionHandler to validate dependency UUIDs and filter invalid values - Update SessionManager to properly handle sessions without dependencies - Add API endpoint documentation with examples and schemas 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * test: Add comprehensive tests for SessionHandler dependency validation Add test coverage for dependency validation logic in SessionHandler: - Filter out invalid dependency values (empty strings, whitespace, "none") - Validate UUID format for dependencies - Handle mixed valid and invalid dependencies - Support empty dependency arrays - Handle arrays with only filtered values This improves test coverage from ~91% to ~97% for SessionHandler. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * fix: Address PR #181 review comments - Remove unused docker-compose.hackathon.yml file - Extract UUID regex to constant for better maintainability - Document breaking changes in BREAKING_CHANGES.md - Add comprehensive examples to Swagger documentation 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Claude <noreply@anthropic.com>
Claude Webhook Testing Framework
This directory contains the test framework for the Claude Webhook service. The tests are organized into three categories: unit tests, integration tests, and end-to-end (E2E) tests.
Test Organization
/test
/unit # Unit tests for individual components
/controllers # Tests for controllers
/services # Tests for services
/security # Security-focused tests
/utils # Tests for utility functions
/integration # Integration tests between components
/github # GitHub integration tests
/claude # Claude API integration tests
/aws # AWS credential tests
/e2e # End-to-end tests
/scripts # Shell scripts and helpers for E2E tests
/scenarios # Jest test scenarios for E2E testing
Running Tests
All Tests
npm test
Specific Test Types
# Run only unit tests
npm run test:unit
# Run only integration tests
npm run test:integration
# Run only E2E tests
npm run test:e2e
# Run tests with coverage
npm run test:coverage
# Run tests in watch mode (for development)
npm run test:watch
Test Types
Unit Tests
Unit tests focus on testing individual components in isolation. They use Jest's mocking capabilities to replace dependencies with test doubles. These tests are fast and reliable, making them ideal for development and CI/CD pipelines.
Chatbot Provider Tests
The chatbot provider system includes comprehensive unit tests for:
- Base Provider Interface (
ChatbotProvider.test.js): Tests the abstract base class and inheritance patterns - Discord Provider (
DiscordProvider.test.js): Tests Discord-specific webhook handling, signature verification, and message parsing - Provider Factory (
ProviderFactory.test.js): Tests dependency injection and provider management - Security Tests (
signature-verification.test.js): Tests webhook signature verification and security edge cases - Payload Tests (
discord-payloads.test.js): Tests real Discord webhook payloads and edge cases
Example:
// Test for DiscordProvider.js
describe('Discord Provider', () => {
test('should parse Discord slash command correctly', () => {
const payload = { type: 2, data: { name: 'claude' } };
const result = provider.parseWebhookPayload(payload);
expect(result.type).toBe('command');
});
});
Integration Tests
Integration tests verify that different components work together correctly. They test the interactions between services, controllers, and external systems like GitHub and AWS.
Example:
// Test for GitHub webhook processing
describe('GitHub Webhook Processing', () => {
test('should process a comment with @MCPClaude mention', async () => {
const response = await request(app).post('/api/webhooks/github').send(webhookPayload);
expect(response.status).toBe(200);
});
});
E2E Tests
End-to-end tests verify that the entire system works correctly from start to finish. These tests often involve setting up Docker containers, simulating webhook events, and verifying that Claude responds correctly.
E2E tests are organized into:
- Scripts: Helper scripts for setting up test environments
- Scenarios: Jest tests that use the helper scripts to run E2E tests
Example:
// Test for Claude container execution
describe('Container Execution E2E Tests', () => {
test('Should create a Claude session', async () => {
const response = await axios.post(
'/api/webhooks/claude',
{
type: 'session.create',
session: {
type: 'implementation',
project: {
repository: 'test-org/test-repo',
requirements: 'Hello Claude'
}
}
},
{
headers: { Authorization: 'Bearer test-secret' }
}
);
expect(response.status).toBe(200);
expect(response.data.success).toBe(true);
expect(response.data.session.id).toBeDefined();
});
});
Shell Scripts
The original shell scripts in /test are being gradually migrated to the new testing framework. Several one-off and debug scripts have been removed to clean up the codebase. The remaining shell scripts serve two purposes:
-
E2E Infrastructure Tests: Scripts that test container/environment configurations and will remain as separate scripts:
test-claude-direct.sh- Tests direct Claude container executiontest-firewall.sh- Tests firewall initializationtest-container-privileged.sh- Tests container privilegestest-full-flow.sh- Tests complete workflow
-
Helper Scripts: Scripts that are used by the E2E Jest tests:
test-basic-container.sh- Used by setupTestContainer.jstest-claude-no-firewall.sh- Used by setupTestContainer.js
Writing New Tests
When writing new tests:
- Determine the appropriate test type (unit, integration, or E2E)
- Place the test in the correct directory
- Follow the naming convention:
*.test.js - Use Jest's mocking capabilities to isolate the component under test
- Write clear, descriptive test names
- Keep tests focused and maintainable
Test Coverage
Run npm run test:coverage to generate a coverage report. The report will show which parts of the codebase are covered by tests and which are not.
CI/CD Integration
The tests are designed to run in a CI/CD pipeline. The Jest configuration includes support for JUnit output via jest-junit, which can be used by CI systems like Jenkins, GitHub Actions, or CircleCI.