fix(458): reject duplicate names on playlist & playlist-group rename #576

Merged
timothy merged 1 commits from feat/458-rename-dup into main 2026-07-23 20:07:43 +02:00
Owner

Closes #458.

Problem

ReplacePlaylistItemsHandler (playlist rename) and RenamePlaylistGroupHandler (group rename) validated name non-empty + length ≤ 50 but never checked uniqueness, whereas the create paths reject a duplicate. So a rename could produce two identically-named sibling playlists/groups.

Fix

Mirror the existing rename-with-dedup sibling pattern (ReplaceBlockItemsHandler.BlockNameMustBeValid, ReplaceTemplateItemsHandler.ValidateTemplateName): a final async .BindT uniqueness step that

  • Playlist — scopes by the loaded playlist.PlaylistGroupId (rename can't move groups; the command carries no group field), matching (PlaylistGroupId, Name)'s unique index and CreatePlaylistHandler's scoping.
  • Group — global scope, matching PlaylistGroup.Name's unique index.
  • Self-excludes by Id, so a no-op rename to its own name still succeeds.
  • Returns BaseError → 422, the same status create uses (both PUT endpoints already declare 422).

For groups this also upgrades a would-be raw DbUpdateException (create-group has no explicit guard — it leans on the DB index) into a clean 422.

Note on the issue premise

The issue said both create handlers reject duplicates; in fact only CreatePlaylistHandler has an explicit check — CreatePlaylistGroupHandler relies solely on the DB unique index. The fix is unchanged (add an explicit guard to both renames) and additionally makes the group path's error clean.

Tests

Extended the two existing handler fixtures (EF InMemory does not enforce unique indexes, so these exercise the explicit check, not the DB constraint):

  • duplicate-in-same-group rejected + not mutated (playlist)
  • duplicate group name rejected; duplicate onto a system group's name rejected
  • same-name (no-op) rename succeeds (both)
  • duplicate in a different group allowed (playlist — scoping guard)

72 Playlist-related tests green locally; format + BOM gate clean.

Review

Independent cold review: MERGEABLE — correct scoping/self-exclusion/pipeline placement, non-vacuous tests, no blockers/highs/mediums.

🤖 Generated with Claude Code

Closes #458. ## Problem `ReplacePlaylistItemsHandler` (playlist rename) and `RenamePlaylistGroupHandler` (group rename) validated name **non-empty** + **length ≤ 50** but never checked **uniqueness**, whereas the create paths reject a duplicate. So a rename could produce two identically-named sibling playlists/groups. ## Fix Mirror the existing rename-with-dedup sibling pattern (`ReplaceBlockItemsHandler.BlockNameMustBeValid`, `ReplaceTemplateItemsHandler.ValidateTemplateName`): a final async `.BindT` uniqueness step that - **Playlist** — scopes by the *loaded* `playlist.PlaylistGroupId` (rename can't move groups; the command carries no group field), matching `(PlaylistGroupId, Name)`'s unique index and `CreatePlaylistHandler`'s scoping. - **Group** — global scope, matching `PlaylistGroup.Name`'s unique index. - Self-excludes by `Id`, so a no-op rename to its own name still succeeds. - Returns `BaseError` → **422**, the same status create uses (both PUT endpoints already declare 422). For groups this also upgrades a would-be raw `DbUpdateException` (create-group has no explicit guard — it leans on the DB index) into a clean 422. ## Note on the issue premise The issue said *both* create handlers reject duplicates; in fact only `CreatePlaylistHandler` has an explicit check — `CreatePlaylistGroupHandler` relies solely on the DB unique index. The fix is unchanged (add an explicit guard to both renames) and additionally makes the group path's error clean. ## Tests Extended the two existing handler fixtures (EF InMemory does **not** enforce unique indexes, so these exercise the explicit check, not the DB constraint): - duplicate-in-same-group rejected + not mutated (playlist) - duplicate group name rejected; duplicate onto a **system** group's name rejected - same-name (no-op) rename succeeds (both) - duplicate in a **different** group allowed (playlist — scoping guard) 72 Playlist-related tests green locally; format + BOM gate clean. ## Review Independent cold review: **MERGEABLE** — correct scoping/self-exclusion/pipeline placement, non-vacuous tests, no blockers/highs/mediums. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
timothy added 1 commit 2026-07-23 19:44:24 +02:00
fix(458): reject duplicate names on playlist & playlist-group rename
PR Gates / CI image pin matches docker/ci (pull_request) Successful in 9s
PR Gates / Docs update reminder (pull_request) Successful in 12s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 13s
PR Gates / decisions lifecycle (pull_request) Successful in 17s
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 1m28s
Build ErsatzTV Image / Functional E2E (curl contracts) (pull_request) Successful in 15m47s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 16m2s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 19m55s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
d12da836f2
ReplacePlaylistItemsHandler (playlist rename) and RenamePlaylistGroupHandler
(group rename) validated name non-empty/length but not uniqueness, so a rename
could produce two identically-named siblings even though the create paths reject
duplicates. Mirror the existing ReplaceBlockItems/ReplaceTemplate sibling
pattern: an async BindT step scoped to the group (playlist) or global (group,
matching PlaylistGroup.Name's unique index), self-excluded so a no-op rename to
its own name still succeeds, returning BaseError -> 422 like create.

For groups this also upgrades a would-be raw DbUpdateException (create-group has
no explicit guard, only the DB index) into a clean 422.

Closes #458.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Author
Owner

Review-verdict: MERGEABLE @ d12da836

Independent cold review (fresh agent, no implementation role) over the full diff: correct group-vs-global scoping, self-exclusion (no-op rename to own name succeeds), correct .BindT pipeline placement (422 after the 404 existence / 422 system-group checks), non-vacuous tests. No blockers/highs/mediums.

The only change after that review was one additive regression test the reviewer itself suggested (Rename_Should_Reject_Name_Taken_By_System_Group) — production code is byte-identical to what was reviewed, so the verdict carries to the current head.

`Review-verdict: MERGEABLE @ d12da836` Independent cold review (fresh agent, no implementation role) over the full diff: correct group-vs-global scoping, self-exclusion (no-op rename to own name succeeds), correct `.BindT` pipeline placement (422 after the 404 existence / 422 system-group checks), non-vacuous tests. No blockers/highs/mediums. The only change after that review was one **additive** regression test the reviewer itself suggested (`Rename_Should_Reject_Name_Taken_By_System_Group`) — production code is byte-identical to what was reviewed, so the verdict carries to the current head.
timothy merged commit 7a7c611267 into main 2026-07-23 20:07:43 +02:00
timothy deleted branch feat/458-rename-dup 2026-07-23 20:07:44 +02:00
Sign in to join this conversation.