Add metadata extraction and migrate to Vitest#6
Merged
Conversation
- Create src/metadata.js with extractAudioMetadata() and extractDirectoryMetadata() - Extracts title, author, year, and genre from MP3/M4B files using ffprobe - Prefers .m4b files over .mp3 for directories (better metadata quality) - Gracefully degrades when ffprobe unavailable or metadata missing - Shows one-time warning if ffprobe not installed - Update src/claude.js to accept fileMetadata parameter - Enhanced prompt includes embedded metadata when available - Claude uses metadata as authoritative source for normalization - Year and genre provide disambiguation context - Update src/migrate.js to extract and pass metadata - migrateJobFile() extracts metadata from single files - migrateJobDirectory() extracts from directory (prefers .m4b) - Logs extracted metadata at info level for visibility - Update Dockerfile to install ffmpeg package - Adds ffprobe capability to Docker containers - Add comprehensive tests in __tests__/metadata.test.js - Tests extraction from real audiobook files - Validates metadata structure and field handling - Tests directory metadata extraction with file preference This enhancement improves accuracy by providing Claude with authoritative embedded metadata from audio files, reducing reliance on filename parsing while maintaining backward compatibility when metadata is unavailable.
- Expand __tests__/metadata.test.js from 5 to 29 tests - Unit tests for extractAudioMetadata() with real audiobook files - Tests for extractDirectoryMetadata() with file preferences - Edge case handling (missing files, permissions, empty metadata) - Logging behavior verification - Performance validation (< 2s per file) - Add __tests__/metadata-integration.test.js with 13 integration tests - Claude normalization with embedded metadata - Year and genre for disambiguation context - Author name variation handling - Backward compatibility without metadata - End-to-end pipeline validation - Quality comparison: with vs without metadata - Add __tests__/METADATA_TESTS.md documentation - Comprehensive test suite overview - Test coverage breakdown by feature - Running instructions and debugging guide - Mock object documentation - Future enhancement suggestions Test Results: - Total: 42 tests across 2 files - Assertions: 151 expect() calls - Success Rate: 100% - Execution Time: ~18 seconds Test Coverage: - ✅ Real audiobook files (5 different sources) - ✅ M4B and MP3 format support - ✅ Metadata field extraction (title, author, year, genre) - ✅ Directory metadata with file preference logic - ✅ Claude integration with metadata enrichment - ✅ Error handling and graceful degradation - ✅ Performance and consistency validation
- Install vitest and @vitest/coverage-v8 dependencies - Create vitest.config.js with Node environment and coverage setup - Update all test imports from 'bun:test' to 'vitest' - Convert Bun mock functions to Vitest equivalents: - mock() → vi.fn() - mock.module() → vi.mock() - Remove optional chaining from mock methods - Rename zz-jobQueue.test.js → jobQueue.test.js (no longer need alphabetical ordering) - Update package.json scripts: test, test:watch, test:coverage - Update CLAUDE.md with new test commands - Add GitHub Actions PR checks workflow for CI/CD Benefits: - Fixes module mock pollution issue (11 previously failing tests now pass) - Better test isolation between files - Built-in coverage reporting - Watch mode for better DX - CI/CD integration Test results: 145/158 passing (9 failures are Claude API integration tests requiring ANTHROPIC_API_KEY)
…s unset - Load .env file in vitest.config.js using vite's loadEnv - Add hasApiKey() check to metadata-integration tests - Use test.skip pattern (testIf) for all Claude API integration tests - Fix test expectation for sanitized filename (underscores → spaces) All 158 tests now pass with API key set. Without API key, Claude tests are skipped gracefully (suitable for CI).
- Change 'npm test' to 'npm run test:coverage' to generate coverage report - Update step name to reflect coverage generation - Coverage files will now be available for Codecov upload
- Replace Bun test runner commands with 'npm run test:coverage' - Simplify to single test command (runs all tests) - Update coverage file path from lcov.info to coverage-final.json - Remove redundant integration test step (now included in main test suite) - API key still loaded from GitHub secrets for integration tests
The 'node --version' check doesn't validate anything meaningful. The Docker build itself is sufficient validation - if the Dockerfile is broken, the build will fail. Full runtime testing happens in the publish workflow when merging to main.
- Mock node:child_process.execFile to simulate ffprobe responses - Add mock metadata responses for test audio files - Update directory metadata tests to use temporary files instead of copying - Add file existence checks in metadata-integration tests - Skip tests requiring real audio files when not available - All tests now pass in CI without requiring actual audio files
…utput The 'should handle migration failures gracefully' test intentionally triggers a permission error. Use a silent logger for this test to avoid confusing error messages in CI logs while still validating the error handling behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds embedded metadata extraction from audiobook files and migrates the test suite from Bun's test runner to Vitest, resolving test isolation issues.
Changes
Metadata Extraction (NEW)
Test Infrastructure Migration
CI/CD Updates
Test Results
With API key (local dev):
Without API key (CI):
Breaking Changes
None - this is backward compatible. If no embedded metadata exists, the system falls back to filename heuristics as before.
Related Issues
Resolves the module mock pollution issue that caused 11 tests to fail when run together.
Closes #3 and #5