Verify queued posting faults remain isolated and retryable

This commit is contained in:
unimatrixgit 2026-11-13 21:50:04 +01:00
commit e713ca2aad
2 changed files with 3 additions and 1 deletions

View file

@ -82,4 +82,4 @@ Amounts are exact decimal strings converted to integer minor units. The transact
The UI retains the same request on an uncertain response and does not automatically resend. Statements show a wide reference, named counterparties with expandable account numbers, signed direction colours, queued/posted/rejected state, posted balance where applicable and 25-row pagination. Queries cannot select another actor's account. Only the bottom collapsed workspace control reloads the view.
Validation before CI: 35 focused bank/cutover/navigation checks passed; isolated real MySQL checks passed five concurrent reservations, two simultaneous posting workers with exactly five posts, balanced ledger legs, instant quota enforcement, recipient lookup and ten statement records. All temporary QA tables were removed; no real customer funds were used. Worker build and complete-source CI remain required before release. Bank administrative views are the following batch; deferred credit/payroll/tax work stays separate.
Validation before CI: 36 focused bank/cutover/navigation checks passed; isolated real MySQL checks passed five concurrent reservations, two simultaneous posting workers with exactly five posts, balanced ledger legs, instant quota enforcement, recipient lookup and ten statement records. All temporary QA tables were removed; no real customer funds were used. Worker build and complete-source CI remain required before release. Bank administrative views are the following batch; deferred credit/payroll/tax work stays separate.

View file

@ -19,3 +19,5 @@ test('failed ledger posting rolls back both balances, instant usage and the inst
test('recipient lookup is literal and statements expose only authorised account records',async()=>{const f=await setup();try{const r=await f.service.recipients(f.users[0],f.current(1).account_number);assert.equal(r.length,1);assert.equal(r[0].number,f.current(1).account_number);assert.equal((await f.service.recipients(f.users[0],'citizen_1')).length,2);assert.deepEqual(await f.service.recipients(f.users[0],'citizen%'),[]);await f.service.transfer(f.users[0],f.input({mode:'instant'}));const statement=await f.service.activity(f.users[0],{accountId:String(f.current(0).id)});assert.equal(statement.records[0].balanceAfter,'90.00');assert.equal(statement.records[0].direction,'debit');await assert.rejects(f.service.activity(f.users[1],{accountId:String(f.current(0).id)}),e=>e.status===403);assert.equal((await f.service.activity(f.users[2])).records.length,0);}finally{f.db.close();}});
test('planned, dormant and system accounts cannot be payment sources or beneficiaries',async()=>{const f=await setup();try{await f.db.query("UPDATE pb_accounts SET system_key='sys_payroll_po' WHERE id=?",[f.savings(0).id]);const opts=await f.service.accounts(f.users[0]);assert.equal(opts.find(a=>a.id===String(f.savings(0).id)).canReceive,false);await assert.rejects(f.service.transfer(f.users[0],f.input()),e=>e.status===409);await f.db.query("UPDATE pb_accounts SET system_key=NULL,state='dormant' WHERE id=?",[f.savings(0).id]);await assert.rejects(f.service.transfer(f.users[0],f.input()),e=>e.status===409);}finally{f.db.close();}});
test('bank transfer routes reject wrong origin, identity overrides and fractional JSON numbers',async()=>{const f=await setup();try{const api=createPostbankApi(null,f.db,{}, {authenticate:async()=>f.users[0],authority:f.authority}),base='https://cp.dunerealms.com';const request=(body,origin=base)=>new Request(base+'/api/bank/transfers',{method:'POST',headers:{Origin:origin,'Content-Type':'application/json'},body:JSON.stringify(body)});assert.equal((await api(request(f.input(),'https://other.invalid'))).status,403);assert.equal((await api(request(f.input({amount:10.1})))).status,400);assert.equal((await api(new Request(base+'/api/bank/activity?actor=other'))).status,400);assert.equal((await api(new Request(base+'/api/bank/transfer-options'))).status,200);}finally{f.db.close();}});
test('one failed queued posting retains its hold without blocking another instruction',async()=>{const f=await setup();try{const bad=f.input(),good=f.input();await f.service.transfer(f.users[0],bad);await f.service.transfer(f.users[0],good);f.db.sqlite.exec("CREATE TRIGGER fail_one_entry BEFORE INSERT ON pb_entries WHEN NEW.order_id='"+bad.requestId+"' BEGIN SELECT RAISE(ABORT,'isolated ledger fault'); END;");const result=await f.service.processQueue();assert.equal(result.failed,1);assert.equal(result.posted,1);const a=await f.db.first('SELECT * FROM pb_accounts WHERE id=?',[f.current(0).id]);assert.equal(a.balance_minor,9000);assert.equal(a.reserved_minor,1000);assert.equal((await f.db.first('SELECT * FROM pb_orders WHERE id=?',[bad.requestId])).state,'queued');f.db.sqlite.exec('DROP TRIGGER fail_one_entry');assert.equal((await f.service.processQueue()).posted,1);assert.equal((await f.db.first('SELECT * FROM pb_accounts WHERE id=?',[f.current(0).id])).reserved_minor,0);}finally{f.db.close();}});