[PR #1407] [MERGED] Collapse slim Chat type duplicate into the engine contract #5074

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

📋 Pull Request Information

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

Base: refactor ← Head: fix/refactor-issue-1344-collapse-slim-chat-types


📝 Commits (4)

  • 950194f Collapse slim Chat type duplicate into the engine contract
  • 232c584 Merge branch 'refactor' into fix/refactor-issue-1344-collapse-slim-chat-types
  • 2967a4f Merge branch 'refactor' into fix/refactor-issue-1344-collapse-slim-chat-types
  • fda4979 Merge branch 'refactor' into fix/refactor-issue-1344-collapse-slim-chat-types

📊 Changes

3 files changed (+11 additions, -78 deletions)

View changed files

📝 src/features/catalog/chats/index.ts (+10 -1)
➖ src/features/catalog/chats/types.ts (+0 -76)
📝 src/features/modes/shared/chat-ui/hooks/use-chat-surface-data.ts (+1 -1)

📄 Description

Why this change

Issue #1344 audit (see issue comment) flagged that src/features/catalog/chats/types.ts re-declared Chat, ChatFolder, Message, MessageExtra, MessageSwipe, ChatMetadata, MessageRole, and ChatMode as a strictly slimmer copy of the canonical types in src/engine/contracts/types/chat.ts.

The slim Chat dropped personaId, promptPresetId, connectionId, connectedChatId, sortOrder, createdAt. The slim ChatFolder dropped createdAt and updatedAt. Consumers importing through the features/catalog/chats barrel were typed against the narrower shape, so an accidental spread or copy that omitted a field the engine considers canonical would not produce a TypeScript error. This is exactly the failure mode behind several of the folder-drop sites in the parity audit (PR #TBD covers the runtime fix; this PR is the type-side cleanup).

What changed

  • Deleted src/features/catalog/chats/types.ts (78 lines).
  • Rewrote src/features/catalog/chats/index.ts to re-export Chat, ChatFolder, ChatMode, ChatMetadata, Message, MessageRole, MessageExtra, MessageSwipe from ../../../engine/contracts/types/chat via export type. The other two barrel export * lines (query-keys and hooks) are unchanged.
  • Added one local widening cast at src/features/modes/shared/chat-ui/hooks/use-chat-surface-data.ts:54 so the existing runtime defensive typeof raw === "string" branch in parseChatCharacterIds survives under the narrower engine Chat.characterIds: string[] shape. SQLite serialization can hand back a JSON-stringified array, so the runtime guard is load-bearing; the cast preserves it without altering the engine contract.

Net diff: 11 insertions, 78 deletions.

Verification

  • pnpm check clean locally (architecture + tsc -b + cargo check + docs; 638 modules / 2265 deps cruised, zero boundary violations).
  • pnpm build produces the production Vite bundle clean.
  • Full vitest suite passes (173/173).
  • grep -rn 'from "./types"' src/features/catalog/chats/ returns no hits.
  • Confirmed every name the deleted slim file exported is in the new barrel — no public-API regression.
  • Pure type refactor: no runtime behavior change other than the load-bearing cast described above. No new tests required.

Follow-ups (deferred, not blocking this PR)

  • use-chat-surface-data.ts lines 162 and 235 still contain chat as unknown as { personaId?: unknown } and chat as unknown as { connectedChatId?: unknown } casts that are now provably redundant — engine Chat already exposes both as string | null. Left in place to keep the diff minimal; small cleanup PR later.
  • A unit test for parseChatCharacterIds's JSON-string fallback branch (now the only consumer of the load-bearing cast) would harden the contract. Not blocking; the SQLite serialization path that motivates the guard is not exercised by any current test.

Linked issue

Refs #1344

Summary by CodeRabbit

  • Refactor
    • Reorganized internal type definitions and improved TypeScript type handling for better code maintainability and consistency across modules.

Review Change Stack


🔄 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/1407 **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-collapse-slim-chat-types` --- ### 📝 Commits (4) - [`950194f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/950194f8f79096dd266e5e7fcafcf168df96b457) Collapse slim Chat type duplicate into the engine contract - [`232c584`](https://github.com/Pasta-Devs/Marinara-Engine/commit/232c5849094b250259f682e7cfe27d59d4ae85ab) Merge branch 'refactor' into fix/refactor-issue-1344-collapse-slim-chat-types - [`2967a4f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2967a4fdd7d4e034a17677e804389500d56578d9) Merge branch 'refactor' into fix/refactor-issue-1344-collapse-slim-chat-types - [`fda4979`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fda4979b392a261280ff4999ecbb503535022d76) Merge branch 'refactor' into fix/refactor-issue-1344-collapse-slim-chat-types ### 📊 Changes **3 files changed** (+11 additions, -78 deletions) <details> <summary>View changed files</summary> 📝 `src/features/catalog/chats/index.ts` (+10 -1) ➖ `src/features/catalog/chats/types.ts` (+0 -76) 📝 `src/features/modes/shared/chat-ui/hooks/use-chat-surface-data.ts` (+1 -1) </details> ### 📄 Description ## Why this change Issue #1344 audit (see [issue comment](https://github.com/Pasta-Devs/Marinara-Engine/issues/1344#issuecomment-4553198550)) flagged that `src/features/catalog/chats/types.ts` re-declared `Chat`, `ChatFolder`, `Message`, `MessageExtra`, `MessageSwipe`, `ChatMetadata`, `MessageRole`, and `ChatMode` as a strictly slimmer copy of the canonical types in `src/engine/contracts/types/chat.ts`. The slim Chat dropped `personaId`, `promptPresetId`, `connectionId`, `connectedChatId`, `sortOrder`, `createdAt`. The slim ChatFolder dropped `createdAt` and `updatedAt`. Consumers importing through the `features/catalog/chats` barrel were typed against the narrower shape, so an accidental spread or copy that omitted a field the engine considers canonical would not produce a TypeScript error. This is exactly the failure mode behind several of the folder-drop sites in the parity audit (PR #TBD covers the runtime fix; this PR is the type-side cleanup). ## What changed - Deleted `src/features/catalog/chats/types.ts` (78 lines). - Rewrote `src/features/catalog/chats/index.ts` to re-export `Chat`, `ChatFolder`, `ChatMode`, `ChatMetadata`, `Message`, `MessageRole`, `MessageExtra`, `MessageSwipe` from `../../../engine/contracts/types/chat` via `export type`. The other two barrel `export *` lines (query-keys and hooks) are unchanged. - Added one local widening cast at `src/features/modes/shared/chat-ui/hooks/use-chat-surface-data.ts:54` so the existing runtime defensive `typeof raw === "string"` branch in `parseChatCharacterIds` survives under the narrower engine `Chat.characterIds: string[]` shape. SQLite serialization can hand back a JSON-stringified array, so the runtime guard is load-bearing; the cast preserves it without altering the engine contract. Net diff: 11 insertions, 78 deletions. ## Verification - `pnpm check` clean locally (architecture + tsc -b + cargo check + docs; 638 modules / 2265 deps cruised, zero boundary violations). - `pnpm build` produces the production Vite bundle clean. - Full vitest suite passes (173/173). - `grep -rn 'from "./types"' src/features/catalog/chats/` returns no hits. - Confirmed every name the deleted slim file exported is in the new barrel — no public-API regression. - Pure type refactor: no runtime behavior change other than the load-bearing cast described above. No new tests required. ## Follow-ups (deferred, not blocking this PR) - `use-chat-surface-data.ts` lines 162 and 235 still contain `chat as unknown as { personaId?: unknown }` and `chat as unknown as { connectedChatId?: unknown }` casts that are now provably redundant — engine `Chat` already exposes both as `string | null`. Left in place to keep the diff minimal; small cleanup PR later. - A unit test for `parseChatCharacterIds`'s JSON-string fallback branch (now the only consumer of the load-bearing cast) would harden the contract. Not blocking; the SQLite serialization path that motivates the guard is not exercised by any current test. ## Linked issue Refs #1344 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Refactor** * Reorganized internal type definitions and improved TypeScript type handling for better code maintainability and consistency across modules. <!-- 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/Pasta-Devs/Marinara-Engine/pull/1407?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 --> --- <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:59 +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#5074
No description provided.