@davoodmehraban89 / Factor-easy-2 Mirror · read-only / commits / 2170974
Fork 0

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

Mirrored from https://github.com/davoodmehraban89/Factor-easy.git

Synced Dec 3, 19:30 UTC

test(wp2): enforce posted source and ledger immutability via real JWT

davoodmehraban89 committed Nov 22, 2026 at 07:57 UTC 21709742c51a296b0d6044dc5125374c017de3aa
3 files changed +68
docs/ACCOUNTING_CORE_ROADMAP_V1.md
+2
@@ -441,6 +441,8 @@ This register maps execution stages A/B to the **existing** accounting Phase 6 (
441
442 | FIN-QA-ATF-CONCURRENCY | اثبات هم‌زمانی شماره عطف دائمی در کاندیدای موجود | QA مستقل؛ یکپارچه‌سازی Codex اصلی | ADR0216، `supabase/candidates/0216_attachment_registry.sql`، WP1 | در بررسی / منتظر CI | دو اتصال واقعی با شناسه مشترک/مستقل، عدم جابه‌جایی شرکت، rollback/tombstone/tenant | QA successor stacked on PR225 | WP1 تک‌نشستی روی PR225 موفق؛ آزمون دو‌نشستی جدید هنوز اجرا نشده | WP1 روی SHA جدید، بازبینی Codex اصلی؛ **فقط کاندیدا، نه محصول** |
443
444 +| FIN-QA-POSTED-SOURCE-GUARD | منع تغییر و حذف سند منشأ قطعی از JWT واقعی | QA مستقل؛ تصمیم نهایی Codex اصلی | PR225 source-autopost و Stage3 guard موجود | در بررسی / منتظر CI | رد صریح PATCH/DELETE، جعل پیوند، سطر دفتر کل و حذف voucher؛ بدون تغییر داده/audit | QA successor stacked on PR226 | PR226 سه گیت موفق؛ WP2 برای SHA جدید باید اجرا شود | آزمون و بازبینی مستقل، بدون تغییر محصول |
445 +
446 **Release boundary:** successful Pages run 43606173842 applies only to `main dab1a45`; no candidate above is `منتشرشده`. Competing PR214/215/217/219 are alternative implementations, not sequential milestones. This worker changes documentation only; Codex main owns integration and release decisions.
447
448
docs/EXECUTION_STATUS.md
+6
@@ -1,5 +1,11 @@
1 # وضعیت اجرای فینورا
2
3 +### ۲۰۲۶-۱۱-۲۲ — FIN-QA-POSTED-SOURCE-GUARD؛ آزمون منع تغییر سند قطعی با JWT
4 +- **مبنای محفوظ:** PR226 `4f9a90c9a955800cd0ed83dc0184a5c2e8343a87`: Quality `44983973522`، WP1 `44983973555`، Security `44983973523` SUCCESS؛ WP2 روی آن SHA اجرا نشده. PR225 WP2 `44982300960` موفق بود و سند قطعی را ایجاد کرد.
5 +- **کار محدود:** افزودن سناریوی منفی به `scripts/wp2-source-autopost-jwt-e2e.mjs` موجود: در tenant مصنوعیِ Supabase موقت پس از ثبت، حالت مالی `enforce` فعال و PATCH/DELETE حقیقی از سمت JWT صاحب سند برای تغییر فیلد تجاری، جعل پیوند، حذف منبع، تغییر سطر posted و حذف voucher از RPC انجام می‌شود. آزمون باید رد صریح guard مالی و عدم تغییر data/audit/counter را اثبات کند، نه تنها پاسخ RLS.
6 +- **مرز:** هیچ SQL migration، RBAC، Auth، کد مالی یا داده Production تغییر نکرده است. وضعیت: در بررسی تا CI exact-head WP2 و Quality/WP1/Security؛ موفقیت پیشین به HEAD جدید قابل تعمیم نیست. اتصال کامل سند موقت و ATF تاریخچه همچنان بازند.
7 +
8 +
9 ### ۲۰۲۶-۱۱-۲۲ — FIN-QA-ATF-CONCURRENCY؛ آزمون دو‌اتصالی کاندیدای شماره عطف
10 - **مرحله B/C قبلی پذیرفته‌شده در تست:** PR225 SHA `9122b8b8da0d0a2e4f8976030a6f7c4ef3bcc91a`: Quality `44982300952`، WP1 `44982300977`، WP2 `44982300960`، Security `44982300947` همگی SUCCESS؛ ۲۵۱/۲۵۱ مرورگر و ۴/۴ تکمیلی، Dependency review skipped. PR225 منتشر/ادغام نشده و Codex اصلی باید مستقل بررسی کند.
11 - **شکاف مشخص:** `supabase/tests/0216_attachment_candidate.sql` تخصیص شماره عطف، retry، tombstone، حذف منطقی و بازگشت را داخل یک نشست PostgreSQL اثبات می‌کند؛ **رقابت دو نشست واقعی** را جداگانه اثبات نکرده بود.
scripts/wp2-source-autopost-jwt-e2e.mjs
+60
@@ -215,3 +215,63 @@ assert.ok(auditCount(a.voucher.id)>=2,'concurrent winner is missing audit trail'
215 assert.equal(auditWrongActors(a.voucher.id),0,
216 'concurrent source posting audit actor must be Auth JWT subject');
217 console.log('FINORA_SOURCE_JWT_ATOMIC_PASS: real user JWT positive source link/replay, injected late-link rollback with unchanged counter, and two-request source concurrency; audit attribution and rollback also verified in disposable Supabase');
218 +
219 +// 4. Auth-JWT negative contract for the REAL persisted posted source.
220 +command('INSERT INTO private.finora_phase1a_guard_modes(organization_id,mode) VALUES ('+
221 + q(org)+",'enforce') ON CONFLICT (organization_id) DO UPDATE SET mode='enforce';");
222 +async function userRestMutation(method,collection,id,data){
223 + const url=new URL(api+'/rest/v1/records');
224 + for(const [key,value] of Object.entries({
225 + organization_id:org,collection,id
226 + }))url.searchParams.set(key,'eq.'+value);
227 + const res=await fetch(url,{method,
228 + headers:{apikey:anon,Authorization:'Bearer '+jwt,
229 + 'Content-Type':'application/json',Prefer:'return=representation'},
230 + ...(data===undefined?{}:{body:JSON.stringify({data})})
231 + });
232 + const raw=await res.text();let body;
233 + try{body=JSON.parse(raw)}catch{body=raw}
234 + return {status:res.status,body};
235 +}
236 +function financialGuardRejected(result,label,pattern){
237 + assert.ok(result.status>=400&&result.status<500,
238 + label+' succeeded or had unexpected status: '+JSON.stringify(result));
239 + assert.ok(result.body&&typeof result.body==='object'&&
240 + ['23514','P0001'].includes(String(result.body.code||'')),
241 + label+' was only RLS denied or did not hit financial guard: '+JSON.stringify(result));
242 + assert.match(JSON.stringify(result.body),pattern,label+' wrong guard error');
243 +}
244 +const frozenSource=(await sourceRow(firstSource)).data;
245 +const frozenVoucher=(await voucherRows(firstSource))[0];
246 +const frozenLines=await voucherLines(firstVoucher);
247 +const frozenCounter=counter(),frozenAudit=auditCount(firstVoucher);
248 +financialGuardRejected(await userRestMutation('PATCH','invoices',firstSource,{
249 + ...frozenSource,description:'forged commercial amendment'
250 +}),'posted sale commercial edit',/FINORA_POSTED_SOURCE_IMMUTABLE|linked to posted\/reversed/i);
251 +financialGuardRejected(await userRestMutation('PATCH','invoices',firstSource,{
252 + ...frozenSource,journalVoucherId:'FORGED_JOURNAL',documentStatus:'draft'
253 +}),'posted sale accounting projection forgery',
254 + /FINORA_POSTED_SOURCE_LINK_PROJECTION_INVALID|linked to posted\/reversed/i);
255 +financialGuardRejected(await userRestMutation('DELETE','invoices',firstSource),
256 + 'posted sale direct delete',/FINORA_POSTED_SOURCE_IMMUTABLE|linked to posted\/reversed/i);
257 +financialGuardRejected(await userRestMutation('PATCH','journalLines',frozenLines[0].id,{
258 + ...frozenLines[0].data,debit:1
259 +}),'posted journal line edit',/FINORA_POSTED_JOURNAL_CHILD_IMMUTABLE/i);
260 +const deniedVoucherDelete=await rpc('finora_journal_delete_draft',{
261 + p_organization_id:org,p_voucher_id:firstVoucher,
262 + p_expected_version:frozenVoucher.version
263 +},jwt);
264 +assert.ok(deniedVoucherDelete.status>=400&&deniedVoucherDelete.status<500,
265 + 'posted source voucher delete_draft RPC succeeded');
266 +assert.match(JSON.stringify(deniedVoucherDelete.body),
267 + /FINORA_JOURNAL_NOT_DRAFT|FINORA_SOURCE|FORBIDDEN/i,
268 + 'posted source voucher RPC did not reject for a financial reason');
269 +assert.deepEqual((await sourceRow(firstSource)).data,frozenSource,
270 + 'posted source changed after denied JWT mutation');
271 +assert.deepEqual((await voucherRows(firstSource))[0],frozenVoucher,
272 + 'posted voucher changed after denied JWT mutation');
273 +assert.deepEqual(await voucherLines(firstVoucher),frozenLines,
274 + 'posted journal lines changed after denied JWT mutation');
275 +assert.equal(counter(),frozenCounter,'denied JWT action changed final counter');
276 +assert.equal(auditCount(firstVoucher),frozenAudit,'denied JWT action changed audit');
277 +console.log('FINORA_POSTED_SOURCE_JWT_IMMUTABLE_PASS: live JWT source edit, forged link, delete, posted journal line edit and linked voucher delete rejected by financial guard; source, voucher, lines, counter and audit unchanged');