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

docs: record exact-head ADR216 history migration guard CI proof and limits

davoodmehraban89 committed Nov 22, 2026 at 12:55 UTC 3cdbfd5a213098f59518fb1b5757c4c16ddeed03
2 files changed +11
PROJECT_STATE.md
+6
@@ -543,3 +543,9 @@ Next action: run and inspect Quality on the latest PR212 head. If any browser te
543 - **Proven issue:** Existing Draft PR217 and PR219 new SQL migrations use `UPDATE public.records ... status='draft'/jsonb_build_object('status','draft')` on existing posted/reversed journal and transactional records without source-status exclusion, deleting posting metadata. Both PRs have RED CI and violate ADR0216. Preserve the immutable posted history regardless of QA green status.
544 - **Next narrowly bounded implementation:** strengthen EXISTING Security workflow with a diff-scoped SQL history-downgrade tripwire for ADDED/MODIFIED `supabase/migrations/*.sql` files on PR base→head. Scan UPDATEs of persisted `public.records` that assign accounting lifecycle status/documentStatus/accountingStatus to `draft`; fail closed with filename/line and explanatory non-release instruction. Use shallow-insensitive checkout fetch-depth 0 and explicit PR base SHA; on push use previous SHA, and for manual dispatch fall back to HEAD parent. Test synthetic exact-shaped PR217/PR219 destructive UPDATEs and safe INSERT-only / unrelated UPDATE examples. This is an automated **heuristic guard** against one dangerous class, NOT proof every migration is non-destructive; manual code review and isolated historical parity tests remain required.
545 - **Strict scope:** only existing `PROJECT_STATE.md`, Security workflow, a minimal reusable guard and focused tests (wire to existing Quality). Do not touch product JS, SQL migrations, RLS/Auth/role grants, posted history, hosted/prod data, owner-held modules, main, merge or deployment. Keep prior QA GREEN SHA recoverable and PR230 Draft. Verify exact new SHA Quality/WP1/Security; WP2 not claimed unless triggered.
546 +
547 +### 2026-11-22 — FIN-ADR216-STOP-DESTRUCTIVE-MIGRATION — verified evidence and handoff
548 +- **Implemented QA/Security defense in depth, not product lifecycle:** SHA `79f0476ffa01abbb9217d07972f1385ff84997a5`, Draft PR230. New read-only/diff-only `scripts/accounting-history-migration-guard.mjs` inspects ADDED/MODIFIED SQL migrations from PR base to HEAD; flags `UPDATE public.records` that assign historical accounting lifecycle fields back to `draft`. Existing Security workflow checks out full history, executes this guard fail-closed; existing Quality runs 3 synthetic diff/SQL tests. No migration, SQL role/grant, posted financial history, hosted database, product JS or protected main changed.
549 +- **Exact-head gate proof:** [Quality 45006315280](https://github.com/davoodmehraban89/Factor-easy/actions/runs/45006315280) SUCCESS (4/4 jobs; 3/3 new tripwire tests, 253/253 browser including two **expected RED** Issue229 cases, 4/4 Pages); [WP1 45006315251](https://github.com/davoodmehraban89/Factor-easy/actions/runs/45006315251) SUCCESS (both jobs; 19/19 SQL, 1000 seeded multi-org events, two-session concurrency, graph and rollback checks; ATF marker explicitly candidate only; artifact `wp1-disposable-ledger-evidence` ID 14748168854); [Security 45006315249](https://github.com/davoodmehraban89/Factor-easy/actions/runs/45006315249) SUCCESS (CodeQL, release QA safety and new history-downgrade migration guard; Security scanned **0 changed migrations** on this QA-only diff; conditional Dependency Review SKIPPED). WP2 NOT triggered on this SHA; predecessor PR228 genuine JWT posted sale+purchase check remains separately green.
550 +- **Actual source inspection (not staged migration execution):** PR217 SQL `20261118100000_document_lifecycle_temp_permanent_atef.sql` matches the conservative guard at lines 123,195; PR219 SQL `20261118100000_journal_document_lifecycle.sql` at lines 204,221,232,394,404,478; PR215 SQL `20261118090000_document_lifecycle_atf_and_atomic_delete.sql` none for this pattern. Later PR219 matches may be draft-CRUD updates, so treat scanner findings as mandatory code review, not automatic proof all matching statements are unsafe. The destructive blanket historical posted→draft statements are in PR217/219. Owner blocking evidence: [Issue216 comment 7077099276](https://github.com/davoodmehraban89/Factor-easy/issues/216#issuecomment-7077099276).
551 +- **Limit and next:** This heuristic does not parse all SQL/dynamic SQL or prove history safety; synthetic QA and repository probe do not replace an approved read-only historical reconciliation and disposable original-posted/reversed graph parity/rollback tests. The two Issue229 browser cases remain intentionally `test.fail` and financial source-linked draft-first CRUD plus independent authorized finalize is NOT implemented. PR230/PR228 remain Draft, unmerged. Protected main stays `dab1a45fcfc4f12e675cfe055e477138cd3e99fa`. Do not close Issue216 or Issue229, merge PR217/219, touch hosted data, or claim production readiness. Codex-main owns final integration.
docs/EXECUTION_STATUS.md
+5
@@ -156,3 +156,8 @@
156 - **SHA دقیق QA:** `dec68c030189b0d6733443f8f3a6e1715844346f`. [Quality 44988270042](https://github.com/davoodmehraban89/Factor-easy/actions/runs/44988270042) موفق: ۲۵۳/۲۵۳ آزمون مرورگر، ۴/۴ آزمون Pages و سه Job دیتابیسی؛ دو آزمون Issue229 عمداً در assertion مالی شکست موردانتظار داشتند و با `test.fail` ثبت شدند. [WP1 44988270066](https://github.com/davoodmehraban89/Factor-easy/actions/runs/44988270066) هر دو Job موفق؛ [Security 44988270049](https://github.com/davoodmehraban89/Factor-easy/actions/runs/44988270049) موفق (CodeQL و Release Safety؛ Dependency Review به‌صورت مشروط Skipped). WP2 به‌علت تغییر صرفاً آزمون/مستندات اجرا نشد.
157 - **شواهد قابل بازرسی WP1:** artifact با شناسه `14741081943`. PostgreSQL 17 مستقل و مشتق‌شده از سورس، ۲۲ مهاجرت مرحله‌ای را اعمال کرد؛ ۱۹/۱۹ آزمون SQL و آزمون هم‌زمانی دو نشست موفق شدند. آزمون تصادفی ۱۰۰۰ رویداد را در دو سازمان ساخت و توازن اسناد و برگشت‌ها و نبود نشت بین سازمانی را کنترل کرد. چرخه UP/DOWN/UP مهاجرت اصلاحی، ابعاد برگشت، guard ویرایش دستی، NULL revision، خواندن گراف، snapshot هم‌زمان و DOWN/UP محافظه‌کارانهٔ کل کاندیدا موفق شدند. محدودیت: این محیط کپی Production یا پذیرش واقعی Auth/JWT/PostgREST نیست؛ DOWN مهاجرت اصلاحی به‌تنهایی schema pristine ایجاد نمی‌کند و شمارنده‌ها/helperها را نگه می‌دارد؛ allocator شماره عطف هنوز candidate است و اتصال نهایی آن به چرخه محصول اثبات نشده است.
158 - **وضعیت محصول تغییر نکرده:** Issue229 و ADR216 باز؛ PR228 و PR230 همچنان Draft و ادغام‌نشده؛ main بدون تغییر در `dab1a45fcfc4f12e675cfe055e477138cd3e99fa`. هیچ کد مالی، migration، دیتابیس میزبانی‌شده یا داده Production تغییر نکرد و انتشار انجام نشد. دو تست expected-RED اثبات نقص هستند، نه رفع آن. اقدام بعدی مالک هسته در Codex اصلی: پیاده‌سازی تراکنش واحد ایجاد/ویرایش/حذف ممیزی‌شدهٔ منبع+پیش‌نویس متصل و قطعی‌سازی مستقل مجاز؛ سپس حذف `test.fail` و اثبات PASS عادی با مرورگر و JWT واقعی. guardهای manual-only و autopost اتمیک فعلی حفظ شوند؛ موتور موازی ساخته نشود.
159 +
160 +### ۲۰۲۶-۱۱-۲۲ — کنترل خودکار مهاجرت‌های مخرب تاریخچه (QA مستقل، بدون انتشار)
161 +- **Commit کد آزموده‌شده:** `79f0476ffa01abbb9217d07972f1385ff84997a5`، Draft PR230. به Security کنترل تفاوت فایل‌های مهاجرت SQL اضافه شد تا دستور UPDATE رکوردهای موجود به `draft` را با پیام متوقف‌کننده علامت‌گذاری کند. کنترل فقط «هشدار محافظه‌کارانه» است و هیچ داده یا اسکیما را نمی‌نویسد.
162 +- **شواهد:** [Quality 45006315280](https://github.com/davoodmehraban89/Factor-easy/actions/runs/45006315280) موفق: ۳/۳ آزمون کنترل مهاجرت، ۲۵۳/۲۵۳ مرورگر (دو مورد Issue229 همچنان شکست موردانتظار هستند)، ۴/۴ Pages و سه Job دیتابیسی. [WP1 45006315251](https://github.com/davoodmehraban89/Factor-easy/actions/runs/45006315251) موفق: هر دو Job، ۱۹ SQL، هزار رویداد، هم‌زمانی و rollback؛ شاهد `14748168854`. [Security 45006315249](https://github.com/davoodmehraban89/Factor-easy/actions/runs/45006315249) موفق: CodeQL و کنترل مهاجرت (در Diff این PR صفر migration تغییر کرده)؛ Dependency Review به‌صورت مشروط Skipped. WP2 روی این SHA اجرا نشده است.
163 +- **بررسی تطبیقی:** متن SQL واقعی PR217 در ۲ نقطه و PR219 در ۶ نقطه با قاعدهٔ محافظه‌کارانه منطبق بود؛ این الزام بررسی است نه اثبات خطرناک‌بودن تک‌تک UPDATEها. مهاجرت عمومی posted→draft در هر دو PR صریحاً ممنوع است. Issue216 و Issue229 باز؛ ادغام، استقرار، تغییر Production، کد مالی، Auth/RLS یا migration انجام نشد. کنترل تا زمان ادغام در شاخه اصلی فعال نیست؛ بررسی مستقل Codex اصلی لازم است.