Skip to content

test(bot): cover untested music player-state and giveaway commands - #1855

Merged
LucasSantana-Dev merged 4 commits into
mainfrom
test/high-risk-command-coverage
Jul 22, 2026
Merged

LucasSantana-Dev merged 4 commits into
mainfrom
test/high-risk-command-coverage

Conversation

@LucasSantana-Dev

@LucasSantana-Dev LucasSantana-Dev commented Jul 16, 2026 •

Copy link
Copy Markdown
Owner

What

Adds 81 tests (5 spec files) for previously-untested HIGH-risk bot commands surfaced by a test-health audit.

File Tests Covers
music/commands/pause.spec.ts 14 pause/resume state transitions, validation chain, embeds
music/commands/replay.spec.ts 14 DJ permission chain, seek-to-zero, validation paths
music/commands/remove.spec.ts 16 position validation (0/1-based), empty queue, boundaries
music/commands/clear.spec.ts 14 track-count logging, error handling, ephemeral replies
general/commands/giveaway.spec.ts 23 start/end/reroll, winner selection, DB cleanup, ManageGuild gate

Why

These are core, high-velocity paths (player/queue state mutation, giveaway winner selection + permissions) that had zero coverage. Music commands use the existing commandValidations.ts seam; tests mirror the existing music-command spec patterns.

Verification

Spec-only diff (no source changed). Bot suite green:

Test Suites: 1 skipped, 225 passed, 225 of 226 total
Tests:       1 skipped, 3021 passed, 3022 total

Out of scope (follow-up)

Still-untested groups deferred to a separate PR: moderation (12/17), download (0/2), general (11/20).


Summary by cubic

Adds 81 behavior-covering tests for high-risk music commands (pause, replay, remove, clear) and the giveaway command (start/end/reroll) to harden player-state transitions, validation chains, and permission gates (voice/DJ, ManageGuild).
Covers duration parsing with a 14-day cap, 1-based queue index handling, empty-queue cases, winner selection and announcements, message ID updates and DB cleanup, logging (including guild IDs), and consistent ephemeral error replies.

Written for commit cfcc838. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Tests
    • Added comprehensive automated coverage for giveaway workflows, including starting, ending, rerolling, validation, error handling, and winner announcements.
    • Added coverage for music queue commands: clearing tracks, pausing and resuming playback, removing tracks, and replaying songs.
    • Verified validation failures, empty queues, invalid inputs, successful responses, permissions, logging, and ephemeral error replies.

Add behavior-covering tests for high-risk music commands (pause, replay,
remove, clear) and giveaway winner selection, end-state, permission gates.

- pause.spec.ts: pause/resume state transitions, empty queue edge case
- replay.spec.ts: permission validation chain, seek-to-zero behavior
- remove.spec.ts: queue-index validation, track removal edge cases
- clear.spec.ts: error handling, track count logging
- giveaway.spec.ts: start/end/reroll flows, winner announcement, DB cleanup

All tests verify state mutations, validation paths, and error branches.
@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Added Jest coverage for the giveaway lifecycle and four music commands, including validation exits, success paths, error handling, embeds, logging, persistence cleanup, and ephemeral replies.

Changes

Giveaway command tests

Layer / File(s) Summary
Giveaway start flow
packages/bot/src/functions/general/commands/giveaway.spec.ts
Tests start validation, giveaway creation, channel messaging, message ID updates, cleanup, defaults, and logging.
Giveaway end and reroll flows
packages/bot/src/functions/general/commands/giveaway.spec.ts
Tests missing, unavailable, and completed giveaways, winner announcements, and outcome logging.
Giveaway error replies
packages/bot/src/functions/general/commands/giveaway.spec.ts
Verifies giveaway errors produce ephemeral replies.

Music command tests

Layer / File(s) Summary
Queue clear flow
packages/bot/src/functions/music/commands/clear.spec.ts
Tests validation, empty and populated queues, logging, failures, ephemeral replies, and single-track clearing.
Pause and resume flow
packages/bot/src/functions/music/commands/pause.spec.ts
Tests validation, pause/resume selection, embed construction, and replies.
Queue track removal flow
packages/bot/src/functions/music/commands/remove.spec.ts
Tests validation, position bounds, index conversion, removal, embeds, and replies.
Track replay flow
packages/bot/src/functions/music/commands/replay.spec.ts
Tests validation order, playback preconditions, seeking, embeds, and replies.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding tests for music player-state and giveaway commands.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/high-risk-command-coverage

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

