Skip to content

chore(tests): phase 1 cleanup — orphan deletion + misplaced specs relocation - #938

Merged
LucasSantana-Dev merged 2 commits into
mainfrom
chore/test-cleanup-backend
May 22, 2026
Merged

LucasSantana-Dev merged 2 commits into
mainfrom
chore/test-cleanup-backend

Conversation

@LucasSantana-Dev

@LucasSantana-Dev LucasSantana-Dev commented May 22, 2026 •

Copy link
Copy Markdown
Owner

Phase 1 of the bot + backend test-cleanup pass triggered by `/test-cleanup`.

Baseline

Pkg Specs Tests Source LOC Target (proportionality)
backend 67 836 9.5k 80–250
bot 181 2865 40k 500–1500
frontend 65 636 20k 200–600 ✓
shared 28 446 13k (utility) ✓

Backend is 3-4× over its target; bot is ~2× over.

What this PR does (high-confidence wins only)

Delete (source is gone):

  • `packages/bot/src/handlers/player/playerFactory.bridge.spec.ts` — 40 tests. The `playerFactory.bridge.ts` source has been gone since a prior player refactor; the spec was testing nothing real (all assertions against mocks).

Move (specs of shared code, misplaced in bot):

  • `packages/bot/src/utils/guildAutomation/diff.spec.ts` → `packages/shared/src/services/guildAutomation/diff.spec.ts` (3 tests)
  • `packages/bot/src/utils/guildAutomation/manifestSchema.spec.ts` → `packages/shared/src/services/guildAutomation/manifestSchema.spec.ts` (2 tests)

Imports rewritten from `@lucky/shared/services/guildAutomation/` to relative `./` to match the new location. Both tests still pass in shared (verified locally).

