@davoodmehraban89 / Factor-easy / commits / 4ff4408
Fork 0

سامانه صدور فاکتور و حسابداری

docs(finora): record suspected pre-delete null-status bug and add strict draft precondition proof plan

davoodmehraban89 committed Nov 23, 2026 at 23:15 UTC 4ff440806a78dd1a5763a90270896e32e5e3db7c
1 file changed +6
PROJECT_STATE.md
+6
@@ -467,3 +467,9 @@ Next action: run and inspect Quality on the latest PR212 head. If any browser te
467 - **Actual WP1 local SQL on QA SHA `72cd4df6d1608b9be297e9bd1de24cd73fcccbac`**, [WP1 #45249837607](https://github.com/davoodmehraban89/Factor-easy/actions/runs/45249837607): `WP4_MANUAL_LIFECYCLE_PASS` and `WP4_TOMBSTONE_AND_NONREUSE_PASS` logged in real disposable PostgreSQL. This proves staged manual draft/post, fail-closed posted-delete and unchanged voucher/registry/2 lines, and draft delete tombstone/ATF nonreuse within test limits. However SQL then FAILED at `wp4_journal_document_lifecycle.sql:210` with `WP4_SOURCE_DELETE_DID_NOT_DELETE_VOUCHER`; **full WP1 test is NOT PASS**.
468 - **Source-level root cause found in QA fixture:** candidate `finora_journal_document_lifecycle_trigger` in `20261118100000_journal_document_lifecycle.sql` source-delete branch (lines ~644–656) looks up `OLD.data->>'journalVoucherId'` to find and delete the linked draft voucher. The SQL fixture manually inserted both synthetic `invoices` rows with `documentStatus/accountingStatus=draft` but **omitted the required `journalVoucherId` pointer**, then independently inserted vouchers with reverse `sourceId`. Consequently voucher→source delete positive path passed (uses sourceId), but source→voucher deletion test attempted deletion of an **unlinked fixture**. This is not evidence of real linked-delete failure.
469 - **Pre-implementation decision:** on QA Draft PR247 correct only the two synthetic invoice fixture JSON objects to reference their corresponding `WP4_SOURCE_V_A` and `WP4_SOURCE_V_B` via `journalVoucherId`. Keep reverse `sourceType/sourceId` parity and all existing source↔voucher/tombstone assertions, no migration/product/permissions/security changes. Rerun exact-head WP1 and examine actual final outcome; fail closed on any new issue. Parent PR219 Quality/Security JS and WP2 auth fixture remain independent blockers. Stage progress A90/B50/C20/D55/E53/F10 unchanged.
470 +
471 +
472 +### 2026-11-23 — FIN-QA-219-WP4-SOURCE-DELETE-RLS-GUARD / real local failure and precondition-proof decision
473 +- **Actual tested QA HEAD `9ede2a596b2f12ad05e530e27d8dcf6587a6ca69`**, [WP1 #45250410434](https://github.com/davoodmehraban89/Factor-easy/actions/runs/45250410434): disposable SQL reached `WP4_MANUAL_LIFECYCLE_PASS` and `WP4_TOMBSTONE_AND_NONREUSE_PASS`, then failed **`source record linked to posted/reversed accounting history is immutable`** when deleting `WP4_INV_B` linked to a just-inserted `WP4_SOURCE_V_B` draft. Error originates from `public.finora_guard_posted_source_records()` (source migration `20261117120000_wp1_stage3_canonical_source_link_projection.sql`), not the fixture's own explicit failure assertion. This is a potentially **real product integration blocker P1** in PR219, distinct from earlier missing JSON link and independent of ordinary posted-history immutability.
474 +- **Code-grounded causal hypothesis**: new PR219 lifecycle BEFORE DELETE trigger (migration `20261118100000_journal_document_lifecycle.sql`, lines ~640–655) deletes linked draft voucher on source DELETE when `journalVoucherId` exists. Existing `finora_guard_posted_source_records()` queries voucher status using `SELECT ... INTO voucher_status`; no matching voucher yields NULL, and `source_locked := ... OR voucher_status IN ('posted','reversed')` becomes NULL for otherwise-unlocked source. `IF NOT source_locked THEN RETURN` does not return on NULL and raises posted-history immutability error. This could arise from ordered BEFORE DELETE triggers; **not yet separately instrumented** to prove trigger order and no preexisting posted status. The earlier unlinked source deletion had simply left an orphan voucher; when link was added the guard now blocks deletion.
475 +- **Before further test edit**, add only explicit existing-PERSISTED source `accountingStatus/documentStatus=draft` and linked journal `status=draft` assertions/NOTICE to the QA SQL fixture immediately before the source DELETE. This will make the next executable log prove whether both rows were definitely draft immediately before the failing request; do not change production guards or weaken posted history protection. Retain strict delete/tombstone assertions (no xfail), verify new exact-head local WP1. If failure survives with both draft preconditions, open separate P1 blocking issue and handoff to Codex-main; do NOT turn failing product scenario into passing QA. Parent PR219 still has independent Quality/Security Syntax, WP2 Auth fixture, historic posted→draft risks. No Prod/main/merge. A90/B50/C20/D55/E53/F10 unchanged.