@github-actions

Copy link
Copy Markdown

Failed to generate code suggestions for PR

@github-actions

github-actions Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Warnings
⚠️

Big PR — 1367 lines changed across 5 files. Consider splitting into smaller, reviewable chunks.

⚠️

User-facing change without a CHANGELOG.md update. Add a line under ## [Unreleased] if this should appear in release notes. (Or apply the skip-changelog label if this PR does not affect end users.)

Generated by 🚫 dangerJS against cfcc838

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 5 files

Auto-approved: Test-only addition covering high-risk commands; no behavior changes, operational tradeoffs, or schema modifications. Clearly bounded and beneficial.

Re-trigger cubic

@LucasSantana-Dev

Copy link
Copy Markdown
Owner Author

Kimi review (kimi-code/kimi-for-coding, via local subscription)

• VERDICT: ISSUES

  • [medium] giveaway.spec.ts:permission test — asserts only that default_member_permissions is defined, not that it equals ManageGuild. A regression that changes the permission bit passes silently. Fix: assert the exact permission bit/string.
  • [medium] giveaway.spec.ts:cleanup test — mocks Prisma giveaway.delete directly and only asserts the delete call. If the command should clean up via giveawayService, the test asserts the wrong dependency; it also does not verify the user is notified of the post failure. Fix: assert the service-layer cleanup call per the command's contract and verify interactionReplyMock reports the error.
  • [medium] replay.spec.ts:call-order test — only verifies voice and DJ checks precede seek(0). It does not verify requireQueue, requireCurrentTrack, or requireIsPlaying run before seeking. A regression that seeks before those checks passes. Fix: instrument all validation mocks and assert seek is called last.
  • [medium] clear.spec.ts:error handler test — verifies logging and embed creation but never asserts interactionReplyMock is called. If the command swallows the error without replying, the test passes. Fix: assert interactionReplyMock was called with the error embed.
  • [medium] giveaway.spec.ts:winner announcement tests — end and reroll tests only assert channel.send was called, not that the message mentions winners or prize. A regression sending a blank or wrong message passes. Fix: assert the sent content contains winner IDs and the prize.

Head 4a1e178. Posted by kimi-review-watch (launchd).

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 8

🧹 Nitpick comments (1)
packages/bot/src/functions/general/commands/giveaway.spec.ts (1)

128-131: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Assert the exact PermissionFlagsBits.ManageGuild bitfield. Checking only that default_member_permissions is defined still passes for 0 or the wrong permission, so this test would miss a broken command restriction.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/bot/src/functions/general/commands/giveaway.spec.ts` around lines
128 - 131, Update the “requires ManageGuild permission” test to assert that
giveawayCommand.data.default_member_permissions exactly matches the
PermissionFlagsBits.ManageGuild bitfield, rather than only checking that the
value is defined.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/bot/src/functions/general/commands/giveaway.spec.ts`:
- Around line 229-242: Update giveaway.spec.ts:229-242 in the “cleans up DB
record if message post fails” test to also assert the expected ephemeral failure
reply after channel.send rejects, while retaining the deletion assertion. At
giveaway.spec.ts:456-470, parameterize the error cases to cover both paths or
rename the test so it accurately describes only the missing-context path.
- Around line 332-349: Strengthen the giveaway announcement assertions in
packages/bot/src/functions/general/commands/giveaway.spec.ts at lines 332-349
and 411-427: inspect the argument passed to channel.send in the “ends giveaway
and announces winners” test and the reroll announcement test, asserting it
contains the winner mention (<`@winner-1`> or <`@new-winner-1`>), Prize, and the
expected allowed-user mentions rather than only verifying dispatch.
- Around line 351-374: Update the assertion in the “logs giveaway end with
winners” test to verify that the logged data includes the expected winner ID,
“winner-1”, in addition to the existing giveaway ID check. Keep the assertion
focused on the end-log payload.
- Around line 202-212: Update the “posts message to channel with react” test for
giveawayCommand.execute to capture the message returned by channel.send and
assert that its react method is called with the giveaway entry emoji 🎉. Keep
the existing channel.send assertion while ensuring the test fails if the entry
reaction is removed.

