Repository navigation
feat(bot): add probe-based URL validation to /queue rescue (#267) - #278
Conversation
❌ Deploy Preview for regal-bunny-0c8efe failed.
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
✅ Deploy Preview for regal-bunny-0c8efe ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
📝 WalkthroughWalkthroughExtends Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant Cmd as /queue Command
participant Rescue as rescueQueue()
participant Probe as probeTrackResolvable()
participant Player as Player/SearchEngine
participant Queue as Queue
User->>Cmd: /queue rescue
Cmd->>Rescue: rescueQueue(queue, { probeResolvable: true })
loop For each playable track
Rescue->>Probe: probeTrackResolvable(track, timeout)
Probe->>Player: player.search(track)
alt Search succeeds
Player-->>Probe: match found
Probe-->>Rescue: true (resolvable)
Rescue->>Queue: retain track
else Timeout/Failure
Probe-->>Rescue: false (unresolvable)
Rescue->>Queue: remove track
end
end
alt queue.size < refillThreshold
Rescue->>Queue: trigger autoplay refill
end
Rescue-->>Cmd: QueueRescueResult
Cmd-->>User: rescue complete message
Estimated Code Review Effort🎯 4 (Complex) | ⏱️ ~40 minutes Suggested Labels
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
📝 Coding Plan
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 |
- Add probeTrackResolvable() helper using player.search + timeout race - Enhance rescueQueue() with RescueQueueOptions (probeResolvable, probeTimeoutMs, refillThreshold) - Wire probe=true in /queue rescue action handler - Add QUEUE_RESCUE_PROBE_TIMEOUT_MS and QUEUE_RESCUE_REFILL_THRESHOLD env constants - Add 2 new tests: probe removes dead tracks, probe timeout treats as unresolvable - Update CHANGELOG.md [Unreleased] section Closes #267
1f77d3f to
3d69ca9
Compare
|
|
There was a problem hiding this comment.
🧹 Nitpick comments (2)
CHANGELOG.md (1)
17-21: Consider adding issue reference to the changelog entry.The PR objectives mention this closes issue
#267, but the changelog entry doesn't reference it. Adding(#267)at the end would align with other entries in this file (e.g., lines 14-16 reference#271).As per coding guidelines: "Update CHANGELOG.md with all changes, include breaking changes documentation, and reference issues and PRs"
📝 Suggested fix
- `/queue rescue` now uses **probe-based URL validation** (`player.search` with configurable timeout, default 5 s) to detect actually unresolvable tracks (removed videos, geo-blocked content, dead links) in addition to the existing - structural check. Configurable via `QUEUE_RESCUE_PROBE_TIMEOUT_MS` and - `QUEUE_RESCUE_REFILL_THRESHOLD` env vars. + structural check. Configurable via `QUEUE_RESCUE_PROBE_TIMEOUT_MS` and + `QUEUE_RESCUE_REFILL_THRESHOLD` env vars (`#267`).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@CHANGELOG.md` around lines 17 - 21, The changelog entry for `/queue rescue` is missing the issue reference; update the sentence that starts with "/queue rescue now uses probe-based URL validation" in CHANGELOG.md to append the issue reference "(`#267`)" at the end of that entry so it matches the other entries (e.g., the one referencing `#271`) and complies with the guideline to include issue/PR references; no behavior changes required—only edit the changelog text.packages/bot/src/utils/music/queueManipulation.ts (1)
417-434: Minor:setTimeouttimer not cleared on successful search.When
queue.player.search()resolves before the timeout, the timer continues running until it fires (harmlessly resolvingnull). While this doesn't cause functional issues, it's a minor resource inefficiency.Consider using
AbortControlleror clearing the timeout on success if this becomes a hot path.♻️ Optional improvement using cleanup
async function probeTrackResolvable( queue: GuildQueue, track: Track, timeoutMs: number, ): Promise<boolean> { const query = track.url || `${track.title} ${track.author}`.trim() try { - const result = await Promise.race([ - queue.player.search(query, { searchEngine: QueryType.AUTO }), - new Promise<null>((resolve) => - setTimeout(() => resolve(null), timeoutMs), - ), - ]) + let timeoutId: ReturnType<typeof setTimeout> | undefined + const result = await Promise.race([ + queue.player.search(query, { searchEngine: QueryType.AUTO }) + .finally(() => timeoutId && clearTimeout(timeoutId)), + new Promise<null>((resolve) => { + timeoutId = setTimeout(() => resolve(null), timeoutMs) + }), + ]) return result !== null && result.tracks.length > 0 } catch { return false } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/bot/src/utils/music/queueManipulation.ts` around lines 417 - 434, The probeTrackResolvable function leaves the setTimeout timer running if queue.player.search(...) resolves first; update probeTrackResolvable to cancel that timer on success by creating a timeoutId for the Promise that resolves after timeoutMs and clearing that timeout when the search Promise resolves successfully (or alternatively use an AbortController to abort the search on timeout); reference probeTrackResolvable, queue.player.search, QueryType.AUTO, and timeoutMs so you locate and modify the Promise.race logic to clear the timeout (or use abort) to avoid the stray timer.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@CHANGELOG.md`:
- Around line 17-21: The changelog entry for `/queue rescue` is missing the
issue reference; update the sentence that starts with "/queue rescue now uses
probe-based URL validation" in CHANGELOG.md to append the issue reference
"(`#267`)" at the end of that entry so it matches the other entries (e.g., the one
referencing `#271`) and complies with the guideline to include issue/PR
references; no behavior changes required—only edit the changelog text.
In `@packages/bot/src/utils/music/queueManipulation.ts`:
- Around line 417-434: The probeTrackResolvable function leaves the setTimeout
timer running if queue.player.search(...) resolves first; update
probeTrackResolvable to cancel that timer on success by creating a timeoutId for
the Promise that resolves after timeoutMs and clearing that timeout when the
search Promise resolves successfully (or alternatively use an AbortController to
abort the search on timeout); reference probeTrackResolvable,
queue.player.search, QueryType.AUTO, and timeoutMs so you locate and modify the
Promise.race logic to clear the timeout (or use abort) to avoid the stray timer.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 50a15575-df56-4149-9ea0-ce6a32155f93
📒 Files selected for processing (5)
CHANGELOG.mdpackages/bot/src/functions/music/commands/queue/index.spec.tspackages/bot/src/functions/music/commands/queue/index.tspackages/bot/src/utils/music/queueManipulation.spec.tspackages/bot/src/utils/music/queueManipulation.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: SonarCloud Scan
- GitHub Check: Quality Gates
🧰 Additional context used
📓 Path-based instructions (24)
{CHANGELOG.md,README.md}
📄 CodeRabbit inference engine (.cursor/rules/agent-rules.mdc)
ALWAYS update CHANGELOG.md and README.md as changes are made.
Files:
CHANGELOG.md
CHANGELOG.md
📄 CodeRabbit inference engine (.cursor/rules/templates-examples.mdc)
CHANGELOG.md must be updated with all changes in pull requests
Always update CHANGELOG.md with all code changes
Update CHANGELOG.md with all changes, include breaking changes documentation, and reference issues and PRs
Update CHANGELOG.md when behavior or setup changes; use Angular-style commit messages with scope
Files:
CHANGELOG.md
{CHANGELOG.md,docs/**}
📄 CodeRabbit inference engine (.cursor/rules/lucky-project.mdc)
Update
CHANGELOG.mdand relevantdocs/files when behavior or setup changes
Files:
CHANGELOG.md
**/*.{js,jsx,ts,tsx,vue,html}
📄 CodeRabbit inference engine (.cursor/rules/accessibility-openness.mdc)
Provide accessible UI components using semantic HTML and ARIA attributes where necessary
Files:
packages/bot/src/utils/music/queueManipulation.spec.tspackages/bot/src/functions/music/commands/queue/index.spec.tspackages/bot/src/functions/music/commands/queue/index.tspackages/bot/src/utils/music/queueManipulation.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/dependency-injection.mdc)
**/*.{ts,tsx,js,jsx}: Prefer constructor injection for classes that require dependencies
Avoid global mutable singletons unless necessary
Use explicit interfaces for external dependencies to make testing easier
**/*.{ts,tsx,js,jsx}: Include required references in PRs/code for non-trivial logic: TypeScript (official docs), MDN (JavaScript reference), and official docs for any runtime/framework/libraries used (e.g., Node.js, React) as applicable.
Before assuming behavior of an API, include the doc link and a ≤25-word quote when the change relies on it.
**/*.{ts,tsx,js,jsx}: Prefer named exports for clear usage and easier refactors in TypeScript/JavaScript
Keep import order consistent: external first, then internal modules
Remove dead code and unused imports
**/*.{ts,tsx,js,jsx}: Use PascalCase naming convention for React/UI components
Use camelCase naming convention for variables and functions
Use UPPER_SNAKE_CASE naming convention for constants
Maintain consistent import grouping and ordering within the project, keeping third-party imports separate from local imports
For external data sources (HTTP, database), always validate and sanitize input using type guards or schema validators
**/*.{ts,tsx,js,jsx}: Use Prettier with no semicolons, single quotes, 4-space indent, 80 character width
Files must not exceed 250 lines and this is enforcedImplement TypeScript typecheck and linter in CI quality checks
**/*.{ts,tsx,js,jsx}: Use TypeScript for enhanced type safety
Implement error handling and error logging
Avoid commenting code unless extremely necessary - code should explain itself with descriptive names
Leave NO todos, placeholders or missing pieces in the code
Variables and functions must use camelCase
Constants must use UPPER_SNAKE_CASE
Use arrow functions for methods and computed properties
Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements
Maintain consistent import grouping/order: external imports first, then...
Files:
packages/bot/src/utils/music/queueManipulation.spec.tspackages/bot/src/functions/music/commands/queue/index.spec.tspackages/bot/src/functions/music/commands/queue/index.tspackages/bot/src/utils/music/queueManipulation.ts
**/*.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/error-handling.mdc)
**/*.{js,jsx,ts,tsx}: Never throw strings. ThrowError(or typed subclasses) with descriptive messages
Include causal error ascausewhen available for better debugging
Define clear, stable error codes (e.g.,ERR_AUTH_EXPIRED,ERR_NETWORK_TIMEOUT)
Provide optional metadata (e.g.,details,retryable,status,correlationId) in error objects
Use domain error classes per area (e.g.,AuthenticationError,ValidationError,NetworkError)
Log errors with structure (message, code, stack, cause, correlationId, user context where appropriate)
MarkretryablevsnonRetryableerrors where helpful for operations
Set timeouts and handle aborts/cancellations; avoid dangling requests in API/network code
Implement backoff for transient failures; avoid infinite retries
Map HTTP status → domain errors; 4xx vs 5xx behave differently (e.g., retry for 5xx/network)
**/*.{js,jsx,ts,tsx}: Use functional components with hooks in React/React Native. Avoid class components.
Keep components focused on a single responsibility; extract complex logic into custom hooks.
Keep state local when possible. Use Context/Zustand/Redux only when necessary for state management.
If props or state traverse more than 3 levels, consider using context or a feature-scoped store instead of prop drilling.
Use performance optimization techniques:React.memo,useMemo,useCallback,Suspense(web), and virtualization for long lists; avoid unnecessary re-renders.
Web accessibility: use semantic HTML, labels, focus management, keyboard navigation, andaria-*attributes as needed.
React Native accessibility: use accessibility props (accessible,accessibilityLabel), proper roles and labels.
Identify and extract repetitive UI components proactively tocomponents/with clear props and minimal coupling.
Web styles: prefer co-located styles or design system tokens; avoid global style leakage.
React Native styles: preferStyleSheet.create, design tokens, and theme providers; avoid in...
Files:
packages/bot/src/utils/music/queueManipulation.spec.tspackages/bot/src/functions/music/commands/queue/index.spec.tspackages/bot/src/functions/music/commands/queue/index.tspackages/bot/src/utils/music/queueManipulation.ts
**/*.{test,spec}.{js,jsx,ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/frontend.mdc)
**/*.{test,spec}.{js,jsx,ts,tsx}: Test behavior, not implementation. Prefer Testing Library utilities for testing React/React Native components.
For React Native tests: mock native modules and test component interactions and accessibility labels.
Files:
packages/bot/src/utils/music/queueManipulation.spec.tspackages/bot/src/functions/music/commands/queue/index.spec.ts
**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/pattern.mdc)
Introduce interfaces at module boundaries to enable testing and substitutions
**/*.{ts,tsx}: Avoid usinganytype in TypeScript. If unavoidable, useunknownwith type guards and justify with a code comment
Preferinterfacefor defining public object shapes in TypeScript, usetypefor unions and utility types
Use TypeScript utility types such asPartial,Pick,Omit,Readonly, andRecordwhen appropriate
UseI{Name}naming convention for interfaces in TypeScript
UseT{Name}naming convention for type aliases and utility types in TypeScript
**/*.{ts,tsx}: Functions must be less than 50 lines with cyclomatic complexity less than 10
Do not useanytypes - ESLint enforces this at error level
**/*.{ts,tsx}: Prefer types over interfaces for most cases
Don't ever useany- type safety always
Avoid enums; use const objects instead
For complex types, create a separate file to declare them and import them
Avoid usinganytype; if unavoidable, useunknownwith type guards and justify with code comment
Preferinterfacefor public API shapes; usetypefor unions and utility types
Use TypeScript utility types (Partial, Pick, Omit, Readonly, Record)Use the
prisma-redis-luckyskill when adding or modifying database schema, migrations, or Redis operations in the shared package
Files:
packages/bot/src/utils/music/queueManipulation.spec.tspackages/bot/src/functions/music/commands/queue/index.spec.tspackages/bot/src/functions/music/commands/queue/index.tspackages/bot/src/utils/music/queueManipulation.ts
**/*.{test,spec}.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/pattern.mdc)
**/*.{test,spec}.{ts,tsx,js,jsx}: Test behavior, not implementation details
Prefer unit tests for core logic; add integration tests at meaningful boundaries
Files:
packages/bot/src/utils/music/queueManipulation.spec.tspackages/bot/src/functions/music/commands/queue/index.spec.ts
**/*.{test,spec}.{js,ts,jsx,tsx}
📄 CodeRabbit inference engine (.cursor/rules/testing-quality.mdc)
**/*.{test,spec}.{js,ts,jsx,tsx}: Use Jest + a React testing library for unit and component tests as applicable
Test behavior, not implementation details
Files:
packages/bot/src/utils/music/queueManipulation.spec.tspackages/bot/src/functions/music/commands/queue/index.spec.ts
**/*.{js,ts,tsx,jsx}
📄 CodeRabbit inference engine (.cursor/rules/documentation.mdc)
**/*.{js,ts,tsx,jsx}: Minimize comments in code; explain the 'why' when non-obvious, let code express the 'what' through clear naming
Document trade-offs briefly when deviating from ideal patterns
**/*.{js,ts,tsx,jsx}: Store secrets, ports, and hosts in environment variables (.env,.env.example) and never hardcode them
Avoid redundant or decorative AI comments; code should be self-explanatory and only commented when logic is non-obvious; prefer refactoring over lengthy comments
Files:
packages/bot/src/utils/music/queueManipulation.spec.tspackages/bot/src/functions/music/commands/queue/index.spec.tspackages/bot/src/functions/music/commands/queue/index.tspackages/bot/src/utils/music/queueManipulation.ts
packages/bot/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/lucky-discord-bot.mdc)
packages/bot/**/*.{ts,tsx}: UseuseMainPlayer()fromdiscord-playerto access the player instance; do not instantiate player directly
Do not duplicate queue or player state outside Discord Player; use shared services from@lucky/sharedfor persistent data like track history and session information
UseerrorLoganddebugLogfrom@lucky/shared/utilsfor logging throughout the bot package
Use embed and reply utilities from@lucky/sharedfor consistent message formatting and error sanitization across the bot
Use services from@lucky/shared(DatabaseService, Redis client) for database and cache access; do not instantiate Prisma or Redis directly in the bot package
Files:
packages/bot/src/utils/music/queueManipulation.spec.tspackages/bot/src/functions/music/commands/queue/index.spec.tspackages/bot/src/functions/music/commands/queue/index.tspackages/bot/src/utils/music/queueManipulation.ts
packages/bot/**
📄 CodeRabbit inference engine (.cursor/rules/lucky-project.mdc)
The
botpackage depends onsharedand contains Discord bot commands and player handlers using Discord.js and Discord Player
Files:
packages/bot/src/utils/music/queueManipulation.spec.tspackages/bot/src/functions/music/commands/queue/index.spec.tspackages/bot/src/functions/music/commands/queue/index.tspackages/bot/src/utils/music/queueManipulation.ts
**/*.{js,mjs,ts,mts}
📄 CodeRabbit inference engine (.cursor/rules/lucky-project.mdc)
Use Node.js version ≥22 with ESM (ECMAScript modules) only; no CommonJS
Files:
packages/bot/src/utils/music/queueManipulation.spec.tspackages/bot/src/functions/music/commands/queue/index.spec.tspackages/bot/src/functions/music/commands/queue/index.tspackages/bot/src/utils/music/queueManipulation.ts
**/*.{spec,test}.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (.cursor/rules/quality.mdc)
**/*.{spec,test}.{ts,tsx,js,jsx}: Use Jest for unit and integration tests
Test behavior, not implementation details
Run unit, integration tests, and coverage report in CI quality checks
Files:
packages/bot/src/utils/music/queueManipulation.spec.tspackages/bot/src/functions/music/commands/queue/index.spec.ts
**/*.spec.ts
📄 CodeRabbit inference engine (.cursor/rules/quality.mdc)
Unit tests must use naming convention
*.spec.ts
Files:
packages/bot/src/utils/music/queueManipulation.spec.tspackages/bot/src/functions/music/commands/queue/index.spec.ts
packages/bot/src/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/subagent-discord.mdc)
Use
@lucky/sharedfor database, Redis, logging, and embed utilities instead of implementing them locally
Files:
packages/bot/src/utils/music/queueManipulation.spec.tspackages/bot/src/functions/music/commands/queue/index.spec.tspackages/bot/src/functions/music/commands/queue/index.tspackages/bot/src/utils/music/queueManipulation.ts
**/*.ts
📄 CodeRabbit inference engine (AGENTS.md)
**/*.ts: Use Discord.js and Discord Player for Discord bot commands and music queue/player functionality; use thediscord-commandsskill for slash command additions or changes
Use thetypescript-advanced-typesskill when working with TypeScript types, removingas anycasts, and improving type safety
Do not hardcode secrets, IPs, or ports; use.envanddocs/for required environment variables
Add or adjust unit and integration tests when changing behavior; follow patterns inpackages/*/testsand roottests/
Files:
packages/bot/src/utils/music/queueManipulation.spec.tspackages/bot/src/functions/music/commands/queue/index.spec.tspackages/bot/src/functions/music/commands/queue/index.tspackages/bot/src/utils/music/queueManipulation.ts
packages/bot/**/*.ts
📄 CodeRabbit inference engine (AGENTS.md)
packages/bot/**/*.ts: Use themoderation-automodskill for moderation commands and AutoModService implementation; useevent-handlersskill for bot event wiring (messageCreate, memberAdd, etc.)
Use themanagement-featuresskill for embed builder, custom commands, and auto-messages implementation
Files:
packages/bot/src/utils/music/queueManipulation.spec.tspackages/bot/src/functions/music/commands/queue/index.spec.tspackages/bot/src/functions/music/commands/queue/index.tspackages/bot/src/utils/music/queueManipulation.ts
packages/bot/src/functions/*/commands/**/*.{ts,tsx}
📄 CodeRabbit inference engine (.cursor/rules/lucky-discord-bot.mdc)
packages/bot/src/functions/*/commands/**/*.{ts,tsx}: Command model must includedata(slash builder),execute, andcategoryproperties exported frompackages/bot/src/models/Command.ts
Use@discordjs/buildersfor building thedata(SlashCommandBuilder) in command definitions
Commandexecutefunction must receive{ interaction, client }parameters fromCommandExecuteParamstype
UseinteractionReplyandcreateUserFriendlyErrorutilities from@lucky/shared/generalutils for command replies and error handling
Use existing validators frompackages/bot/src/utils/command/for voice channel, queue, and guild validations in commands
Files:
packages/bot/src/functions/music/commands/queue/index.spec.tspackages/bot/src/functions/music/commands/queue/index.ts
packages/bot/src/functions/{general,music,download}/commands/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/subagent-discord.mdc)
packages/bot/src/functions/{general,music,download}/commands/**/*.ts: Apply.cursor/rules/lucky-discord-bot.mdcrules for Discord bot commands and player implementation
Use.cursor/skills/discord-commands/SKILL.mdfor implementing slash commands
Files:
packages/bot/src/functions/music/commands/queue/index.spec.tspackages/bot/src/functions/music/commands/queue/index.ts
packages/bot/src/functions/music/commands/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/subagent-discord.mdc)
Use
.cursor/skills/music-queue-player/SKILL.mdfor play, queue, skip, volume commands and player lifecycle management
Files:
packages/bot/src/functions/music/commands/queue/index.spec.tspackages/bot/src/functions/music/commands/queue/index.ts
packages/bot/src/functions/music/**/*.ts
📄 CodeRabbit inference engine (.cursor/rules/subagent-discord.mdc)
Use existing voice/queue/guild validators before manipulating player or queue state
Files:
packages/bot/src/functions/music/commands/queue/index.spec.tspackages/bot/src/functions/music/commands/queue/index.ts
**/index.ts
📄 CodeRabbit inference engine (.cursor/rules/pattern.mdc)
Use
index.tsonly to re-export a small, intentional surface per module
Files:
packages/bot/src/functions/music/commands/queue/index.ts
🧠 Learnings (8)
📚 Learning: 2026-03-09T20:21:52.065Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/subagent-discord.mdc:0-0
Timestamp: 2026-03-09T20:21:52.065Z
Learning: Applies to packages/bot/src/functions/music/**/*.ts : Use existing voice/queue/guild validators before manipulating player or queue state
Applied to files:
packages/bot/src/utils/music/queueManipulation.spec.tspackages/bot/src/functions/music/commands/queue/index.spec.tspackages/bot/src/functions/music/commands/queue/index.tspackages/bot/src/utils/music/queueManipulation.ts
📚 Learning: 2026-03-09T20:21:52.065Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/subagent-discord.mdc:0-0
Timestamp: 2026-03-09T20:21:52.065Z
Learning: Applies to packages/bot/src/functions/music/commands/**/*.ts : Use `.cursor/skills/music-queue-player/SKILL.md` for play, queue, skip, volume commands and player lifecycle management
Applied to files:
packages/bot/src/utils/music/queueManipulation.spec.tspackages/bot/src/functions/music/commands/queue/index.spec.tspackages/bot/src/functions/music/commands/queue/index.tspackages/bot/src/utils/music/queueManipulation.ts
📚 Learning: 2026-03-09T20:20:47.877Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/lucky-discord-bot.mdc:0-0
Timestamp: 2026-03-09T20:20:47.877Z
Learning: Applies to packages/bot/**/*.{ts,tsx} : Do not duplicate queue or player state outside Discord Player; use shared services from `lucky/shared` for persistent data like track history and session information
Applied to files:
packages/bot/src/utils/music/queueManipulation.spec.tspackages/bot/src/functions/music/commands/queue/index.tspackages/bot/src/utils/music/queueManipulation.ts
📚 Learning: 2026-03-09T20:21:08.612Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/lucky-project.mdc:0-0
Timestamp: 2026-03-09T20:21:08.612Z
Learning: Applies to {packages/*/tests/**/*.test.{js,ts},tests/**/*.test.{js,ts}} : Add or adjust unit and integration tests when changing behavior; follow existing patterns in `packages/*/tests` and root `tests/` directories
Applied to files:
packages/bot/src/utils/music/queueManipulation.spec.ts
📚 Learning: 2026-03-15T14:34:47.397Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-03-15T14:34:47.397Z
Learning: Applies to **/*.ts : Add or adjust unit and integration tests when changing behavior; follow patterns in `packages/*/tests` and root `tests/`
Applied to files:
packages/bot/src/utils/music/queueManipulation.spec.ts
📚 Learning: 2026-03-15T14:34:47.397Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-03-15T14:34:47.397Z
Learning: Applies to **/*.ts : Use Discord.js and Discord Player for Discord bot commands and music queue/player functionality; use the `discord-commands` skill for slash command additions or changes
Applied to files:
packages/bot/src/functions/music/commands/queue/index.spec.tspackages/bot/src/functions/music/commands/queue/index.ts
📚 Learning: 2026-03-09T20:21:52.065Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/subagent-discord.mdc:0-0
Timestamp: 2026-03-09T20:21:52.065Z
Learning: Applies to packages/bot/src/functions/{general,music,download}/commands/**/*.ts : Apply `.cursor/rules/lucky-discord-bot.mdc` rules for Discord bot commands and player implementation
Applied to files:
packages/bot/src/functions/music/commands/queue/index.ts
📚 Learning: 2026-03-09T20:20:47.877Z
Learnt from: CR
Repo: LucasSantana-Dev/Lucky PR: 0
File: .cursor/rules/lucky-discord-bot.mdc:0-0
Timestamp: 2026-03-09T20:20:47.877Z
Learning: Applies to packages/bot/src/functions/*/commands/**/*.{ts,tsx} : Use existing validators from `packages/bot/src/utils/command/` for voice channel, queue, and guild validations in commands
Applied to files:
packages/bot/src/functions/music/commands/queue/index.ts
🔇 Additional comments (9)
packages/bot/src/utils/music/queueManipulation.ts (4)
17-24: LGTM!Environment variable parsing with
parseIntand sensible defaults (5s timeout, threshold of 3) aligns with the PR objectives. The radix parameter is correctly specified.
436-440: LGTM!The
RescueQueueOptionstype provides a clean interface for the new configurable rescue behavior with sensible optional properties.
457-474: LGTM!The iterative filtering logic correctly handles both structural validation (
isPlayableTrack) and optional probe-based validation. Sequential probing is appropriate here since probing in parallel could overwhelm the search endpoint.
480-484: Rescue queue correctly refills regardless of autoplay mode.The
rescueQueuefunction intentionally removed thequeue.repeatMode === QueueRepeatMode.AUTOPLAYcheck when callingreplenishQueue. This is correct—rescue operations should restore queue health independently of autoplay settings. The conditionqueue.currentTrack && queue.tracks.size < refillThresholdis sufficient here. Other callers intrackHandlers.tsretain their own AUTOPLAY mode guards where appropriate.packages/bot/src/utils/music/queueManipulation.spec.ts (3)
495-504: LGTM!Adding
{ refillThreshold: 0 }isolates the rescue filtering logic from replenishment, making the test more focused and deterministic.
506-545: LGTM!Good test coverage for the probe-based rescue feature. The mock correctly simulates search returning results for resolvable tracks and empty results for dead tracks. Assertions verify both track retention and removal.
547-573: LGTM!Excellent test for the timeout scenario using a never-resolving promise. The short
probeTimeoutMs: 50keeps tests fast while still exercising the timeout path.packages/bot/src/functions/music/commands/queue/index.spec.ts (1)
143-148: LGTM!Test correctly updated to verify that the rescue action passes
{ probeResolvable: true }torescueQueue, aligning with the implementation change.packages/bot/src/functions/music/commands/queue/index.ts (1)
107-121: LGTM!Clean integration of the probe-based rescue feature. The
{ probeResolvable: true }option enables live track validation, and the response message accurately reports the rescue results to users. Based on learnings: "Use existing voice/queue/guild validators before manipulating player or queue state" - this is properly handled viarequireGuildandrequireQueueearlier in the execute flow.
- Add probeTrackResolvable() helper using player.search + timeout race - Enhance rescueQueue() with RescueQueueOptions (probeResolvable, probeTimeoutMs, refillThreshold) - Wire probe=true in /queue rescue action handler - Add QUEUE_RESCUE_PROBE_TIMEOUT_MS and QUEUE_RESCUE_REFILL_THRESHOLD env constants - Add 2 new tests: probe removes dead tracks, probe timeout treats as unresolvable - Update CHANGELOG.md [Unreleased] section Closes #267



Summary
Implements issue #267: enhances
/queue rescuewith optional probe-based URL validation to detect dead/unresolvable tracks.probeTrackResolvable(): Usesplayer.search()+setTimeoutrace to verify each track is resolvable within a configurable timeout (default 5s viaQUEUE_RESCUE_PROBE_TIMEOUT_MS)RescueQueueOptions: New type withprobeResolvable,probeTimeoutMs,refillThresholdoptionsrescueQueue()enhanced: Supports probe-based filtering on top of existing empty-field detection; refill threshold now env-configurable viaQUEUE_RESCUE_REFILL_THRESHOLD(default 3)/queue rescueaction: Now passes{ probeResolvable: true }to enable live probingCloses #267
Summary by CodeRabbit