Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
(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.
- `/queue show` upcoming tracks list now appends an inline **recommendation
reason tag** (e.g. `fresh artist rotation`, `similar title mood`) next to
autoplay-sourced tracks, making the autoplay decision transparent at a glance.
- **Now Playing** section in `/queue show` appends a `Recommended because:`
line when the current track originated from autoplay.
Comment on lines +22 to +26

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Add the linked issue/PR reference to these changelog bullets.

These are the only new 2.6.19 entries without a traceability suffix, which makes it harder to tie the behavior back to issue #266 / PR #275.

📝 Suggested changelog tweak
 - `/queue show` upcoming tracks list now appends an inline **recommendation
   reason tag** (e.g. `fresh artist rotation`, `similar title mood`) next to
-  autoplay-sourced tracks, making the autoplay decision transparent at a glance.
+  autoplay-sourced tracks, making the autoplay decision transparent at a glance. (`#266`, PR `#275`)
 - **Now Playing** section in `/queue show` appends a `Recommended because:`
-  line when the current track originated from autoplay.
+  line when the current track originated from autoplay. (`#266`, PR `#275`)

Based on learnings, "Update CHANGELOG.md with all changes, include breaking changes documentation, and reference issues and PRs."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@CHANGELOG.md` around lines 17 - 21, Update the two 2.6.19 bullets in
CHANGELOG.md (the `/queue show` upcoming tracks bullet and the “Now Playing”
recommended line) to include the traceability suffix linking to issue `#266` and
PR `#275` (e.g., append “(see `#266`, `#275`)” or add a Markdown issue/PR link),
ensuring both entries for `/queue show` and `Now Playing` explicitly reference
the related issue and PR.


### Changed

Expand Down
161 changes: 161 additions & 0 deletions packages/bot/src/functions/music/commands/queue/queueDisplay.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import { beforeEach, describe, expect, it, jest } from '@jest/globals'
import {
createQueueSummary,
createTrackListDisplay,
findSimilarTracksInQueue,
formatTrackForDisplay,
} from './queueDisplay'
import type { QueueDisplayOptions } from './types'

const getTrackInfoMock = jest.fn()
const isSimilarTitleMock = jest.fn()

jest.mock('../../../../utils/music/trackUtils', () => ({
getTrackInfo: (...args: unknown[]) => getTrackInfoMock(...args),
}))

jest.mock('../../../../utils/music/titleComparison', () => ({
isSimilarTitle: (...args: unknown[]) => isSimilarTitleMock(...args),
}))

const defaultOptions: QueueDisplayOptions = {
showCurrentTrack: true,
showUpcomingTracks: true,
maxTracksToShow: 10,
showTotalDuration: true,
showQueueStats: true,
}

function createTrack(overrides: Record<string, unknown> = {}): unknown {
return {
title: 'Test Track',
author: 'Test Artist',
url: 'https://example.com/track',
thumbnail: undefined,
requestedBy: undefined,
metadata: {},
...overrides,
}
}

describe('queueDisplay', () => {
beforeEach(() => {
jest.clearAllMocks()
getTrackInfoMock.mockResolvedValue({ duration: '3:30' })
isSimilarTitleMock.mockResolvedValue(false)
})

describe('formatTrackForDisplay', () => {
it('returns basic display info without recommendation reason for normal tracks', async () => {
const track = createTrack()

const result = await formatTrackForDisplay(track as any, 1, defaultOptions)

expect(result.title).toBe('Test Track')
expect(result.author).toBe('Test Artist')
expect(result.isAutoplay).toBeUndefined()
expect(result.recommendationReason).toBeUndefined()
})

it('surfaces isAutoplay and recommendationReason from track metadata', async () => {
const track = createTrack({
metadata: { isAutoplay: true, recommendationReason: 'fresh artist rotation' },
})

const result = await formatTrackForDisplay(track as any, 1, defaultOptions)

expect(result.isAutoplay).toBe(true)
expect(result.recommendationReason).toBe('fresh artist rotation')
})
})

describe('createTrackListDisplay', () => {
it('renders plain track entry without reason tag for non-autoplay tracks', async () => {
const track = createTrack()
const result = await createTrackListDisplay([track as any], defaultOptions)

expect(result).toContain('[Test Track]')
expect(result).not.toContain('_')
})

it('appends recommendation reason tag for autoplay tracks', async () => {
const track = createTrack({
metadata: { isAutoplay: true, recommendationReason: 'fresh artist rotation' },
})

const result = await createTrackListDisplay([track as any], defaultOptions)

expect(result).toContain('fresh artist rotation')
expect(result).toContain('_fresh artist rotation_')
})

it('does not append reason tag when isAutoplay is true but reason is empty', async () => {
const track = createTrack({
metadata: { isAutoplay: true, recommendationReason: '' },
})

const result = await createTrackListDisplay([track as any], defaultOptions)

expect(result).not.toContain('_')
})

it('shows overflow message when tracks exceed maxTracksToShow', async () => {
const tracks = Array.from({ length: 15 }, (_, i) =>
createTrack({ title: `Track ${i}` }),
)
const options = { ...defaultOptions, maxTracksToShow: 10 }
const result = await createTrackListDisplay(tracks as any[], options)

expect(result).toContain('5 more tracks')
})
})

describe('findSimilarTracksInQueue', () => {
it('returns tracks whose titles are similar to the current track', async () => {
const current = createTrack({ title: 'Amazing Song' })
const similar = createTrack({ title: 'Amazing Song (Remix)' })
const different = createTrack({ title: 'Something Else' })

isSimilarTitleMock
.mockResolvedValueOnce(true)
.mockResolvedValueOnce(false)

const result = await findSimilarTracksInQueue(
current as any,
[similar as any, different as any],
)

expect(result).toHaveLength(1)
expect(result[0]).toBe(similar)
})

it('returns empty array when no tracks are similar', async () => {
const current = createTrack({ title: 'Amazing Song' })
const unrelated = createTrack({ title: 'Completely Different' })

isSimilarTitleMock.mockResolvedValue(false)

const result = await findSimilarTracksInQueue(current as any, [unrelated as any])

expect(result).toHaveLength(0)
})
})

describe('createQueueSummary', () => {
it('returns total tracks and duration without position when currentPosition is 0', () => {
const result = createQueueSummary(10, '45:00', 0)

expect(result).toContain('**Total Tracks:** 10')
expect(result).toContain('**Total Duration:** 45:00')
expect(result).not.toContain('Current Position')
})

it('includes current position formatted as M:SS when currentPosition is greater than 0', () => {
const result = createQueueSummary(5, '20:00', 90)

expect(result).toContain('**Total Tracks:** 5')
expect(result).toContain('**Total Duration:** 20:00')
expect(result).toContain('**Current Position:** 1:30')
})
})
Comment on lines +41 to +160

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search the bot test tree for coverage of the new now-playing recommendation branch.
rg -n --glob '*.{spec,test}.ts' "createQueueEmbed|Recommended because:" packages/bot

Repository: LucasSantana-Dev/Lucky

Length of output: 708


🏁 Script executed:

#!/bin/bash
# Search for queueEmbed spec files and check the implementation
fd -e 'spec.ts' -e 'test.ts' 'queueEmbed' packages/bot

# Also check if queueEmbed.ts exists and see its structure
fd -e 'ts' -e 'tsx' 'queueEmbed' packages/bot | head -20

Repository: LucasSantana-Dev/Lucky

Length of output: 127


🏁 Script executed:

#!/bin/bash
# Read the queueEmbed.ts file
cat -n packages/bot/src/functions/music/commands/queue/queueEmbed.ts

Repository: LucasSantana-Dev/Lucky

Length of output: 5090


Add unit test for the new autoplay recommendation branch in createQueueEmbed().

The queueDisplay.spec.ts suite covers queue-row display helpers but not the embed layer. The new Recommended because: branch in queueEmbed.ts (lines 23–26) is untested in isolation. Add a focused test for addCurrentTrackInfo() that verifies the recommendation reason is rendered when metadata.isAutoplay and metadata.recommendationReason are both set.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bot/src/functions/music/commands/queue/queueDisplay.spec.ts` around
lines 41 - 160, Add a unit test that targets the embed layer: call
addCurrentTrackInfo (from queueEmbed.ts / createQueueEmbed flow) with a track
whose metadata includes isAutoplay: true and recommendationReason: 'fresh artist
rotation', then assert the returned/embed description contains the "Recommended
because:" label and the recommendation text; ensure you import or mock any
dependencies used by addCurrentTrackInfo (e.g., getTrackInfo or formatting
helpers) and place the test alongside the other queueDisplay specs so it runs
with the suite.

})
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export async function formatTrackForDisplay(
_options: QueueDisplayOptions,
): Promise<TrackDisplayInfo> {
const trackInfo = await getTrackInfo(track)
const metadata = (track.metadata ?? {}) as { isAutoplay?: boolean; recommendationReason?: string }

return {
title: track.title,
Expand All @@ -21,6 +22,8 @@ export async function formatTrackForDisplay(
thumbnail: track.thumbnail,
requestedBy: track.requestedBy?.username,
position,
isAutoplay: metadata.isAutoplay,
recommendationReason: metadata.recommendationReason,
}
}

Expand All @@ -38,7 +41,11 @@ export async function createTrackListDisplay(
const track = displayTracks[i]
const trackInfo = await formatTrackForDisplay(track, i + 1, options)

const trackDisplay = `${i + 1}. [${trackInfo.title}](${trackInfo.url}) - ${trackInfo.author} (${trackInfo.duration})`
const reasonTag =
trackInfo.isAutoplay && trackInfo.recommendationReason
? ` — _${trackInfo.recommendationReason}_`
: ''
const trackDisplay = `${i + 1}. [${trackInfo.title}](${trackInfo.url}) - ${trackInfo.author} (${trackInfo.duration})${reasonTag}`
Comment on lines +44 to +48

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Truncate the inline reason tag before rendering it.

Issue #266 calls for a truncated queue tag, but this prints the full recommendationReason. Longer labels will quickly take over the queue row instead of behaving like a compact tag.

✂️ Suggested fix
-        const reasonTag =
-            trackInfo.isAutoplay && trackInfo.recommendationReason
-                ? ` — _${trackInfo.recommendationReason}_`
-                : ''
+        const normalizedReason = trackInfo.recommendationReason?.trim()
+        const truncatedReason =
+            normalizedReason && normalizedReason.length > 24
+                ? `${normalizedReason.slice(0, 23)}…`
+                : normalizedReason
+        const reasonTag =
+            trackInfo.isAutoplay && truncatedReason
+                ? ` — _${truncatedReason}_`
+                : ''
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/bot/src/functions/music/commands/queue/queueDisplay.ts` around lines
44 - 48, The inline reason tag currently uses trackInfo.recommendationReason
raw; update the logic that builds reasonTag (the ternary that checks
trackInfo.isAutoplay && trackInfo.recommendationReason) to truncate
recommendationReason to a fixed max length (e.g., 30 chars) and append an
ellipsis when truncated, keeping the existing formatting (the " — _..._"
italics/underscores) so trackDisplay remains `${i + 1}.
[${trackInfo.title}](${trackInfo.url}) - ${trackInfo.author}
(${trackInfo.duration})${reasonTag}`; implement truncation either inline (using
slice/substring and length check) or via a small helper function (e.g.,
truncateReason) and use that helper when composing reasonTag.

trackDisplays.push(trackDisplay)
}

Expand Down
Loading
Loading