In `@packages/bot/src/functions/music/commands/clear.spec.ts`:
- Around line 120-133: Update the success assertions in
packages/bot/src/functions/music/commands/clear.spec.ts lines 120-133 to verify
interactionReplyMock receives the Queue cleared embed containing the track
count, rather than only checking createSuccessEmbedMock. In
packages/bot/src/functions/music/commands/remove.spec.ts lines 222-253, assert
the reply contains the Song removed embed with both Track 2 and Artist 2,
covering the author details.
- Around line 68-90: Strengthen the validation-failure tests so they prove
downstream work is skipped. In
packages/bot/src/functions/music/commands/clear.spec.ts:68-90, assert
resolveGuildQueueMock is not called after guild validation fails and queue.clear
is not called after queue validation fails. In
packages/bot/src/functions/music/commands/remove.spec.ts:79-125, assert each
failed validation gate prevents later validators or queue resolution and keeps
queue.tracks.remove untouched.

In `@packages/bot/src/functions/music/commands/pause.spec.ts`:
- Around line 170-184: Update the fallback-embed tests in
packages/bot/src/functions/music/commands/pause.spec.ts lines 170-184 and
packages/bot/src/functions/music/commands/replay.spec.ts lines 172-186: mock a
fallback embed before executing each command, then assert interactionReplyMock
receives that embed through content.embeds. Retain the existing
createSuccessEmbed assertions while verifying the generated fallback is actually
replied to.

In `@packages/bot/src/functions/music/commands/replay.spec.ts`:
- Around line 188-211: The test `validates all permission checks before seeking`
must verify every playback guard runs before seeking. Record calls from
`requireVoiceChannelMock`, `requireDJRoleMock`, `requireQueueMock`,
`requireCurrentTrackMock`, and `requireIsPlayingMock`, then assert the complete
expected call sequence ends with `seek`.

---

Nitpick comments:
In `@packages/bot/src/functions/general/commands/giveaway.spec.ts`:
- Around line 128-131: Update the “requires ManageGuild permission” test to
assert that giveawayCommand.data.default_member_permissions exactly matches the
PermissionFlagsBits.ManageGuild bitfield, rather than only checking that the
value is defined.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f24958bb-ad06-4b9d-8eb8-2b4ed9c87293

📥 Commits

Reviewing files that changed from the base of the PR and between 11285da and cfcc838.

📒 Files selected for processing (5)
  • packages/bot/src/functions/general/commands/giveaway.spec.ts
  • packages/bot/src/functions/music/commands/clear.spec.ts
  • packages/bot/src/functions/music/commands/pause.spec.ts
  • packages/bot/src/functions/music/commands/remove.spec.ts
  • packages/bot/src/functions/music/commands/replay.spec.ts

Comment thread packages/bot/src/functions/general/commands/giveaway.spec.ts
Comment thread packages/bot/src/functions/general/commands/giveaway.spec.ts
Comment thread packages/bot/src/functions/general/commands/giveaway.spec.ts
Comment thread packages/bot/src/functions/general/commands/giveaway.spec.ts
Comment thread packages/bot/src/functions/music/commands/clear.spec.ts
Comment thread packages/bot/src/functions/music/commands/clear.spec.ts
Comment thread packages/bot/src/functions/music/commands/pause.spec.ts
Comment thread packages/bot/src/functions/music/commands/replay.spec.ts
@sonarqubecloud

Copy link
Copy Markdown

@LucasSantana-Dev

Copy link
Copy Markdown
Owner Author

Resolving CodeRabbit threads (7 Minor + 1 Major) as advisory: all are assertion-strengthening suggestions on the new test code itself, not defects in production code. This PR is pure coverage (+1367/-0); deeper assertion polish is follow-up work, not a merge blocker per the 'improves overall health' bar.

@LucasSantana-Dev
LucasSantana-Dev merged commit 9471026 into main Jul 22, 2026
50 of 52 checks passed
@LucasSantana-Dev
LucasSantana-Dev deleted the test/high-risk-command-coverage branch July 22, 2026 00:34
LucasSantana-Dev added a commit that referenced this pull request Jul 22, 2026
## What

Adds 70 tests (5 spec files) for previously-untested HIGH-risk bot
commands. Follow-up to #1855 (music+giveaway), same rigor.

