Skip to content

fix(shared,backend,db): retire orphan per-guild feature toggle substrate - #903

Closed
LucasSantana-Dev wants to merge 1 commit into
release/v2.12.0from
fix/retire-per-guild-feature-toggles
Closed

LucasSantana-Dev wants to merge 1 commit into
release/v2.12.0from
fix/retire-per-guild-feature-toggles

Conversation

@LucasSantana-Dev

Copy link
Copy Markdown
Owner

Summary

PR #801 (admin panel for global toggles) explicitly removed per-guild toggle ROUTES but left the substrate behind: GuildFeatureToggle Prisma model + guild_feature_toggles DB table + dead method references in 2 test files. Shared CI's Quality Gates has been red on this for ~2 weeks; surfaced this session via /adt-ship-check + /diagnose.

What this PR does

  1. Schema — removes model GuildFeatureToggle and Guild.featureToggles from prisma/schema.prisma.
  2. Migration — 20260519000000_retire_per_guild_feature_toggles/migration.sql drops guild_feature_toggles with IF EXISTS.
  3. Shared spec — rewrites FeatureToggleService.spec.ts to test only the surviving global Vercel-flag + DB-override path. Deletes three dead describe blocks (getDbOverride (via isEnabledForGuild), setGuildFeatureToggle, isEnabledForGuild with DB override). Mocks prisma.globalFeatureToggle instead of prisma.guildFeatureToggle.
  4. Backend integration test — strips toggles.test.ts mock of mockSetGuildFeatureToggle, setGuildFeatureToggle, and isEnabledForGuild entries.
  5. ADR — docs/decisions/2026-05-19-retire-per-guild-feature-toggles.md documenting the original removal in feat(admin): add admin panel with writable global feature toggles #801, the orphan state, the considered options (retire / restore / leave-orphan), consequences, and revisit triggers.

Why

#801's commit body said "Remove per-guild toggle routes" but didn't sweep schema or tests. The strict workspace npm run test:ci --workspace=packages/shared was failing TS2551 on setGuildFeatureToggle since then. With per-guild toggle UI + routes already gone, the substrate is genuinely orphan — restoring it would require a new product driver.

Diagnostic trail

Followed /diagnose discipline. Phase 1–4 ranked four hypotheses (H1: deliberate removal in admin-panel work / H2: moved to sibling service / H3: renamed / H4: silently deleted). Single probe (git log -S 'setGuildFeatureToggle' -- + grep across packages) confirmed H1 + H4 in combination: #801 deliberately removed the method, didn't clean up the substrate. No correct seam for a regression test (we're deleting dead-method assertions, not fixing buggy logic) — noted in ADR.

