[PR #731] [MERGED] test(file-storage): cover post-heal .bak refresh + tidy adjacent comments #4751

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

📋 Pull Request Information

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

Base: main ← Head: improve/file-native-self-heal-followup


📝 Commits (1)

  • 56b82d8 test(file-storage): cover post-heal .bak refresh + tidy adjacent comments

📊 Changes

2 files changed (+57 additions, -5 deletions)

View changed files

📝 packages/server/src/db/file-backed-store.ts (+10 -5)
📝 packages/server/test/file-backed-store.test.ts (+47 -0)

📄 Description

Linked issue

Follows up on #728 / #730 — small regression test plus comment polish on top of @NeoKazuya's fix. No separate issue.

Why this change

  • #730 proves the recovery .bak survives the heal write. The other half of the contract — that a subsequent ordinary save refreshes .bak from the now-healed primary (i.e. backupRecoveredPaths.clear() actually runs) — isn't pinned by a test. A future refactor that forgot to clear the set would leave all four existing tests green while real users had permanently frozen backups.
  • After #730, the comment block above atomicWriteFile's skip-refresh if has two skip conditions sandwiching the durability rationale. Reads cleaner with the two skip-reasons broken out as numbered siblings.
  • After #730, the recovered-from-backup comment in loadFileSnapshots still describes only the primary-rewrite half. Mentioning .bak preservation makes the mental model match what the new tracking actually does.

What changed

  • Add file-native subsequent save after self-heal refreshes .bak from the healed primary test — wrecks .bak with [] after the first heal, performs an ordinary insert + close, asserts .bak was refreshed to the pre-save healed primary's state. Pins the clear() half of #730's contract.
  • Restructure the atomicWriteFile skip-refresh comment so the two skip conditions (caller-driven, NUL-corrupted) read as numbered siblings rather than bracketing the refresh rationale.
  • Update the loadFileSnapshots recovery comment to mention the .bak preservation effect of the new tracking.

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

  • Manually verify pnpm --dir packages/server exec tsx --import ./test/setup-env.ts --test test/file-backed-store.test.ts passes — the new test should appear alongside the existing four corruption-recovery cases (total 10/10 pass expected).
  • Manually verify the deployed image still loads existing file-native storage on boot (existing chats/personas/characters appear after a container restart).
  • Manually verify a CRUD round-trip: create + read + delete a persona, confirm the on-disk personas.json and personas.json.bak both remain valid JSON after each save cycle.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Version/release files updated (only if this PR includes a version bump)

UI evidence (if applicable)

N/A — server-side test + comment changes only.

Summary by CodeRabbit

  • Documentation

    • Improved internal documentation for data backup and recovery mechanisms.
  • Tests

    • Enhanced test coverage for backup file integrity after data recovery operations.

Note: This release contains internal improvements to code reliability and maintainability with no user-facing changes.

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/731 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 5/12/2026 **Status:** ✅ Merged **Merged:** 5/12/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `main` ← **Head:** `improve/file-native-self-heal-followup` --- ### 📝 Commits (1) - [`56b82d8`](https://github.com/Pasta-Devs/Marinara-Engine/commit/56b82d848a901f3000ea41783724471c84616fb3) test(file-storage): cover post-heal .bak refresh + tidy adjacent comments ### 📊 Changes **2 files changed** (+57 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/db/file-backed-store.ts` (+10 -5) 📝 `packages/server/test/file-backed-store.test.ts` (+47 -0) </details> ### 📄 Description ## Linked issue Follows up on #728 / #730 — small regression test plus comment polish on top of @NeoKazuya's fix. No separate issue. ## Why this change - #730 proves the recovery `.bak` survives the heal write. The other half of the contract — that a subsequent ordinary save refreshes `.bak` from the now-healed primary (i.e. `backupRecoveredPaths.clear()` actually runs) — isn't pinned by a test. A future refactor that forgot to clear the set would leave all four existing tests green while real users had permanently frozen backups. - After #730, the comment block above `atomicWriteFile`'s skip-refresh `if` has two skip conditions sandwiching the durability rationale. Reads cleaner with the two skip-reasons broken out as numbered siblings. - After #730, the recovered-from-backup comment in `loadFileSnapshots` still describes only the primary-rewrite half. Mentioning `.bak` preservation makes the mental model match what the new tracking actually does. ## What changed - Add `file-native subsequent save after self-heal refreshes .bak from the healed primary` test — wrecks `.bak` with `[]` after the first heal, performs an ordinary insert + close, asserts `.bak` was refreshed to the pre-save healed primary's state. Pins the `clear()` half of #730's contract. - Restructure the `atomicWriteFile` skip-refresh comment so the two skip conditions (caller-driven, NUL-corrupted) read as numbered siblings rather than bracketing the refresh rationale. - Update the `loadFileSnapshots` recovery comment to mention the `.bak` preservation effect of the new tracking. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] 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` ### Manual verification notes - Manually verify `pnpm --dir packages/server exec tsx --import ./test/setup-env.ts --test test/file-backed-store.test.ts` passes — the new test should appear alongside the existing four corruption-recovery cases (total 10/10 pass expected). - Manually verify the deployed image still loads existing file-native storage on boot (existing chats/personas/characters appear after a container restart). - Manually verify a CRUD round-trip: create + read + delete a persona, confirm the on-disk `personas.json` and `personas.json.bak` both remain valid JSON after each save cycle. ## Docs and release impact - [x] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Version/release files updated (only if this PR includes a version bump) ## UI evidence (if applicable) N/A — server-side test + comment changes only. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Improved internal documentation for data backup and recovery mechanisms. * **Tests** * Enhanced test coverage for backup file integrity after data recovery operations. --- **Note:** This release contains internal improvements to code reliability and maintainability with no user-facing changes. [![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/731) <!-- 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:10:21 +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#4751
No description provided.