[PR #6089] [MERGED] fix: remove a deleted card from every chat, and count only existing cards in Chat Settings (#6084) #7057

Closed
opened 2026-10-23 04:16:09 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6089
Author: @ghost
Created: 9/12/2026
Status: ✅ Merged
Merged: 9/12/2026
Merged by: @undefined

Base: staging ← Head: fix/deleted-card-chat-membership-6084


📝 Commits (5)

  • 233483d fix: remove a deleted card from every chat, and count only existing cards in Chat Settings
  • 5c03db7 Merge remote-tracking branch 'origin/staging' into fix/deleted-card-chat-membership-6084
  • 6c4d5a5 test: align deleted-card regression with all chat modes
  • 6c433f5 Merge branch 'staging' into fix/deleted-card-chat-membership-6084
  • 29f59db fix: keep character counts stable while cards load

📊 Changes

5 files changed (+123 additions, -8 deletions)

View changed files

📝 CHANGELOG.md (+2 -0)
📝 packages/client/src/components/chat/ChatSettingsDrawer.tsx (+6 -4)
📝 packages/server/src/services/storage/characters.storage.ts (+5 -2)
📝 scripts/regressions/assigned-chat-sweep.regression.ts (+2 -2)
➕ scripts/regressions/character-delete-chat-membership.regression.ts (+108 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #6084

Why this change

  • Deleting a character card scrubbed its id from Game chats only (#6026 / #6021). Roleplay and Conversation chats kept the dead id, and Chat Settings → Characters showed a count one higher than the rows under it (badge 2, one row).

What changed

  • packages/server/src/services/storage/characters.storage.ts — the deletion transaction's chat scrub now selects every chat instead of mode === "game". The Game party/setup branches are untouched and no-op for the other modes (metadata defaults to {}, so the existing guards hold). Chats that never held the card are not rewritten.
  • packages/client/src/components/chat/ChatSettingsDrawer.tsx — the Characters section's count and its two empty-state checks use the resolved chatCharacters.length instead of the raw chatCharIds.length, the same change #6026 made for the Game Party count. This covers chats that are already stale (deleted before this lands, or imported). 3 lines.
  • scripts/regressions/character-delete-chat-membership.regression.ts — new: two cards, four chats (roleplay/conversation/game/untouched), one group; deletes a card and asserts membership, game party/setup/GM, the untouched chat's updatedAt, and the group. Fails on staging at "Roleplay chat drops the deleted card"; passes with this change.
  • CHANGELOG.md — one line under Unreleased.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

Branch built from staging @ 5e3dd361e; pnpm check ran all stages to completion (the one lint warning is pre-existing, GameNarration.tsx:1404). node ./scripts/run-regressions.mjs --filter character-delete-chat-membership → 1/1.

Two servers side by side on a clone of real data, macOS 26.6.2 arm64, Chromium 1400×900:

scenario staging 5e3dd361e this branch
Roleplay chat with cards A+B, delete B → GET /api/chats/:id .characterIds [A, B] [A]
same chat, Chat Settings → Characters badge / rows 2 / 1 1 / 1
planted stale id (PATCH /api/chats/:id {characterIds:[A,"stale-…"]}, no deletion) → badge / rows 2 / 1 1 / 1
Roleplay chat with no cards → badge / empty-state text none / shown none / shown
Conversation chat with one card → badge / rows 1 / 1 1 / 1
Game chat with A+B, delete B (already covered by #6026) scrubbed scrubbed

Downstream checks on the branch build:

  • Sidebar order: the scrub bumps updatedAt on each chat that held the card (as #6026 already does for Game). "Recent" sorts on lastMessageAt || createdAt || updatedAt (lib/chat-recency.ts), so the order does not change for any chat with a createdAt. Measured: the raw GET /api/chats order moved, the sidebar comparator does not.
  • Open drawer: deleting the card from inside the app invalidates chatKeys.all (hooks/use-characters.ts), so the badge and rows refresh in place. Deleting over the API from outside the browser leaves the open drawer stale until reload (badge 2 → after reload 1); that is the cache, not this change, and the resolved count keeps the badge equal to the rows in either window.
  • Chats that never held the card are not rewritten (regression asserts updatedAt unchanged).

Not verified by me: container build; mobile viewport; light vs dark (the change is a number and a boolean, no styling).

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

CHANGELOG only; nothing under docs/.

UI evidence (if applicable)

Before/after of the Characters section for the planted-stale-id row above (badge 2 vs 1 over the same single row) — screenshots to follow in a comment.

Summary by CodeRabbit

  • Bug Fixes

    • Deleting a character card now removes it from Roleplay, Conversation, and Game chats.
    • Chat Settings now counts only existing character cards and displays accurate empty states.
    • Game chat metadata is cleaned up when a character card is deleted, including clearing deleted game masters where applicable.
    • Unaffected chat memberships remain unchanged.
  • Tests

    • Added coverage to verify character deletion and chat membership cleanup across all chat modes.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/6089 **Author:** [@ghost](https://github.com/ghost) **Created:** 9/12/2026 **Status:** ✅ Merged **Merged:** 9/12/2026 **Merged by:** [@undefined](undefined) **Base:** `staging` ← **Head:** `fix/deleted-card-chat-membership-6084` --- ### 📝 Commits (5) - [`233483d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/233483d8cdd6434a1ece6d34bc62b2acd59e9cb0) fix: remove a deleted card from every chat, and count only existing cards in Chat Settings - [`5c03db7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5c03db7f520fa75947df7b7a1122d756b5baca4f) Merge remote-tracking branch 'origin/staging' into fix/deleted-card-chat-membership-6084 - [`6c4d5a5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6c4d5a59f2aa7b60c871fb5029efdaea4d36d05f) test: align deleted-card regression with all chat modes - [`6c433f5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6c433f5133b6518c50f7cbe2f46c7ff2ef999a94) Merge branch 'staging' into fix/deleted-card-chat-membership-6084 - [`29f59db`](https://github.com/Pasta-Devs/Marinara-Engine/commit/29f59db5658c5c1b705588af870060ea0e588956) fix: keep character counts stable while cards load ### 📊 Changes **5 files changed** (+123 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+2 -0) 📝 `packages/client/src/components/chat/ChatSettingsDrawer.tsx` (+6 -4) 📝 `packages/server/src/services/storage/characters.storage.ts` (+5 -2) 📝 `scripts/regressions/assigned-chat-sweep.regression.ts` (+2 -2) ➕ `scripts/regressions/character-delete-chat-membership.regression.ts` (+108 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #6084 ## Why this change - Deleting a character card scrubbed its id from **Game** chats only (#6026 / #6021). Roleplay and Conversation chats kept the dead id, and Chat Settings → Characters showed a count one higher than the rows under it (badge `2`, one row). ## What changed - `packages/server/src/services/storage/characters.storage.ts` — the deletion transaction's chat scrub now selects every chat instead of `mode === "game"`. The Game party/setup branches are untouched and no-op for the other modes (`metadata` defaults to `{}`, so the existing guards hold). Chats that never held the card are not rewritten. - `packages/client/src/components/chat/ChatSettingsDrawer.tsx` — the Characters section's `count` and its two empty-state checks use the resolved `chatCharacters.length` instead of the raw `chatCharIds.length`, the same change #6026 made for the Game Party count. This covers chats that are already stale (deleted before this lands, or imported). 3 lines. - `scripts/regressions/character-delete-chat-membership.regression.ts` — new: two cards, four chats (roleplay/conversation/game/untouched), one group; deletes a card and asserts membership, game party/setup/GM, the untouched chat's `updatedAt`, and the group. Fails on `staging` at "Roleplay chat drops the deleted card"; passes with this change. - `CHANGELOG.md` — one line under Unreleased. ## Validation - [x] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes Branch built from `staging` @ `5e3dd361e`; `pnpm check` ran all stages to completion (the one lint warning is pre-existing, `GameNarration.tsx:1404`). `node ./scripts/run-regressions.mjs --filter character-delete-chat-membership` → 1/1. Two servers side by side on a clone of real data, macOS 26.6.2 arm64, Chromium 1400×900: | scenario | `staging` 5e3dd361e | this branch | |---|---|---| | Roleplay chat with cards A+B, delete B → `GET /api/chats/:id .characterIds` | `[A, B]` | `[A]` | | same chat, Chat Settings → Characters badge / rows | **2** / 1 | **1** / 1 | | planted stale id (`PATCH /api/chats/:id {characterIds:[A,"stale-…"]}`, no deletion) → badge / rows | **2** / 1 | **1** / 1 | | Roleplay chat with no cards → badge / empty-state text | none / shown | none / shown | | Conversation chat with one card → badge / rows | 1 / 1 | 1 / 1 | | Game chat with A+B, delete B (already covered by #6026) | scrubbed | scrubbed | Downstream checks on the branch build: - Sidebar order: the scrub bumps `updatedAt` on each chat that held the card (as #6026 already does for Game). "Recent" sorts on `lastMessageAt || createdAt || updatedAt` (`lib/chat-recency.ts`), so the order does not change for any chat with a `createdAt`. Measured: the raw `GET /api/chats` order moved, the sidebar comparator does not. - Open drawer: deleting the card from inside the app invalidates `chatKeys.all` (`hooks/use-characters.ts`), so the badge and rows refresh in place. Deleting over the API from outside the browser leaves the open drawer stale until reload (badge 2 → after reload 1); that is the cache, not this change, and the resolved count keeps the badge equal to the rows in either window. - Chats that never held the card are not rewritten (regression asserts `updatedAt` unchanged). Not verified by me: container build; mobile viewport; light vs dark (the change is a number and a boolean, no styling). ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) CHANGELOG only; nothing under `docs/`. ## UI evidence (if applicable) Before/after of the Characters section for the planted-stale-id row above (badge 2 vs 1 over the same single row) — screenshots to follow in a comment. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Deleting a character card now removes it from Roleplay, Conversation, and Game chats. * Chat Settings now counts only existing character cards and displays accurate empty states. * Game chat metadata is cleaned up when a character card is deleted, including clearing deleted game masters where applicable. * Unaffected chat memberships remain unchanged. * **Tests** * Added coverage to verify character deletion and chat membership cleanup across all chat modes. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:16:09 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#7057
No description provided.