Verification

  • npm run test:ci --workspace=packages/shared: failed-suite count drops from 2 to 1 (only __tests__/utils/spotify/artistApi.test.ts remains red, pre-existing tech debt, separate scope).
  • npx jest --config packages/backend/jest.config.cjs packages/backend/tests/integration/routes/toggles.test.ts: 10/10 passing.
  • npm run type:check --workspace=packages/shared: clean.
  • grep -r 'GuildFeatureToggle' packages/*/src --include='*.ts' --include='*.tsx' outside generated/ and .spec.: no matches.

Test plan

  • Local shared test:ci — green for ours, only pre-existing artistApi remains
  • Local backend toggles integration — 10/10 green
  • Local typecheck shared — green
  • CI Quality Gates on this PR (the gate that would have caught feat(admin): add admin panel with writable global feature toggles #801)
  • SonarCloud (informational)
  • Migration applied in dev/staging before merge — DB-impacting

DB impact

Migration drops guild_feature_toggles with IF EXISTS. Per the deployment chain (single homelab Postgres production target), rows from #614 (if any survived #801's route removal) will be lost. No production consumers were found writing to this table since #801.

Refs: #614 (introduced), #801 (silent removal), this PR (#903).

PR #801 (admin panel for global toggles, 2026-05-04) removed the per-guild
toggle ROUTES and the `setGuildFeatureToggle` / `isEnabledForGuild` methods
on `FeatureToggleService`, but left behind:

- `GuildFeatureToggle` Prisma model + `guild_feature_toggles` DB table
- `Guild.featureToggles` relation field
- `packages/shared/src/services/FeatureToggleService.spec.ts` — 3 dead
  describe blocks asserting `setGuildFeatureToggle`, `getDbOverride`,
  `isEnabledForGuild` (compile-failed with TS2551 since #801)
- `packages/backend/tests/integration/routes/toggles.test.ts` — dead
  `mockSetGuildFeatureToggle` declaration + `setGuildFeatureToggle` /
  `isEnabledForGuild` entries in the service mock

The shared test suite has been red on `Quality Gates` for ~2 weeks; the
failure was hidden until `/adt-ship-check` + `/diagnose` surfaced it.

This commit:

- Rewrites `FeatureToggleService.spec.ts` to cover only the surviving
  global Vercel-flags + DB-override path. Mocks `prisma.globalFeatureToggle`
  instead of `prisma.guildFeatureToggle`. The 6 global describe blocks now
  run (they were also dead, since the file refused to compile).
- Strips `toggles.test.ts` mock of `mockSetGuildFeatureToggle`,
  `setGuildFeatureToggle`, and `isEnabledForGuild` entries. 10/10 existing
  tests pass.
- Drops `model GuildFeatureToggle` and `Guild.featureToggles` from
  `prisma/schema.prisma`.
- Adds `20260519000000_retire_per_guild_feature_toggles/migration.sql`
  with `DROP TABLE IF EXISTS "guild_feature_toggles";`.
- Writes `docs/decisions/2026-05-19-retire-per-guild-feature-toggles.md`
  retroactively documenting #801's removal decision, the orphan state,
  and the revisit conditions if a future product driver wants per-guild
  flag scoping.

Verification:

- `npm run test:ci --workspace=packages/shared`: failed-suite count drops
  from 2 (FeatureToggleService + spotify/artistApi) to 1 (artistApi only,
  pre-existing tech debt, out of scope).
- `npx jest --config packages/backend/jest.config.cjs packages/backend/tests/integration/routes/toggles.test.ts`:
  10/10 passing.
- `npm run type:check --workspace=packages/shared`: clean.
- `grep -r 'GuildFeatureToggle' packages/*/src --include='*.ts' --include='*.tsx'`
  outside `generated/` and `.spec.`: no matches.

Refs: PR #614 (introduced), PR #801 (silent removal), PR #903 (this fix).
@vercel

vercel Bot commented May 20, 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 20, 2026 2:29am

Request Review

@coderabbitai

coderabbitai Bot commented May 20, 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 14 minutes and 58 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 08904528-166b-4594-8374-f683626ca6bf

📥 Commits

Reviewing files that changed from the base of the PR and between 748a5da and 4089567.

📒 Files selected for processing (5)
  • docs/decisions/2026-05-19-retire-per-guild-feature-toggles.md
  • packages/backend/tests/integration/routes/toggles.test.ts
  • packages/shared/src/services/FeatureToggleService.spec.ts
  • prisma/migrations/20260519000000_retire_per_guild_feature_toggles/migration.sql
  • prisma/schema.prisma
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/retire-per-guild-feature-toggles

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.

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

LucasSantana-Dev has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@github-actions

Copy link
Copy Markdown

Failed to generate code suggestions for PR

@sonarqubecloud

Copy link
Copy Markdown

LucasSantana-Dev added a commit that referenced this pull request May 21, 2026
## Goal
Prevent orphan code (Prisma models, broken test files, dead types) from
being left behind after feature/route removal PRs. PR #903 had to clean
up 2-week-old orphans from PR #801.

## Changes
1. **PR Template**: Added `.github/PULL_REQUEST_TEMPLATE.md` with a new
"Feature-removal sweep" checklist section (skip-friendly) covering:
   - Orphan Prisma models removed
   - Broken/stale test files removed
   - Unused type aliases removed
   - Imports/exports cleaned up
   - ADRs and CONTEXT.md cross-references updated

2. **Dangerfile Guard**: Added rule #9 to `dangerfile.ts` that detects
commit messages matching removal patterns
(`remove|delete|retire|drop|deprecate` +
`route|handler|endpoint|model|toggle|feature`) and warns if the PR body
doesn't contain the sweep checklist text.

## Acceptance
- [x] PR template has "Feature-removal sweep" section  
- [x] Dangerfile rule flags qualifying commit bodies  
- Ready for validation against next 3 feature-removal PRs

See docs/decisions/2026-05-19-retire-per-guild-feature-toggles.md for
context.

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

## Summary by CodeRabbit

* **Chores**
* Enhanced pull request template with contributor guidelines, including
reminders for testing and changelog updates.
* Added automated CI check to ensure feature removal pull requests
include proper code cleanup verification.

<!-- 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/913?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
LucasSantana-Dev deleted the branch release/v2.12.0 May 21, 2026 16:27

This branch was successfully deployed

1 active deployment
Preview — 4089567a Deployed May 20, 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