Skip to content

refactor: extract lastFmSeeder from queueManipulation (phase 1.1) - #665

Closed
LucasSantana-Dev wants to merge 1 commit into
mainfrom
refactor/phase-1-lastfm-seeder
Closed

LucasSantana-Dev wants to merge 1 commit into
mainfrom
refactor/phase-1-lastfm-seeder

Conversation

@LucasSantana-Dev

Copy link
Copy Markdown
Owner

Summary

Extracted collectLastFmCandidates function from the 2,070-LOC queueManipulation.ts god-object into a new dedicated autoplay/lastFmSeeder.ts module as Phase 1.1 of the multi-phase refactor.

Changes

  • New file: packages/bot/src/utils/music/autoplay/lastFmSeeder.ts (267 LOC)

    • collectLastFmCandidates() - main Last.fm seeding function for autoplay
    • Helper functions: shouldIncludeCandidate(), upsertScoredCandidate(), normalizeTrackKey(), etc.
    • Duplicated helpers to avoid circular dependencies with queueManipulation.ts
  • Modified file: packages/bot/src/utils/music/queueManipulation.ts (reduced by 134 LOC)

    • Removed collectLastFmCandidates function body (lines 1117-1250)
    • Exported searchLastFmQuery and calculateRecommendationScore for lastFmSeeder imports
    • Re-imported collectLastFmCandidates for backward compatibility with existing call in replenishQueue()

Testing

  • All 131 queueManipulation tests pass
  • No algorithm or behavior changes - pure extraction with strict fidelity
  • TypeScript compilation clean
  • Circular dependency resolved by keeping shared functions in queueManipulation.ts

Phase Status

Phase 1.1 Complete: Part of Lucky refactor plan Phase 1 - Breaking up queueManipulation.ts god object.

Prior Phases Shipped:

Approach Consistency:

This extraction follows the established pattern from prior phases:

  1. Leaf-first extraction (dependencies remain in original module or in lower-level modules)
  2. Re-export from original module for backward compatibility
  3. New module placed in autoplay/ subdirectory
  4. All tests pass without modification

Metrics

  • New module: 267 LOC
  • Removed from queueManipulation: 134 LOC
  • Test coverage: 131/131 passing
  • Behavior preservation: 100% (strict extraction, no logic changes)

Extract collectLastFmCandidates function to dedicated lastFmSeeder.ts module as part of Phase 1.1 of queueManipulation refactor. Maintains strict behavior preservation with all 131 existing tests passing.

## Changes
- **New file**: packages/bot/src/utils/music/autoplay/lastFmSeeder.ts (267 LOC)
  - collectLastFmCandidates() - main Last.fm seeding function
  - Internal helper functions for candidate filtering and scoring
  - Dependencies: searchLastFmQuery, calculateRecommendationScore imported from queueManipulation

- **Modified file**: packages/bot/src/utils/music/queueManipulation.ts (-134 LOC)
  - Removed collectLastFmCandidates function body
  - Exported searchLastFmQuery and calculateRecommendationScore for lastFmSeeder dependency
  - Re-imported collectLastFmCandidates for backward compatibility

## Testing
- All 131 queueManipulation tests pass
- No behavior changes - pure extraction
- Circular dependency avoided by keeping searchLastFmQuery and calculateRecommendationScore in queueManipulation

## Phase 1 Status
Part of Lucky refactor plan Phase 1: Breaking up queueManipulation.ts god object.
Prior phases: #658 candidateScorer, #659 diversitySelector, #662 spotifyRecommender

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lucky Ready Ready Preview, Comment Apr 16, 2026 11:15pm

Request Review

@coderabbitai

coderabbitai Bot commented Apr 16, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@LucasSantana-Dev has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 23 minutes and 52 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 23 minutes and 52 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3135dfdd-86fd-4ec6-87fc-59c2d4282911

📥 Commits

Reviewing files that changed from the base of the PR and between 7d5b357 and 860767e.

📒 Files selected for processing (2)
  • packages/bot/src/utils/music/autoplay/lastFmSeeder.ts
  • packages/bot/src/utils/music/queueManipulation.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/phase-1-lastfm-seeder

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
6.9% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@LucasSantana-Dev

Copy link
Copy Markdown
Owner Author

Superseded by #668 which includes a thorough 297 LOC test suite for lastFmSeeder. Closing to avoid duplicate refactor merge conflict.

auto-merge was automatically disabled April 16, 2026 23:37

Pull request was closed

This branch was successfully deployed

1 active deployment
Preview — 860767ea Deployed Apr 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant