fix: carry the budget in SREF backups (format 3) and keep it on restore (#520) #533

Merged
maximus merged 4 commits from issue-520-restore-budget-sref3 into main 2026-11-07 18:59:04 +00:00
Owner

Resolves #520

Generated autonomously by /autopilot run of 2026-11-04

Position in the stack

Link 3 of 3 of the milestone planned-2026-11-04-restauration-sauvegarde: #518 (PR #531, base main) → #521 (PR #532, base issue-518-restore-split-ids) → #520 (this PR, base issue-521-restore-fk-failures, the head of PR #532, eafd67d). Strictly linear; the stack merges as a block (Max's decision of 2026-10-29). Nothing is merged yet: the diff of this PR is against PR #532's branch.

Summary

A restore with categories (« Transactions avec catégories », « Catégories uniquement », and « Rétablir la sauvegarde » of the categories migration) ran DELETE FROM categories; budget_entries, budget_template_entries and adjustment_entries name a category ON DELETE CASCADE, and the backup held none of them: the restore succeeded and left the budget, the template lines and the adjustment lines empty, without a word (the probe of the issue: 1, 1, 1 → 0, 0, 0). Option A of the issue, chosen by Max: SREF format 3 carries the budget, and it comes back.

  • Export (collectExportData(mode), dataExportService.ts): the two modes that carry the categories, and the backup taken before the categories migration, add budget_entries (by category, year and month), budget_templates (by name, with their lines) and adjustments (with their lines). « Transactions uniquement » and the CSV do not change. One function now gathers the arrays of each mode, for « Exporter » (useDataExport) and for createPreMigrationBackup.
  • Restore (dataRestoreService.ts), in the transaction of runRestore, through its handle: takeBudget reads then removes the three line tables before DELETE FROM categories, in both formats. Once the categories are in, restoreBudget puts, at format 3, the file's budget lines and adjustments in place of the profile's, upserts each file template by name (ON CONFLICT(name) DO UPDATE) with the file's lines, and gives a template absent from the file back its lines whose category returns; below format 3 (every backup written so far, pre-migration ones included) it puts back, as they were, the profile's lines whose category returns, on the category id alone (the accepted limit of ADR 0025).
  • The format is given, never guessed: importTransactionsWithCategories(data, filename, formatVersion) and importCategoriesOnly(data, formatVersion); useDataImport passes state.summary.formatVersion, applyBackup passes envelope.format_version ?? LEGACY_SREF_FORMAT_VERSION.
  • Refusals before anything is deleted (pure, at the parse and at the head of the two restores): a format newer than this build (text 10, checked right after the envelope's required fields, before its mode); a format_version that is not an integer of at least 1 (the existing « Invalid export file format » error); at format 3, a missing array or a line the tables cannot hold (text 9: Number.isFinite(amount), year integer 1900–2200, month integer 1–12, category present in the file, no duplicate (category_id, year, month), (template, category_id) or template name, text name and date).
  • restoreCategories writes i18n_key: the standard categories came back under their French name in the English interface.
  • Confirmations: willDeleteCategories and willDeleteAll name the budget (texts 1 and 2); the card counts the budget lines, templates and adjustments of a format-3 file (text 3); a file older than format 3 gets the note of text 4, in the card and in the second confirmation of « Rétablir la sauvegarde » (created by #521); the confirmation of « Réinitialiser » names what it erases (text 11).

Commits

  1. 09c7b32 fix: format 3, the restore, the validations, the windows, the i18n keys, and the tests (regression test red on the base, below).
  2. b45616f test: a test of the export hook (useDataExport.test.ts, new) and a recurring adjustment with a recurrence rule in the test budget, so that the mutations below have a test that sees them.
  3. 0225705 docs: ADR 0025 for the stack and its pointer from ADR 0010's amendment, docs/architecture.md, guide and in-app docs (tip appended at index 9), CHANGELOG FR/EN.
  4. Last commit: the STATE.md line of the stack (it carries the closing keyword).

Texts

Texts 1 to 4 and 9 to 11 verbatim from « Textes arrêtés » (answer of Max of 2026-11-04), checked byte for byte against the live issue body by a script (10 keys, 0 difference; text 3 is three keys, one segment each, in the order the body names them):

  • Text 1, settings.dataManagement.import.willDeleteCategories: « Toutes les catégories, fournisseurs et mots-clés, ainsi que le budget, les modèles de budget et les ajustements » / "All categories, suppliers, and keywords, along with the budget, budget templates, and adjustments"
  • Text 2, …import.willDeleteAll: « Toutes les transactions, catégories, fournisseurs, mots-clés et l'historique d'import, ainsi que le budget, les modèles de budget et les ajustements » / "All transactions, categories, suppliers, keywords, and import history, along with the budget, budget templates, and adjustments"
  • Text 3, …import.countBudgetEntries, countBudgetTemplates, countAdjustments: « {{count}} ligne(s) de budget », « {{count}} modèle(s) de budget », « {{count}} ajustement(s) » / "{{count}} budget line(s)", "{{count}} budget template(s)", "{{count}} adjustment(s)"
  • Text 4, …import.legacyBudgetNote and settings.categoriesCard.restoreModal.legacyBudgetNote: « Cette sauvegarde date d'avant l'ajout du budget aux sauvegardes : elle ne contient ni budget, ni modèles de budget, ni ajustements. Les lignes actuelles dont la catégorie revient seront gardées, les autres supprimées. » / "This backup predates budgets in backups: it holds no budget, budget templates, or adjustments. Current lines whose category comes back are kept; the others are deleted."
  • Text 9, …import.errors.invalidBudgetRows: « Ce fichier ne peut pas être importé : des lignes de budget, de modèle de budget ou d'ajustement sont invalides ou visent une catégorie absente du fichier. Rien n'a été modifié. » / "This file cannot be imported: some budget, budget template, or adjustment lines are invalid or refer to a category missing from the file. Nothing has been modified."
  • Text 10, …import.errors.newerFormat: « Ce fichier vient d'une version plus récente de Simpl'Résultat. Mettez l'application à jour pour l'importer. Rien n'a été modifié. » / "This file comes from a newer version of Simpl'Résultat. Update the app to import it. Nothing has been modified."
  • Text 11, categories.reinitializeConfirm: « Réinitialiser toutes les catégories et mots-clés à leurs valeurs par défaut ? Les catégories des transactions seront dissociées, et le budget, les modèles de budget et les ajustements seront effacés. Cette action est irréversible. » / "Reset all categories and keywords to their default values? Transaction categories will be unlinked, and the budget, budget templates, and adjustments will be erased. This cannot be undone."

Not verbatim (MEDIUM, decisions comment): the CHANGELOG entries, the guide (Import tip of :226, Settings feature of :592, a new tip) and their in-app mirrors (docs.import.tips[8], docs.settings.features[5], docs.settings.tips[9]).

Files

  • src/services/dataExportService.ts, src/services/dataRestoreService.ts, src/services/categoryRestoreService.ts, src/services/categoryBackupService.ts, src/hooks/useDataExport.ts, src/hooks/useDataImport.ts, src/components/settings/ImportConfirmModal.tsx, src/components/settings/CategoriesMigrationRestoreModal.tsx
  • src/i18n/locales/fr.json, src/i18n/locales/en.json (texts 1 to 4 and 9 to 11, docs.*)
  • Tests: src/__integration__/restore.test.ts (+29 cases, 54 → 83, the real categories migration among them), src/services/dataExportService.test.ts (FakeDb gains the five budget tables; collectExportData per mode, the format check, each validation bound, the order of the deletes), src/hooks/useDataExport.test.ts (new), src/hooks/useDataImport.test.ts, src/services/categoryRestoreService.test.ts, src/services/categoryBackupService.test.ts, src/services/categoryService.test.ts (text 11), src/components/settings/ImportConfirmModal.render.test.tsx, src/components/settings/CategoriesMigrationRestoreModal.wiring.test.ts, src/__integration__/category-migration.test.ts (getter mocks removed), src/__integration__/regression-v2-v1.test.ts (fixtures at format 3)
  • Docs: docs/adr/0025-contenu-restauration-sauvegarde-sref.md (new), docs/adr/0010-fk-restrict-balance-transfers.md, docs/architecture.md, docs/guide-utilisateur.md, CHANGELOG.md, CHANGELOG.fr.md, STATE.md (one line)
  • src-tauri/ untouched: the version byte of the encrypted container (export_import_commands.rs, 0x01) is independent of the envelope's format_version, which only the front reads.

Decisions (tiers)

The comment « Décisions prises sans Max (autopilot) » on this PR gives each one in full.

  • MEDIUM: (1) a malformed format_version gets the existing message as is (Invalid export file format — missing required fields); (2) the validation also refuses a template name, an adjustment name or date that is not a text, and entries that is not an array (NOT NULL columns; review caveat « types validés »); (3) public texts the issue does not give verbatim (CHANGELOG, guide, in-app docs).
  • HIGH: the planning contract as written; text 3 as three keys; envelope shapes without ids or timestamps; takeBudget reads then deletes (pattern of takeTransfers), so the restore no longer depends on the cascade; format-2 lines put back as they were (ids and dates); templates of the file upserted by name, description included; newerFormat before the mode; integer year and month; budget validated at the parse for the two modes with categories only; layout of texts 3 and 4; tests in restore.test.ts with the real migration; ADR 0025 for the stack; tip appended at index 9; src-tauri/ untouched; level normal.

Proofs

Regression test red on the base (520-red-on-base.log in the run folder, from a detached worktree of origin/issue-521-restore-fk-failures, eafd67d, removed after use):

  • A throwaway probe with the base API, the probe of the issue (a budget line on 1111, a template and its line, an adjustment and its line, exported as the base « Exporter » did): 5 of 5 red — importTransactionsWithCategories and importCategoriesOnly in the same profile and « Rétablir la sauvegarde » (readBackup + applyBackup): expected [ +0, +0, +0 ] to deeply equal [ 1, 1, 1 ] (the headers stay, [1, 1]); the categories of the seed: expected +0 to be 150 (i18n_key lost); a file of format 4: accepted.
  • The new restore.test.ts of this branch copied onto the base: 79 of 83 red. 77 fail on collectExportData is not a function (the shared export this PR adds, which every backup of the file goes through); the 2 cases that only need the base API fail on their assertions: after the real categories migration, « Rétablir la sauvegarde » of the format-3 backup gives entries: [] instead of the budget of the former state; with a format-2 backup, the adjustment lines are deleted instead of kept. With the fix: 83/83 green.

Mutations (implementation committed first, 09c7b32 + b45616f; one at a time, restored by git checkout -- <file>, git status --short empty after each; 13 test files run each time, baseline 416/416 green). The five of the body are M1 (arrays removed from the export), M2a/M2b/M2c (lines of the format-3 file not reinserted, per table), M3 (format-2 fallback removed), M4 (i18n_key removed from the INSERT) and M5 (validation removed from the parse); the others cover each rule added: the fallback part by part (M3a–M3e), the format-3 file replacing the profile's lines (M7a–M7e), the format checks (M9a–M9g), format 3 without one of its arrays (M10, M10a–M10d), each validation bound (M11a–M11s), templates by name (M8a–M8f), the taking out before DELETE FROM categories (M6a–M6g), the arrays of each mode (M12a–M12f), the format passed to the restores (M13a, M13b), the legacy note and the counts in both windows (M14a–M14d, M15a, M15b), and the texts (M16a–M16e, text 11 among them). 80 mutations, no survivor.

# File Mutation Failing rc Failing tests (the first; all in 520-mutations.json of the run folder)
M1 dataExportService.ts budget arrays removed from the export (collectExportData) 60 1 category-migration.test.ts: integration: plan → backup → migrate (happy path) > produces a plan, verifies backup round-trip, then applies migration atomically
(+59 more)
M2a dataRestoreService.ts format 3: the file's budget lines not inserted 8 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were
(+7 more)
M2b dataRestoreService.ts format 3: the file's adjustments not inserted 8 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were
(+7 more)
M2c dataRestoreService.ts format 3: the lines of the file's templates not inserted 10 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were
(+9 more)
M3 dataRestoreService.ts format-2 fallback removed (no line taken out comes back) 6 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories: a template of the file is updated by its name, its lines replaced; a template absent from the file keeps its header and its lines whose category comes back
(+5 more)
M4 dataRestoreService.ts i18n_key no longer written by restoreCategories 5 1 restore.test.ts: a restore with categories keeps the translation key of each category (#520) > transactions_with_categories, same profile: every category comes back with its i18n_key
(+4 more)
M5 dataExportService.ts budget validation removed from parseImportedJson 9 1 restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > transactions_with_categories: a budget line that names a category missing from the file is refused at the parse and at the head of the restore
(+8 more)
M3a dataRestoreService.ts format 2: budget lines taken out never come back 3 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, a backup of the previous version (format 2): the lines whose category comes back are kept as they were, the others go
(+2 more)
M3b dataRestoreService.ts template lines taken out never come back 5 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories: a template of the file is updated by its name, its lines replaced; a template absent from the file keeps its header and its lines whose category comes back
(+4 more)
M3c dataRestoreService.ts format 2: adjustment lines taken out never come back 4 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, a backup of the previous version (format 2): the lines whose category comes back are kept as they were, the others go
(+3 more)
M3d dataRestoreService.ts format 2: every line taken out comes back, its category gone or not 3 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, a backup of the previous version (format 2): the lines whose category comes back are kept as they were, the others go
(+2 more)
M3e dataRestoreService.ts format 2: a budget line put back under a new id and new dates 3 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, a backup of the previous version (format 2): the lines whose category comes back are kept as they were, the others go
(+2 more)
M6a dataRestoreService.ts takeBudget reads nothing (the lines read after the cascade) 6 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories: a template of the file is updated by its name, its lines replaced; a template absent from the file keeps its header and its lines whose category comes back
(+5 more)
M6b dataRestoreService.ts takeBudget no longer deletes the budget lines 2 1 dataExportService.test.ts: a restore takes the budget out before it deletes the categories (#520) > transactions with categories: the budget lines, template lines and adjustment lines go before the categories
(+1 more)
M6c dataRestoreService.ts takeBudget no longer deletes the template lines 2 1 dataExportService.test.ts: a restore takes the budget out before it deletes the categories (#520) > transactions with categories: the budget lines, template lines and adjustment lines go before the categories
(+1 more)
M6d dataRestoreService.ts takeBudget no longer deletes the adjustment lines 2 1 dataExportService.test.ts: a restore takes the budget out before it deletes the categories (#520) > transactions with categories: the budget lines, template lines and adjustment lines go before the categories
(+1 more)
M6e dataRestoreService.ts categories only: the budget not taken out (no takeBudget, nothing put back) 3 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > categories_only: a template of the file is updated by its name, its lines replaced; a template absent from the file keeps its header and its lines whose category comes back
(+2 more)
M6f dataRestoreService.ts with categories: the budget not put back (restoreBudget not called) 9 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were
(+8 more)
M6g dataRestoreService.ts categories only: the budget not put back (restoreBudget not called) 5 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > categories_only, same profile: the budget lines, the templates and the adjustments come back as they were
(+4 more)
M7a dataRestoreService.ts format 3: the profile's adjustments kept beside the file's 6 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were
(+5 more)
M7b dataRestoreService.ts format 3: the file's budget lines lose their notes 8 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were
(+7 more)
M7c dataRestoreService.ts format 3: an adjustment loses its recurrence 8 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were
(+7 more)
M7d dataRestoreService.ts format 3: an adjustment loses its recurrence rule 8 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were
(+7 more)
M7e dataRestoreService.ts format 3: an adjustment line loses its description 8 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were
(+7 more)
M8a dataRestoreService.ts a template of the file inserted without ON CONFLICT (plain INSERT) 8 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were
(+7 more)
M8b dataRestoreService.ts a template of the file keeps the profile's description 2 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories: a template of the file is updated by its name, its lines replaced; a template absent from the file keeps its header and its lines whose category comes back
(+1 more)
M8c dataRestoreService.ts a new template of the file loses its description 10 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were
(+9 more)
M8d dataRestoreService.ts format 3: the lines of a template absent from the file are lost 2 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories: a template of the file is updated by its name, its lines replaced; a template absent from the file keeps its header and its lines whose category comes back
(+1 more)
M8e dataRestoreService.ts format 3: the profile's lines of a template of the file come back beside the file's 7 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were
(+6 more)
M8f dataRestoreService.ts a line of a template absent from the file comes back without its category 5 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories: a template of the file is updated by its name, its lines replaced; a template absent from the file keeps its header and its lines whose category comes back
(+4 more)
M9a dataExportService.ts format check removed from parseImportedJson 3 1 restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > a file of a newer version (format 4) is refused in the card and in « Rétablir la sauvegarde », and nothing is deleted
(+2 more)
M9b dataExportService.ts a newer format accepted (text 10 removed from the validator) 5 1 restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > a file of a newer version (format 4) is refused in the card and in « Rétablir la sauvegarde », and nothing is deleted
(+4 more)
M9c dataRestoreService.ts format check removed from the head of importTransactionsWithCategories 2 1 restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > a file of a newer version (format 4) is refused in the card and in « Rétablir la sauvegarde », and nothing is deleted
(+1 more)
M9d dataRestoreService.ts format check removed from the head of importCategoriesOnly 2 1 restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > a file of a newer version (format 4) is refused in the card and in « Rétablir la sauvegarde », and nothing is deleted
(+1 more)
M9e dataExportService.ts a format_version that is not an integer accepted 4 1 dataExportService.test.ts: the format of a file is checked before anything is deleted (#520) > refuses a format_version of 2.5 as a malformed file
(+3 more)
M9f dataExportService.ts format 0 accepted (lower bound 1 -> 0) 3 1 dataExportService.test.ts: the format of a file is checked before anything is deleted (#520) > refuses a format_version of 0 as a malformed file
(+2 more)
M9g dataExportService.ts the newer format checked after the mode (a newer mode named first) 1 1 dataExportService.test.ts: the format of a file is checked before anything is deleted (#520) > refuses a newer file at PARSE time, before its mode is even read
M10 dataExportService.ts format 3: a missing array read as empty (all three) 10 1 restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > transactions_with_categories, a file of format 3 that lacks one of its three arrays > without budget_entries: refused at the parse and at the head of the restore, the budget never emptied
(+9 more)
M10a dataExportService.ts format 3: a missing budget_entries read as empty 4 1 restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > transactions_with_categories, a file of format 3 that lacks one of its three arrays > without budget_entries: refused at the parse and at the head of the restore, the budget never emptied
(+3 more)
M10b dataExportService.ts format 3: a missing budget_templates read as empty 3 1 restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > transactions_with_categories, a file of format 3 that lacks one of its three arrays > without budget_templates: refused at the parse and at the head of the restore, the budget never emptied
(+2 more)
M10c dataExportService.ts format 3: a missing adjustments read as empty 3 1 restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > transactions_with_categories, a file of format 3 that lacks one of its three arrays > without adjustments: refused at the parse and at the head of the restore, the budget never emptied
(+2 more)
M10d dataExportService.ts the budget checked below format 3 too 14 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, a backup of the previous version (format 2): the lines whose category comes back are kept as they were, the others go
(+13 more)
M11a dataExportService.ts a line on a category missing from the file accepted 8 1 restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > transactions_with_categories: a budget line that names a category missing from the file is refused at the parse and at the head of the restore
(+7 more)
M11b dataExportService.ts a non-finite amount accepted (typeof number) 4 1 dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with a budget amount that is not finite
(+3 more)
M11c dataExportService.ts any amount accepted 5 1 dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with a budget amount that is not a number
(+4 more)
M11d dataExportService.ts year lower bound 1900 -> 1899 1 1 dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with a year before 1900
M11e dataExportService.ts year upper bound 2200 -> 2201 1 1 dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with a year after 2200
M11f dataExportService.ts a year that is not an integer accepted 1 1 dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with a year that is not an integer
M11g dataExportService.ts month lower bound 1 -> 0 1 1 dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with month 0
M11h dataExportService.ts month upper bound 12 -> 13 2 1 dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with month 13
(+1 more)
M11i dataExportService.ts a month that is not an integer accepted 1 1 dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with a month that is not an integer
M11j dataExportService.ts two budget lines on the same category and month accepted 1 1 dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with two budget lines on the same category and month
M11k dataExportService.ts two templates of the same name accepted 1 1 dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with two templates of the same name
M11l dataExportService.ts a template without a text name accepted 1 1 dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with a template without a name
M11m dataExportService.ts two lines of a template on the same category accepted 1 1 dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with two lines of a template on the same category
M11n dataExportService.ts the lines of a template no longer checked 2 1 dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with a template line on a category missing from the file
(+1 more)
M11o dataExportService.ts an adjustment without a text name or date accepted 2 1 dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with an adjustment without a name
(+1 more)
M11p dataExportService.ts the lines of an adjustment no longer checked 2 1 dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with an adjustment line on a category missing from the file
(+1 more)
M11q dataExportService.ts the budget validator removed from both restores' parse and heads (validateImportedBudget a no-op) 38 1 restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > transactions_with_categories: a budget line that names a category missing from the file is refused at the parse and at the head of the restore
(+37 more)
M11r dataRestoreService.ts budget validation removed from the head of importTransactionsWithCategories 5 1 restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > transactions_with_categories: a budget line that names a category missing from the file is refused at the parse and at the head of the restore
(+4 more)
M11s dataRestoreService.ts budget validation removed from the head of importCategoriesOnly 5 1 restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > categories_only: a budget line that names a category missing from the file is refused at the parse and at the head of the restore
(+4 more)
M12a dataExportService.ts the budget carried by « Transactions uniquement » too 2 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > witness: « Transactions uniquement » carries no budget and leaves the profile's as it is
(+1 more)
M12b dataExportService.ts the import configurations carried by « Catégories uniquement » too 1 1 dataExportService.test.ts: collectExportData gathers the arrays of each mode (#520) > categories_only carries ["categories","suppliers","keywords","budget_entries","budget_templates","adjustments"]
M12c categoryBackupService.ts the pre-migration backup gathers another mode 7 1 category-migration.test.ts: integration: plan → backup → migrate (happy path) > produces a plan, verifies backup round-trip, then applies migration atomically
(+6 more)
M12d useDataExport.ts « Exporter » no longer writes what collectExportData gathered (its budget dropped) 2 1 useDataExport.test.ts: useDataExport writes what collectExportData gathers for the mode (#520) > transactions_with_categories: the JSON carries the arrays of its mode, at the format of this build
(+1 more)
M12e dataExportService.ts a template exported without its lines 11 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were
(+10 more)
M12f dataExportService.ts an adjustment exported without its lines 9 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were
(+8 more)
M13a useDataImport.ts useDataImport passes this build's format, not the file's 2 1 useDataImport.test.ts: useDataImport — the outcome of the restore reaches the success state (#521) > transactions_with_categories, a backup of the previous version: the restore is given the format the file declares (NaN) (#520)
(+1 more)
M13b categoryRestoreService.ts applyBackup passes this build's format, not the file's 4 1 restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > « Rétablir la sauvegarde » of a backup of the previous version: the lines whose category comes back are kept
(+3 more)
M14a ImportConfirmModal.tsx the budget counts no longer listed (text 3) 2 1 ImportConfirmModal.render.test.tsx: ImportConfirmModal — the budget, its templates and the adjustments (#520) > categories_only, format 3: counts the budget lines, templates and adjustments the file brings back, no note
(+1 more)
M14b ImportConfirmModal.tsx the note of a file older than format 3 never shown (text 4) 3 1 ImportConfirmModal.render.test.tsx: ImportConfirmModal — the budget, its templates and the adjustments (#520) > categories_only, format 2: the note says the file holds no budget, next to the warning, and nothing is counted
(+2 more)
M14c ImportConfirmModal.tsx the note shown at every format 3 1 ImportConfirmModal.render.test.tsx: ImportConfirmModal — the budget, its templates and the adjustments (#520) > categories_only, format 3: counts the budget lines, templates and adjustments the file brings back, no note
(+2 more)
M14d ImportConfirmModal.tsx « Transactions uniquement » takes the budget note and counts too 1 1 ImportConfirmModal.render.test.tsx: ImportConfirmModal — the budget, its templates and the adjustments (#520) > « Transactions uniquement » leaves the budget alone: neither count nor note, whatever the format
M15a CategoriesMigrationRestoreModal.tsx the note of a backup older than format 3 never shown 2 1 CategoriesMigrationRestoreModal.wiring.test.ts: CategoriesMigrationRestoreModal — a second confirmation, then « Sauvegarde rétablie » (#521) > a backup of format 2: the second confirmation says it holds no budget (#520)
(+1 more)
M15b CategoriesMigrationRestoreModal.tsx the note shown at every format 1 1 CategoriesMigrationRestoreModal.wiring.test.ts: CategoriesMigrationRestoreModal — a second confirmation, then « Sauvegarde rétablie » (#521) > a backup of format 3 carries its budget: no note (#520)
M16a fr.json text 11 FR reverted to the former text 1 1 categoryService.test.ts: « Réinitialiser » says what it erases (#520) > names the budget, the budget templates and the adjustments, in French and in English
M16b en.json text 11 EN reverted to the former text 1 1 categoryService.test.ts: « Réinitialiser » says what it erases (#520) > names the budget, the budget templates and the adjustments, in French and in English
M16c fr.json text 1 FR reverted to the former text 1 1 dataExportService.test.ts: the texts of a restore with the budget exist in both languages (#520) > the confirmation names the budget, the budget templates and the adjustments among what is deleted
M16d en.json text 2 EN reverted to the former text 1 1 dataExportService.test.ts: the texts of a restore with the budget exist in both languages (#520) > the confirmation names the budget, the budget templates and the adjustments among what is deleted
M16e en.json text 9 removed from EN (key in one language only) 2 1 locales.keys.test.ts: locale keys: fr.json and en.json (#453) > en.json declares every key of fr.json
(+1 more)

M6b, M6c and M6d (one delete of takeBudget removed) are caught by the FakeDb test of the order of the deletes only: under real foreign keys the cascade of DELETE FROM categories removes the same rows, so the explicit deletes are what keeps the restore independent of the cascade.

Counts. vitest before (base eafd67d): 182 files / 3043 tests; after: 183 files / 3154 tests, all green; npm run build green. Probe: sonde rc=1 (src/zz_tmp_probe.test.ts, deleted).

Level

Normal, computed on REVIEW.md of main (bf4eae7), file by file, in the self-review comment: no Haut row designates a touched file. src/services/dataExportService.ts is « au moins normal » (line 50); dataRestoreService.ts and the other source files are designated by no Haut row, and the « code livré » row is not met (no network call, no URL, no consent touched; read_import_file, write_export_file and pick_save_file are local commands already called); no file added at the root or under src-tauri/; docs/adr/**, docs/architecture.md normal (line 53). No line of « Niveaux » is touched, and no fact of REVIEW.md becomes false (line 109: one transaction, notification after the COMMIT; line 118: the encryption).

Vérifications manuelles dues (prochaine release)

Base edition (Budget and Ajustements are Base: src/shared/entitlements.ts), in French, then the same in English (EN labels: Settings → Data → Data Management, « Transactions with categories », « Categories only », « Restore the backup », « Migrate to the standard structure », « Re-initialize »). Preparation: a profile with a budget (a few amounts on the Budget page), a budget template saved from it, and an adjustment with two lines on the Adjustments page.

  1. Paramètres → Données → Gestion des données → Exporter « Transactions avec catégories » (JSON), then « Catégories uniquement » (JSON). Importer each file into the same profile: the confirmation lists « Toutes les catégories, fournisseurs et mots-clés, ainsi que le budget, les modèles de budget et les ajustements » (or the « Toutes les transactions… » variant) among what is deleted, and « N ligne(s) de budget · N modèle(s) de budget · N ajustement(s) » among what is imported, without the note of an old backup. Expected after « Remplacer les données »: the Budget page shows the same amounts, the template is there with its lines, the Adjustments page shows the adjustment and its two lines.
  2. In a new profile (Paramètres → Utilisateurs), import the two files of step 1. Expected: the same budget, template and adjustment.
  3. After an export, change an amount of the budget and add an adjustment, then import the export. Expected: the budget and the adjustments of the file, the added adjustment gone. Create a budget template after the export, then import it again: that template stays, with its lines.
  4. On a profile still on the former categories (or after « Réinitialiser », which puts them back), with a budget, a template and an adjustment: Paramètres → Données → Catégories → « Migrer vers la structure standard », then « Rétablir la sauvegarde » (banner or « Rétablir une sauvegarde »). Expected: the second confirmation shows no note about the budget; after « Rétablir », the budget, the template and the adjustment of the former categories, as they were before the migration.
  5. A backup of the previous version (format 2): a JSON exported by v0.17.2, or a JSON of step 1 edited in a text editor ("format_version": 2, the arrays budget_entries, budget_templates and adjustments deleted). Import it into a profile with a budget. Expected: the confirmation shows « Cette sauvegarde date d'avant l'ajout du budget aux sauvegardes : elle ne contient ni budget, ni modèles de budget, ni ajustements. Les lignes actuelles dont la catégorie revient seront gardées, les autres supprimées. » and no budget count; after the import, the budget lines whose category is in the file are still there. Through « Rétablir la sauvegarde » with a pre-migration backup written by v0.17.2: the same note in the second confirmation.
  6. A file of a newer version: a JSON of step 1 edited ("format_version": 4). Import it. Expected: refused at once with « Ce fichier vient d'une version plus récente de Simpl'Résultat. Mettez l'application à jour pour l'importer. Rien n'a été modifié. » (EN: "This file comes from a newer version of Simpl'Résultat. Update the app to import it. Nothing has been modified."), the confirmation never opens, the profile is unchanged. Same file through « Rétablir la sauvegarde »: move the recorded pre-migration backup out of its folder so that the window offers « Choisir un fichier de sauvegarde », pick the edited file: the same message in the window, nothing replaced (put the backup back afterwards).
  7. Catégories → « Réinitialiser »: the confirmation reads « Réinitialiser toutes les catégories et mots-clés à leurs valeurs par défaut ? Les catégories des transactions seront dissociées, et le budget, les modèles de budget et les ajustements seront effacés. Cette action est irréversible. » (EN: "Reset all categories and keywords to their default values? Transaction categories will be unlinked, and the budget, budget templates, and adjustments will be erased. This cannot be undone."). Cancel.
  8. Interface in English, on a profile on the standard categories: export « Transactions with categories », import it. Expected: the categories of the Categories page, the Budget page and the category menus show their English names.

Hors périmètre

  • From the issue: the migration already deletes the budget lines that collide on one standard category (wanted by its preview and consent); no computation reads adjustment_entries outside adjustmentService.ts; « Réinitialiser » puts the v2 seed back even on a standard profile; the Bilan, the preferences, source_id / supplier_id and the import history are not in the backup.
  • Seen, not fixed: the categories migration rewrites the budget lines and the template lines onto the standard categories but leaves the adjustment lines on the former ones, which it deactivates (the test « Rétablir la sauvegarde » after the categories migration shows it: from a format-2 backup they come back). No issue opened.
  • An earlier version (v0.17.2 and before) has no refusal of newer formats: it restores a format-3 file without its three arrays, and its cascade empties the budget as before (ADR 0025, negatives).

For the reviewer

  • This link was resumed after an interruption: the run was cut by the session limit (HTTP 429) during the mutation pass, which had completed (80 mutations, all red, tree clean at b45616f). On the resume (2026-11-05, about 20:15), the worktree was treated as unreliable: the diff against the base re-read line by line, a check that no mutation leaked into 09c7b32 or b45616f (every original text present with its expected count, 166 checks), then npm ci, the probe (sonde rc=1), npm run build and the whole npm test (183 files / 3154 tests) replayed from scratch on b45616f before the docs commit.
  • The format-2 fallback trusts the category id alone (accepted limit of ADR 0025): after a migration, or with the file of another profile, an id can come back on another category.
  • takeBudget deletes explicitly, so the restore no longer depends on ON DELETE CASCADE; held lines come back with their ids (no collision: their tables were emptied, and AUTOINCREMENT never hands out an id below its sequence).
  • At the parse the budget is validated for the two modes that carry the categories only; importTransactionsOnly keeps its signature (contract) and touches no budget table (FakeDb test).
  • The fixtures of #331, #518 and #521 that serializeToJson stamps at the current format gain the three empty arrays (a format-3 file without them is refused, text 9), or declare their own format; category-migration.test.ts loses getter mocks that collectExportData (which calls the getters inside its module) made inert.
  • restore.test.ts runs the real categories migration on node:sqlite (createPreMigrationBackup, computeMigrationPlan, applyMigration, with invoke and getVersion mocked), for the criterion « Rétablir la sauvegarde rend le budget de l'état v2 exact ».

🤖 Generated with Claude Code

Resolves #520 Generated autonomously by /autopilot run of 2026-11-04 ## Position in the stack Link 3 of 3 of the milestone `planned-2026-11-04-restauration-sauvegarde`: #518 (PR #531, base `main`) → #521 (PR #532, base `issue-518-restore-split-ids`) → #520 (this PR, base `issue-521-restore-fk-failures`, the head of PR #532, `eafd67d`). Strictly linear; the stack merges as a block (Max's decision of 2026-10-29). Nothing is merged yet: the diff of this PR is against PR #532's branch. ## Summary A restore with categories (« Transactions avec catégories », « Catégories uniquement », and « Rétablir la sauvegarde » of the categories migration) ran `DELETE FROM categories`; `budget_entries`, `budget_template_entries` and `adjustment_entries` name a category `ON DELETE CASCADE`, and the backup held none of them: the restore succeeded and left the budget, the template lines and the adjustment lines empty, without a word (the probe of the issue: 1, 1, 1 → 0, 0, 0). Option A of the issue, chosen by Max: **SREF format 3** carries the budget, and it comes back. - **Export** (`collectExportData(mode)`, `dataExportService.ts`): the two modes that carry the categories, and the backup taken before the categories migration, add `budget_entries` (by category, year and month), `budget_templates` (by name, with their lines) and `adjustments` (with their lines). « Transactions uniquement » and the CSV do not change. One function now gathers the arrays of each mode, for « Exporter » (`useDataExport`) and for `createPreMigrationBackup`. - **Restore** (`dataRestoreService.ts`), in the transaction of `runRestore`, through its handle: `takeBudget` reads then removes the three line tables before `DELETE FROM categories`, in both formats. Once the categories are in, `restoreBudget` puts, at format 3, the file's budget lines and adjustments in place of the profile's, upserts each file template by name (`ON CONFLICT(name) DO UPDATE`) with the file's lines, and gives a template absent from the file back its lines whose category returns; below format 3 (every backup written so far, pre-migration ones included) it puts back, as they were, the profile's lines whose category returns, on the category id alone (the accepted limit of ADR 0025). - **The format is given, never guessed**: `importTransactionsWithCategories(data, filename, formatVersion)` and `importCategoriesOnly(data, formatVersion)`; `useDataImport` passes `state.summary.formatVersion`, `applyBackup` passes `envelope.format_version ?? LEGACY_SREF_FORMAT_VERSION`. - **Refusals before anything is deleted** (pure, at the parse and at the head of the two restores): a format newer than this build (text 10, checked right after the envelope's required fields, before its mode); a `format_version` that is not an integer of at least 1 (the existing « Invalid export file format » error); at format 3, a missing array or a line the tables cannot hold (text 9: `Number.isFinite(amount)`, `year` integer 1900–2200, `month` integer 1–12, category present in the file, no duplicate `(category_id, year, month)`, `(template, category_id)` or template name, text name and date). - **`restoreCategories` writes `i18n_key`**: the standard categories came back under their French name in the English interface. - **Confirmations**: `willDeleteCategories` and `willDeleteAll` name the budget (texts 1 and 2); the card counts the budget lines, templates and adjustments of a format-3 file (text 3); a file older than format 3 gets the note of text 4, in the card and in the second confirmation of « Rétablir la sauvegarde » (created by #521); the confirmation of « Réinitialiser » names what it erases (text 11). ## Commits 1. `09c7b32` `fix:` format 3, the restore, the validations, the windows, the i18n keys, and the tests (regression test red on the base, below). 2. `b45616f` `test:` a test of the export hook (`useDataExport.test.ts`, new) and a recurring adjustment with a recurrence rule in the test budget, so that the mutations below have a test that sees them. 3. `0225705` `docs:` ADR 0025 for the stack and its pointer from ADR 0010's amendment, `docs/architecture.md`, guide and in-app docs (tip appended at index 9), CHANGELOG FR/EN. 4. Last commit: the `STATE.md` line of the stack (it carries the closing keyword). ## Texts Texts 1 to 4 and 9 to 11 verbatim from « Textes arrêtés » (answer of Max of 2026-11-04), checked byte for byte against the live issue body by a script (10 keys, 0 difference; text 3 is three keys, one segment each, in the order the body names them): - Text 1, `settings.dataManagement.import.willDeleteCategories`: « Toutes les catégories, fournisseurs et mots-clés, ainsi que le budget, les modèles de budget et les ajustements » / "All categories, suppliers, and keywords, along with the budget, budget templates, and adjustments" - Text 2, `…import.willDeleteAll`: « Toutes les transactions, catégories, fournisseurs, mots-clés et l'historique d'import, ainsi que le budget, les modèles de budget et les ajustements » / "All transactions, categories, suppliers, keywords, and import history, along with the budget, budget templates, and adjustments" - Text 3, `…import.countBudgetEntries`, `countBudgetTemplates`, `countAdjustments`: « {{count}} ligne(s) de budget », « {{count}} modèle(s) de budget », « {{count}} ajustement(s) » / "{{count}} budget line(s)", "{{count}} budget template(s)", "{{count}} adjustment(s)" - Text 4, `…import.legacyBudgetNote` and `settings.categoriesCard.restoreModal.legacyBudgetNote`: « Cette sauvegarde date d'avant l'ajout du budget aux sauvegardes : elle ne contient ni budget, ni modèles de budget, ni ajustements. Les lignes actuelles dont la catégorie revient seront gardées, les autres supprimées. » / "This backup predates budgets in backups: it holds no budget, budget templates, or adjustments. Current lines whose category comes back are kept; the others are deleted." - Text 9, `…import.errors.invalidBudgetRows`: « Ce fichier ne peut pas être importé : des lignes de budget, de modèle de budget ou d'ajustement sont invalides ou visent une catégorie absente du fichier. Rien n'a été modifié. » / "This file cannot be imported: some budget, budget template, or adjustment lines are invalid or refer to a category missing from the file. Nothing has been modified." - Text 10, `…import.errors.newerFormat`: « Ce fichier vient d'une version plus récente de Simpl'Résultat. Mettez l'application à jour pour l'importer. Rien n'a été modifié. » / "This file comes from a newer version of Simpl'Résultat. Update the app to import it. Nothing has been modified." - Text 11, `categories.reinitializeConfirm`: « Réinitialiser toutes les catégories et mots-clés à leurs valeurs par défaut ? Les catégories des transactions seront dissociées, et le budget, les modèles de budget et les ajustements seront effacés. Cette action est irréversible. » / "Reset all categories and keywords to their default values? Transaction categories will be unlinked, and the budget, budget templates, and adjustments will be erased. This cannot be undone." Not verbatim (MEDIUM, decisions comment): the CHANGELOG entries, the guide (Import tip of `:226`, Settings feature of `:592`, a new tip) and their in-app mirrors (`docs.import.tips[8]`, `docs.settings.features[5]`, `docs.settings.tips[9]`). ## Files - `src/services/dataExportService.ts`, `src/services/dataRestoreService.ts`, `src/services/categoryRestoreService.ts`, `src/services/categoryBackupService.ts`, `src/hooks/useDataExport.ts`, `src/hooks/useDataImport.ts`, `src/components/settings/ImportConfirmModal.tsx`, `src/components/settings/CategoriesMigrationRestoreModal.tsx` - `src/i18n/locales/fr.json`, `src/i18n/locales/en.json` (texts 1 to 4 and 9 to 11, `docs.*`) - Tests: `src/__integration__/restore.test.ts` (+29 cases, 54 → 83, the real categories migration among them), `src/services/dataExportService.test.ts` (FakeDb gains the five budget tables; `collectExportData` per mode, the format check, each validation bound, the order of the deletes), `src/hooks/useDataExport.test.ts` (new), `src/hooks/useDataImport.test.ts`, `src/services/categoryRestoreService.test.ts`, `src/services/categoryBackupService.test.ts`, `src/services/categoryService.test.ts` (text 11), `src/components/settings/ImportConfirmModal.render.test.tsx`, `src/components/settings/CategoriesMigrationRestoreModal.wiring.test.ts`, `src/__integration__/category-migration.test.ts` (getter mocks removed), `src/__integration__/regression-v2-v1.test.ts` (fixtures at format 3) - Docs: `docs/adr/0025-contenu-restauration-sauvegarde-sref.md` (new), `docs/adr/0010-fk-restrict-balance-transfers.md`, `docs/architecture.md`, `docs/guide-utilisateur.md`, `CHANGELOG.md`, `CHANGELOG.fr.md`, `STATE.md` (one line) - `src-tauri/` untouched: the version byte of the encrypted container (`export_import_commands.rs`, `0x01`) is independent of the envelope's `format_version`, which only the front reads. ## Decisions (tiers) The comment « Décisions prises sans Max (autopilot) » on this PR gives each one in full. - MEDIUM: (1) a malformed `format_version` gets the existing message as is (`Invalid export file format — missing required fields`); (2) the validation also refuses a template name, an adjustment name or date that is not a text, and `entries` that is not an array (NOT NULL columns; review caveat « types validés »); (3) public texts the issue does not give verbatim (CHANGELOG, guide, in-app docs). - HIGH: the planning contract as written; text 3 as three keys; envelope shapes without ids or timestamps; `takeBudget` reads then deletes (pattern of `takeTransfers`), so the restore no longer depends on the cascade; format-2 lines put back as they were (ids and dates); templates of the file upserted by name, description included; `newerFormat` before the mode; integer year and month; budget validated at the parse for the two modes with categories only; layout of texts 3 and 4; tests in `restore.test.ts` with the real migration; ADR 0025 for the stack; tip appended at index 9; `src-tauri/` untouched; level normal. ## Proofs **Regression test red on the base** (`520-red-on-base.log` in the run folder, from a detached worktree of `origin/issue-521-restore-fk-failures`, `eafd67d`, removed after use): - A throwaway probe with the base API, the probe of the issue (a budget line on 1111, a template and its line, an adjustment and its line, exported as the base « Exporter » did): **5 of 5 red** — `importTransactionsWithCategories` and `importCategoriesOnly` in the same profile and « Rétablir la sauvegarde » (`readBackup` + `applyBackup`): `expected [ +0, +0, +0 ] to deeply equal [ 1, 1, 1 ]` (the headers stay, `[1, 1]`); the categories of the seed: `expected +0 to be 150` (`i18n_key` lost); a file of format 4: accepted. - The new `restore.test.ts` of this branch copied onto the base: **79 of 83 red**. 77 fail on `collectExportData is not a function` (the shared export this PR adds, which every backup of the file goes through); the 2 cases that only need the base API fail on their assertions: after the real categories migration, « Rétablir la sauvegarde » of the format-3 backup gives `entries: []` instead of the budget of the former state; with a format-2 backup, the adjustment lines are deleted instead of kept. With the fix: 83/83 green. **Mutations** (implementation committed first, `09c7b32` + `b45616f`; one at a time, restored by `git checkout -- <file>`, `git status --short` empty after each; 13 test files run each time, baseline 416/416 green). The five of the body are M1 (arrays removed from the export), M2a/M2b/M2c (lines of the format-3 file not reinserted, per table), M3 (format-2 fallback removed), M4 (`i18n_key` removed from the INSERT) and M5 (validation removed from the parse); the others cover each rule added: the fallback part by part (M3a–M3e), the format-3 file replacing the profile's lines (M7a–M7e), the format checks (M9a–M9g), format 3 without one of its arrays (M10, M10a–M10d), each validation bound (M11a–M11s), templates by name (M8a–M8f), the taking out before `DELETE FROM categories` (M6a–M6g), the arrays of each mode (M12a–M12f), the format passed to the restores (M13a, M13b), the legacy note and the counts in both windows (M14a–M14d, M15a, M15b), and the texts (M16a–M16e, text 11 among them). **80 mutations, no survivor.** | # | File | Mutation | Failing | rc | Failing tests (the first; all in `520-mutations.json` of the run folder) | |---|---|---|---|---|---| | M1 | `dataExportService.ts` | budget arrays removed from the export (collectExportData) | 60 | 1 | category-migration.test.ts: integration: plan → backup → migrate (happy path) > produces a plan, verifies backup round-trip, then applies migration atomically<br>(+59 more) | | M2a | `dataRestoreService.ts` | format 3: the file's budget lines not inserted | 8 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were<br>(+7 more) | | M2b | `dataRestoreService.ts` | format 3: the file's adjustments not inserted | 8 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were<br>(+7 more) | | M2c | `dataRestoreService.ts` | format 3: the lines of the file's templates not inserted | 10 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were<br>(+9 more) | | M3 | `dataRestoreService.ts` | format-2 fallback removed (no line taken out comes back) | 6 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories: a template of the file is updated by its name, its lines replaced; a template absent from the file keeps its header and its lines whose category comes back<br>(+5 more) | | M4 | `dataRestoreService.ts` | i18n_key no longer written by restoreCategories | 5 | 1 | restore.test.ts: a restore with categories keeps the translation key of each category (#520) > transactions_with_categories, same profile: every category comes back with its i18n_key<br>(+4 more) | | M5 | `dataExportService.ts` | budget validation removed from parseImportedJson | 9 | 1 | restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > transactions_with_categories: a budget line that names a category missing from the file is refused at the parse and at the head of the restore<br>(+8 more) | | M3a | `dataRestoreService.ts` | format 2: budget lines taken out never come back | 3 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, a backup of the previous version (format 2): the lines whose category comes back are kept as they were, the others go<br>(+2 more) | | M3b | `dataRestoreService.ts` | template lines taken out never come back | 5 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories: a template of the file is updated by its name, its lines replaced; a template absent from the file keeps its header and its lines whose category comes back<br>(+4 more) | | M3c | `dataRestoreService.ts` | format 2: adjustment lines taken out never come back | 4 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, a backup of the previous version (format 2): the lines whose category comes back are kept as they were, the others go<br>(+3 more) | | M3d | `dataRestoreService.ts` | format 2: every line taken out comes back, its category gone or not | 3 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, a backup of the previous version (format 2): the lines whose category comes back are kept as they were, the others go<br>(+2 more) | | M3e | `dataRestoreService.ts` | format 2: a budget line put back under a new id and new dates | 3 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, a backup of the previous version (format 2): the lines whose category comes back are kept as they were, the others go<br>(+2 more) | | M6a | `dataRestoreService.ts` | takeBudget reads nothing (the lines read after the cascade) | 6 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories: a template of the file is updated by its name, its lines replaced; a template absent from the file keeps its header and its lines whose category comes back<br>(+5 more) | | M6b | `dataRestoreService.ts` | takeBudget no longer deletes the budget lines | 2 | 1 | dataExportService.test.ts: a restore takes the budget out before it deletes the categories (#520) > transactions with categories: the budget lines, template lines and adjustment lines go before the categories<br>(+1 more) | | M6c | `dataRestoreService.ts` | takeBudget no longer deletes the template lines | 2 | 1 | dataExportService.test.ts: a restore takes the budget out before it deletes the categories (#520) > transactions with categories: the budget lines, template lines and adjustment lines go before the categories<br>(+1 more) | | M6d | `dataRestoreService.ts` | takeBudget no longer deletes the adjustment lines | 2 | 1 | dataExportService.test.ts: a restore takes the budget out before it deletes the categories (#520) > transactions with categories: the budget lines, template lines and adjustment lines go before the categories<br>(+1 more) | | M6e | `dataRestoreService.ts` | categories only: the budget not taken out (no takeBudget, nothing put back) | 3 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > categories_only: a template of the file is updated by its name, its lines replaced; a template absent from the file keeps its header and its lines whose category comes back<br>(+2 more) | | M6f | `dataRestoreService.ts` | with categories: the budget not put back (restoreBudget not called) | 9 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were<br>(+8 more) | | M6g | `dataRestoreService.ts` | categories only: the budget not put back (restoreBudget not called) | 5 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > categories_only, same profile: the budget lines, the templates and the adjustments come back as they were<br>(+4 more) | | M7a | `dataRestoreService.ts` | format 3: the profile's adjustments kept beside the file's | 6 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were<br>(+5 more) | | M7b | `dataRestoreService.ts` | format 3: the file's budget lines lose their notes | 8 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were<br>(+7 more) | | M7c | `dataRestoreService.ts` | format 3: an adjustment loses its recurrence | 8 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were<br>(+7 more) | | M7d | `dataRestoreService.ts` | format 3: an adjustment loses its recurrence rule | 8 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were<br>(+7 more) | | M7e | `dataRestoreService.ts` | format 3: an adjustment line loses its description | 8 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were<br>(+7 more) | | M8a | `dataRestoreService.ts` | a template of the file inserted without ON CONFLICT (plain INSERT) | 8 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were<br>(+7 more) | | M8b | `dataRestoreService.ts` | a template of the file keeps the profile's description | 2 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories: a template of the file is updated by its name, its lines replaced; a template absent from the file keeps its header and its lines whose category comes back<br>(+1 more) | | M8c | `dataRestoreService.ts` | a new template of the file loses its description | 10 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were<br>(+9 more) | | M8d | `dataRestoreService.ts` | format 3: the lines of a template absent from the file are lost | 2 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories: a template of the file is updated by its name, its lines replaced; a template absent from the file keeps its header and its lines whose category comes back<br>(+1 more) | | M8e | `dataRestoreService.ts` | format 3: the profile's lines of a template of the file come back beside the file's | 7 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were<br>(+6 more) | | M8f | `dataRestoreService.ts` | a line of a template absent from the file comes back without its category | 5 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories: a template of the file is updated by its name, its lines replaced; a template absent from the file keeps its header and its lines whose category comes back<br>(+4 more) | | M9a | `dataExportService.ts` | format check removed from parseImportedJson | 3 | 1 | restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > a file of a newer version (format 4) is refused in the card and in « Rétablir la sauvegarde », and nothing is deleted<br>(+2 more) | | M9b | `dataExportService.ts` | a newer format accepted (text 10 removed from the validator) | 5 | 1 | restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > a file of a newer version (format 4) is refused in the card and in « Rétablir la sauvegarde », and nothing is deleted<br>(+4 more) | | M9c | `dataRestoreService.ts` | format check removed from the head of importTransactionsWithCategories | 2 | 1 | restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > a file of a newer version (format 4) is refused in the card and in « Rétablir la sauvegarde », and nothing is deleted<br>(+1 more) | | M9d | `dataRestoreService.ts` | format check removed from the head of importCategoriesOnly | 2 | 1 | restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > a file of a newer version (format 4) is refused in the card and in « Rétablir la sauvegarde », and nothing is deleted<br>(+1 more) | | M9e | `dataExportService.ts` | a format_version that is not an integer accepted | 4 | 1 | dataExportService.test.ts: the format of a file is checked before anything is deleted (#520) > refuses a format_version of 2.5 as a malformed file<br>(+3 more) | | M9f | `dataExportService.ts` | format 0 accepted (lower bound 1 -> 0) | 3 | 1 | dataExportService.test.ts: the format of a file is checked before anything is deleted (#520) > refuses a format_version of 0 as a malformed file<br>(+2 more) | | M9g | `dataExportService.ts` | the newer format checked after the mode (a newer mode named first) | 1 | 1 | dataExportService.test.ts: the format of a file is checked before anything is deleted (#520) > refuses a newer file at PARSE time, before its mode is even read | | M10 | `dataExportService.ts` | format 3: a missing array read as empty (all three) | 10 | 1 | restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > transactions_with_categories, a file of format 3 that lacks one of its three arrays > without budget_entries: refused at the parse and at the head of the restore, the budget never emptied<br>(+9 more) | | M10a | `dataExportService.ts` | format 3: a missing budget_entries read as empty | 4 | 1 | restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > transactions_with_categories, a file of format 3 that lacks one of its three arrays > without budget_entries: refused at the parse and at the head of the restore, the budget never emptied<br>(+3 more) | | M10b | `dataExportService.ts` | format 3: a missing budget_templates read as empty | 3 | 1 | restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > transactions_with_categories, a file of format 3 that lacks one of its three arrays > without budget_templates: refused at the parse and at the head of the restore, the budget never emptied<br>(+2 more) | | M10c | `dataExportService.ts` | format 3: a missing adjustments read as empty | 3 | 1 | restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > transactions_with_categories, a file of format 3 that lacks one of its three arrays > without adjustments: refused at the parse and at the head of the restore, the budget never emptied<br>(+2 more) | | M10d | `dataExportService.ts` | the budget checked below format 3 too | 14 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, a backup of the previous version (format 2): the lines whose category comes back are kept as they were, the others go<br>(+13 more) | | M11a | `dataExportService.ts` | a line on a category missing from the file accepted | 8 | 1 | restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > transactions_with_categories: a budget line that names a category missing from the file is refused at the parse and at the head of the restore<br>(+7 more) | | M11b | `dataExportService.ts` | a non-finite amount accepted (typeof number) | 4 | 1 | dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with a budget amount that is not finite<br>(+3 more) | | M11c | `dataExportService.ts` | any amount accepted | 5 | 1 | dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with a budget amount that is not a number<br>(+4 more) | | M11d | `dataExportService.ts` | year lower bound 1900 -> 1899 | 1 | 1 | dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with a year before 1900 | | M11e | `dataExportService.ts` | year upper bound 2200 -> 2201 | 1 | 1 | dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with a year after 2200 | | M11f | `dataExportService.ts` | a year that is not an integer accepted | 1 | 1 | dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with a year that is not an integer | | M11g | `dataExportService.ts` | month lower bound 1 -> 0 | 1 | 1 | dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with month 0 | | M11h | `dataExportService.ts` | month upper bound 12 -> 13 | 2 | 1 | dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with month 13<br>(+1 more) | | M11i | `dataExportService.ts` | a month that is not an integer accepted | 1 | 1 | dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with a month that is not an integer | | M11j | `dataExportService.ts` | two budget lines on the same category and month accepted | 1 | 1 | dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with two budget lines on the same category and month | | M11k | `dataExportService.ts` | two templates of the same name accepted | 1 | 1 | dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with two templates of the same name | | M11l | `dataExportService.ts` | a template without a text name accepted | 1 | 1 | dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with a template without a name | | M11m | `dataExportService.ts` | two lines of a template on the same category accepted | 1 | 1 | dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with two lines of a template on the same category | | M11n | `dataExportService.ts` | the lines of a template no longer checked | 2 | 1 | dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with a template line on a category missing from the file<br>(+1 more) | | M11o | `dataExportService.ts` | an adjustment without a text name or date accepted | 2 | 1 | dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with an adjustment without a name<br>(+1 more) | | M11p | `dataExportService.ts` | the lines of an adjustment no longer checked | 2 | 1 | dataExportService.test.ts: the import boundary refuses a budget the restore could not write back (#520) > refuses a format-3 file with an adjustment line on a category missing from the file<br>(+1 more) | | M11q | `dataExportService.ts` | the budget validator removed from both restores' parse and heads (validateImportedBudget a no-op) | 38 | 1 | restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > transactions_with_categories: a budget line that names a category missing from the file is refused at the parse and at the head of the restore<br>(+37 more) | | M11r | `dataRestoreService.ts` | budget validation removed from the head of importTransactionsWithCategories | 5 | 1 | restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > transactions_with_categories: a budget line that names a category missing from the file is refused at the parse and at the head of the restore<br>(+4 more) | | M11s | `dataRestoreService.ts` | budget validation removed from the head of importCategoriesOnly | 5 | 1 | restore.test.ts: a budget the restore could not write back, or a newer file, is refused before anything is deleted (#520) > categories_only: a budget line that names a category missing from the file is refused at the parse and at the head of the restore<br>(+4 more) | | M12a | `dataExportService.ts` | the budget carried by « Transactions uniquement » too | 2 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > witness: « Transactions uniquement » carries no budget and leaves the profile's as it is<br>(+1 more) | | M12b | `dataExportService.ts` | the import configurations carried by « Catégories uniquement » too | 1 | 1 | dataExportService.test.ts: collectExportData gathers the arrays of each mode (#520) > categories_only carries ["categories","suppliers","keywords","budget_entries","budget_templates","adjustments"] | | M12c | `categoryBackupService.ts` | the pre-migration backup gathers another mode | 7 | 1 | category-migration.test.ts: integration: plan → backup → migrate (happy path) > produces a plan, verifies backup round-trip, then applies migration atomically<br>(+6 more) | | M12d | `useDataExport.ts` | « Exporter » no longer writes what collectExportData gathered (its budget dropped) | 2 | 1 | useDataExport.test.ts: useDataExport writes what collectExportData gathers for the mode (#520) > transactions_with_categories: the JSON carries the arrays of its mode, at the format of this build<br>(+1 more) | | M12e | `dataExportService.ts` | a template exported without its lines | 11 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were<br>(+10 more) | | M12f | `dataExportService.ts` | an adjustment exported without its lines | 9 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > transactions_with_categories, same profile: the budget lines, the templates and the adjustments come back as they were<br>(+8 more) | | M13a | `useDataImport.ts` | useDataImport passes this build's format, not the file's | 2 | 1 | useDataImport.test.ts: useDataImport — the outcome of the restore reaches the success state (#521) > transactions_with_categories, a backup of the previous version: the restore is given the format the file declares (NaN) (#520)<br>(+1 more) | | M13b | `categoryRestoreService.ts` | applyBackup passes this build's format, not the file's | 4 | 1 | restore.test.ts: restoring a backup with its budget, its templates and its adjustments (#520) > « Rétablir la sauvegarde » of a backup of the previous version: the lines whose category comes back are kept<br>(+3 more) | | M14a | `ImportConfirmModal.tsx` | the budget counts no longer listed (text 3) | 2 | 1 | ImportConfirmModal.render.test.tsx: ImportConfirmModal — the budget, its templates and the adjustments (#520) > categories_only, format 3: counts the budget lines, templates and adjustments the file brings back, no note<br>(+1 more) | | M14b | `ImportConfirmModal.tsx` | the note of a file older than format 3 never shown (text 4) | 3 | 1 | ImportConfirmModal.render.test.tsx: ImportConfirmModal — the budget, its templates and the adjustments (#520) > categories_only, format 2: the note says the file holds no budget, next to the warning, and nothing is counted<br>(+2 more) | | M14c | `ImportConfirmModal.tsx` | the note shown at every format | 3 | 1 | ImportConfirmModal.render.test.tsx: ImportConfirmModal — the budget, its templates and the adjustments (#520) > categories_only, format 3: counts the budget lines, templates and adjustments the file brings back, no note<br>(+2 more) | | M14d | `ImportConfirmModal.tsx` | « Transactions uniquement » takes the budget note and counts too | 1 | 1 | ImportConfirmModal.render.test.tsx: ImportConfirmModal — the budget, its templates and the adjustments (#520) > « Transactions uniquement » leaves the budget alone: neither count nor note, whatever the format | | M15a | `CategoriesMigrationRestoreModal.tsx` | the note of a backup older than format 3 never shown | 2 | 1 | CategoriesMigrationRestoreModal.wiring.test.ts: CategoriesMigrationRestoreModal — a second confirmation, then « Sauvegarde rétablie » (#521) > a backup of format 2: the second confirmation says it holds no budget (#520)<br>(+1 more) | | M15b | `CategoriesMigrationRestoreModal.tsx` | the note shown at every format | 1 | 1 | CategoriesMigrationRestoreModal.wiring.test.ts: CategoriesMigrationRestoreModal — a second confirmation, then « Sauvegarde rétablie » (#521) > a backup of format 3 carries its budget: no note (#520) | | M16a | `fr.json` | text 11 FR reverted to the former text | 1 | 1 | categoryService.test.ts: « Réinitialiser » says what it erases (#520) > names the budget, the budget templates and the adjustments, in French and in English | | M16b | `en.json` | text 11 EN reverted to the former text | 1 | 1 | categoryService.test.ts: « Réinitialiser » says what it erases (#520) > names the budget, the budget templates and the adjustments, in French and in English | | M16c | `fr.json` | text 1 FR reverted to the former text | 1 | 1 | dataExportService.test.ts: the texts of a restore with the budget exist in both languages (#520) > the confirmation names the budget, the budget templates and the adjustments among what is deleted | | M16d | `en.json` | text 2 EN reverted to the former text | 1 | 1 | dataExportService.test.ts: the texts of a restore with the budget exist in both languages (#520) > the confirmation names the budget, the budget templates and the adjustments among what is deleted | | M16e | `en.json` | text 9 removed from EN (key in one language only) | 2 | 1 | locales.keys.test.ts: locale keys: fr.json and en.json (#453) > en.json declares every key of fr.json<br>(+1 more) | M6b, M6c and M6d (one delete of `takeBudget` removed) are caught by the FakeDb test of the order of the deletes only: under real foreign keys the cascade of `DELETE FROM categories` removes the same rows, so the explicit deletes are what keeps the restore independent of the cascade. **Counts.** vitest before (base `eafd67d`): 182 files / 3043 tests; after: **183 files / 3154 tests**, all green; `npm run build` green. Probe: sonde rc=1 (`src/zz_tmp_probe.test.ts`, deleted). ## Level Normal, computed on `REVIEW.md` of `main` (`bf4eae7`), file by file, in the self-review comment: no Haut row designates a touched file. `src/services/dataExportService.ts` is « au moins normal » (line 50); `dataRestoreService.ts` and the other source files are designated by no Haut row, and the « code livré » row is not met (no network call, no URL, no consent touched; `read_import_file`, `write_export_file` and `pick_save_file` are local commands already called); no file added at the root or under `src-tauri/`; `docs/adr/**`, `docs/architecture.md` normal (line 53). No line of « Niveaux » is touched, and no fact of `REVIEW.md` becomes false (line 109: one transaction, notification after the COMMIT; line 118: the encryption). ## Vérifications manuelles dues (prochaine release) **Base edition** (Budget and Ajustements are Base: `src/shared/entitlements.ts`), in French, then the same in English (EN labels: Settings → Data → Data Management, « Transactions with categories », « Categories only », « Restore the backup », « Migrate to the standard structure », « Re-initialize »). Preparation: a profile with a budget (a few amounts on the Budget page), a budget template saved from it, and an adjustment with two lines on the Adjustments page. 1. Paramètres → Données → Gestion des données → Exporter « Transactions avec catégories » (JSON), then « Catégories uniquement » (JSON). Importer each file into the same profile: the confirmation lists « Toutes les catégories, fournisseurs et mots-clés, ainsi que le budget, les modèles de budget et les ajustements » (or the « Toutes les transactions… » variant) among what is deleted, and « N ligne(s) de budget · N modèle(s) de budget · N ajustement(s) » among what is imported, without the note of an old backup. Expected after « Remplacer les données »: the Budget page shows the same amounts, the template is there with its lines, the Adjustments page shows the adjustment and its two lines. 2. In a new profile (Paramètres → Utilisateurs), import the two files of step 1. Expected: the same budget, template and adjustment. 3. After an export, change an amount of the budget and add an adjustment, then import the export. Expected: the budget and the adjustments of the file, the added adjustment gone. Create a budget template after the export, then import it again: that template stays, with its lines. 4. On a profile still on the former categories (or after « Réinitialiser », which puts them back), with a budget, a template and an adjustment: Paramètres → Données → Catégories → « Migrer vers la structure standard », then « Rétablir la sauvegarde » (banner or « Rétablir une sauvegarde »). Expected: the second confirmation shows no note about the budget; after « Rétablir », the budget, the template and the adjustment of the former categories, as they were before the migration. 5. A backup of the previous version (format 2): a JSON exported by v0.17.2, or a JSON of step 1 edited in a text editor (`"format_version": 2`, the arrays `budget_entries`, `budget_templates` and `adjustments` deleted). Import it into a profile with a budget. Expected: the confirmation shows « Cette sauvegarde date d'avant l'ajout du budget aux sauvegardes : elle ne contient ni budget, ni modèles de budget, ni ajustements. Les lignes actuelles dont la catégorie revient seront gardées, les autres supprimées. » and no budget count; after the import, the budget lines whose category is in the file are still there. Through « Rétablir la sauvegarde » with a pre-migration backup written by v0.17.2: the same note in the second confirmation. 6. A file of a newer version: a JSON of step 1 edited (`"format_version": 4`). Import it. Expected: refused at once with « Ce fichier vient d'une version plus récente de Simpl'Résultat. Mettez l'application à jour pour l'importer. Rien n'a été modifié. » (EN: "This file comes from a newer version of Simpl'Résultat. Update the app to import it. Nothing has been modified."), the confirmation never opens, the profile is unchanged. Same file through « Rétablir la sauvegarde »: move the recorded pre-migration backup out of its folder so that the window offers « Choisir un fichier de sauvegarde », pick the edited file: the same message in the window, nothing replaced (put the backup back afterwards). 7. Catégories → « Réinitialiser »: the confirmation reads « Réinitialiser toutes les catégories et mots-clés à leurs valeurs par défaut ? Les catégories des transactions seront dissociées, et le budget, les modèles de budget et les ajustements seront effacés. Cette action est irréversible. » (EN: "Reset all categories and keywords to their default values? Transaction categories will be unlinked, and the budget, budget templates, and adjustments will be erased. This cannot be undone."). Cancel. 8. Interface in English, on a profile on the standard categories: export « Transactions with categories », import it. Expected: the categories of the Categories page, the Budget page and the category menus show their English names. ## Hors périmètre - From the issue: the migration already deletes the budget lines that collide on one standard category (wanted by its preview and consent); no computation reads `adjustment_entries` outside `adjustmentService.ts`; « Réinitialiser » puts the v2 seed back even on a standard profile; the Bilan, the preferences, `source_id` / `supplier_id` and the import history are not in the backup. - Seen, not fixed: the categories migration rewrites the budget lines and the template lines onto the standard categories but leaves the adjustment lines on the former ones, which it deactivates (the test « Rétablir la sauvegarde » after the categories migration shows it: from a format-2 backup they come back). No issue opened. - An earlier version (v0.17.2 and before) has no refusal of newer formats: it restores a format-3 file without its three arrays, and its cascade empties the budget as before (ADR 0025, negatives). ## For the reviewer - **This link was resumed after an interruption**: the run was cut by the session limit (HTTP 429) during the mutation pass, which had completed (80 mutations, all red, tree clean at `b45616f`). On the resume (2026-11-05, about 20:15), the worktree was treated as unreliable: the diff against the base re-read line by line, a check that no mutation leaked into `09c7b32` or `b45616f` (every original text present with its expected count, 166 checks), then `npm ci`, the probe (sonde rc=1), `npm run build` and the whole `npm test` (183 files / 3154 tests) **replayed from scratch on `b45616f`** before the docs commit. - The format-2 fallback trusts the category id alone (accepted limit of ADR 0025): after a migration, or with the file of another profile, an id can come back on another category. - `takeBudget` deletes explicitly, so the restore no longer depends on `ON DELETE CASCADE`; held lines come back with their ids (no collision: their tables were emptied, and `AUTOINCREMENT` never hands out an id below its sequence). - At the parse the budget is validated for the two modes that carry the categories only; `importTransactionsOnly` keeps its signature (contract) and touches no budget table (FakeDb test). - The fixtures of #331, #518 and #521 that `serializeToJson` stamps at the current format gain the three empty arrays (a format-3 file without them is refused, text 9), or declare their own format; `category-migration.test.ts` loses getter mocks that `collectExportData` (which calls the getters inside its module) made inert. - `restore.test.ts` runs the real categories migration on `node:sqlite` (`createPreMigrationBackup`, `computeMigrationPlan`, `applyMigration`, with `invoke` and `getVersion` mocked), for the criterion « Rétablir la sauvegarde rend le budget de l'état v2 exact ». 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A restore with categories (full backup, categories only, and "Restore the
backup" of the categories migration) ran DELETE FROM categories, whose
ON DELETE CASCADE took every budget line, template line and adjustment
line with it, while the backup held none: the restore succeeded and left
the budget empty.

- SREF format 3: the two modes that carry the categories now carry
  budget_entries, budget_templates (by name, with their lines) and
  adjustments (with their lines). collectExportData(mode) gathers the
  arrays of each mode for the export and for the pre-migration backup.
- Restore: the profile's budget lines, template lines and adjustment
  lines are read and taken out before DELETE FROM categories, in both
  formats, through the restore's handle. At format 3 the file's budget
  lines and adjustments replace the profile's, each file template is
  upserted by name with its lines replaced, and a template absent from
  the file keeps its header and its lines whose category comes back.
  Below format 3 the lines whose category comes back are put back as
  they were.
- The restores of the two category modes take the file's format
  (formatVersion), passed by useDataImport and applyBackup.
- Pure validation at the parse and at the head of each restore: a
  format newer than this build is refused (newerFormat), a non-integer
  or below 1 gets the malformed-file error, and at format 3 a missing
  array or a line the tables cannot hold is refused (invalidBudgetRows).
- restoreCategories writes i18n_key.
- Confirmations: willDeleteCategories and willDeleteAll name the budget,
  the counts of budget lines, templates and adjustments, and the note of
  a backup older than format 3 in the card and in the second
  confirmation of "Restore the backup"; categories.reinitializeConfirm
  names what "Re-initialize" erases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- useDataExport.test.ts (new): "Exporter" writes, for each mode, the
  arrays collectExportData gathers, at the format of this build; a CSV
  still starts with its id column.
- restore.test.ts: the adjustment of the test budget is recurring and
  carries a recurrence rule, so that a restore which drops either shows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs: SREF format 3, the budget in backups, ADR 0025 for the stack (#520)
All checks were successful
PR Check — Frontend / frontend (pull_request) Successful in 3m7s
0225705836
- ADR 0025 "Contenu et restauration d'une sauvegarde SREF": what each
  mode carries (format 3), the ids of #518, the Bilan transfers of #521,
  the categories, the budget of a format-3 file, the fallback of formats
  1 and 2 and its accepted limit on the category id alone, the format
  given and never guessed, the refusals, and the container's version
  byte independent of format_version. ADR 0010's amendment points to it.
- docs/architecture.md: dataExportService and dataRestoreService rows,
  useDataImport and useDataExport rows, section 4 (format 3), the tests
  of restore.test.ts, the ADR index.
- User guide and in-app docs: the Import tip on the backup, the export
  feature of Settings, and a tip appended at the end of
  docs.settings.tips (index 9).
- CHANGELOG FR/EN: Fixed / Corrigé and Changed / Modifié.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner

Décisions prises sans Max (autopilot)

Issue #520, maillon 3 de 3 de planned-2026-11-04-restauration-sauvegarde. Le détail est aussi dans decisions-log.md du run.

MEDIUM

1. Le message d'un format_version mal formé.

  • Question : la planification dit qu'un format non entier ou inférieur à 1 reçoit « l'erreur existante « Invalid export file format » », sans dire s'il faut garder son texte entier.
  • Choix : le message existant tel quel, Invalid export file format — missing required fields, désormais une seule constante pour ses deux usages (enveloppe incomplète, format illisible).
  • Écarté : un message nouveau, parce que ce serait un texte public que l'issue ne donne pas (la carte affiche ce message brut, en anglais, tel quel).
  • Effet visible : un fichier fait à la main avec "format_version": 2.5, 0 ou "3" affiche ce message dans la carte, et « Le fichier de sauvegarde n'a pas pu être lu. Il est peut-être corrompu. » dans « Rétablir la sauvegarde ». Un fichier écrit par l'application n'est jamais concerné.

2. Une validation un peu plus large que la liste de la planification.

  • Question : la liste nomme le montant, l'année, le mois, la catégorie et les trois clés uniques ; la mise en garde de /review-spec dit « types et clés uniques des nouveaux tableaux validés ».
  • Choix : refuser aussi (texte 9) un modèle dont le nom n'est pas un texte, un ajustement dont le nom ou la date n'est pas un texte, et des entries qui ne sont pas un tableau : ce sont des colonnes NOT NULL de tables non STRICT.
  • Écarté : la liste seule, parce qu'un tel fichier échouerait en cours de restauration sur le message brut de SQLite (restauration annulée, rien de perdu, mais rien de lisible).
  • Effet visible : aucun pour un fichier écrit par l'application ; un fichier fait à la main de ce genre est refusé avec le texte 9.

3. Textes publics que l'issue ne donne pas mot pour mot (CHANGELOG FR/EN sous Corrigé / Fixed et Modifié / Changed, guide d'utilisation et docs intégrées).

  • Question : quels mots pour annoncer le budget dans la sauvegarde, le repli d'une ancienne sauvegarde et le refus d'un fichier plus récent, là où l'issue demande la mise à jour du guide (:226 et :592) et des docs intégrées.
  • Choix : le préfixe des entrées de #518 et #521 (« Export/import de données : » / "Data export/import:"), la section « Effet » et les décisions de l'issue, les vrais libellés de l'application (« Transactions avec catégories », « Catégories uniquement », « Rétablir la sauvegarde », « Réinitialiser ») ; l'astuce du guide de l'import (:226, docs.import.tips[8]) et la fonctionnalité d'export des Paramètres (:592, docs.settings.features[5]) complétées, et une astuce ajoutée en fin de liste (docs.settings.tips[9], si bien que tips[6], que cite REVIEW.md, garde son indice).
  • Écarté : laisser :226 et :592 tels quels, parce que l'issue les nomme.
  • Effet visible : l'historique des versions (Paramètres → Système) et le guide d'utilisation.

HIGH

  • Contrat de la planification appliqué tel quel : SREF_FORMAT_VERSION = 3 ; importTransactionsWithCategories(data, filename, formatVersion) et importCategoriesOnly(data, formatVersion), format obligatoire ; useDataImport passe state.summary.formatVersion ; applyBackup passe envelope.format_version ?? LEGACY_SREF_FORMAT_VERSION ; collectExportData(mode) dans dataExportService.ts pour « Exporter » et la sauvegarde d'avant migration ; importTransactionsOnly garde sa signature.
  • Texte 3 lu comme trois clés, un segment chacune, dans l'ordre du corps ; textes 1 à 4 et 9 à 11 vérifiés octet pour octet contre le corps de l'issue (10 clés, 0 écart).
  • Formes de l'enveloppe : une ligne de budget par catégorie, année et mois ; un modèle par son nom, avec ses lignes ; un ajustement avec ses lignes ; ni identifiant ni date dans le fichier, comme les catégories et les transactions.
  • takeBudget lit puis supprime les trois tables de lignes avant DELETE FROM categories (motif de takeTransfers, #521) : la restauration ne dépend plus de la cascade ; les en-têtes des modèles et des ajustements restent, et au format 3 DELETE FROM adjustments les remplace par ceux du fichier.
  • Repli des formats 1 et 2 : les lignes reviennent telles quelles (même identifiant, mêmes dates pour une ligne de budget) ; au format 3, les lignes du fichier prennent de nouveaux identifiants.
  • Modèles du fichier : ON CONFLICT(name) DO UPDATE SET description = excluded.description, identifiant relu par le nom comme restoreImportTemplates ; leurs lignes sont celles du fichier ; un modèle absent du fichier garde ses lignes dont la catégorie revient, sous leurs identifiants.
  • Le format plus récent (newerFormat) est vérifié juste après les champs obligatoires de l'enveloppe, avant son mode : une version plus récente peut apporter un mode inconnu, et « mettez l'application à jour » est alors le bon message.
  • Année et mois entiers (Number.isInteger).
  • Au parse, le budget n'est validé que pour les deux modes qui portent les catégories (« Transactions uniquement » n'en porte pas et sa restauration n'y touche pas) ; le résumé compte les tableaux du fichier, la carte ne les affiche qu'à partir du format 3.
  • Carte : le texte 4 dans l'encadré d'avertissement, au-dessus du texte 5 ; les décomptes du texte 3 après ceux des catégories (après les mots-clés pour « Catégories uniquement », après les transactions pour la sauvegarde complète), avant les configurations d'import, seulement quand ils ne sont pas nuls. « Rétablir la sauvegarde » : le texte 4 dans la seconde confirmation, dans l'encadré du texte 5, au-dessus de lui.
  • Tests : cas ajoutés à src/__integration__/restore.test.ts (aucun adaptateur de plus), dont la vraie migration des catégories (createPreMigrationBackup, computeMigrationPlan, applyMigration sur node:sqlite) ; FakeDb de dataExportService.test.ts étendu aux cinq tables du budget ; fixtures des maillons précédents complétées des trois tableaux vides ou portant leur propre format ; simulations de lecture inertes retirées de category-migration.test.ts ; nouveau src/hooks/useDataExport.test.ts.
  • ADR 0025 « Contenu et restauration d'une sauvegarde SREF » pour toute la pile ; l'amendement de l'ADR 0010 y renvoie.
  • src-tauri/ intact : l'octet de version du conteneur chiffré est indépendant de format_version.
  • Niveau calculé normal sur le REVIEW.md de main ; aucun fait de REVIEW.md ne devient faux.
  • Maillon interrompu par la limite de session pendant la passe de mutations (terminée, 80 rouges), repris le 2026-11-05 vers 20 h 15 : diff relu, aucune mutation dans les commits, build et suite rejoués depuis zéro.
## Décisions prises sans Max (autopilot) Issue #520, maillon 3 de 3 de `planned-2026-11-04-restauration-sauvegarde`. Le détail est aussi dans `decisions-log.md` du run. ### MEDIUM **1. Le message d'un `format_version` mal formé.** - Question : la planification dit qu'un format non entier ou inférieur à 1 reçoit « l'erreur existante « Invalid export file format » », sans dire s'il faut garder son texte entier. - Choix : le message existant tel quel, `Invalid export file format — missing required fields`, désormais une seule constante pour ses deux usages (enveloppe incomplète, format illisible). - Écarté : un message nouveau, parce que ce serait un texte public que l'issue ne donne pas (la carte affiche ce message brut, en anglais, tel quel). - Effet visible : un fichier fait à la main avec `"format_version": 2.5`, `0` ou `"3"` affiche ce message dans la carte, et « Le fichier de sauvegarde n'a pas pu être lu. Il est peut-être corrompu. » dans « Rétablir la sauvegarde ». Un fichier écrit par l'application n'est jamais concerné. **2. Une validation un peu plus large que la liste de la planification.** - Question : la liste nomme le montant, l'année, le mois, la catégorie et les trois clés uniques ; la mise en garde de `/review-spec` dit « types et clés uniques des nouveaux tableaux validés ». - Choix : refuser aussi (texte 9) un modèle dont le nom n'est pas un texte, un ajustement dont le nom ou la date n'est pas un texte, et des `entries` qui ne sont pas un tableau : ce sont des colonnes NOT NULL de tables non STRICT. - Écarté : la liste seule, parce qu'un tel fichier échouerait en cours de restauration sur le message brut de SQLite (restauration annulée, rien de perdu, mais rien de lisible). - Effet visible : aucun pour un fichier écrit par l'application ; un fichier fait à la main de ce genre est refusé avec le texte 9. **3. Textes publics que l'issue ne donne pas mot pour mot** (CHANGELOG FR/EN sous Corrigé / Fixed et Modifié / Changed, guide d'utilisation et docs intégrées). - Question : quels mots pour annoncer le budget dans la sauvegarde, le repli d'une ancienne sauvegarde et le refus d'un fichier plus récent, là où l'issue demande la mise à jour du guide (`:226` et `:592`) et des docs intégrées. - Choix : le préfixe des entrées de #518 et #521 (« Export/import de données : » / "Data export/import:"), la section « Effet » et les décisions de l'issue, les vrais libellés de l'application (« Transactions avec catégories », « Catégories uniquement », « Rétablir la sauvegarde », « Réinitialiser ») ; l'astuce du guide de l'import (`:226`, `docs.import.tips[8]`) et la fonctionnalité d'export des Paramètres (`:592`, `docs.settings.features[5]`) complétées, et une astuce ajoutée en fin de liste (`docs.settings.tips[9]`, si bien que `tips[6]`, que cite `REVIEW.md`, garde son indice). - Écarté : laisser `:226` et `:592` tels quels, parce que l'issue les nomme. - Effet visible : l'historique des versions (Paramètres → Système) et le guide d'utilisation. ### HIGH - Contrat de la planification appliqué tel quel : `SREF_FORMAT_VERSION = 3` ; `importTransactionsWithCategories(data, filename, formatVersion)` et `importCategoriesOnly(data, formatVersion)`, format obligatoire ; `useDataImport` passe `state.summary.formatVersion` ; `applyBackup` passe `envelope.format_version ?? LEGACY_SREF_FORMAT_VERSION` ; `collectExportData(mode)` dans `dataExportService.ts` pour « Exporter » et la sauvegarde d'avant migration ; `importTransactionsOnly` garde sa signature. - Texte 3 lu comme trois clés, un segment chacune, dans l'ordre du corps ; textes 1 à 4 et 9 à 11 vérifiés octet pour octet contre le corps de l'issue (10 clés, 0 écart). - Formes de l'enveloppe : une ligne de budget par catégorie, année et mois ; un modèle par son nom, avec ses lignes ; un ajustement avec ses lignes ; ni identifiant ni date dans le fichier, comme les catégories et les transactions. - `takeBudget` lit puis supprime les trois tables de lignes avant `DELETE FROM categories` (motif de `takeTransfers`, #521) : la restauration ne dépend plus de la cascade ; les en-têtes des modèles et des ajustements restent, et au format 3 `DELETE FROM adjustments` les remplace par ceux du fichier. - Repli des formats 1 et 2 : les lignes reviennent telles quelles (même identifiant, mêmes dates pour une ligne de budget) ; au format 3, les lignes du fichier prennent de nouveaux identifiants. - Modèles du fichier : `ON CONFLICT(name) DO UPDATE SET description = excluded.description`, identifiant relu par le nom comme `restoreImportTemplates` ; leurs lignes sont celles du fichier ; un modèle absent du fichier garde ses lignes dont la catégorie revient, sous leurs identifiants. - Le format plus récent (`newerFormat`) est vérifié juste après les champs obligatoires de l'enveloppe, avant son mode : une version plus récente peut apporter un mode inconnu, et « mettez l'application à jour » est alors le bon message. - Année et mois entiers (`Number.isInteger`). - Au parse, le budget n'est validé que pour les deux modes qui portent les catégories (« Transactions uniquement » n'en porte pas et sa restauration n'y touche pas) ; le résumé compte les tableaux du fichier, la carte ne les affiche qu'à partir du format 3. - Carte : le texte 4 dans l'encadré d'avertissement, au-dessus du texte 5 ; les décomptes du texte 3 après ceux des catégories (après les mots-clés pour « Catégories uniquement », après les transactions pour la sauvegarde complète), avant les configurations d'import, seulement quand ils ne sont pas nuls. « Rétablir la sauvegarde » : le texte 4 dans la seconde confirmation, dans l'encadré du texte 5, au-dessus de lui. - Tests : cas ajoutés à `src/__integration__/restore.test.ts` (aucun adaptateur de plus), dont la vraie migration des catégories (`createPreMigrationBackup`, `computeMigrationPlan`, `applyMigration` sur `node:sqlite`) ; FakeDb de `dataExportService.test.ts` étendu aux cinq tables du budget ; fixtures des maillons précédents complétées des trois tableaux vides ou portant leur propre format ; simulations de lecture inertes retirées de `category-migration.test.ts` ; nouveau `src/hooks/useDataExport.test.ts`. - ADR 0025 « Contenu et restauration d'une sauvegarde SREF » pour toute la pile ; l'amendement de l'ADR 0010 y renvoie. - `src-tauri/` intact : l'octet de version du conteneur chiffré est indépendant de `format_version`. - Niveau calculé normal sur le `REVIEW.md` de `main` ; aucun fait de `REVIEW.md` ne devient faux. - Maillon interrompu par la limite de session pendant la passe de mutations (terminée, 80 rouges), repris le 2026-11-05 vers 20 h 15 : diff relu, aucune mutation dans les commits, build et suite rejoués depuis zéro.
docs(state): name the manual checks of the budget in backups (#520)
All checks were successful
PR Check — Frontend / frontend (pull_request) Successful in 2m58s
e63029e7c3
The line of the stack in the checks due at the next release now names
the three links and their PRs (#531, #532, #533).

Resolves #520

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
Owner

Niveau : normal

Verdict : APPROVE

Auto-revue de l'auteur (worker /autopilot du 2026-11-04, repris le 2026-11-05 après une interruption), pas une revue indépendante : la checklist de /pr-review appliquée par celui qui a écrit le code et ses tests. Elle ne porte volontairement aucune ligne Reviewed-SHA : la première /pr-review de cette PR reste une revue complète, et ses mutations doivent venir du relecteur. Tête relue : e63029e.

Résumé

Une restauration avec catégories ne vide plus le budget, les modèles de budget ni les ajustements : le format SREF 3 les porte dans les deux modes qui portent les catégories et dans la sauvegarde d'avant migration (collectExportData), la restauration lit puis retire leurs lignes avant DELETE FROM categories et les remet (celles du fichier au format 3, celles du profil dont la catégorie revient en dessous), le format est donné par l'appelant et jamais deviné, un format plus récent ou un budget illisible est refusé avant toute suppression, restoreCategories écrit i18n_key, et les confirmations nomment ce qui est effacé. Test de régression rouge sur la base (sonde de l'issue 5/5, migration réelle comprise), 80 mutations toutes rouges. Aucun constat bloquant.

Niveau, fichier par fichier (REVIEW.md de main, bf4eae7)

  • src/services/dataExportService.ts : normal, « Restent au moins normaux » (ligne 50) ; la ligne « code livré » ne s'applique pas : ni appel réseau, ni URL, ni consentement.
  • src/services/dataRestoreService.ts : normal, aucune ligne du tableau Haut ne le désigne sur main ; « code livré » non rempli.
  • src/services/categoryBackupService.ts, src/services/categoryRestoreService.ts, src/hooks/useDataExport.ts, src/hooks/useDataImport.ts, src/components/settings/ImportConfirmModal.tsx, src/components/settings/CategoriesMigrationRestoreModal.tsx : normal, même raison. write_export_file, read_import_file et pick_save_file sont des commandes locales déjà appelées : ce que le fichier écrit change, aucun appel réseau n'envoie autre chose.
  • Les douze fichiers de test (dont src/hooks/useDataExport.test.ts, nouveau, sous src/) : normal.
  • src/i18n/locales/fr.json, en.json : normal (traductions).
  • docs/adr/0025-contenu-restauration-sauvegarde-sref.md (ajouté, sous docs/, ni à la racine ni dans un dossier caché nouveau), docs/adr/0010-fk-restrict-balance-transfers.md, docs/architecture.md : normal (ligne 53, jamais de niveau bas).
  • CHANGELOG.md, CHANGELOG.fr.md, docs/guide-utilisateur.md, STATE.md : bas.

La PR prend le plus haut : normal. Aucune ligne de la section « Niveaux » n'est touchée ; aucun fichier ajouté, renommé ou supprimé à la racine ni sous src-tauri/ ; src-tauri/ intact.

Checklist, profondeur normale

Security. Ni secret, ni jeton, ni .env ; balayage des 2108 lignes ajoutées du diff (/pulls/533.diff) : 0 affectation de secret, 0 préfixe connu, 0 URL à identifiants, 0 motif dangereux, 0 courriel ni adresse IP, 0 appel réseau dans le code livré. SQL : toutes les requêtes ajoutées sont des constantes qui lient leurs valeurs par $N (takeBudget, restoreBudget, les trois lecteurs de l'export) ; la seule interpolation (idOf de restore.test.ts) est dans un test, sur une union de deux noms de table littéraux. Frontière : c'est ce que la PR ajoute, pure, au parse et en tête des deux restaurations qui portent les catégories, avant runRestore (db.log vide sur un refus, testé).

Correctness. Conforme au corps, aux décisions de Max du 2026-10-29, à la planification et aux mises en garde du 2026-11-04. Vérifié en plus :

  • le corps de runRestore ne passe que par son db (lectures du budget et des catégories comprises, aucun getDb(), aucun BEGIN brut ; l'adaptateur node:sqlite lève sur getDb() en transaction et la suite passe) ; is_recurring lié par toSqlFlag ; la notification reste unique, après le COMMIT, et couvre budget_entries, que lit COUNTERS_SQL ;
  • une ligne gardée revient sous son identifiant sans collision : sa table a été vidée par takeBudget, et AUTOINCREMENT ne rend jamais un identifiant sous sa séquence, si bien que les lignes du fichier, insérées avant ou après, ont des identifiants plus grands ;
  • au format 3, un modèle du profil du même nom est mis à jour en place (identifiant gardé, testé) et ses anciennes lignes ne reviennent pas (M8e) ; un modèle absent du fichier garde ses lignes dont la catégorie revient (M8d, M8f) ;
  • les en-têtes des ajustements ne nomment aucune catégorie : au format 2 ils restent, au format 3 DELETE FROM adjustments les remplace (M7a) ;
  • « Transactions uniquement » ne touche aucune table du budget (test FakeDb) et garde sa signature ; un fichier transactions_only de format 3 qui porterait des tableaux de budget les voit ignorés, jamais validés ni écrits ;
  • newerFormat passe avant le mode (M9g) : un fichier d'une version plus récente qui apporterait un mode inconnu reçoit le message qui aide ;
  • la vraie migration des catégories tourne dans restore.test.ts : le budget, les modèles et les ajustements de l'ancienne structure reviennent exactement avec une sauvegarde de format 3, et une sauvegarde de format 2 ne rend pas les lignes que la migration a réécrites sur les catégories standard (limite de l'ADR 0025).

Tests. Test de régression : sur la base eafd67d, la sonde de l'issue par l'API de la base (5/5 rouges : lignes 1, 1, 1 → 0, 0, 0 dans les deux modes et par « Rétablir la sauvegarde », i18n_key perdu, format 4 accepté), et le nouveau restore.test.ts (79/83 rouges, dont 77 sur collectExportData is not a function et les 2 cas de la migration réelle sur leurs assertions) ; 83/83 verts ici. Ni only ni skip. Suite : 183 fichiers / 3154 tests verts sur la tête (182 / 3043 sur la base), npm run build vert, sonde rc=1, tous rejoués depuis zéro après la reprise.

Quality. Textes d'interface par i18next dans les deux langues, textes 1 à 4 et 9 à 11 vérifiés octet pour octet contre l'issue (10 clés, 0 écart), mêmes variables {{count}} (locales.keys.test.ts vert), astuce ajoutée à l'indice 9 et docs.settings.tips[6] à son indice (readme-guard vert). Commits au format conventionnel ; mot-clé de fermeture dans le seul dernier commit et en première ligne du corps ; timeline de #520 : une entrée pull_ref de cette PR, closes ; timelines de #518 et #521 : none seulement de cette PR.

Data. Aucune migration touchée ni ajoutée, consolidated_schema.sql et src-tauri/ inchangés ; l'action ON DELETE CASCADE reste celle du schéma.

Mutations (une par règle, garde ou comportement ajouté)

80 mutations, une à la fois, après le commit de l'implémentation, chacune restaurée par git checkout -- <fichier> puis git status --short vide : toutes rouges, aucune survivante (tableau complet dans le corps de la PR). Les cinq du corps : tableaux retirés de l'export (60 rouges), lignes du fichier de format 3 non réinsérées (8, 8 et 10 selon la table), repli du format 2 retiré (6), i18n_key retiré de l'INSERT (5), validation retirée du parse (9). Après la reprise, un contrôle a vérifié qu'aucune mutation n'est restée dans 09c7b32 ni b45616f (166 vérifications, 0 écart).

Règles des zones que touche le diff

  • Vie privée : aucun appel réseau, aucune URL, aucun consentement touché ; aucune ligne du Journal ajoutée.
  • Migrations, profils et données : tout ce que fait le corps de runRestore passe par son db ; booléen lié en 1/0 ; notification après le COMMIT inchangée ; comptes de tables, d'index et de migrations inchangés.
  • i18n et documentation : clés dans les deux langues avec les mêmes variables, CHANGELOG FR/EN sous Corrigé / Fixed et Modifié / Changed, guide et docs.*, docs/architecture.md (services, hooks, § 4, tests, index des ADR), ADR 0025 nouveau, renvoi depuis l'amendement de l'ADR 0010.
  • Règles de revue : aucun fait de REVIEW.md ne devient faux (la ligne 109 tient : une seule transaction, notification après le COMMIT ; la ligne 118 parle du chiffrement, inchangé).

Décisions autopilot à confirmer

Trois MEDIUM, détaillées dans le commentaire 31774 : (1) un format_version mal formé reçoit le message existant tel quel (« Invalid export file format — missing required fields ») ; (2) la validation refuse aussi un nom de modèle, un nom ou une date d'ajustement qui n'est pas un texte et des entries qui ne sont pas un tableau ; (3) les textes publics que l'issue ne donne pas mot pour mot (CHANGELOG, guide, docs intégrées).

À corriger dans cette PR

Aucun.

Non retenu

  • Le repli du format 2 se fie au seul identifiant de catégorie : limite acceptée par la mise en garde de /review-spec et écrite dans l'ADR 0025.
  • La migration des catégories ne réécrit pas les lignes d'ajustement (elles restent sur les anciennes catégories désactivées) : antérieur, hors de l'issue, constaté par le test de la migration réelle et signalé dans « Hors périmètre ».
  • Une version antérieure (v0.17.2 et avant) restaure un fichier de format 3 sans ses tableaux, faute de refus des formats plus récents : conséquence écrite dans l'ADR 0025.
  • L'export d'un profil passe toujours sa propre validation, à ma lecture : clés étrangères, UNIQUE et NOT NULL tiennent les lignes, et un montant non fini ne peut pas être écrit (l'IPC le transmet en null, que NOT NULL refuse) ; non prouvé par un test.
  • collectExportData lit ses neuf tableaux hors transaction, comme les six de #331 : une écriture entre deux lectures donnerait un fichier que la relecture de la sauvegarde d'avant migration refuserait (migration annulée, rien de perdu).
  • M6b, M6c et M6d ne rougissent que le test FakeDb de l'ordre des suppressions : sous clés étrangères, la cascade retire les mêmes lignes ; les suppressions explicites rendent la restauration indépendante de la cascade.
Niveau : normal Verdict : APPROVE Auto-revue de l'auteur (worker `/autopilot` du 2026-11-04, repris le 2026-11-05 après une interruption), pas une revue indépendante : la checklist de `/pr-review` appliquée par celui qui a écrit le code et ses tests. Elle ne porte volontairement aucune ligne `Reviewed-SHA` : la première `/pr-review` de cette PR reste une revue complète, et ses mutations doivent venir du relecteur. Tête relue : `e63029e`. ## Résumé Une restauration avec catégories ne vide plus le budget, les modèles de budget ni les ajustements : le format SREF 3 les porte dans les deux modes qui portent les catégories et dans la sauvegarde d'avant migration (`collectExportData`), la restauration lit puis retire leurs lignes avant `DELETE FROM categories` et les remet (celles du fichier au format 3, celles du profil dont la catégorie revient en dessous), le format est donné par l'appelant et jamais deviné, un format plus récent ou un budget illisible est refusé avant toute suppression, `restoreCategories` écrit `i18n_key`, et les confirmations nomment ce qui est effacé. Test de régression rouge sur la base (sonde de l'issue 5/5, migration réelle comprise), 80 mutations toutes rouges. Aucun constat bloquant. ## Niveau, fichier par fichier (`REVIEW.md` de `main`, `bf4eae7`) - `src/services/dataExportService.ts` : normal, « Restent au moins normaux » (ligne 50) ; la ligne « code livré » ne s'applique pas : ni appel réseau, ni URL, ni consentement. - `src/services/dataRestoreService.ts` : normal, aucune ligne du tableau Haut ne le désigne sur `main` ; « code livré » non rempli. - `src/services/categoryBackupService.ts`, `src/services/categoryRestoreService.ts`, `src/hooks/useDataExport.ts`, `src/hooks/useDataImport.ts`, `src/components/settings/ImportConfirmModal.tsx`, `src/components/settings/CategoriesMigrationRestoreModal.tsx` : normal, même raison. `write_export_file`, `read_import_file` et `pick_save_file` sont des commandes locales déjà appelées : ce que le fichier écrit change, aucun appel réseau n'envoie autre chose. - Les douze fichiers de test (dont `src/hooks/useDataExport.test.ts`, nouveau, sous `src/`) : normal. - `src/i18n/locales/fr.json`, `en.json` : normal (traductions). - `docs/adr/0025-contenu-restauration-sauvegarde-sref.md` (ajouté, sous `docs/`, ni à la racine ni dans un dossier caché nouveau), `docs/adr/0010-fk-restrict-balance-transfers.md`, `docs/architecture.md` : normal (ligne 53, jamais de niveau bas). - `CHANGELOG.md`, `CHANGELOG.fr.md`, `docs/guide-utilisateur.md`, `STATE.md` : bas. La PR prend le plus haut : normal. Aucune ligne de la section « Niveaux » n'est touchée ; aucun fichier ajouté, renommé ou supprimé à la racine ni sous `src-tauri/` ; `src-tauri/` intact. ## Checklist, profondeur normale **Security.** Ni secret, ni jeton, ni `.env` ; balayage des 2108 lignes ajoutées du diff (`/pulls/533.diff`) : 0 affectation de secret, 0 préfixe connu, 0 URL à identifiants, 0 motif dangereux, 0 courriel ni adresse IP, 0 appel réseau dans le code livré. SQL : toutes les requêtes ajoutées sont des constantes qui lient leurs valeurs par `$N` (`takeBudget`, `restoreBudget`, les trois lecteurs de l'export) ; la seule interpolation (`idOf` de `restore.test.ts`) est dans un test, sur une union de deux noms de table littéraux. Frontière : c'est ce que la PR ajoute, pure, au parse et en tête des deux restaurations qui portent les catégories, avant `runRestore` (`db.log` vide sur un refus, testé). **Correctness.** Conforme au corps, aux décisions de Max du 2026-10-29, à la planification et aux mises en garde du 2026-11-04. Vérifié en plus : - le corps de `runRestore` ne passe que par son `db` (lectures du budget et des catégories comprises, aucun `getDb()`, aucun `BEGIN` brut ; l'adaptateur `node:sqlite` lève sur `getDb()` en transaction et la suite passe) ; `is_recurring` lié par `toSqlFlag` ; la notification reste unique, après le `COMMIT`, et couvre `budget_entries`, que lit `COUNTERS_SQL` ; - une ligne gardée revient sous son identifiant sans collision : sa table a été vidée par `takeBudget`, et `AUTOINCREMENT` ne rend jamais un identifiant sous sa séquence, si bien que les lignes du fichier, insérées avant ou après, ont des identifiants plus grands ; - au format 3, un modèle du profil du même nom est mis à jour en place (identifiant gardé, testé) et ses anciennes lignes ne reviennent pas (M8e) ; un modèle absent du fichier garde ses lignes dont la catégorie revient (M8d, M8f) ; - les en-têtes des ajustements ne nomment aucune catégorie : au format 2 ils restent, au format 3 `DELETE FROM adjustments` les remplace (M7a) ; - « Transactions uniquement » ne touche aucune table du budget (test FakeDb) et garde sa signature ; un fichier `transactions_only` de format 3 qui porterait des tableaux de budget les voit ignorés, jamais validés ni écrits ; - `newerFormat` passe avant le mode (M9g) : un fichier d'une version plus récente qui apporterait un mode inconnu reçoit le message qui aide ; - la vraie migration des catégories tourne dans `restore.test.ts` : le budget, les modèles et les ajustements de l'ancienne structure reviennent exactement avec une sauvegarde de format 3, et une sauvegarde de format 2 ne rend pas les lignes que la migration a réécrites sur les catégories standard (limite de l'ADR 0025). **Tests.** Test de régression : sur la base `eafd67d`, la sonde de l'issue par l'API de la base (5/5 rouges : lignes 1, 1, 1 → 0, 0, 0 dans les deux modes et par « Rétablir la sauvegarde », `i18n_key` perdu, format 4 accepté), et le nouveau `restore.test.ts` (79/83 rouges, dont 77 sur `collectExportData is not a function` et les 2 cas de la migration réelle sur leurs assertions) ; 83/83 verts ici. Ni `only` ni `skip`. Suite : 183 fichiers / 3154 tests verts sur la tête (182 / 3043 sur la base), `npm run build` vert, sonde rc=1, tous rejoués depuis zéro après la reprise. **Quality.** Textes d'interface par i18next dans les deux langues, textes 1 à 4 et 9 à 11 vérifiés octet pour octet contre l'issue (10 clés, 0 écart), mêmes variables `{{count}}` (`locales.keys.test.ts` vert), astuce ajoutée à l'indice 9 et `docs.settings.tips[6]` à son indice (`readme-guard` vert). Commits au format conventionnel ; mot-clé de fermeture dans le seul dernier commit et en première ligne du corps ; timeline de #520 : une entrée `pull_ref` de cette PR, `closes` ; timelines de #518 et #521 : `none` seulement de cette PR. **Data.** Aucune migration touchée ni ajoutée, `consolidated_schema.sql` et `src-tauri/` inchangés ; l'action `ON DELETE CASCADE` reste celle du schéma. ## Mutations (une par règle, garde ou comportement ajouté) 80 mutations, une à la fois, après le commit de l'implémentation, chacune restaurée par `git checkout -- <fichier>` puis `git status --short` vide : toutes rouges, aucune survivante (tableau complet dans le corps de la PR). Les cinq du corps : tableaux retirés de l'export (60 rouges), lignes du fichier de format 3 non réinsérées (8, 8 et 10 selon la table), repli du format 2 retiré (6), `i18n_key` retiré de l'`INSERT` (5), validation retirée du parse (9). Après la reprise, un contrôle a vérifié qu'aucune mutation n'est restée dans `09c7b32` ni `b45616f` (166 vérifications, 0 écart). ## Règles des zones que touche le diff - Vie privée : aucun appel réseau, aucune URL, aucun consentement touché ; aucune ligne du Journal ajoutée. - Migrations, profils et données : tout ce que fait le corps de `runRestore` passe par son `db` ; booléen lié en `1`/`0` ; notification après le `COMMIT` inchangée ; comptes de tables, d'index et de migrations inchangés. - i18n et documentation : clés dans les deux langues avec les mêmes variables, CHANGELOG FR/EN sous Corrigé / Fixed et Modifié / Changed, guide et `docs.*`, `docs/architecture.md` (services, hooks, § 4, tests, index des ADR), ADR 0025 nouveau, renvoi depuis l'amendement de l'ADR 0010. - Règles de revue : aucun fait de `REVIEW.md` ne devient faux (la ligne 109 tient : une seule transaction, notification après le `COMMIT` ; la ligne 118 parle du chiffrement, inchangé). ## Décisions autopilot à confirmer Trois MEDIUM, détaillées dans le commentaire 31774 : (1) un `format_version` mal formé reçoit le message existant tel quel (« Invalid export file format — missing required fields ») ; (2) la validation refuse aussi un nom de modèle, un nom ou une date d'ajustement qui n'est pas un texte et des `entries` qui ne sont pas un tableau ; (3) les textes publics que l'issue ne donne pas mot pour mot (CHANGELOG, guide, docs intégrées). ## À corriger dans cette PR Aucun. ## Non retenu - Le repli du format 2 se fie au seul identifiant de catégorie : limite acceptée par la mise en garde de `/review-spec` et écrite dans l'ADR 0025. - La migration des catégories ne réécrit pas les lignes d'ajustement (elles restent sur les anciennes catégories désactivées) : antérieur, hors de l'issue, constaté par le test de la migration réelle et signalé dans « Hors périmètre ». - Une version antérieure (v0.17.2 et avant) restaure un fichier de format 3 sans ses tableaux, faute de refus des formats plus récents : conséquence écrite dans l'ADR 0025. - L'export d'un profil passe toujours sa propre validation, à ma lecture : clés étrangères, `UNIQUE` et `NOT NULL` tiennent les lignes, et un montant non fini ne peut pas être écrit (l'IPC le transmet en `null`, que `NOT NULL` refuse) ; non prouvé par un test. - `collectExportData` lit ses neuf tableaux hors transaction, comme les six de #331 : une écriture entre deux lectures donnerait un fichier que la relecture de la sauvegarde d'avant migration refuserait (migration annulée, rien de perdu). - M6b, M6c et M6d ne rougissent que le test FakeDb de l'ordre des suppressions : sous clés étrangères, la cascade retire les mêmes lignes ; les suppressions explicites rendent la restauration indépendante de la cascade.
Author
Owner

Niveau : normal

Verdict : APPROVE

Résumé

Le correctif tient : le format SREF 3 porte le budget, les modèles de budget et les ajustements dans les deux modes qui portent les catégories et dans la sauvegarde d'avant migration ; la restauration retire leurs lignes avant DELETE FROM categories et les remet (celles du fichier au format 3, celles du profil dont la catégorie revient en dessous) ; un format plus récent ou un budget illisible est refusé avant toute suppression. Revue rejouée hors dépôt : build et suite verts, 84 mutations du relecteur, 83 rouges. Deux points non bloquants à corriger en tête de pile : la mutation survivante (aucun test n'exporte deux ajustements) et la fin de l'entrée « Corrigé » du CHANGELOG, qui promet plus que le code pour les sauvegardes déjà écrites.

Niveau

Section « Niveaux » de REVIEW.md lue sur main (bf4eae7) : aucune ligne du tableau Haut ne désigne un fichier touché.

  • src/services/dataExportService.ts : au moins normal (« Restent au moins normaux »).
  • dataRestoreService.ts, categoryBackupService.ts, categoryRestoreService.ts, useDataExport.ts, useDataImport.ts et les deux fenêtres : code livré dont le diff n'ajoute aucun appel invoke, fetch ni ouverture d'URL et ne touche aucun consentement (lignes ajoutées balayées) ; normal.
  • Tests, traductions, docs/adr/**, docs/architecture.md : normal. CHANGELOG*.md, STATE.md, docs/guide-utilisateur.md : bas.
  • Aucun fichier ajouté, renommé ou supprimé à la racine ni sous src-tauri/, intact. Même niveau que l'auto-revue.

Ce que la revue a exécuté

  • Copie hors dépôt (git archive de la tête, npm ci) : npm run build vert, npx vitest run 183 fichiers et 3154 tests verts. main est ancêtre de la tête : ce dernier maillon est l'état de la pile après merge.
  • 84 mutations, une à la fois, la copie remise à neuf par git et vérifiée propre après chacune ; chaque mutation tuée fait sortir vitest en code 1, ce qui tient lieu de sonde. 83 rouges :
    • les deux appels de restoreBudget retirés : 9 et 5 rouges ; takeBudget remplacé par une prise vide : 8 ; les suppressions de takeBudget laissées à la cascade : 2 ;
    • au format 3, chaque insertion retirée (lignes de budget, ajustements, lignes d'ajustement, lignes de modèle) : 8 à 10 ; DELETE FROM adjustments retiré : 6 ; is_recurring, recurrence_rule, notes, descriptions ou montants perdus : 8 à 10 ;
    • ON CONFLICT(name) DO NOTHING : 2 ; lignes de modèle rattachées au lastInsertId de l'upsert au lieu de l'identifiant relu par nom : 8 ; lignes gardées des modèles (celles d'un modèle du fichier remises, sans filtre de catégorie, jamais remises, nom du modèle non lu) : 5 à 7 ;
    • repli des formats 1 et 2 sans réinsertion, sans filtre de catégorie, sous de nouveaux identifiants, de nouvelles dates ou sans notes : 2 à 4 ;
    • i18n_key retiré de l'INSERT : 5 ;
    • chaque borne et chaque type de validateImportedBudget et de validateImportedFormatVersion : 1 à 10 ; validation des formats 1 et 2 comme un format 3 : 14 ; contrôle du format placé après le mode : 1 ; validation retirée du parse ou de la tête d'une restauration : 3 à 9 ; appliquée aussi à « Transactions uniquement » : 29 ;
    • contenu de chaque mode de collectExportData (tableaux, champs, regroupement des lignes de modèle) : 1 à 16 ; sauvegarde d'avant migration prise en « Catégories uniquement » : 1 ; SREF_FORMAT_VERSION remis à 2 : 22 ;
    • format passé par useDataImport et applyBackup : 1 à 4 ; décomptes du résumé, note, décomptes et seuil des deux fenêtres : 1 à 3.
  • Textes 1 à 4 et 9 à 11 comparés par script à la section « Textes arrêtés » de #520 : 10 clés, FR et EN, 0 écart.
  • Schéma : UNIQUE(name) de budget_templates, clés UNIQUE des lignes et AUTOINCREMENT des trois tables de lignes, dans schema.sql (v1, profil par défaut, qu'aucune migration ne reconstruit) comme dans consolidated_schema.sql : l'ON CONFLICT(name) vaut sur les deux chemins, et une ligne gardée revient sous son identifiant sans heurter celles du fichier.

Checklist

  • Sécurité : ni secret, ni jeton, ni .env, ni coordonnée de tiers dans les lignes ajoutées ; SQL lié par $N (seule interpolation : un nom de table littéral, dans un test) ; la frontière valide avant toute suppression, au parse et en tête des deux restaurations qui portent les catégories.
  • Exactitude : conforme au corps et aux critères de #520, aux décisions de Max du 2026-10-29 et du 2026-11-04 (dont l'entrée de DECISIONS.md sur le format plus récent) et aux mises en garde de /review-spec. Le corps de runRestore ne passe que par son handle ; is_recurring lié par toSqlFlag ; une seule notification, après le COMMIT.
  • Tests : régression sur node:sqlite avec les vrais services des pages Budget et Ajustements, même profil et profil neuf, formats 3 et 2, et la vraie migration des catégories avant « Rétablir la sauvegarde » ; ni only ni skip.
  • Qualité : chaînes par i18next, mêmes clés et variables FR/EN ; commits au format conventionnel ; Resolves #520 dans le corps et dans le seul dernier commit. Timelines : #520 closes depuis cette PR, #518 et #521 none.
  • Données : aucune migration touchée ni ajoutée ; comptes de tables, d'index et de migrations inchangés.

Décisions autopilot à confirmer

Les trois MEDIUM du commentaire 31774 :

  1. Un format_version mal formé (2.5, 0, "3") reçoit le message existant, brut et en anglais, « Invalid export file format — missing required fields ». Conforme à la planification (« l'erreur existante »), ne touche qu'un fichier fait à la main.
  2. La validation refuse aussi (texte 9) un nom de modèle, un nom ou une date d'ajustement qui n'est pas un texte, et des entries qui ne sont pas un tableau. Conforme à la mise en garde « types et clés uniques des nouveaux tableaux validés », ne touche qu'un fichier fait à la main.
  3. Les textes publics que l'issue ne donne pas mot pour mot (CHANGELOG, guide, docs intégrées) : exacts, sauf la fin de l'entrée « Corrigé » (point 1 ci-dessous).

À corriger dans cette PR

  1. CHANGELOG.fr.md:35 et CHANGELOG.md:35, entrée Corrigé / Fixed : « Elles reviennent désormais telles quelles, dans le même profil comme dans un profil neuf, et « Rétablir la sauvegarde » rend exactement le budget des anciennes catégories » ne vaut que pour une sauvegarde écrite par cette version (format 3). Scénario : une personne qui a migré ses catégories avec la v0.17.x fait la mise à jour, lit l'historique des versions et clique « Rétablir la sauvegarde » ; sa sauvegarde est de format 2, les lignes de budget et de modèle que la migration a réécrites sur les catégories standard ne reviennent pas, et la note de la seconde confirmation (texte 4) contredit l'historique. L'entrée « Modifié » dit le repli ; l'entrée « Corrigé », lue seule, le contredit. Formulation à faire valider par Max (texte public), par exemple : « Avec une sauvegarde écrite par cette version, elles reviennent désormais telles quelles, dans le même profil comme dans un profil neuf, et « Rétablir la sauvegarde » d'une migration faite avec cette version rend exactement le budget des anciennes catégories. », et l'équivalent anglais.
  2. src/services/dataExportService.ts:359 (getExportAdjustments) : la mutation .filter((line) => line.adjustment_id === adjustment.id) → .filter(() => true) survit à toute la suite (3154 verts), faute d'un test qui exporte deux ajustements. Avec ce défaut, chaque ajustement partirait avec les lignes de tous, et la restauration les multiplierait sans erreur. Le cas FakeDb « collectExportData gathers the arrays of each mode » (src/services/dataExportService.test.ts:1333) sème deux modèles mais un seul ajustement : un second ajustement avec sa propre ligne suffit. Sonde faite sur la copie : un cas à deux ajustements (lignes de 10 et de 20) passe sur la tête et rougit sous la mutation (« A » reçoit [10, 20]).

Non retenu

  • Le commentaire « lastInsertId is 0 on the conflict branch » (dataRestoreService.ts:675, repris de :313) est inexact : sur la branche du conflit, SQLite rend l'identifiant du dernier INSERT de la connexion, pas 0 (la mutation du lastInsertId rattache les lignes au mauvais modèle, 8 rouges). Le code relit l'identifiant par nom, ce qui est correct ; le commentaire invite un raccourci lastInsertId || SELECT qui serait faux.
  • Les bornes d'année 1900–2200 ne sont pas celles de la page Budget, dont le changement d'année n'a pas de borne (useBudget.ts:454) : une ligne posée 130 ans en arrière rendrait toute sauvegarde du profil refusée (texte 9) et bloquerait la sauvegarde d'avant migration (verification_mismatch). Inatteignable en usage normal.
  • L'ADR 0025 (§ 8) et docs/architecture.md disent le format vérifié « en tête de chaque restauration » ; importTransactionsOnly ne le reçoit pas (signature gardée par contrat), seul le parse le contrôle.
  • Le texte 11 dit les modèles et les ajustements « effacés », les textes 1 et 2 « supprimés » : leurs en-têtes restent (constat de l'issue), et au format 3 un modèle absent du fichier garde ses lignes. Textes arrêtés par Max sur ce constat.
  • L'astuce de l'import (guide :226, docs.import.tips[8]) range le budget à côté des sources d'import, qui ne voyagent pas dans les mêmes modes (sources avec les transactions, budget avec les catégories).
  • Les points « Non retenu » de l'auto-revue tiennent : repli sur le seul identifiant de catégorie (limite de l'ADR 0025), lignes d'ajustement laissées sur les anciennes catégories par la migration, version antérieure qui ignore le format 3, lectures de collectExportData hors transaction.

Décisions techniques prises par défaut (à contester)

  • L'entrée « Corrigé » du CHANGELOG est classée « À corriger dans cette PR », non bloquante. Écarté : bloquer la PR, parce que le code et les deux confirmations disent vrai et que le texte se corrige en tête de pile.
  • Le test qui manque à la mutation de getExportAdjustments est classé « À corriger dans cette PR ». Écarté : « Non retenu », parce que c'est la seule logique nouvelle du chemin de sauvegarde qu'aucun test ne tient et que sa régression multiplierait des lignes d'ajustement sans erreur.

Actions faites

  • Copie hors dépôt /tmp/pr533-copy et scripts de mutation /tmp/pr533-mut/ supprimés avant ce commentaire ; fichiers /tmp/pr533-* et dossier de contexte supprimés après son envoi. Aucun fichier du dépôt modifié.
  • Label de #520 : status:review → status:approved.

Reviewed-SHA: e63029e7c3

Niveau : normal **Verdict : APPROVE** ## Résumé Le correctif tient : le format SREF 3 porte le budget, les modèles de budget et les ajustements dans les deux modes qui portent les catégories et dans la sauvegarde d'avant migration ; la restauration retire leurs lignes avant `DELETE FROM categories` et les remet (celles du fichier au format 3, celles du profil dont la catégorie revient en dessous) ; un format plus récent ou un budget illisible est refusé avant toute suppression. Revue rejouée hors dépôt : build et suite verts, 84 mutations du relecteur, 83 rouges. Deux points non bloquants à corriger en tête de pile : la mutation survivante (aucun test n'exporte deux ajustements) et la fin de l'entrée « Corrigé » du CHANGELOG, qui promet plus que le code pour les sauvegardes déjà écrites. ## Niveau Section « Niveaux » de `REVIEW.md` lue sur `main` (`bf4eae7`) : aucune ligne du tableau Haut ne désigne un fichier touché. - `src/services/dataExportService.ts` : au moins normal (« Restent au moins normaux »). - `dataRestoreService.ts`, `categoryBackupService.ts`, `categoryRestoreService.ts`, `useDataExport.ts`, `useDataImport.ts` et les deux fenêtres : code livré dont le diff n'ajoute aucun appel `invoke`, `fetch` ni ouverture d'URL et ne touche aucun consentement (lignes ajoutées balayées) ; normal. - Tests, traductions, `docs/adr/**`, `docs/architecture.md` : normal. `CHANGELOG*.md`, `STATE.md`, `docs/guide-utilisateur.md` : bas. - Aucun fichier ajouté, renommé ou supprimé à la racine ni sous `src-tauri/`, intact. Même niveau que l'auto-revue. ## Ce que la revue a exécuté - Copie hors dépôt (`git archive` de la tête, `npm ci`) : `npm run build` vert, `npx vitest run` 183 fichiers et 3154 tests verts. `main` est ancêtre de la tête : ce dernier maillon est l'état de la pile après merge. - 84 mutations, une à la fois, la copie remise à neuf par git et vérifiée propre après chacune ; chaque mutation tuée fait sortir vitest en code 1, ce qui tient lieu de sonde. 83 rouges : - les deux appels de `restoreBudget` retirés : 9 et 5 rouges ; `takeBudget` remplacé par une prise vide : 8 ; les suppressions de `takeBudget` laissées à la cascade : 2 ; - au format 3, chaque insertion retirée (lignes de budget, ajustements, lignes d'ajustement, lignes de modèle) : 8 à 10 ; `DELETE FROM adjustments` retiré : 6 ; `is_recurring`, `recurrence_rule`, notes, descriptions ou montants perdus : 8 à 10 ; - `ON CONFLICT(name) DO NOTHING` : 2 ; lignes de modèle rattachées au `lastInsertId` de l'upsert au lieu de l'identifiant relu par nom : 8 ; lignes gardées des modèles (celles d'un modèle du fichier remises, sans filtre de catégorie, jamais remises, nom du modèle non lu) : 5 à 7 ; - repli des formats 1 et 2 sans réinsertion, sans filtre de catégorie, sous de nouveaux identifiants, de nouvelles dates ou sans notes : 2 à 4 ; - `i18n_key` retiré de l'`INSERT` : 5 ; - chaque borne et chaque type de `validateImportedBudget` et de `validateImportedFormatVersion` : 1 à 10 ; validation des formats 1 et 2 comme un format 3 : 14 ; contrôle du format placé après le mode : 1 ; validation retirée du parse ou de la tête d'une restauration : 3 à 9 ; appliquée aussi à « Transactions uniquement » : 29 ; - contenu de chaque mode de `collectExportData` (tableaux, champs, regroupement des lignes de modèle) : 1 à 16 ; sauvegarde d'avant migration prise en « Catégories uniquement » : 1 ; `SREF_FORMAT_VERSION` remis à 2 : 22 ; - format passé par `useDataImport` et `applyBackup` : 1 à 4 ; décomptes du résumé, note, décomptes et seuil des deux fenêtres : 1 à 3. - Textes 1 à 4 et 9 à 11 comparés par script à la section « Textes arrêtés » de #520 : 10 clés, FR et EN, 0 écart. - Schéma : `UNIQUE(name)` de `budget_templates`, clés `UNIQUE` des lignes et `AUTOINCREMENT` des trois tables de lignes, dans `schema.sql` (v1, profil par défaut, qu'aucune migration ne reconstruit) comme dans `consolidated_schema.sql` : l'`ON CONFLICT(name)` vaut sur les deux chemins, et une ligne gardée revient sous son identifiant sans heurter celles du fichier. ## Checklist - **Sécurité** : ni secret, ni jeton, ni `.env`, ni coordonnée de tiers dans les lignes ajoutées ; SQL lié par `$N` (seule interpolation : un nom de table littéral, dans un test) ; la frontière valide avant toute suppression, au parse et en tête des deux restaurations qui portent les catégories. - **Exactitude** : conforme au corps et aux critères de #520, aux décisions de Max du 2026-10-29 et du 2026-11-04 (dont l'entrée de `DECISIONS.md` sur le format plus récent) et aux mises en garde de `/review-spec`. Le corps de `runRestore` ne passe que par son handle ; `is_recurring` lié par `toSqlFlag` ; une seule notification, après le `COMMIT`. - **Tests** : régression sur `node:sqlite` avec les vrais services des pages Budget et Ajustements, même profil et profil neuf, formats 3 et 2, et la vraie migration des catégories avant « Rétablir la sauvegarde » ; ni `only` ni `skip`. - **Qualité** : chaînes par i18next, mêmes clés et variables FR/EN ; commits au format conventionnel ; `Resolves #520` dans le corps et dans le seul dernier commit. Timelines : #520 `closes` depuis cette PR, #518 et #521 `none`. - **Données** : aucune migration touchée ni ajoutée ; comptes de tables, d'index et de migrations inchangés. ## Décisions autopilot à confirmer Les trois MEDIUM du commentaire 31774 : 1. Un `format_version` mal formé (`2.5`, `0`, `"3"`) reçoit le message existant, brut et en anglais, « Invalid export file format — missing required fields ». Conforme à la planification (« l'erreur existante »), ne touche qu'un fichier fait à la main. 2. La validation refuse aussi (texte 9) un nom de modèle, un nom ou une date d'ajustement qui n'est pas un texte, et des `entries` qui ne sont pas un tableau. Conforme à la mise en garde « types et clés uniques des nouveaux tableaux validés », ne touche qu'un fichier fait à la main. 3. Les textes publics que l'issue ne donne pas mot pour mot (CHANGELOG, guide, docs intégrées) : exacts, sauf la fin de l'entrée « Corrigé » (point 1 ci-dessous). ## À corriger dans cette PR 1. `CHANGELOG.fr.md:35` et `CHANGELOG.md:35`, entrée Corrigé / Fixed : « Elles reviennent désormais telles quelles, dans le même profil comme dans un profil neuf, et « Rétablir la sauvegarde » rend exactement le budget des anciennes catégories » ne vaut que pour une sauvegarde écrite par cette version (format 3). Scénario : une personne qui a migré ses catégories avec la v0.17.x fait la mise à jour, lit l'historique des versions et clique « Rétablir la sauvegarde » ; sa sauvegarde est de format 2, les lignes de budget et de modèle que la migration a réécrites sur les catégories standard ne reviennent pas, et la note de la seconde confirmation (texte 4) contredit l'historique. L'entrée « Modifié » dit le repli ; l'entrée « Corrigé », lue seule, le contredit. Formulation à faire valider par Max (texte public), par exemple : « Avec une sauvegarde écrite par cette version, elles reviennent désormais telles quelles, dans le même profil comme dans un profil neuf, et « Rétablir la sauvegarde » d'une migration faite avec cette version rend exactement le budget des anciennes catégories. », et l'équivalent anglais. 2. `src/services/dataExportService.ts:359` (`getExportAdjustments`) : la mutation `.filter((line) => line.adjustment_id === adjustment.id)` → `.filter(() => true)` survit à toute la suite (3154 verts), faute d'un test qui exporte deux ajustements. Avec ce défaut, chaque ajustement partirait avec les lignes de tous, et la restauration les multiplierait sans erreur. Le cas FakeDb « collectExportData gathers the arrays of each mode » (`src/services/dataExportService.test.ts:1333`) sème deux modèles mais un seul ajustement : un second ajustement avec sa propre ligne suffit. Sonde faite sur la copie : un cas à deux ajustements (lignes de 10 et de 20) passe sur la tête et rougit sous la mutation (« A » reçoit `[10, 20]`). ## Non retenu - Le commentaire « `lastInsertId` is 0 on the conflict branch » (`dataRestoreService.ts:675`, repris de `:313`) est inexact : sur la branche du conflit, SQLite rend l'identifiant du dernier `INSERT` de la connexion, pas 0 (la mutation du `lastInsertId` rattache les lignes au mauvais modèle, 8 rouges). Le code relit l'identifiant par nom, ce qui est correct ; le commentaire invite un raccourci `lastInsertId || SELECT` qui serait faux. - Les bornes d'année 1900–2200 ne sont pas celles de la page Budget, dont le changement d'année n'a pas de borne (`useBudget.ts:454`) : une ligne posée 130 ans en arrière rendrait toute sauvegarde du profil refusée (texte 9) et bloquerait la sauvegarde d'avant migration (`verification_mismatch`). Inatteignable en usage normal. - L'ADR 0025 (§ 8) et `docs/architecture.md` disent le format vérifié « en tête de chaque restauration » ; `importTransactionsOnly` ne le reçoit pas (signature gardée par contrat), seul le parse le contrôle. - Le texte 11 dit les modèles et les ajustements « effacés », les textes 1 et 2 « supprimés » : leurs en-têtes restent (constat de l'issue), et au format 3 un modèle absent du fichier garde ses lignes. Textes arrêtés par Max sur ce constat. - L'astuce de l'import (guide `:226`, `docs.import.tips[8]`) range le budget à côté des sources d'import, qui ne voyagent pas dans les mêmes modes (sources avec les transactions, budget avec les catégories). - Les points « Non retenu » de l'auto-revue tiennent : repli sur le seul identifiant de catégorie (limite de l'ADR 0025), lignes d'ajustement laissées sur les anciennes catégories par la migration, version antérieure qui ignore le format 3, lectures de `collectExportData` hors transaction. ## Décisions techniques prises par défaut (à contester) - L'entrée « Corrigé » du CHANGELOG est classée « À corriger dans cette PR », non bloquante. Écarté : bloquer la PR, parce que le code et les deux confirmations disent vrai et que le texte se corrige en tête de pile. - Le test qui manque à la mutation de `getExportAdjustments` est classé « À corriger dans cette PR ». Écarté : « Non retenu », parce que c'est la seule logique nouvelle du chemin de sauvegarde qu'aucun test ne tient et que sa régression multiplierait des lignes d'ajustement sans erreur. ## Actions faites - Copie hors dépôt `/tmp/pr533-copy` et scripts de mutation `/tmp/pr533-mut/` supprimés avant ce commentaire ; fichiers `/tmp/pr533-*` et dossier de contexte supprimés après son envoi. Aucun fichier du dépôt modifié. - Label de #520 : `status:review` → `status:approved`. Reviewed-SHA: e63029e7c32e858c8641021a2fbcd44c1530764a
Author
Owner

Réponses de Max (2026-11-05, relayées par la session principale après /pr-review)

  1. Fin de l'entrée « Corrigé » du CHANGELOG (revue 31876, « À corriger » 1) : formulation de la revue. FR : « Avec une sauvegarde écrite par cette version, elles reviennent désormais telles quelles, dans le même profil comme dans un profil neuf, et « Rétablir la sauvegarde » d'une migration faite avec cette version rend exactement le budget des anciennes catégories. » ; l'anglais suit la même phrase.
  2. Numéro de format mal formé (décision MEDIUM 1 du commentaire 31774) : message traduit, nouvelle clé FR/EN : « Ce fichier ne peut pas être importé : son numéro de format est invalide. Rien n'a été modifié. » / « This file cannot be imported: its format number is invalid. Nothing has been modified. » Le cas des champs manquants garde son message brut.

Suite : ces deux points, le test à deux ajustements (« À corriger » 2 de la revue 31876) et le registre DECISIONS.md partent dans un maillon de suites en tête de pile (nouvelle PR sur issue-520-restore-budget-sref3, Refs #520), relu par sa propre /pr-review.

Décisions techniques prises par défaut (à contester)

  • Validation élargie (nom ou date qui n'est pas un texte, entries qui n'est pas un tableau ; MEDIUM 2 du commentaire 31774), gardée sans question. Écarté : la liste de la planification seule, parce qu'un tel fichier échouerait en cours de route sur le message brut de SQLite.
  • Les corrections partent dans un maillon de suites, pas sur la branche de cette PR. Écarté : les pousser sur issue-520-restore-budget-sref3, parce que la revue 31876 et son Reviewed-SHA restent valides et que le maillon de suites a sa propre revue (précédent : PR #529 de la pile du 2026-11-02).
## Réponses de Max (2026-11-05, relayées par la session principale après `/pr-review`) 1. Fin de l'entrée « Corrigé » du CHANGELOG (revue 31876, « À corriger » 1) : **formulation de la revue**. FR : « Avec une sauvegarde écrite par cette version, elles reviennent désormais telles quelles, dans le même profil comme dans un profil neuf, et « Rétablir la sauvegarde » d'une migration faite avec cette version rend exactement le budget des anciennes catégories. » ; l'anglais suit la même phrase. 2. Numéro de format mal formé (décision MEDIUM 1 du commentaire 31774) : **message traduit**, nouvelle clé FR/EN : « Ce fichier ne peut pas être importé : son numéro de format est invalide. Rien n'a été modifié. » / « This file cannot be imported: its format number is invalid. Nothing has been modified. » Le cas des champs manquants garde son message brut. Suite : ces deux points, le test à deux ajustements (« À corriger » 2 de la revue 31876) et le registre `DECISIONS.md` partent dans un maillon de suites en tête de pile (nouvelle PR sur `issue-520-restore-budget-sref3`, `Refs #520`), relu par sa propre `/pr-review`. ## Décisions techniques prises par défaut (à contester) - Validation élargie (nom ou date qui n'est pas un texte, `entries` qui n'est pas un tableau ; MEDIUM 2 du commentaire 31774), gardée sans question. Écarté : la liste de la planification seule, parce qu'un tel fichier échouerait en cours de route sur le message brut de SQLite. - Les corrections partent dans un maillon de suites, pas sur la branche de cette PR. Écarté : les pousser sur `issue-520-restore-budget-sref3`, parce que la revue 31876 et son `Reviewed-SHA` restent valides et que le maillon de suites a sa propre revue (précédent : PR #529 de la pile du 2026-11-02).
maximus changed target branch from issue-521-restore-fk-failures to main 2026-11-07 18:58:34 +00:00
maximus deleted branch issue-520-restore-budget-sref3 2026-11-07 18:59:05 +00:00
Author
Owner

Merge /merge-stack (2026-11-07)

Mergée en fast-forward par l'API, épinglée sur e63029e, la tête relue par 31876. Ses deux points « À corriger » sont corrigés dans le maillon de suites #534. Tête cumulée 6356aad éprouvée avant le merge dans un worktree jetable : npm ci, sonde par npm test rc=1, npm run build vert, 183 fichiers / 3156 tests verts ; aucun fichier sous src-tauri/, .cargo/, .forgejo/ ni de package.json / package-lock.json changé par la pile. Mergée par /merge-stack (tapé par Max le 2026-11-07), dans l'ordre 531 → 532 → 533 → 534, chaque maillon reciblé sur main par Forgejo après le précédent.

#520 fermée par Resolves #520 (commit e63029e), status:approved retiré.

Non retenu (revue 31876) : commentaire « lastInsertId is 0 on the conflict branch » inexact (dataRestoreService.ts) ; bornes d'année 1900–2200 plus étroites que la page Budget ; ADR 0025 § 8 et docs/architecture.md disent le format vérifié « en tête de chaque restauration », alors qu'importTransactionsOnly ne le reçoit pas ; texte 11 « effacés » alors que les en-têtes restent ; astuce de l'import qui range le budget à côté des sources d'import.

## Merge `/merge-stack` (2026-11-07) Mergée en fast-forward par l'API, épinglée sur `e63029e`, la tête relue par 31876. Ses deux points « À corriger » sont corrigés dans le maillon de suites #534. Tête cumulée `6356aad` éprouvée avant le merge dans un worktree jetable : `npm ci`, sonde par `npm test` rc=1, `npm run build` vert, 183 fichiers / 3156 tests verts ; aucun fichier sous `src-tauri/`, `.cargo/`, `.forgejo/` ni de `package.json` / `package-lock.json` changé par la pile. Mergée par `/merge-stack` (tapé par Max le 2026-11-07), dans l'ordre 531 → 532 → 533 → 534, chaque maillon reciblé sur `main` par Forgejo après le précédent. #520 fermée par `Resolves #520` (commit `e63029e`), `status:approved` retiré. Non retenu (revue 31876) : commentaire « `lastInsertId` is 0 on the conflict branch » inexact (`dataRestoreService.ts`) ; bornes d'année 1900–2200 plus étroites que la page Budget ; ADR 0025 § 8 et `docs/architecture.md` disent le format vérifié « en tête de chaque restauration », alors qu'`importTransactionsOnly` ne le reçoit pas ; texte 11 « effacés » alors que les en-têtes restent ; astuce de l'import qui range le budget à côté des sources d'import.
Sign in to join this conversation.
No reviewers
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
maximus/Simpl-Resultat!533
No description provided.