[PR #4857] [MERGED] fix: enforce strict Persona API server boundaries #6519

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/4857
Author: @Xelvanis
Created: 8/10/2026
Status: ✅ Merged
Merged: 8/10/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/persona-strict-decoded-boundary


📝 Commits (2)

  • 304b2de fix: enforce strict Persona API server boundaries
  • b26ab63 fix: address Persona boundary review feedback

📊 Changes

9 files changed (+1334 additions, -241 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 package.json (+2 -1)
📝 packages/server/src/routes/characters.routes.ts (+190 -128)
📝 packages/server/src/services/import/marinara.importer.ts (+110 -58)
📝 packages/server/src/services/personas/persona-projector.ts (+59 -1)
📝 packages/server/src/services/storage/characters.storage.ts (+32 -53)
📝 packages/shared/src/index.ts (+1 -0)
➕ packages/shared/src/schemas/persona.schema.ts (+304 -0)
➕ scripts/regressions/persona-api-normalization.regression.ts (+635 -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 #4646. That issue is already closed and cannot be reopened; it is listed with the repository's required issue-link syntax. This PR implements the strict server write/import/export boundary from that Persona API normalization work, while client write migration remains a separate follow-up.

Why this change

Persona fields such as tags, stats, conversation behavior, crop data, and tracker configuration are structured values at the API boundary but serialized JSON in file-backed storage. Loose request handling made validation inconsistent and could make historical Persona imports or exports fail because of one malformed recoverable field.

Direct API writes should be strict, while legacy native files and saved rows should remain recoverable. Serialization should happen once at the server/storage boundary rather than leaking storage representation into the public contract.

What changed

  • Added shared strict Persona create/update schemas for decoded structured values, with compatibility for one documented serialized legacy layer.
  • Added explicit Persona encoders so valid structured fields are serialized exactly once before storage and projected back as decoded responses.
  • Kept direct create and PATCH strict, including field-specific failures before storage mutation.
  • Made native Persona import preserve valid content while dropping or defaulting malformed or unsafe fields before final strict validation.
  • Made native and compatible exports normalize only the downloaded copy, including historical structured values, blank-name fallback, and unsafe paint removal, without mutating the saved Persona.
  • Preserved existing single/bulk download behavior and isolated the new tracker semantics to Persona routes; Character tracker behavior is unchanged.
  • Added focused Persona API regression coverage, wired the decoded-read and normalization scripts into the broad regression lane, and added a concise changelog entry.

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

Automated and focused checks completed

  • pnpm check
  • pnpm regression:persona-api (runs decoded reads followed by normalization)
  • pnpm --filter @marinara-engine/server lint
  • shared/server/client builds on the production-identical implementation state
  • tracked and untracked whitespace checks
  • client export-path base-equivalence checks
  • final four-lens Bunny review with cold verification and zero open findings
  • independent review of the final regression-scope reduction and broad-lane wiring with no actionable findings

The final checks passed after rebasing the committed PR onto freshly fetched origin/staging.

Manual verification notes

An isolated headed local-browser session covered the final reviewed source state:

  1. Created a Persona through the Personas UI, edited and saved it, reloaded, and confirmed the value persisted. The create and update requests returned 200.
  2. Imported a crafted malformed native Persona through the isolated loopback API because the browser wrapper intentionally prohibits file upload; the recovered Imported Persona appeared in the Personas panel.
  3. Exported a Persona through the UI and observed a successful 200 response.
  4. Selected one seeded historical Persona and one ordinary Persona for bulk export; the request returned 200 and the unchanged Exported 2 personas toast appeared.
  5. Inspected the isolated exported payloads and confirmed blank-name fallback, unsafe paint omission, historical RPG-pool normalization, two non-colliding ZIP entries, and no mutation of the saved historical row.
  6. Rechecked the Personas flow at 390×844. The browser reported zero console errors and no failed non-static local requests.

No client or UI files changed in this PR, so light/dark visual evidence is not applicable.

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.md includes the user-facing entry. No docs/, translated-documentation, localization, or version files are affected.

UI evidence (if applicable)

Not applicable: this is a server/shared boundary change and all client/UI paths remain unchanged. Isolated browser verification is described above.

Summary by CodeRabbit

  • Bug Fixes

    • Improved Persona reliability when creating, editing, importing, and exporting data.
    • Added clearer validation for invalid Persona details, tracker-card settings, and gallery references.
    • Improved support for clearing or resetting fields while preserving portrait metadata.
    • Added safer cleanup for invalid appearance and paint data.
  • Compatibility

    • Improved handling of legacy fields and malformed serialized values.
    • Persona exports and imports now better preserve supported settings.
    • Added fallback handling for missing or invalid Persona names.

🔄 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/4857 **Author:** [@Xelvanis](https://github.com/Xelvanis) **Created:** 8/10/2026 **Status:** ✅ Merged **Merged:** 8/10/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/persona-strict-decoded-boundary` --- ### 📝 Commits (2) - [`304b2de`](https://github.com/Pasta-Devs/Marinara-Engine/commit/304b2de55cfa99d7fa00477f39bc20fe784f7286) fix: enforce strict Persona API server boundaries - [`b26ab63`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b26ab63c1d2408a4d5381e59a00523c4ede914e4) fix: address Persona boundary review feedback ### 📊 Changes **9 files changed** (+1334 additions, -241 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `package.json` (+2 -1) 📝 `packages/server/src/routes/characters.routes.ts` (+190 -128) 📝 `packages/server/src/services/import/marinara.importer.ts` (+110 -58) 📝 `packages/server/src/services/personas/persona-projector.ts` (+59 -1) 📝 `packages/server/src/services/storage/characters.storage.ts` (+32 -53) 📝 `packages/shared/src/index.ts` (+1 -0) ➕ `packages/shared/src/schemas/persona.schema.ts` (+304 -0) ➕ `scripts/regressions/persona-api-normalization.regression.ts` (+635 -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`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #4646. That issue is already closed and cannot be reopened; it is listed with the repository's required issue-link syntax. This PR implements the strict server write/import/export boundary from that Persona API normalization work, while client write migration remains a separate follow-up. ## Why this change Persona fields such as tags, stats, conversation behavior, crop data, and tracker configuration are structured values at the API boundary but serialized JSON in file-backed storage. Loose request handling made validation inconsistent and could make historical Persona imports or exports fail because of one malformed recoverable field. Direct API writes should be strict, while legacy native files and saved rows should remain recoverable. Serialization should happen once at the server/storage boundary rather than leaking storage representation into the public contract. ## What changed - Added shared strict Persona create/update schemas for decoded structured values, with compatibility for one documented serialized legacy layer. - Added explicit Persona encoders so valid structured fields are serialized exactly once before storage and projected back as decoded responses. - Kept direct create and PATCH strict, including field-specific failures before storage mutation. - Made native Persona import preserve valid content while dropping or defaulting malformed or unsafe fields before final strict validation. - Made native and compatible exports normalize only the downloaded copy, including historical structured values, blank-name fallback, and unsafe paint removal, without mutating the saved Persona. - Preserved existing single/bulk download behavior and isolated the new tracker semantics to Persona routes; Character tracker behavior is unchanged. - Added focused Persona API regression coverage, wired the decoded-read and normalization scripts into the broad regression lane, and added a concise changelog entry. ## Validation <!-- Checkboxes intentionally remain for the human submitter to confirm. --> - [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) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Automated and focused checks completed - `pnpm check` - `pnpm regression:persona-api` (runs decoded reads followed by normalization) - `pnpm --filter @marinara-engine/server lint` - shared/server/client builds on the production-identical implementation state - tracked and untracked whitespace checks - client export-path base-equivalence checks - final four-lens Bunny review with cold verification and zero open findings - independent review of the final regression-scope reduction and broad-lane wiring with no actionable findings The final checks passed after rebasing the committed PR onto freshly fetched `origin/staging`. ### Manual verification notes An isolated headed local-browser session covered the final reviewed source state: 1. Created a Persona through the Personas UI, edited and saved it, reloaded, and confirmed the value persisted. The create and update requests returned 200. 2. Imported a crafted malformed native Persona through the isolated loopback API because the browser wrapper intentionally prohibits file upload; the recovered `Imported Persona` appeared in the Personas panel. 3. Exported a Persona through the UI and observed a successful 200 response. 4. Selected one seeded historical Persona and one ordinary Persona for bulk export; the request returned 200 and the unchanged `Exported 2 personas` toast appeared. 5. Inspected the isolated exported payloads and confirmed blank-name fallback, unsafe paint omission, historical RPG-pool normalization, two non-colliding ZIP entries, and no mutation of the saved historical row. 6. Rechecked the Personas flow at 390×844. The browser reported zero console errors and no failed non-static local requests. No client or UI files changed in this PR, so light/dark visual evidence is not applicable. ## Docs and release impact - [ ] No docs changes needed - [x] 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.md` includes the user-facing entry. No `docs/`, translated-documentation, localization, or version files are affected. ## UI evidence (if applicable) Not applicable: this is a server/shared boundary change and all client/UI paths remain unchanged. Isolated browser verification is described above. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Bug Fixes** - Improved Persona reliability when creating, editing, importing, and exporting data. - Added clearer validation for invalid Persona details, tracker-card settings, and gallery references. - Improved support for clearing or resetting fields while preserving portrait metadata. - Added safer cleanup for invalid appearance and paint data. - **Compatibility** - Improved handling of legacy fields and malformed serialized values. - Persona exports and imports now better preserve supported settings. - Added fallback handling for missing or invalid Persona names. <!-- 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:11:11 +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#6519
No description provided.