[PR #1406] [MERGED] Inherit folder assignment when creating derived chats #5073

Closed
opened 2026-10-22 04:12:58 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1406
Author: @Romuromylus
Created: 5/27/2026
Status: ✅ Merged
Merged: 5/27/2026
Merged by: @Romuromylus

Base: refactor ← Head: fix/refactor-issue-1344-folder-inheritance


📝 Commits (5)

  • 4b08599 Inherit folder assignment when creating derived chats
  • 588b244 Add test coverage for the three uncovered fix sites
  • 3edd771 Merge branch 'refactor' into fix/refactor-issue-1344-folder-inheritance
  • c91d75f Merge branch 'refactor' into fix/refactor-issue-1344-folder-inheritance
  • c2d149c Merge branch 'refactor' into fix/refactor-issue-1344-folder-inheritance

📊 Changes

5 files changed (+445 additions, -0 deletions)

View changed files

📝 src-tauri/src/commands/storage/profile/legacy.rs (+56 -0)
➕ src/engine/modes/roleplay/scene/scene-service.test.ts (+239 -0)
📝 src/engine/modes/roleplay/scene/scene-service.ts (+2 -0)
➕ src/features/modes/game/api/game-api.test.ts (+145 -0)
📝 src/features/modes/game/api/game-api.ts (+3 -0)

📄 Description

Why this change

Issue #1344 asked for chat-folder parity verification against v1.6.0/v1.6.1. The audit (see issue comment) found four call sites where a derived chat is built from an explicit object literal that omits folderId. Result: a chat in folder X spawns a derived chat at root instead of staying in the same folder.

Affected paths:

  • Roleplay scene creation (createRoleplayScene) from a chat inside a folder.
  • Roleplay scene fork (forkRoleplayScene) from a scene chat inside a folder, both clone and convert modes.
  • Game creation (gameApi.createGame) when the UI does not reuse an existing chat id.
  • Next-session continuation (gameApi.startSession) carrying over from the previous session in a folder.

Storage-layer paths (native and v1.6.x legacy profile import, branch_chat in Rust) already preserve folderId correctly, those need no change. This PR is scoped to the four engine and feature paths where the create payload was the bug.

What changed

  • src/engine/modes/roleplay/scene/scene-service.ts:150 — createRoleplayScene now passes folderId: originChat.folderId ?? null into the new chat's create payload.
  • src/engine/modes/roleplay/scene/scene-service.ts:240 — forkRoleplayScene propagates folderId: sceneChat.folderId ?? null for both clone and convert modes.
  • src/features/modes/game/api/game-api.ts:778, 799 — gameApi.createGame gains an optional folderId input and the new-chat branch passes folderId: data.folderId ?? null through. The existing-chat-id branch was already correct via partial patch and is unchanged.
  • src/features/modes/game/api/game-api.ts:958 — gameApi.startSession carries folderId: previousChat?.folderId ?? null forward.
  • src/engine/modes/roleplay/scene/scene-service.test.ts — vitest covering scene create, fork-clone, and fork-convert folder inheritance (4 cases, including a null-origin sanity check).
  • src/features/modes/game/api/game-api.test.ts — new vitest covering createGame new-chat folderId propagation, createGame null-default behavior, and startSession previousChat folderId carryover (3 cases).
  • src-tauri/src/commands/storage/profile/legacy.rs — new legacy_chat_import_preserves_folder_assignment test asserts a v1.6.x profile import preserves the chat's folder assignment across the legacy table roundtrip.

The ?? null normalization is for legacy chats predating the field; engine Chat.folderId is string | null but rows from older user data can surface the field as undefined.

Verification

  • pnpm check clean locally (architecture + tsc -b + cargo check + docs).
  • cargo clippy --workspace --all-targets -- -D warnings clean (CI parity for the test-arg signature check).
  • All 4 new scene-service.test.ts cases pass, all 3 new game-api.test.ts cases pass. Full vitest suite stays green.
  • New Rust test passes standalone; full cargo test --workspace passes apart from one pre-existing environmental flake (crates/assets symlink test requires admin on Windows; unrelated to this PR).
  • Tier 1c end-to-end verification against the real Tauri shell: drove createRoleplayScene through the live pnpm tauri dev window via Playwright over WebView2 CDP (port 9223). Seeded a chat folder + a roleplay chat in that folder via real storage_create invokes, called createRoleplayScene against the dynamically-imported engine module from the page context, then asserted the new scene chat's folderId matched the seeded folder id via storage_get. PASS. Confirms the fix line at scene-service.ts:150 round-trips correctly through the real Rust storage layer.

Follow-ups (deferred, not blocking this PR)

  • UI wiring for "create new game in current folder" — gameApi.createGame now accepts an optional folderId, but no caller passes it yet. Adding the field at the input boundary keeps the API ready without a churnful follow-up.
  • The audit also flagged folder-delete cascade behavior (deleted folders leave chats holding a dangling folderId). Needs a separate Tier 1c runtime check to confirm, will file independently if reproduced.
  • useCreateChat (the generic chat hook) does not accept folderId for "new chat into current folder" either. That is a deliberate design decision, not in scope here.
  • The agent create_chat slash command in connected-commands.ts also writes without folderId. Plausibly correct (the agent has no folder context), but worth a deliberate call from upstream.

Linked issue

Refs #1344


🔄 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/1406 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 5/27/2026 **Status:** ✅ Merged **Merged:** 5/27/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `refactor` ← **Head:** `fix/refactor-issue-1344-folder-inheritance` --- ### 📝 Commits (5) - [`4b08599`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4b085997f3b41a16e240ed0c997636205c0da04f) Inherit folder assignment when creating derived chats - [`588b244`](https://github.com/Pasta-Devs/Marinara-Engine/commit/588b244d6fccba7c21c96cefe75beec3cc3a2b22) Add test coverage for the three uncovered fix sites - [`3edd771`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3edd7710201acab6bf173c450da05256760ff2c1) Merge branch 'refactor' into fix/refactor-issue-1344-folder-inheritance - [`c91d75f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c91d75f8a3a9eb6c3b99b4433548395c2cfa021b) Merge branch 'refactor' into fix/refactor-issue-1344-folder-inheritance - [`c2d149c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c2d149caa826f5fb550945be8a67d98394117bfe) Merge branch 'refactor' into fix/refactor-issue-1344-folder-inheritance ### 📊 Changes **5 files changed** (+445 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `src-tauri/src/commands/storage/profile/legacy.rs` (+56 -0) ➕ `src/engine/modes/roleplay/scene/scene-service.test.ts` (+239 -0) 📝 `src/engine/modes/roleplay/scene/scene-service.ts` (+2 -0) ➕ `src/features/modes/game/api/game-api.test.ts` (+145 -0) 📝 `src/features/modes/game/api/game-api.ts` (+3 -0) </details> ### 📄 Description ## Why this change Issue #1344 asked for chat-folder parity verification against v1.6.0/v1.6.1. The audit (see [issue comment](https://github.com/Pasta-Devs/Marinara-Engine/issues/1344#issuecomment-4553198550)) found four call sites where a derived chat is built from an explicit object literal that omits `folderId`. Result: a chat in folder X spawns a derived chat at root instead of staying in the same folder. Affected paths: - Roleplay scene creation (`createRoleplayScene`) from a chat inside a folder. - Roleplay scene fork (`forkRoleplayScene`) from a scene chat inside a folder, both clone and convert modes. - Game creation (`gameApi.createGame`) when the UI does not reuse an existing chat id. - Next-session continuation (`gameApi.startSession`) carrying over from the previous session in a folder. Storage-layer paths (native and v1.6.x legacy profile import, `branch_chat` in Rust) already preserve `folderId` correctly, those need no change. This PR is scoped to the four engine and feature paths where the create payload was the bug. ## What changed - `src/engine/modes/roleplay/scene/scene-service.ts:150` — `createRoleplayScene` now passes `folderId: originChat.folderId ?? null` into the new chat's create payload. - `src/engine/modes/roleplay/scene/scene-service.ts:240` — `forkRoleplayScene` propagates `folderId: sceneChat.folderId ?? null` for both clone and convert modes. - `src/features/modes/game/api/game-api.ts:778, 799` — `gameApi.createGame` gains an optional `folderId` input and the new-chat branch passes `folderId: data.folderId ?? null` through. The existing-chat-id branch was already correct via partial patch and is unchanged. - `src/features/modes/game/api/game-api.ts:958` — `gameApi.startSession` carries `folderId: previousChat?.folderId ?? null` forward. - `src/engine/modes/roleplay/scene/scene-service.test.ts` — vitest covering scene create, fork-clone, and fork-convert folder inheritance (4 cases, including a null-origin sanity check). - `src/features/modes/game/api/game-api.test.ts` — new vitest covering `createGame` new-chat folderId propagation, `createGame` null-default behavior, and `startSession` previousChat folderId carryover (3 cases). - `src-tauri/src/commands/storage/profile/legacy.rs` — new `legacy_chat_import_preserves_folder_assignment` test asserts a v1.6.x profile import preserves the chat's folder assignment across the legacy table roundtrip. The `?? null` normalization is for legacy chats predating the field; engine `Chat.folderId` is `string | null` but rows from older user data can surface the field as `undefined`. ## Verification - `pnpm check` clean locally (architecture + tsc -b + cargo check + docs). - `cargo clippy --workspace --all-targets -- -D warnings` clean (CI parity for the test-arg signature check). - All 4 new `scene-service.test.ts` cases pass, all 3 new `game-api.test.ts` cases pass. Full vitest suite stays green. - New Rust test passes standalone; full `cargo test --workspace` passes apart from one pre-existing environmental flake (`crates/assets` symlink test requires admin on Windows; unrelated to this PR). - **Tier 1c end-to-end verification against the real Tauri shell**: drove `createRoleplayScene` through the live `pnpm tauri dev` window via Playwright over WebView2 CDP (port 9223). Seeded a chat folder + a roleplay chat in that folder via real `storage_create` invokes, called `createRoleplayScene` against the dynamically-imported engine module from the page context, then asserted the new scene chat's `folderId` matched the seeded folder id via `storage_get`. PASS. Confirms the fix line at `scene-service.ts:150` round-trips correctly through the real Rust storage layer. ## Follow-ups (deferred, not blocking this PR) - UI wiring for "create new game in current folder" — `gameApi.createGame` now accepts an optional `folderId`, but no caller passes it yet. Adding the field at the input boundary keeps the API ready without a churnful follow-up. - The audit also flagged folder-delete cascade behavior (deleted folders leave chats holding a dangling `folderId`). Needs a separate Tier 1c runtime check to confirm, will file independently if reproduced. - `useCreateChat` (the generic chat hook) does not accept `folderId` for "new chat into current folder" either. That is a deliberate design decision, not in scope here. - The agent `create_chat` slash command in `connected-commands.ts` also writes without `folderId`. Plausibly correct (the agent has no folder context), but worth a deliberate call from upstream. ## Linked issue Refs #1344 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-22 04:12:58 +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#5073
No description provided.