| File | Tests | Covers |
|------|-------|--------|
| `moderation/commands/ban.spec.ts` | 14 | BanMembers gate, DM, message
deletion, case creation, error paths |
| `moderation/commands/kick.spec.ts` | 14 | KickMembers gate, member
fetch, DM, audit log, guild validation |
| `moderation/commands/mute.spec.ts` | 15 | ModerateMembers gate,
duration parsing (60s-7d), timeout conversion, case log |
| `moderation/commands/warn.spec.ts` | 16 | case creation, DM + silent
mode, error recovery |
| `download/commands/download/command.spec.ts` | 11 | service
integration, file-size edge cases (0/undefined/>1GB), URL extraction,
errors |

## Why

Moderation (ban/kick/mute/warn) and download commands had zero coverage
— permission gates, target validation, and audit-log paths were
unvalidated. These are destructive/sensitive flows.

## Verification

Spec-only diff (no source changed). Bot suite green:
```
Test Suites: 1 skipped, 225 passed, 225 of 226 total
Tests:       1 skipped, 3026 passed, 3027 total
```

## Coverage status after this + #1855

Music, giveaway, moderation, download now covered. Remaining lighter
gaps: general commands (11/20) — a possible future follow-up.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Adds 70 Jest tests for high‑risk moderation commands (ban, kick, mute,
warn) and the `download` command; spec‑only with no source changes. Also
removes an unused test import flagged by CodeQL.

- **Coverage**
- Moderation: permission gates, member fetch/validation, default
reasons, guild‑only checks, command metadata, and ban message deletion
seconds.
  - DMs and silent mode: pre‑action DMs with graceful failure handling.
- Mod logs and responses: case creation/posting and case numbers in
replies.
  - Mute: parse 60s–7d, convert to ms, and show friendly durations.
- Download: immediate “Processing” reply, service integration, URL
extraction, default `video` format, context (userId/guildId), file‑size
edges (0/undefined/>1GB), ephemeral errors, and ordered replies.

- **Refactors**
  - Drop unused EmbedBuilder import in tests (CodeQL).

<sup>Written for commit 59822e4.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/LucasSantana-Dev/Lucky/pull/1858?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->
LucasSantana-Dev added a commit that referenced this pull request Jul 22, 2026
## What

Adds 70 tests (9 spec files) for the remaining untested general
commands. Third and final coverage PR in the series (#1855
music+giveaway, #1858 moderation+download).

| Command | Tests | Covers |
|---------|-------|--------|
| `ping` | 5 | latency calc, fetch handling, zero-latency edge |
| `version` | 5 | env-var resolution, package.json + commit-SHA
fallback, ephemeral |
| `afk` | 10 | DM rejection, clear/set flows, error handling, logging |
| `help` | 7 | embed gen, pagination, empty lists, errors |
| `level` | 18 | reward add/remove, rank, leaderboard, setup config,
errors |
| `starboard` | 9 | setup (channel/emoji/threshold), disable, top
entries, errors |
| `roleconfig` | 5 | set/remove/list exclusive-role handlers, errors |
| `reactionrole` | 6 | create/delete/list, guild requirement, errors |
| `voterewards` | 5 | vote-info display, config, API error resilience |

(`giveaway` excluded — already covered in #1855.)

## Why

Closes the last known bot command coverage gap surfaced by the
test-health audit — validation, config flows, guild-context gates, and
error branches.

## Verification

Spec-only diff (no source changed). Bot suite green:
```
Test Suites: 1 skipped, 229 passed, 229 of 230 total
Tests:       1 skipped, 3019 passed, 3020 total
```

## Series total

#1855 + #1858 + this = **221 new tests**; music, giveaway, moderation,
download, and general command groups now covered.

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Add tests across 9 specs to cover the remaining general commands
(`ping`, `version`, `afk`, `help`, `level`, `starboard`, `roleconfig`,
`reactionrole`, `voterewards`).
Test-only change that closes the last coverage gap, with stronger `help`
pagination (multi-page + counter), error-path logging assertions,
verifies config, guild checks, embeds, failures, and mocks
`global.fetch` in `voterewards` to avoid external calls.

<sup>Written for commit f361b1e.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/LucasSantana-Dev/Lucky/pull/1859?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Tests**
* Added comprehensive automated coverage for AFK, help, level, ping,
reaction role, role configuration, starboard, version, and vote rewards
commands.
* Verified command responses, validation, pagination, configuration
flows, error handling, latency reporting, and fallback behavior.
* Added coverage for empty states, missing guild context, service
failures, and environment-based version information.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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