fix: only select songs from songs/ directory#110
Conversation
listArtistSongs searched all mp3s under artists/{slug}/ which included
clips from the content/ directory. These are short asset clips, not
full songs, causing fal.ai transcription to fail with Bad Request.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughA test suite was added for the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/content/__tests__/listArtistSongs.test.ts (2)
24-51: Tests correctly validate the fix. Consider adding coverage for the submodule fallback path.The current tests verify the core filtering behavior. For more complete coverage, consider adding tests for:
- The
parseSongPathhelper (also exported)- Successful org submodule fallback when songs are found there
💡 Example additional test case
it("falls back to org submodule when main repo has no songs", async () => { // Main repo has no songs/ mp3s mockFetch.mockResolvedValueOnce(makeTreeResponse([])); // .gitmodules returns a submodule mockFetch.mockResolvedValueOnce({ ok: true, text: () => Promise.resolve("url = https://github.com/org/artist-repo"), }); // Submodule repo has songs mockFetch.mockResolvedValueOnce( makeTreeResponse(["artists/gatsby-grace/songs/track.mp3"]), ); const songs = await listArtistSongs("https://github.com/org/repo", "gatsby-grace"); expect(songs).toEqual([ "__ORG_REPO__https://github.com/org/artist-repo__artists/gatsby-grace/songs/track.mp3", ]); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/content/__tests__/listArtistSongs.test.ts` around lines 24 - 51, Add tests to cover the submodule fallback and parseSongPath helper: create a new test that mocks fetch to return an empty tree for the main repo, then a successful .gitmodules response (ok: true with text() returning a submodule URL), then a tree response from the submodule containing a songs mp3 and assert listArtistSongs returns the prefixed submodule path (use listArtistSongs and the same makeTreeResponse helper); also add unit tests for parseSongPath exported function to validate it parses/filters paths correctly (e.g., accepts songs/.../*.mp3 and rejects content/ mp3s) so both the fallback path and helper are covered.
7-7: Clean up environment variable after tests to prevent leakage.Setting
process.env.GITHUB_TOKENat module level without cleanup could affect other test files running in the same process.♻️ Suggested fix
+const originalToken = process.env.GITHUB_TOKEN; process.env.GITHUB_TOKEN = "test-token"; + +afterAll(() => { + process.env.GITHUB_TOKEN = originalToken; +});You'll also need to add
afterAllto the import:-import { describe, it, expect, vi, beforeEach } from "vitest"; +import { describe, it, expect, vi, beforeEach, afterAll } from "vitest";🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/content/__tests__/listArtistSongs.test.ts` at line 7, The test currently sets process.env.GITHUB_TOKEN = "test-token" at module scope and never cleans it up, so add lifecycle cleanup: save the original value (const _origGithubToken = process.env.GITHUB_TOKEN) before overwriting, then ensure you import and use afterAll to restore or delete process.env.GITHUB_TOKEN (e.g., in afterAll restore _origGithubToken or delete process.env.GITHUB_TOKEN) so the environment change does not leak to other tests; also add afterAll to the test imports if your test runner requires explicit import.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/content/__tests__/listArtistSongs.test.ts`:
- Around line 24-51: Add tests to cover the submodule fallback and parseSongPath
helper: create a new test that mocks fetch to return an empty tree for the main
repo, then a successful .gitmodules response (ok: true with text() returning a
submodule URL), then a tree response from the submodule containing a songs mp3
and assert listArtistSongs returns the prefixed submodule path (use
listArtistSongs and the same makeTreeResponse helper); also add unit tests for
parseSongPath exported function to validate it parses/filters paths correctly
(e.g., accepts songs/.../*.mp3 and rejects content/ mp3s) so both the fallback
path and helper are covered.
- Line 7: The test currently sets process.env.GITHUB_TOKEN = "test-token" at
module scope and never cleans it up, so add lifecycle cleanup: save the original
value (const _origGithubToken = process.env.GITHUB_TOKEN) before overwriting,
then ensure you import and use afterAll to restore or delete
process.env.GITHUB_TOKEN (e.g., in afterAll restore _origGithubToken or delete
process.env.GITHUB_TOKEN) so the environment change does not leak to other
tests; also add afterAll to the test imports if your test runner requires
explicit import.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 69086aa9-94d4-407e-a360-5e4dfbb86951
📒 Files selected for processing (2)
src/content/__tests__/listArtistSongs.test.tssrc/content/listArtistSongs.ts
Summary
listArtistSongssearched all.mp3files underartists/{slug}/which included clips from thecontent/directory (e.g.content/social-pack-bedroom-lip-sync/assets/clip_bridge_15s.mp3)Bad Requestartists/{slug}/songs/Test plan
songs/mp3s are returned🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
Tests
Bug Fixes