- Add TempDir field to Config struct to read TEMP_DIR env var
- Update NewUnifiedTranscriptionService to accept tempDir and outputDir parameters
- Remove hardcoded "data/temp" and "data/transcripts" paths from unified service
- Update NewUnifiedJobProcessor to pass directory paths from config
- Update main.go to use cfg.TempDir and cfg.TranscriptsDir
- Update all test files to use new function signatures
- Fix database.go to use directory from DATABASE_PATH instead of hardcoded "data/"
Phase 5: Refactor queue.go (10 DB calls removed)
- Added JobRepository to TaskQueue struct and constructor
- Added UpdateStatus, UpdateError, FindByStatus, CountByStatus methods to JobRepository
- Replaced all database.DB calls with repository methods
Phase 6: Refactor chat_handlers.go and summarize_handlers.go (6 DB calls removed)
- Added GetMessageCountsBySessionIDs and GetLastMessagesBySessionIDs to ChatRepository
- Added UpdateSummary to JobRepository
- Replaced batch queries and update calls with repository methods
- Removed database import from both files
Phase 7: Refactor quick_transcription.go (3 DB calls removed)
- Added JobRepository injection to QuickTranscriptionService
- Updated constructor and all callers
Summary: 46+ database.DB calls replaced with repository methods across 7 phases.
All tests pass, build succeeds.
Phase 1: Define interfaces
- Created internal/interfaces/ package with AuthServiceInterface, TaskQueueInterface, JobProcessorInterface
Phase 2: Refactor handlers.go (21 DB calls removed)
- Replaced all database.DB calls with repository methods
- Added RefreshTokenRepository for token management
- Added new repository methods: Count, FindActiveTrackJobs, FindLatestCompletedExecution, FindByName
Phase 3: Refactor dropzone.go (3 DB calls removed)
- Added CountWithAutoTranscription to UserRepository
- Injected JobRepository and UserRepository into Service
Phase 4: Refactor multitrack_processor.go
- Changed constructor to accept *gorm.DB and JobRepository
- Updated Handler to inject MultiTrackProcessor
Updated all test files with new dependencies and mock implementations.
Hi there, I wanted to pull this in to my CI/CD platform and saw your unit tests were due for a refactor, so I did it for you. Enjoy!
## Summary
This PR refactors and fixes all unit tests to achieve 7/7 passing test suites (up from 3/7). The changes validate PR #260's dependency injection pattern and update tests to match the current adapter-based architecture.
## Changes Made
### 1. New Adapter Registration Tests
- Created comprehensive test suite for PR #260's dependency injection pattern
- Tests verify all adapters accept custom envPath parameters
- Validates model storage location fix works correctly
- Tests registry clearing and adapter registration
### 2. Registry Test Helpers
- Added ClearRegistry() - clears all registered adapters for test isolation
- Added GetTranscriptionAdapters() - retrieves all transcription adapters
- Added GetDiarizationAdapters() - retrieves all diarization adapters
- These helpers enable proper testing of adapter registration
### 3. Migrated Tests to New Architecture
Updated three test files to use UnifiedJobProcessor instead of removed WhisperXService:
- tests/security_test.go
- tests/api_handlers_test.go
- Retired tests/transcription_service_test.go (renamed to .old)
### 4. Fixed Queue Test Failures
Fixed 5 failing tests in tests/queue_test.go:
- Updated stats field: "workers" changed to "current_workers" (2 tests)
- Updated mock method: "ProcessJob" changed to "ProcessJobWithProcess" with third parameter (3 tests)
### 5. Test Script Improvements
Enhanced run_tests.sh:
- Added frontend build check and automatic build if needed
- Fixed database cleanup bug using find instead of glob patterns
- Properly captures test exit codes
- Added adapter registration test suite
### 6. API Handler Fixes
Fixed tests/api_handlers_test.go:
- Updated queue stats expectations
- Fixed supported models response (array to map)
- Migrated to UnifiedJobProcessor
## Test Results
Before: 3/7 passing (Security, Auth, LLM)
After: 7/7 passing (all suites)
Test Suites:
1. Security Tests
2. Authentication Service Tests
3. LLM Integration Tests
4. Database Tests
5. Queue Management Tests
6. API Handler Tests
7. Adapter Registration Tests (NEW)