diff --git a/website/docs/PILLAGER-RAID-CONTRACT-20261129.md b/website/docs/PILLAGER-RAID-CONTRACT-20261129.md index e833b556..4e1dbbd5 100644 --- a/website/docs/PILLAGER-RAID-CONTRACT-20261129.md +++ b/website/docs/PILLAGER-RAID-CONTRACT-20261129.md @@ -45,6 +45,8 @@ Require transactional/replay/cancel-race tests, actor/deed/funding/Home Block ch ## Implemented integration and operation boundaries +Acceptance reserves native delivery capacity before posting: at most100 active paid orders per server and at most262144 bytes for the full UTF-8 poll response. Overflow refuses the next debit; existing orders are never silently truncated. The global500-order register guard remains a reconciliation boundary. Regression coverage also exercises the actual central MySQL root interface (`query/transaction`, without a root `first` convenience), including original-war storage qualification. + `imperial-raid-runtime.mjs` combines the existing banking/key adapter, durable order service and post-commit jobs. The existing central scheduler drains jobs every15 seconds; no second payment worker or native reward command is introduced. Feature activation requires `IMPERIAL_RAIDS_ENABLED=true`, `POSTBANK_ENABLED=true` and `WAR_BRIDGE_ENABLED=true`. `ops/configure-imperial-raids.mjs` is a plan-by-default built helper, restricted to the exact immutable reviewed release via `--source=<40-character commit>`. `--apply` privately backs up the environment and changes only its feature flag, preserving ownership/mode. It neither seeds balances nor runs a payment. Restart uses the existing release process. Do not run a draft/local script on the host. Paid acceptance and normal war booking use the ORIGINAL bank calendar lock. Acceptance rechecks current campaign/slot records before posting, and new matching clan calendar agreement is refused while a paid raid is pending/active. Known third-retaliation peace, full-roster and province failures are checked before charge and rechecked at actual launch. A later changed original-war rule leaves the stable war job queued; it cannot invent permission or silently substitute a campaign. Complete rosters are bounded at5000 per side: exceeding the verified bound rejects rather than truncates. Ordinary war limits/hour rules remain unchanged. diff --git a/website/node/imperial-raid-orders.mjs b/website/node/imperial-raid-orders.mjs index 2ff02086..8ca8f2ba 100644 --- a/website/node/imperial-raid-orders.mjs +++ b/website/node/imperial-raid-orders.mjs @@ -61,7 +61,7 @@ export function createImperialRaidOrders(db,{resolveActor,resolveContext,charge, } async function clan(tx,id,create=false){ if(create)await tx.query('INSERT INTO jarvis_imperial_raid_clans(clan_id) VALUES(?) ON DUPLICATE KEY UPDATE clan_id=VALUES(clan_id)',[id]); - return await tx.first('SELECT * FROM jarvis_imperial_raid_clans WHERE clan_id=?'+(create?' FOR UPDATE':''),[id])||{clan_id:id}; + return (await tx.query('SELECT * FROM jarvis_imperial_raid_clans WHERE clan_id=?'+(create?' FOR UPDATE':''),[id]))[0]||{clan_id:id}; } async function quote(tx,input,{lock=false}={}){ const context=await resolveContext(tx,input,{lock}),a=await clan(tx,input.orderingClanId,lock),b=await clan(tx,input.targetClanId,lock),now=clock(); diff --git a/website/node/imperial-raid-war.mjs b/website/node/imperial-raid-war.mjs index bcf01e94..a165dcc0 100644 --- a/website/node/imperial-raid-war.mjs +++ b/website/node/imperial-raid-war.mjs @@ -19,7 +19,7 @@ const warTables=['jarvis_war_calendar_guard','jarvis_war_proposals','jarvis_war_ // This automates inputs to the existing War Exchange records and shared launch // commit path. It does not introduce another campaign/capture/settlement engine. export function createImperialRaidWar(central,bank,{clock=Date.now,verifyStorage,readState=readGameNativeState,allowBlock=async(db,parties,block,now)=>!await paxBlocksWar(db,parties,block,now)}={}){ - const banking=atomicBankAccess(central,bank,{verifyStorage,centralTables:['jarvis_imperial_raid_guard','jarvis_imperial_raid_orders','jarvis_imperial_raid_jobs','organisation_keys','site_clans','site_clan_charters','site_claim_registry'],bankTables:warTables}); + const banking=atomicBankAccess(boardReadStore(central,central),bank,{verifyStorage,centralTables:['jarvis_imperial_raid_guard','jarvis_imperial_raid_orders','jarvis_imperial_raid_jobs','organisation_keys','site_clans','site_clan_charters','site_claim_registry'],bankTables:warTables}); async function launch(_job,payload){ await banking.ready();return central.transaction(async raw=>{ const tx=boardReadStore(raw,central);tx.readSnapshot=undefined;await lockImperialRaidGuard(tx); diff --git a/website/tests/game-imperial-raids.test.mjs b/website/tests/game-imperial-raids.test.mjs index 1a50ad06..2b8c94b0 100644 --- a/website/tests/game-imperial-raids.test.mjs +++ b/website/tests/game-imperial-raids.test.mjs @@ -4,8 +4,19 @@ import {createGameImperialRaidsAPI} from '../node/game-imperial-raids.mjs'; import {createImperialRaidRuntime} from '../node/imperial-raid-runtime.mjs'; import {imperialRaidHomeReservations,imperialRaidCalendarAvailable} from '../node/imperial-raid-reservations.mjs'; import {imperialRaidFixture} from './imperial-raid-fixture.mjs'; +import {createImperialRaidWar} from '../node/imperial-raid-war.mjs'; const settings={GAME_LINK_SECRET:'synthetic-test-secret'.repeat(3),IMPERIAL_RAIDS_ENABLED:'true',WAR_BRIDGE_ENABLED:'true',POSTBANK_ENABLED:'true'}; const req=(body,options={})=>new Request('https://example.invalid/internal/game/imperial-raids'+(options.query||''),{method:options.method||'POST',headers:{'content-type':'application/json',authorization:'Bearer '+settings.GAME_LINK_SECRET,...options.headers},...(options.method==='GET'?{}:{body:JSON.stringify(body)})}); +test('actual central MySQL root contract needs query/transaction only; first is supplied by transaction/read adapters',async()=>{ + const f=await imperialRaidFixture();try{ + const raw={query:f.db.query.bind(f.db),transaction:f.db.transaction.bind(f.db)},entity=(await f.db.first('SELECT entity_id FROM pb_clients')).entity_id; + const runtime=createImperialRaidRuntime(raw,f.db,f.keys,{clock:f.clock,verifyStorage:async()=>undefined,verifyCampaigns:false,readState:f.readState,warAuthority:async()=>({canManageWar:true}),bankAuthority:()=>async()=>({entities:[{id:entity,canPay:true,canView:true}]})}); + const i=f.intent();assert.equal((await runtime.execute({action:'context',server:i.server,uuid:i.uuid,orderingClanId:i.orderingClanId,targetClanId:i.targetClanId})).context.uniqueSourceAccountId,'1'); + const central={...raw,query:async(sql,args=[])=>sql.startsWith('SELECT DATABASE()')?[{db:'synthetic_central',host:'fixture',port:3306,server_id:1}]:sql.includes('information_schema.TABLES')?args.slice(1).map(name=>({name,engine:'InnoDB'})):sql.includes('`.pb_accounts')?[{id:1}]:f.db.query(sql,args)}; + const bank={first:async()=>({db:'synthetic_bank',host:'fixture',port:3306,server_id:1})}; + await assert.rejects(createImperialRaidWar(central,bank,{clock:f.clock}).launch(null,{orderId:i.requestId}),/paid third-retaliation receipt/); + }finally{f.close();} +}); test('strict authenticated feature-gated bridge validates before running domain code and hides private exceptions',async()=>{ let calls=0;const runtime={execute:async input=>{calls++;return {ok:true,schema:1,orders:[],server:input.server};}},api=createGameImperialRaidsAPI(runtime,settings),poll={action:'poll',server:'arrakis'}; for(const [input,options,status]of [[poll,{method:'GET'},405],[poll,{headers:{authorization:'Bearer wrong'}},401],[poll,{query:'?a=1'},400],[{...poll,feeMinor:'1'},{},400],[{...poll,server:'lobby'},{},400],[{...poll,large:'a'.repeat(17000)},{},400]])assert.equal((await api(req(input,options))).status,status);