test(fleet): verify two-customer departure rollback in TEST

This commit is contained in:
2026-10-04 10:32:26 +08:00
parent c46a68e32b
commit 8a735020e3
6 changed files with 206 additions and 2 deletions
@@ -33,7 +33,7 @@ export const fixtureContract = Object.freeze({
/** Import/default call is network-free. Explicit execute:true requires separately authorized TEST execution.
* Tokens stay in the caller, never in the persisted proof. Failure retains fixture and exact request keys.
*/
export async function verifyFleetCrossCustomer(context, fixture, { execute = false, readInventory } = {}) {
export async function verifyFleetCrossCustomer(context, fixture, { execute = false, readInventory, verifyDepartureRollback } = {}) {
if (!execute) return fixtureContract
if (!context?.marker || fixture?.marker !== context.marker || fixture.stage !== fixtureContract.stage
|| !fixture.tripNo || !fixture.warehouseId || !fixture.pdaToken || typeof readInventory !== 'function'
@@ -159,6 +159,13 @@ export async function verifyFleetCrossCustomer(context, fixture, { execute = fal
const ready=await snapshot('READY')
const departBody={recordVersion:reviewed.trip.recordVersion,idempotencyKey:key('DEPART'),remark:context.marker}
const departPath=`${PDA}/${encode(fixture.members[0].dispatchNo)}/depart`
if(verifyDepartureRollback!==undefined) {
check('Explicit rollback verifier is callable',typeof verifyDepartureRollback==='function')
const rollback=await verifyDepartureRollback({context,fixture,ready,departPath,departBody,snapshot})
check('Mid-transaction rollback has exact owned verification',rollback?.verified===true && rollback.scope==='OWNED_TWO_CUSTOMER_DEPARTURE_ROLLBACK')
equal(ready,await snapshot('ROLLBACK_RESTORED'),'Mid-transaction rollback restores both complete customer execution and inventory snapshots')
proof.rollbackEvidence=rollback;proof.midTransactionRollback='VERIFIED'
}
const departed=await request('POST',departPath,departBody,'Depart whole trip once',true)
check('Departure includes both customer dispatches',departed.tripNo===fixture.tripNo && departed.status==='IN_TRANSIT' && integer(departed.shippedPackages)===2
&& canonical(departed.dispatches.map(row=>row.dispatchNo).sort())===canonical(fixture.members.map(row=>row.dispatchNo).sort()))