fix: a split's offset line follows its parent when it is recategorized (#454) #515
No reviewers
Labels
No labels
autopilot:pending-human
source:analyste
source:defenseur
source:human
source:medic
source:revue
status:approved
status:blocked
status:in-progress
status:needs-clarification
status:needs-fix
status:ready
status:review
status:to-test
status:triage
type:bug
type:feature
type:infra
type:refactor
type:schema
type:security
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
maximus/Simpl-Resultat!515
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "issue-454-split-offset-follows-parent"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Resolves #454
Generated autonomously by /autopilot run of 2026-10-27
Link 1 of 3 of the stack #454 → #513 → #479, milestone
planned-2026-10-27-periode-et-repartition. Base:main(eecbd2b).Level: normal, set by
src/services/transactionService.ts(application code). No file of the Haut table: no network call, no consent, no migration, neither lock nor manifest;db.tsis read only.docs/architecture.md,docs/adr/0022-canal-evenements-donnees.mdandCLAUDE.mdstay at least normal; the CHANGELOGs andSTATE.mdare low.Summary
Recategorizing a split transaction moved the parent only. Its offset line, the child of
+50thatsaveSplitAdjustmentwrites in the parent's category to cancel the part sent to other categories, stayed in the former category. Every report adds all rows, so a transaction of −120 with −50 split to B, moved from A to C, left +50 in A and −120 in C instead of −70 in C. The keyword path had the same defect, and its preview also offered the children of a split (they carry the parent's description), which it then recategorized alone.src/utils/splitOffset.ts(new):isOffsetChild(parent, child)on{ description, amount }: the parent's description, the sign opposite to the parent's, a non-zero amount. The split window's rule, without its category condition (decision D1: no role column, no migration). Header comment: unrelated tosrc/shared/splitGate.ts.src/services/splitOffsetService.ts(new):propagateCategoryToOffsets(db, parentId, categoryId): Promise<number>. On the handle it receives: reads the row (id, description, amount, is_split, parent_transaction_id), returns 0 without writing for an unknown id, a transaction that is not split, or a child (children carryis_split = 1too); otherwise reads the children (WHERE parent_transaction_id = $1 ORDER BY id) and givescategoryId(andupdated_at) to each oneisOffsetChildrecognizes, whatever its current category (decision D2: an offset left in a former category is repaired at the parent's next change). It never issuesBEGIN/COMMIT/ROLLBACK, never callsgetDb(), never notifies;is_manually_categorizedof the offset is left as it is.transactionService.ts:updateTransactionCategoryrunswithTransaction((db) => updateTransactionCategoryInTransaction(db, …)), which issuesBEGIN, the parent'sUPDATE(unchanged,toSqlFlag), the propagation,COMMIT, andROLLBACKthen rethrow in itscatch(the pattern ofapplyKeywordInTransaction).notifyDataChanged()afterwithTransactionreturns, never on a failure.categorizationService.ts:previewKeywordMatchesaddsAND t.parent_transaction_id IS NULL; inapplyKeywordInTransaction, the loop'sUPDATEaddsAND parent_transaction_id IS NULL(a child passed by mistake is never recategorized alone),updatedTransactionsaddsrowsAffected, andpropagateCategoryToOffsets(db, txId, input.categoryId)runs for each id before theCOMMIT.SplitAdjustmentModal.tsx: the children are filtered with!isOffsetChild(transaction, c), so an offset left in a former category is no longer shown as a row of the split.No migration (v1→v17 untouched),
consolidated_schema.sqlandsrc-tauri/**untouched. No import cycle:Files
src/utils/splitOffset.ts,src/utils/splitOffset.test.ts(new, 7 tests).src/services/splitOffsetService.ts,src/services/splitOffsetService.test.ts(new, 10 tests;getDb()mocked to reject, a subscriber catches any notification).src/services/transactionService.ts,src/services/transactionService.test.ts(regression test, plain transaction, failed offset move, handle only; the tests of #390 and #396 find the parent'sUPDATEby its SQL and answer the reads of the propagation).src/services/categorizationService.ts,src/services/categorizationService.test.ts(preview filter, offset moved by the keyword, child never alone withrowsAffected, failed offset move, handle only; reads answered in every existing test, theBEGIN/COMMITorder test included).src/components/transactions/SplitAdjustmentModal.tsx,src/components/transactions/SplitAdjustmentModal.test.ts(new, 3 tests throughsrc/test/hookHarness.ts: the loading effect run bycommit(), the rows read from the props of theirCategoryComboboxand amount field).docs/architecture.md(29 services, 23 described, 21 utilities; rows oftransactionService.ts,categorizationService.ts,splitOffsetService.ts),docs/adr/0022-canal-evenements-donnees.md(row oftransactionService.ts: notification after theCOMMIT, none after aROLLBACK),CLAUDE.md(line 59 only: « 28 services métier » → 29),CHANGELOG.md,CHANGELOG.fr.md(one Fixed / Corrigé entry),STATE.md(one sub-bullet).Decisions (tier)
All in the decisions comment that follows; in short:
STATE.mdsub-bullet): the tests and the SQLite replay do not run the Tauri runtime on the most frequent write path, now a transaction, nor the real split window and reports.main; mocked reads answered by SQL; tests added beyond the list of the issue to kill mutations it left green (split window M12,getDb()M14/M15, zero amount M7);is_splitread throughtoSqlFlag;rowsAffectedcounted as incategoryMigrationService.ts; counts recomputed with the commandarchitecture.mdcites; ADR 0022 row updated; user guide unchanged (same action, right totals).Proof
Regression test, on the code of
main(eecbd2b, the test file of this branch only):SQLite replay (no vitest test runs the SQL: they mock the database). python3 3.12.3, SQLite 3.45.1,
consolidated_schema.sqlof the branch,PRAGMA foreign_keys = ONas sqlx sets it. The SQL is extracted from the TypeScript sources as written (template literals ofsaveSplitAdjustment,getSplitChildren,updateTransactionCategoryInTransaction,propagateCategoryToOffsets,previewKeywordMatches,applyKeywordInTransaction;git show origin/main:for the code before the fix),$1bound by name; explicitBEGIN/COMMIT/ROLLBACKin autocommit mode. Totals by category add every row, as the reports do. Script and log in the run folder, nothing committed.saveSplitAdjustment)main: parent A → Cmain: keyword, every offered row checked (the dialog's default); the preview offers the parent, the entry and the offsetupdatedTransactions1, 1 offset movedupdatedTransactions0 (rowsAffected), 0 movedmain(S1), then fix C → D, by the list and by the keywordUPDATEfails (TEMP triggerRAISE(ABORT))ROLLBACK: parent still in A, A −70, B −50, no open transactionRows of the split window after S1 (SQL of
getSplitChildren): the filter ofmaingives[B 50, A 50],!isOffsetChildgives[B 50].Probe, build, tests:
src/zz_probe.test.tswith one failingexpect,npx vitest run src/zz_probe.test.ts: rc=1, file removed.npm run build(tsc + vite) green.npm test: 165 files / 2776 tests onmain→ 168 files / 2805 tests, all green.Mutations: 18, one at a time on the committed code, each restored by
git checkout --withgit status --shortempty after it; the five test files of the change run after each (script and log in the run folder). All red.transactionService.tscategorizationService.tssplitOffset.tssplitOffset.tscategorizationService.tstransactionService.tsROLLBACKremovedsplitOffset.tschild.amount !== 0removede130c34)splitOffsetService.tsparent_transaction_id) removedsplitOffsetService.tsis_splitcheck removedcategorizationService.tsAND parent_transaction_id IS NULLof the loop removedcategorizationService.tsupdatedTransactions++againSplitAdjustmentModal.tsxmainbacktransactionService.tstransactionService.tsawait getDb()(a deadlock under the real lock)categorizationService.tstransactionService.tsCOMMITsplitOffsetService.tstransactionService.tsBEGINremovedREVIEW.md
Zone « Migrations, profils et données »:
withTransaction:updateTransactionCategorynow holds the lock for its wholeBEGIN..COMMIT, on the handle its callback receives;propagateCategoryToOffsetsuses only the handle it is given (M14, M15) and issues noBEGIN/COMMIT, since it also runs inside theBEGINof the keyword path. Piège « Transaction hors verrou » avoided.toSqlFlag: the parent'sUPDATEstill bindstoSqlFlag(isManual)(tests of #390); no boolean bound anywhere;is_splitread throughtoSqlFlag.notifyDataChanged()after success: afterwithTransactionreturns (after theCOMMIT, lock released), never after aROLLBACK(tests of #396, M13); ADR 0022 row updated to say so.consolidated_schema.sqland the table/index/migration counts untouched.Zone « i18n et documentation »: no new string;
architecture.mdand both CHANGELOGs updated; user guide unchanged (no change of usage). Pièges « Tests sans jsdom » and « Fauxt»: the split window test goes throughhookHarness(effect run bycommit()) andi18nMock.REVIEW.mditself unchanged: no fact it cites becomes false.Hors périmètre
saveSplitAdjustmentanddeleteSplitAdjustment(neitherwithTransactionnor notification): #513, the next link of this stack, which starts from this branch.attachTransactions(dataExportService.ts) re-inserts the exported children with their oldparent_transaction_idafterDELETE FROM transactions, while the parents get new ids, and sqlx opens SQLite withforeign_keys = ON(sqlx-sqlite0.8.6,options/mod.rs:185). Replayed onconsolidated_schema.sqlwith the export query and theINSERTas written:FOREIGN KEY constraint failed. Not checked in the app.For the reviewer
updatedTransactionsnow counts the rows the guardedUPDATEchanged (rowsAffected): a child's id counts 0.AddKeywordDialogdoes not display it today.isOffsetChild(same description, opposite sign, non-zero) differ only for an offset whose description differs from its parent's: no query changes a description (planning decision of the issue).Vérifications manuelles dues (prochaine release)
Also added as one sub-bullet at the end of « Vérifications dues à la release suivante » in
STATE.md.In the Base edition, on a test profile, in FR then in EN:
🤖 Generated with Claude Code
Décisions prises sans Max (autopilot)
MEDIUM
STATE.md.db.ts, sur le chemin d'écriture le plus fréquent, devenu une transaction) ni la vraie fenêtre de répartition et les vrais rapports.HIGH
main(eecbd2b) : rouge,expected undefined to deeply equal [ 9, 7 ](aucunUPDATEde la compensation).answerSplitReads,answerReads), toute autre lecture faisant échouer le test, dans chaque test existant deupdateTransactionCategoryet d'applyKeywordWithReassignment, celui de l'ordreBEGIN/COMMITcompris.hookHarness(M12), « tout passe par le handle, rien pargetDb()» sur les deux chemins (M14, M15), un parent nul avec un enfant nul (M7, resté vert au premier passage, tué pare130c34).is_splitlu partoSqlFlag, lien au parent testé par!= null; enfants lusORDER BY id; la compensation ne reçoit quecategory_idetupdated_at(is_manually_categorizedintact, décision de planification).updatedTransactions += Number(result.rowsAffected ?? 0), le motif decategoryMigrationService.ts; propagation pour chaque identifiant, juste après sonUPDATE, la fonction écartant elle-même ce qui n'est pas un parent.architecture.mdcite pour les hooks, appliquée àsrc/services), 23 décrits, 21 utilitaires ; ligne 59 deCLAUDE.mdseule ; ligne detransactionService.tsdu tableau de l'ADR 0022 mise à jour (notification après leCOMMIT, aucune après unROLLBACK) ; guide d'utilisation et clésdocs.*inchangés : même geste, totaux justes.FOREIGN KEY constraint failed, rejoué surconsolidated_schema.sql), détail dans « Hors périmètre » du corps de la PR.Niveau : normal
Verdict : APPROVE
Auto-revue de l'auteur (worker
/autopilot, maillon 1 sur 3), pas une revue indépendante : la checklist de/pr-reviewappliquée à la profondeur du niveau normal sur le diff complet de la PR contre sa basemain(eecbd2b), tête1fad948. Elle ne remplace pas/pr-review.Résumé
La ligne de compensation d'une répartition suit désormais son parent sur les deux chemins de reclassement (liste des transactions, mot-clé avec réaffectation), dans la même transaction que lui, et ni l'aperçu d'un mot-clé ni sa boucle ne touchent plus un enfant seul. Le plan de l'issue est suivi point par point, D1 et D2 compris ; chaque critère d'acceptation a son test, les cinq mutations de l'issue rougissent, et le rejeu SQLite prouve les totaux par catégorie avec le SQL tel qu'il est écrit dans les sources.
Niveau (Step 0bis,
REVIEW.mddemain), fichier par fichiersrc/services/transactionService.ts,categorizationService.ts,splitOffsetService.ts(nouveau),src/utils/splitOffset.ts(nouveau),src/components/transactions/SplitAdjustmentModal.tsxet leurs tests : normal. La ligne « code livré » (zone Vie privée) n'est pas remplie : aucun appel réseau, aucun champ envoyé, aucune URL ouverte, aucun consentement touché. Aucune autre ligne du tableau Haut ne les désigne.docs/architecture.md,docs/adr/0022-canal-evenements-donnees.md,CLAUDE.md: normal (jamais bas).CHANGELOG.md,CHANGELOG.fr.md,STATE.md: bas.src-tauri/; aucun manifeste, lock, workflow, capability niREVIEW.md.Checklist
$1,$2), sans interpolation ; aucun secret, aucun.env; aucune entrée nouvelle venue de l'extérieur (les identifiants viennent de la base ou de la liste cochée de l'aperçu).src/services/transactionService.ts:309-344:withTransactionpuisBEGIN, l'UPDATEdu parent inchangé (toSqlFlag(isManual)),propagateCategoryToOffsetssur le handle reçu,COMMIT;ROLLBACKpuis relance dans lecatch;notifyDataChanged()l. 319, après le retour dewithTransactionseulement. Motif d'applyKeywordInTransaction, sans écart.src/services/splitOffsetService.ts:47-80: un identifiant inconnu, une transaction non répartie ou un enfant (l. 58,parent_transaction_id != null, puisque les enfants portent aussiis_split = 1) ne déclenchent aucune écriture ; la lecture des enfants n'a aucune condition de catégorie (D2) ; niBEGIN, nigetDb(), ni notification ; aucun import detransactionService.tsni decategorizationService.ts(grep dans le corps de la PR).src/services/categorizationService.ts:178: l'aperçu exclut les enfants ; l. 287-291 : l'UPDATEde la boucle ne touche qu'une ligne sans parent,updatedTransactionscompterowsAffected, la propagation tourne pour chaque identifiant avant leCOMMIT.src/components/transactions/SplitAdjustmentModal.tsx:52: la règle n'a plus de condition de catégorie ; l'ancienne et la nouvelle ne diffèrent que pour une compensation dont la description diffère de celle du parent, cas qu'aucune requête ne produit (aucunUPDATEdetransactionsne touchedescription, vérifié par grep).categoryIdnul (la compensation passe à nul), revenu réparti (compensation négative), parent de montant nul (aucune compensation reconnue), même catégorie choisie de nouveau (unUPDATEsans effet visible), identifiant coché deux fois (impossible,checkedest unSet).main(expected undefined to deeply equal [ 9, 7 ]) ; 29 tests de plus, aucunskipnionly; tests existants de #390 et #396 réécrits pour viser l'UPDATEdu parent par son SQL, avec les lectures de la propagation répondues par leur SQL (toute autre lecture fait échouer le test). Rejoué dans le worktree (npm ci) : sonde rc=1,npm run buildvert,npm test165/2776 surmain→ 168/2805, tous verts. 18 mutations, une à la fois, arbre propre après chacune : toutes rouges, dont les cinq de l'issue (propagation retirée M1/M2, signe inversé M3, description retirée M4, filtre de l'aperçu retiré M5,ROLLBACKretiré M6). Une seule était restée verte au premier passage (M7,child.amount !== 0retiré : seule une compensation nulle sous un parent nul passe le test de signe) ; tuée pare130c34.propagateCategoryToOffsetsrend un nombre que ses appelants n'utilisent pas, comme le plan le fixe, et que ses tests lisent ; conventions du dépôt (en-têtes de module,Number(result.rowsAffected ?? 0)decategoryMigrationService.ts) ; aucune chaîne visible ajoutée. Commits conventionnels,(#454)en fin de titre ; un seul mot-clé de fermeture, celui de la première ligne du corps, repris dans deux commits, et la timeline de l'issue porte exactement unpull_refcloses, celui de cette PR.consolidated_schema.sqlintact ; aucun seed.Zones de
REVIEW.mdtouchéeswithTransactionavec son handle (la propagation n'utilise que le handle reçu, mutations M14 et M15) ; booléen lié partoSqlFlag;notifyDataChanged()après succès seulement, avec ses tests (#396, mutation M13), et le tableau de l'ADR 0022 mis à jour.architecture.md(service, utilitaire, comptes recalculés parls … | grep -v '\.test\.ts$' | wc -l) et les deux CHANGELOG à jour ; guide inchangé, aucun changement d'usage.hookHarness, l'effet de chargement joué parcommit()puis un second rendu, ce que le test exerce bien (M12 le prouve) ; « Fauxt» :i18nMock.À corriger dans cette PR
Rien.
Non retenu
node:sqlite, commecategoryService.test.ts, garderait le SQL de la propagation exécuté par la CI ; le rejeu Python l'a exécuté une fois, sans rien commiter, comme le run le demandait.propagateCategoryToOffsetslit chaque transaction cochée par le mot-clé, répartie ou non : une lecture par clé primaire de plus par identifiant, sans effet mesurable.previewKeywordMatchesparle encore deLIKE ?1alors que la requête écrit$1: antérieur à la PR.Niveau : normal
Verdict : APPROVE
La compensation d'une répartition suit son parent sur les deux chemins de reclassement, dans la même transaction que lui, et le rejeu sur une vraie base le confirme. Un trou reste ouvert par « Catégoriser automatiquement » après un retrait de catégorie (item 1 ci-dessous, non bloquant :
mainest déjà faux dès le retrait).Ce que la revue a exécuté
git archive 1fad948,npm ci) : sonde rc=1,npm run buildvert,npm testà 168 fichiers et 2805 tests verts, comme le corps l'annonce. CI de la tête :check-frontend(run 670) vert ;check-rustnon déclenché, aucun fichier soussrc-tauri/.saveSplitAdjustment,updateTransactionCategory,previewKeywordMatches,applyKeywordWithReassignment,autoCategorizeTransactions,importTransactionsOnly) branchés surnode:sqlite, schéma d'un profil neuf (consolidated_schema.sql, seed compris), clés étrangères actives comme sous sqlx :main(eecbd2b) est rouge : le défaut est reproduit avec le code réel.updatedTransactionsà 1.cmp, avec les cinq fichiers de tests de la PR après chacune : sept rouges, une survivante.… || c.category_id !== transaction.category_id)nullau lieu decategoryIdisOffsetChild:!==au lieu de=== -entre les signesROLLBACKsans relancer l'erreurwithTransaction!parentretiréeCOMMITÀ corriger dans cette PR
src/services/splitOffsetService.ts:44-45et:74: la compensation gardeis_manually_categorized = 0, parce que « nothing reads it on a child » (docstring, et décision par défaut de la planification de #454). C'est faux :autoCategorizeTransactions(src/services/transactionService.ts:387) choisitcategory_id IS NULL AND is_manually_categorized = 0sur toutes les lignes, enfants compris.METROdu seed vers 1111 (Épicerie régulière) : −120 « EPICERIE METRO » réparti avec −50 vers B, puis « Aucune catégorie » dans la liste (TransactionTable.tsx:241,updateTransactionCategory(id, null, true)). Le parent passe à NULL avec le drapeau 1, la compensation à NULL avec le drapeau 0 ; totaux NULL −70 et B −50, corrects. Puis « Catégoriser automatiquement » : une ligne catégorisée, la compensation seule, en 1111. Totaux : 1111 +50, B −50, NULL −120. La compensation ne suit plus son parent jusqu'à son prochain changement de catégorie (D2).main, la même suite laisse +50 dans A dès le retrait de la catégorie. C'est un trou dans ce que la PR promet.is_manually_categorizeddans le SELECT du parent (fait après son UPDATE, donc le drapeau neuf) et l'écrire sur la compensation (SET category_id = $1, is_manually_categorized = $2, …, partoSqlFlag). R-S3 reste alors à NULL −70 et B −50. Neuf tests qui épinglent le texte ou les paramètres de l'UPDATE de la compensation sont à mettre à jour, un test du scénario à ajouter, la docstring à corriger.Décisions techniques prises par défaut (à contester)
is_manually_categorizedde son parent. Écarté : exclure les enfants de répartition d'autoCategorizeTransactionset y propager la catégorie, parce que ce diff sort du plan de l'issue et change le sort des entrées qu'une réinitialisation des catégories laisse à NULL.Non retenu
updateTransactionCategoryInTransaction, unROLLBACKqui échoue masque l'erreur d'origine, querunRestoregarde ; même motif qu'applyKeywordInTransaction.saveSplitAdjustmentcrée la compensation avec le drapeau 0, même sous un parent catégorisé à la main : après « Réinitialiser les catégories » (reinitializeCategoriesmet tout à NULL et remet les mots-clés du seed), « Catégoriser automatiquement » la sépare de son parent de la même façon. Antérieur à ce diff ; #513 réécrit cette fonction.Hors périmètre (observation de l'auteur, confirmée)
La restauration d'une sauvegarde qui contient une répartition échoue.
importTransactionsOnly, réel, sur les lignes degetExportTransactions:FOREIGN KEY constraint failed.attachTransactionsréinsère les enfants avec l'ancienparent_transaction_id, qu'AUTOINCREMENTne redonne jamais après leDELETE. LeROLLBACKderunRestorelaisse le profil intact.importTransactionsWithCategoriespasse par la même fonction. Cette revue n'ouvre pas d'issue.Décision autopilot
STATE.md. Elle ne change aucun comportement et ne s'écarte pas de l'issue : rien à confirmer.Vérifié sans constat
src/sont du code applicatif, sans appel réseau, URL ni consentement ; aucun manifeste, lock, workflow, migration ni fichier ajouté à la racine ou danssrc-tauri/.CLAUDE.md,docs/architecture.mdet l'ADR 0022 restent normaux ; les CHANGELOG etSTATE.mdsont bas.withTransaction, aucungetDb();is_splitlu partoSqlFlag, drapeau du parent lié partoSqlFlag; notification après leCOMMITseulement ; aucune migration,consolidated_schema.sqlintact.docs/architecture.mdet deCLAUDE.mdrecomptés : 29 services, 23 décrits, 21 utilitaires. CHANGELOG FR et EN sous Corrigé et Fixed ; aucune chaîne visible ajoutée.onlyniskip, commits conventionnels.Resolves #454; la timeline de #454 porte un seulcloses, celui de cette PR ; #513 est cité sans mot-clé.Actions faites
/tmp/pr515-*, scripts de mutation et journaux supprimés en fin de revue ; dépôt local non modifié (git statusvide).Reviewed-SHA:
1fad948f92Décisions de Max (2026-10-28, réponses à
/pr-reviewsur la pile)is_manually_categorizedde son parent quand celui-ci change de catégorie (remède de la revue), et aussi à la création d'une répartition (même trou, point « Non retenu » de la revue :reinitializeCategoriespuis la catégorisation automatique la séparaient de son parent). La PR #519 passe par/pr-reviewavant/merge-stack.type:bug,status:triage), seule issuesource:revuede la pile.Mergée en avance rapide par l'API, épinglée sur la tête relue
1fad948f9225f26bdcd5e8d2b5b6958e32691bee(revue 29728). Tip cumulé de la pile #515 → #516 → #517 → #519 éprouvé dans un worktree jetable (npm cipropre) : sonde rc=1, build vert, 172 fichiers / 2853 tests ; la pile ne touche nisrc-tauri/, ni.cargo/, ni les workflows, ni les manifestes et locks npm. Point 1 « À corriger » (drapeau manuel de la compensation) corrigé dans la pile par #519, sur décision de Max (29888) ; restauration d'une sauvegarde qui contient une répartition suivie en #518. Non retenu (revue 29728) : mot-clé appliqué à plusieurs identifiants dont un parent réparti qui n'est pas le premier, sans test (RM3) ;ROLLBACKen échec qui masque l'erreur d'origine ; drapeau 0 de la compensation à sa création, traité depuis par #519.