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

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

test(phase1a): prevent false client compatibility PASS with enforced guard

davoodmehraban89 committed Oct 17, 2026 at 07:20 UTC 4f45335aaf20662c6c86bb9e5e74ac6301121ddf
2 files changed +8 -1
PROJECT_STATE.md
+5
@@ -93,3 +93,8 @@
93
94 ### 2026-10-17 — Stage 1 seeded full PASS, counter test private-grant fix (PENDING NEW CI)
95 - Exact SHA 2e708fdec5bc29d3b5530b59035d0da82702b4a6, run 38998387737: 1000 seeded events and 238 full/114 partial reversals, voucher balance, both organization balances and cross-org leak assertion PASS. Two-year counter test line 65 failed only when authenticated test role tried SELECT of deliberately private counters. Kept ACL unchanged; moves private table read-only assertions after RESET ROLE to disposable PostgreSQL DBA while all posting operations remain authenticated RPC. CI rerun pending, no Production writes or Stage2/3 work.
96 +
97 +### 2026-10-17 — Stage 1 exact-SHA isolated server QA PASS; Stage 2 legacy client test fixture exposed as false-positive
98 +- GitHub Actions run 38999356580 on exact branch SHA 8ff8357e12f772188e2f7c818778ae2447bbcdc6 concluded SUCCESS. Logs verify deterministic 1000 event seed 20261016 / 2 organizations / 238 full+114 partial reversals, all ledger and tenant property checks; 2-year counter baseline 40->41 and 11->12 with rollback; true 2-connection simultaneous duplicate draft and gapless posts plus same-line partial reversal race (one winner), conservative UP/DOWN/UP (audit/counters/posted original retained), every public/private SECURITY DEFINER searched and none with unsafe path/effective anon/PUBLIC grants, 1069 matching baseline objects and 154 lexical-equivalent function sources.
99 +- IMPORTANT QA limitation: scripts/phase1a-positive-client-contract.mjs was PASS 3/3 only because fixture guard was implicitly OFF; that pass CANNOT establish real client compatibility with enforce. Test fixture now sets disposable org to enforce, re-executes same real psql 3 scenarios, and should expose known Stage2 legacy JS incompatibility. Do not remove or mark compatibility green if it fails. Exact new SHA run is PENDING.
100 +- Stage 1 server SQL foundation has positive evidence, but source autopost currently guarantees persisted source identity/type, amount and journal sum, NOT fully canonical source-account mappings for each module (Stage 3 risk); full Production readiness, staging browser E2E, actual encrypted backup/restore and Production guard enforce all NOT VERIFIED. Owner-approved work STOP before Stage2 and Stage3, main merge, Production DDL/DML, deployment.
scripts/phase1a-positive-client-contract.mjs
+3 -1
@@ -1,5 +1,7 @@
1 #!/usr/bin/env node
2 // POSITIVE legacy JS client contract -- must pass before any 1A deployment.
3 +// IMPORTANT: synthetic organization must use guard mode enforce. A default-off
4 +// fixture yields a false green and MUST NOT certify Stage 2 compatibility.
5 // Existing js/journal-engine.js creates draft with status/number, then posts
6 // by mutating status/postedAt. Authenticated/RLS path must remain operable
7 // through an approved server-controlled action contract, not raw field bypass.
@@ -10,7 +12,7 @@ const q=s=>"'"+JSON.stringify(s).replace(/'/g,"''")+"'::jsonb";
12 const voucher={id:'POSITIVE_JV_1',companyId:'CO',fiscalYearId:'FY',date:'1405/07/24',status:'draft',number:'1',totalDebit:100,totalCredit:100,createdBy:uid};
13 const line=(id,debit,credit)=>({collection:'journalLines',id,data:{voucherId:voucher.id,companyId:'CO',accountId:id,debit,credit},expected_version:0});
14 const v={collection:'journalVouchers',id:voucher.id,data:voucher,expected_version:0};
13 -const head=["BEGIN;","INSERT INTO auth.users(id,instance_id,aud,role,email,email_confirmed_at,raw_user_meta_data) VALUES('"+uid+"','00000000-0000-0000-0000-000000000000','authenticated','authenticated','phase1a-positive@example.invalid',now(),'{}'::jsonb);"].join('\n');
15 +const head=["BEGIN;","INSERT INTO auth.users(id,instance_id,aud,role,email,email_confirmed_at,raw_user_meta_data) VALUES('"+uid+"','00000000-0000-0000-0000-000000000000','authenticated','authenticated','phase1a-positive@example.invalid',now(),'{}'::jsonb);","INSERT INTO private.finora_phase1a_guard_modes(organization_id,mode) SELECT organization_id,'enforce' FROM public.organization_members WHERE user_id='"+uid+"';"].join('\n');
16 const rpc=(up)=>"SELECT public.finora_sync_records_v2("+q(up)+",'[]'::jsonb,"+org+");";
17 const scenarios=[
18 {name:'existing-client-draft-with-status-and-number',body:[rpc([v])]},