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

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

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

Synced Dec 4, 06:45 UTC

test(finora): preserve retry replay PASS and execute stable-ID P0 expected RED for sale/purchase

davoodmehraban89 committed Nov 22, 2026 at 20:12 UTC 79bf54020e07c1406690afd8e6ab924af329b48d
1 file changed +42 -7
scripts/journal-rpc-adapter.test.mjs
+42 -7
@@ -228,19 +228,54 @@ test('auto-post never calls server when source draft persistence is not acknowle
228 assert.equal(h.calls.some(x=>x.name==='finora_journal_autopost'),false);
229 });
230
231 -test('ambiguous auto-post retry reuses source identity and accepts server idempotent replay',async()=>{
232 - const h=sourceHarness('sale',{loseFirstResponse:true});
233 - await assert.rejects(()=>h.context.jeRpcAutoPost('sale',h.source.id),/network response lost/);
231 +// Contract sentinel: unlike a TODO/XFAIL, these assertions must fail CI if
232 +// source identity, tenant, fiscal context, persisted link or replay changes.
233 +// The separate TODO cases below test the still-broken *request identity* rule.
234 +async function observeAmbiguousAutoPostReplay(kind){
235 + const h=sourceHarness(kind,{loseFirstResponse:true});
236 + await assert.rejects(()=>h.context.jeRpcAutoPost(kind,h.source.id),/network response lost/);
237 assert.equal(h.source.accountingPostingPending,true);
235 - const v=await h.context.jeRpcAutoPost('sale',h.source.id);
238 + const voucher=await h.context.jeRpcAutoPost(kind,h.source.id);
239 assert.equal(h.source.accountingPostingPending,undefined);
240 const calls=h.calls.filter(x=>x.name==='finora_journal_autopost');
241 assert.equal(calls.length,2);
242 + const collection=kind==='sale'?'invoices':'purchases';
243 + for(const {args} of calls){
244 + assert.equal(args.p_organization_id,'ORG_A');
245 + assert.equal(args.p_source_collection,collection);
246 + assert.equal(args.p_source_id,h.source.id);
247 + assert.equal(args.p_header.companyId,'CO_A');
248 + assert.equal(args.p_header.fiscalYearId,'FY_A');
249 + assert.equal(args.p_header.sourceType,kind);
250 + assert.equal(args.p_header.sourceVersion,'1');
251 + assert.ok(typeof args.p_voucher_id==='string'&&args.p_voucher_id.length>0);
252 + assert.deepEqual(Array.from(args.p_lines),[]);
253 + }
254 assert.equal(calls[0].args.p_source_id,calls[1].args.p_source_id);
255 assert.equal(calls[0].args.p_source_collection,calls[1].args.p_source_collection);
241 - assert.notEqual(calls[0].args.p_voucher_id,calls[1].args.p_voucher_id);
242 - assert.equal(v.id,'JV_SERVER_sale');
243 -});
256 + assert.equal(voucher.id,'JV_SERVER_'+kind);
257 + assert.equal(h.source.journalVoucherId,voucher.id);
258 + assert.equal(h.source.accountingStatus,'posted');
259 + assert.equal(h.source.documentStatus,'posted');
260 + assert.equal(h.records.journalVouchers.filter(v=>v.id===voucher.id).length,1);
261 + return {calls};
262 +}
263 +
264 +for(const kind of ['sale','purchase']){
265 + test('ambiguous '+kind+' auto-post keeps tenant/source/version and replays only one linked voucher',async()=>{
266 + await observeAmbiguousAutoPostReplay(kind);
267 + });
268 + test('P0 expected RED: ambiguous '+kind+' auto-post must reuse exact voucher request ID',{
269 + todo:'#216: current jeRpcAutoPostOnce generates a NEW p_voucher_id on retry; TODO executes the required equality assertion'
270 + },async()=>{
271 + const {calls}=await observeAmbiguousAutoPostReplay(kind);
272 + const before=calls[0].args.p_voucher_id,after=calls[1].args.p_voucher_id;
273 + // The normal-PASS case above checks the fixture and result independently;
274 + // only this one known product invariant may be a transparent expected RED.
275 + if(before!==after)console.log('FINORA_ISSUE216_RETRY_ID_EXPECTED_RED '+kind+': source replay succeeded but p_voucher_id changed across ambiguous response');
276 + assert.equal(after,before,'ADR216 requires the exact request identity on retry');
277 + });
278 +}
279
280
281 test('source finalizers no longer create or post journal rows through the legacy local engine',async()=>{