diff --git a/website/node/political-decisions.mjs b/website/node/political-decisions.mjs index a1f38b2d..afbc7af9 100644 --- a/website/node/political-decisions.mjs +++ b/website/node/political-decisions.mjs @@ -37,6 +37,9 @@ async function officeAuthority(tx,d,actor,now,lock=false){ return holder; } export function createPoliticalDecisions(db,bank,keys,deps={}){ + // The production central pool exposes prepared reads rather than first(). + // Keep every transaction callback on its original connection. + db={...boardReadStore(db,db),transaction:db.transaction.bind(db)}; const clock=deps.clock||Date.now,banking=atomicBankAccess(db,bank,{verifyStorage:deps.verifyStorage,centralTables:['jarvis_political_decisions','political_proclamations','political_office_terms','political_office_charters','organisation_keys','organisation_key_events','codex_instance_editions','account_audit','jarvis_pol_progression_seasons','jarvis_pol_progression_accounts','jarvis_pol_progression_history','jarvis_pol_progression_outbox']}); async function accounts(tx,actor,d){const b=banking.view(tx),r=boardReadStore(tx,db),authority=deps.authority||createPostbankAuthority(r,{bank:b,clock});const rights=await authority(actor,{bank:b});return(await b.query(accountsSQL+' WHERE c.entity_id=? AND a.system_key IS NULL ORDER BY a.id',[funding(d)])).filter(a=>ordinaryPaymentAccount(a)&&canDebitAccount(rights,a.entity_id,a.id));} async function recipients(tx,actor,d,search=''){ diff --git a/website/tests/political-decisions.test.mjs b/website/tests/political-decisions.test.mjs index e9ad6abf..b24beb6a 100644 --- a/website/tests/political-decisions.test.mjs +++ b/website/tests/political-decisions.test.mjs @@ -22,7 +22,7 @@ async function fixture(office='emperor'){ await new PostbankService(f.db,authority).activate(f.people.Owner,{entityId:entity.id,packageKey:'pb_civic',termsVersion:BANK_VERSION,accepted:true,requestId:randomUUID()});const source=await f.db.first("SELECT * FROM pb_accounts WHERE type_code='107'");await f.db.query('UPDATE pb_accounts SET balance_minor=2000000 WHERE id=?',[source.id]);await f.db.query("INSERT INTO pb_accounts(system_key,type_code,display_name,balance_minor,state,created_at) VALUES('sys_tax_treasury','979','Tax',0,'active',1)"); const service=createPoliticalDecisions(f.db,f.db,f.keys,{verifyStorage:async()=>null,authority,clock:()=>now}); const input=(decisionId='IMP-04')=>({decisionId,requestId:randomUUID(),sourceAccount:String(source.id),confirmed:true,...(decisionId==='IMP-04'?{title:'A public proclamation',body:'A message to the people of the realm.'}:{recipientId:f.people.Other.id,citation:'Recognised for service to the realm.'})}); - return{...f,service,pol,source,term,input,setTime:n=>now=n}; + return{...f,service,pol,source,term,input,authority,setTime:n=>now=n}; } test('catalogue prices, Reputation requirements and XP agree with connected policy',()=>{for(const d of POLITICAL_DECISIONS){const row=DECISION_CATALOGUE.find(r=>r.id===d.id);assert.equal(row.level,d.level);assert.equal(row.xp,d.xp);const [dm,hours]=row.cost.replaceAll(',','').split(' / ');assert.equal(Number(dm)*100,d.feeMinor);assert.equal(Number(hours.replace('h',''))*3600000,d.cooldownMs);}}); test('proclamation payment, publication, XP and key roll back together; concurrent identical retries post once',async()=>{const f=await fixture();try{ @@ -63,3 +63,6 @@ test('Imperial and Corrino recognitions use fixed fees, existing profile markup test('separate MySQL hosts fail before any mutation or qualified-table access',async()=>{ let writes=0;const db={first:async()=>({db:'central',host:'central-host',port:3306,server_id:1}),query:async()=>{writes++;return[];}},bank={first:async()=>({db:'bank',host:'another-host',port:3306,server_id:2})};await assert.rejects(atomicBankAccess(db,bank).ready(),/One transactional bank server/);assert.equal(writes,0); }); +test('production central adapter needs only query, prepare and transaction, without a first convenience method',async()=>{const f=await fixture();try{ + const central={...f.db,first:undefined,transaction:f.db.transaction.bind(f.db)},service=createPoliticalDecisions(central,f.db,f.keys,{verifyStorage:async()=>null,authority:f.authority,clock:()=>1000});assert.equal((await service.read(f.people.Owner,'IMP-04')).canManage,true);assert.equal((await service.execute(f.people.Owner,f.input())).ok,true); + }finally{f.db.close();}});