- Create comprehensive E2E test suite for job orchestration - Add test fixtures for Discord, BullMQ, and Prisma mocks - Implement 9 end-to-end test scenarios covering: * Happy path: webhook → job → step execution → completion * Event emission throughout job lifecycle * Step failure and retry handling * Job failure after max retries * Discord command parsing and job creation * WebSocket status updates integration * Job cancellation workflow * Job retry mechanism * Progress percentage tracking - Add helper methods to services for simplified testing: * JobStepsService: start(), complete(), fail(), findByJob() * RunnerJobsService: updateStatus(), updateProgress() * JobEventsService: findByJob() - Configure vitest.e2e.config.ts for E2E test execution - All 9 E2E tests passing - All 1405 unit tests passing - Quality gates: typecheck, lint, build all passing Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
3.5 KiB
3.5 KiB
Issue #175: E2E Test Harness
Objective
Create a comprehensive end-to-end test harness that validates the complete flow from webhook to job completion, including chat integration.
Approach
- Explore existing test patterns in the codebase
- Set up E2E test directory structure
- Create test fixtures (Mock Discord, BullMQ, Prisma)
- Implement E2E test scenarios following TDD
- Verify all quality gates pass
Progress
- Create scratchpad
- Pull latest code (skipped - unstaged changes)
- Explore existing test patterns
- Create E2E directory structure
- Create vitest.e2e.config.ts
- Implement test fixtures
- Mock Discord client fixture
- Mock BullMQ queues fixture
- Mock Prisma client fixture
- Write E2E tests (TDD)
- Happy path: webhook → job → completion
- Error handling: step failure → retry
- Chat integration: command → job → updates
- Add helper methods to services
- JobStepsService: start(), complete(), fail(), findByJob()
- RunnerJobsService: updateStatus(), updateProgress()
- JobEventsService: findByJob()
- Run quality gates
- All 9 E2E tests passing
- All 1405 unit tests passing
- Typecheck passing
- Lint passing
- Build passing
- Commit changes
Test Patterns Observed
- Use Vitest with NestJS Testing module
- Mock services with vi.fn()
- Use Test.createTestingModule for DI
- Follow existing integration test pattern from quality-orchestrator
- Mock child_process.exec for command execution
- Create helper functions for test data
Testing
Test Scenarios
- Happy Path: webhook → job creation → step execution → completion
- Error Handling: step failure → retry → final failure
- Chat Integration: command → job → status updates
Quality Gates
- pnpm typecheck
- pnpm lint
- pnpm test
- pnpm build
Notes
- All dependencies (Phase 1-4) are complete
- Herald (#172) may complete during this task
- Follow TDD: RED → GREEN → REFACTOR
- Use existing test patterns as reference
Implementation Summary
Files Created
apps/api/vitest.e2e.config.ts- E2E test configurationapps/api/test/fixtures/- Mock fixtures directorymock-discord.fixture.ts- Mock Discord client and messagesmock-bullmq.fixture.ts- Mock BullMQ queues and jobsmock-prisma.fixture.ts- Mock Prisma service with CRUD operationsindex.ts- Fixture exports
apps/api/test/e2e/job-orchestration.e2e-spec.ts- 9 E2E tests
Files Modified
-
apps/api/src/job-steps/job-steps.service.ts- Added
start(id)- simplified start without jobId parameter - Added
complete(id, data)- simplified complete with optional output/tokens - Added
fail(id, data)- simplified fail with optional error message - Added
findByJob(jobId)- alias for findAllByJob
- Added
-
apps/api/src/runner-jobs/runner-jobs.service.ts- Added
updateStatus(id, workspaceId, status, data)- update job status with timestamps - Added
updateProgress(id, workspaceId, progressPercent)- update job progress
- Added
-
apps/api/src/job-events/job-events.service.ts- Added
findByJob(jobId)- get all events for a job without pagination
- Added
E2E Tests Coverage
- Happy path: webhook → job creation → step execution → completion
- Event emission throughout job lifecycle
- Step failure and retry handling
- Job failure after max retries
- Discord command parsing and job creation
- WebSocket status updates
- Job cancellation
- Job retry mechanism
- Progress percentage tracking