Kept (with notes):

  • `onboardingMapper.spec.ts` — could move to shared too but imports `discord.js` (not a shared dep). Defer.
  • `spotifyApiRetry.spec.ts` — misnamed (tests `spotifyApi.ts` retry logic, the file's been merged). Rename in a later pass.
  • `queueResolver.guard.spec.ts` — structural FS-convention guard. Keep.

Out of scope (future PRs)

  • Filler-pattern sweep (`toBeDefined`, `toBeInstanceOf`, etc.).
  • Redundant-test consolidation in backend (836 → ~250) and bot (2865 → ~1500).
  • Replacement integration tests for any coverage gaps deletion exposes.
  • `/test-cleanup` skill ran a baseline + bad-name triage + orphan scan; the bigger deletion sweep will be a separate dispatched pass with its own coverage-gate verification.

Risk

Very low. Only deleted code that no longer has a source counterpart, and only moved specs without changing test assertions.

Changelog

Not user-facing; no CHANGELOG entry.

Summary by CodeRabbit

  • Tests
    • Updated test module import paths across multiple areas of the codebase to improve code consistency, maintainability, and enhance the overall quality of the test infrastructure
    • Removed comprehensive test coverage for audio streaming and playback functionality, search result discovery capabilities, and various error-handling and fallback mechanisms

Review Change Stack

…ocation

Phase 1 of the bot+backend test-cleanup pass.

Deleted (source file gone):
- packages/bot/src/handlers/player/playerFactory.bridge.spec.ts (40 tests)
  The 'playerFactory.bridge.ts' source has been gone since the player
  refactor; the spec was testing nothing real (mocks-only).

Moved (specs of shared code, misplaced in bot):
- packages/bot/src/utils/guildAutomation/diff.spec.ts
  -> packages/shared/src/services/guildAutomation/diff.spec.ts (3 tests)
- packages/bot/src/utils/guildAutomation/manifestSchema.spec.ts
  -> packages/shared/src/services/guildAutomation/manifestSchema.spec.ts (2 tests)

Imports rewritten from '@lucky/shared/services/guildAutomation/<name>' to
relative './<name>' to match the new location.

Kept (with notes for later):
- packages/bot/src/utils/guildAutomation/onboardingMapper.spec.ts (2 tests)
  Could move to shared too but it imports 'discord.js' which shared
  doesn't depend on. Defer until shared adds the type dep or stubs it.
- packages/bot/src/spotify/spotifyApiRetry.spec.ts (15 tests)
  Misnamed but tests REAL spotifyApi retry logic. Rename in a later pass.
- packages/bot/src/utils/music/queueResolver.guard.spec.ts (1 test)
  Structural FS guard enforcing a convention — has value, keep.

Net: bot specs 181 -> 176, shared specs 28 -> 30. Test-count delta
mostly comes from the playerFactory.bridge.spec deletion. Coverage
gates are still safely above thresholds (the deleted spec was
all-mocks, so its 'coverage' was synthetic anyway).

Next phases: filler-pattern sweep + redundant-test consolidation in
backend (836 -> ~250) and bot (2865 -> ~1500). Dispatched separately.
@vercel

vercel Bot commented May 22, 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 May 22, 2026 4:47am

Request Review

@greptile-apps greptile-apps 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.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@github-actions

Copy link
Copy Markdown

Failed to generate code suggestions for PR

@coderabbitai

coderabbitai Bot commented May 22, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 267656fe-f7d9-47a3-b5a9-801970af4825

📥 Commits

Reviewing files that changed from the base of the PR and between 44f302e and 2ca0f94.

📒 Files selected for processing (3)
  • packages/bot/src/handlers/player/playerFactory.bridge.spec.ts
  • packages/shared/src/services/guildAutomation/diff.spec.ts
  • packages/shared/src/services/guildAutomation/manifestSchema.spec.ts
💤 Files with no reviewable changes (1)
  • packages/bot/src/handlers/player/playerFactory.bridge.spec.ts

📝 Walkthrough

Walkthrough

This PR updates import statements in guildAutomation test files from absolute package aliases to local relative paths, and removes the playerFactory bridge test suite entirely. The test logic and assertions remain unchanged in the updated files.

Changes

guildAutomation Test Import Path Updates

Layer / File(s) Summary
Test import path normalization
packages/shared/src/services/guildAutomation/diff.spec.ts, packages/shared/src/services/guildAutomation/manifestSchema.spec.ts
diff.spec.ts imports createAutomationPlan and isPlanIdempotent from local ./diff and GuildAutomationManifestDocument from ./types; manifestSchema.spec.ts imports validateGuildAutomationManifest from local ./manifestSchema. All changes use relative paths instead of @lucky/shared/... aliases.

playerFactory Bridge Test Suite Removal

Layer / File(s) Summary
Deleted bridge test coverage
packages/bot/src/handlers/player/playerFactory.bridge.spec.ts
Entire test file removed (615 lines), eliminating coverage for parseDurationString, findMatchingSoundCloudResult, streamViaSoundCloud, streamViaYtDlp, streamViaYtDlpSearch, and createResilientStream test cases and mocks.

Possibly related PRs

  • LucasSantana-Dev/Lucky#550: Adds and adjusts createResilientStream bridge-fallback tests and SoundCloud provider-health gating, directly related to deleted playerFactory bridge test coverage.
  • LucasSantana-Dev/Lucky#390: Expands playerFactory handler tests including yt-dlp command and streaming behavior in the same player factory area.
  • LucasSantana-Dev/Lucky#171: Introduces local guildAutomation modules (./diff, ./manifestSchema) whose imports are now normalized in this PR's test files.

Suggested labels

bot, shared, size/s

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: phase 1 test cleanup involving deletion of an orphan test file and relocation of misplaced specs.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 chore/test-cleanup-backend

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

@LucasSantana-Dev
LucasSantana-Dev merged commit d7c760e into main May 22, 2026
28 of 29 checks passed
@LucasSantana-Dev
LucasSantana-Dev deleted the chore/test-cleanup-backend branch May 22, 2026 05:32
LucasSantana-Dev added a commit that referenced this pull request May 22, 2026
**Phase 2** of the bot + backend test-cleanup pass. Follows PR #938
(Phase 1: orphan deletion + misplaced specs relocation).

## What this PR does

Deletes 15 backend tests across 3 batches. Coverage stays well above the
70% gate.

| Commit | What | Count |
|---|---|---|
| 6ad6169 | drop 2 flaky webhook unit tests | -2 |
| 6114e0b | drop 9 duplicative middleware unit tests (requireAdmin,
requestLogger) | -9 |
| 52cff15 | drop 4 trivial bootstrap unit tests | -4 |

Net: backend 838 → 823 tests.

## Coverage (after final commit)

| Metric | Before | After | Gate |
|---|---|---|---|
| Statements | ~87% | 87.45% | 70% ✓ |
| Branches | ~78% | 78.57% | 70% ✓ |
| Functions | ~88% | 88.52% | 70% ✓ |
| Lines | ~88% | 88.08% | 70% ✓ |

All four metrics remain ≥ 17 points above the gate. The deletions were
targeted at tests with explicit redundancy / flakiness; no replacement
integration tests needed.

## Conservative-by-design

The subagent that executed this phase was given a target of \`backend:
836 → ~250\` and chose to stay conservative because the per-deletion
signal-to-risk ratio dropped sharply after the obvious wins. The
remaining gap (823 → 250, another ~570 tests) requires a more aggressive
sweep with replacement integration tests; that's deferred to a follow-up
PR if/when the user wants it.

## Don't-touch list honored

- \`packages/backend/tests/integration/recommendations.test.ts\` (just
shipped in PR #935) — untouched.

## Risk

Low. Only deleted tests that were either:
- Flaky (intermittent failure history not captured by suite),
- Duplicative of integration coverage already in place,
- Trivial bootstrap structure tests (\`should be defined\` etc.).

No source code changes.
LucasSantana-Dev added a commit that referenced this pull request May 22, 2026
…k LOC removed) (#940)

**Phase 3** of the bot + backend test-cleanup pass. Follows PRs #938
(Phase 1: orphans + misplaced specs) and #939 (Phase 2: 15 backend
deletions).

## Honest framing

This PR was scoped to reduce \`packages/bot/src\` specs from ~2865 to
~1500 tests. The dispatched subagent hit the coverage gate well before
the target. The final shape is a **conservative cleanup** that:

- Removes ~4,800 LOC of test scaffolding across 19 spec files (mostly
mock-heavy wrapper / metadata-only command tests for moderation +
general command surfaces).
- Nets only **22 fewer tests** because the deleted high-LOC files were
replaced by restored handler specs needed to clear the coverage gate.
- Keeps all four coverage gates **at or above threshold**.

## Coverage (final)

| Metric | Final | Gate | Margin |
|---|---|---|---|
| Statements | 65.41% | 65% | +0.41 |
| Branches | 63.43% | 60% | +3.43 |
| Functions | 61.70% | 60% | +1.70 |
| Lines | 66.31% | 65% | +1.31 |

Tight margins on statements + lines — any further deletion will require
**integration-test replacement** (the \`/test-cleanup\` skill's Step 7),
not pure pruning.

## What was deleted (kept after coverage check)

- moderation: \`history\`, \`mute\`, \`purge\`, \`digest\`,
\`lockdown\`, \`kick\`, \`ban\` wrapper specs (~437 tests)
- general: \`giveaway\`, \`level\`, \`voterewards\` (~113 tests —
\`leaderboard\` kept as it has real assertions)
- music: \`case\`, \`session\`, \`music\`, \`slowmode\` wrapper specs
(~88 tests)
- weak metadata-only command tests (38)
- 21 orphan/guard/config specs (the 4 I'd explicitly listed as keep were
restored separately)

## What was restored (4 reverts)

The subagent had to revert these four batches to clear the gate:
1. command/interaction handler specs (+109 tests back)
2. client/member handler specs (presence, member — +206 back)
3. reactionrole/roleconfig handler specs (+133 back)
4. automessage/serversetup mgmt wrappers (+101 back)

Plus the 4 explicitly-protected files I'd flagged in Phase 1
(\`spotifyApiRetry.spec.ts\`, \`spotifyConfig.spec.ts\`,
\`onboardingMapper.spec.ts\`, \`queueResolver.guard.spec.ts\`) — these
were over-deleted; restored in commit \`1fe5f2d3\`.

## Lesson learned

Lucky's bot package has a coverage gate (statements 65, branches 60,
functions 60, lines 65) that's tightly bound to the existing unit-test
surface. The proportionality target of 500-1500 tests from the
\`/test-cleanup\` skill table is **unreachable through pure deletion**
at the current gate; further reduction requires:

1. Writing integration tests that subsume clusters of unit tests
(\`it.each\` over realistic flows).
2. OR lowering the gate (architectural decision).

This PR ships the safe-by-coverage subset and documents the cap. A
follow-up phase with integration-test replacement work is the right next
move when there's time for it.

## Don't-touch list honored (after restoration)

All recently-added test files from PRs #926-#935 untouched.

## Squash-merge recommended

15 commits (10 deletions + 5 restorations + 4 reverts). Suggest
squashing on merge to keep main history clean.

## Risk

Low. All deletions are wrapper/metadata-only specs; the deleted files
mocked their SUTs and provided minimal real coverage. Tight coverage
margins mean any regression in unit tests in the future will need
attention.

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

## Summary by CodeRabbit

* **Tests**
* Removed test suites for multiple bot commands and utilities across
various modules.
  * Reformatted test function calls for improved code readability.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/LucasSantana-Dev/Lucky/pull/940?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
LucasSantana-Dev added a commit that referenced this pull request May 23, 2026
## What

Patch release v2.14.1.

## Changes since v2.14.0

### Fixed
- fix(docker): include repo-root `CHANGELOG.md` in the frontend build
stage context — resolves broken production frontend image since v2.13.0
(#937)

### Internal
- ci: split sequential `quality-gates` job into four parallel test jobs;
absorb `sonarcloud.yml` into `ci.yml` — tests run once with coverage,
SonarCloud downloads artifacts. PR wall time ~8–10 min vs ~13–15 min
(#942)
- chore(tests): three-phase bot + backend test cleanup — ~77 tests + ~5k
LOC removed (#938 #939 #940)
- chore: add `.husky/post-merge` hook to auto-prune local branches whose
remote has been deleted (#941)

This branch was successfully deployed

1 active deployment
Preview — 2ca0f943 Deployed May 22, 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