modes:{read:'Only login/logout and GET: selected current-run work, exact FBA allocations/private dispatch pallets, shared trips, explicit retired replacements and actual dates.',
workflow:'Also writes SAVE_FOLLOWUP on one pending fixture item; verifies reader denial, exact replay, stale version and changed-payload rejection. Optional CUSTOMER SAVE_REQUIREMENT records no booking, without execution.'},
prerequisites:['Latest IAM/Firstleg/Lastleg and permission/DDL baseline deployed by coordinator',
'Current-run formal HTTP producer report, its SHA256 and an explicit fixture; no historical discovery or fabricated inventory',
'CHONGCHONG_ENV=test and CHONGCHONG_ADMIN_API_BASE_URL ending /api; CHONGCHONG_ADMIN_USERNAME/PASSWORD',
'CHONGCHONG_MERCHANT_USERNAME/PASSWORD for customer denial; workflow also APPOINTMENT_WORK_READER_USERNAME/PASSWORD (platform list + source reads, without followup/manage-work)',
'Owner is an active platform IAM user; scheduled synchronization complete before execution'],
cases:[{name:'customer',containerBookingId:'<id>',type:'DELIVERY',flow:'TRANSFER',requirementKey:'DISPATCH:<id>',batchKey:'DISPATCH:<id>',batchNo:'<dispatch business number>',
'sharedTrips:[{case,tripNo,tripId,containerIds,dispatches:[{dispatchNo,customerId,packageCount}]}]. The case must select TRANSPORT.',
'retired:[{workItemKey,containerBookingId,replacementCases:[name]}] checks absence from active container work and exact named replacements in old detail.',
'For COMPLETED cases provide expected.actual and calendarDate/dateBasis=ACTUAL; completed rows are loaded with their date filter.',
'workflow requires one pending item exposing SAVE_FOLLOWUP; noBooking additionally requires editable CUSTOMER DELIVERY and no original appointment plan.'],
notes:'Uses its existing ADMIN_TEST_* and ADMIN_PDA_* configuration. Dependency closure creates a new customer/order, measurement/loading/customs/outbound and formal ship-node evidence. Select only the current report createdResources.phase3CarrierScheduleQuery.containerBookingId. First acceptance can target its UNKNOWN ROUTE work with workflow.noBooking=false; this does not prove stable batches.',
batchPrerequisites:'Then use current formal route, cargo-verification/FBA appointment or PRIVATE receiving/pre-arrange APIs to prepare new stable batches; shared trip and completion stages need actual original dispatch/fleet/PDA execution before a new read report.',
batchProducer:'Select phase4-overseas-inbound-operations with the same four-box arguments to exercise independent cargo verification, dedicated DELETE cancellation, split/merge conservation, immutable batch identity and replacement history. It also runs prerequisite PDA and reversible inventory writes; offline checks do not establish HTTP readiness. Retain samples and obtain the corresponding environment/cancellation authorization before execution.'},
remaining:['This package does not create sailed containers, appointments, dispatches, stock or fleet trips, cancel original businesses, pick/depart/sign, or run internal synchronization.',
'Prepare/advance those samples with existing formal producers; run a new read report after each state transition. This is not end-to-end execution proof.',
'PRIVATE per-order pick quantity conservation and DIRECT receiving-write rejection require the original PDA/dispatch producer; this reader checks public batch identity/pallet quantities and completed facts only.',
boundary:'Default plan is zero network/file writes. Execute claims a new report directory, journals before every write, stops on unknown outcome, retains samples, and logs out only its sessions. No SQL, deployment, deletes or automatic resume.'}
&&/^[A-Za-z0-9][A-Za-z0-9_-]{0,47}$/.test(values.get('run-id')||'')&&['read','workflow'].includes(values.get('mode'))&&values.get('fixture'),'Explicit TEST, new run-id, mode and fixture required')
&&resolve(execArgs[0].slice(11)).replaceAll('\\','/').endsWith('/.codex/env/chongchong-global/test-acceptance.env'),'Explicit authorized TEST env-file required')
requireFact(['http:','https:'].includes(base.protocol)&&base.pathname.replace(/\/$/,'')==='/api'&&!base.username&&!base.password&&!base.search&&!base.hash,'Unified TEST API base required')
&&['UNKNOWN','TRANSFER','DIRECT'].includes(c.flow)&&Array.isArray(c.containerIds)&&c.containerIds.includes(c.containerBookingId),'Exact case scope required')
&&['NONE','TARGET','CONFIRMED','ACTUAL'].includes(c.expected?.dateBasis)&&Object.hasOwn(c.expected,'calendarDate'),'Explicit status and calendar expectation required')
if(c.expected.executionStatus==='COMPLETED')requireFact(c.expected.actual&&c.expected.dateBasis==='ACTUAL'&&/^\d{4}-\d{2}-\d{2}$/.test(c.expected.calendarDate||''),'Completion requires independent actual evidence and date')
}
for(constkeyof['batches','sharedTrips','retired'])requireFact(Array.isArray(f[key])&&f[key].length<=30,`${key} must be an explicit bounded list`)
for(constboff.batches){
constc=f.cases.find(c=>c.name===b.case)
requireFact(c?.type==='DELIVERY'&&c.batchKey&&['FBA','CUSTOMER'].includes(b.kind),'Batch requires its delivery case')
requireFact(total==null||total===count(response.total),'Work scope changed during pagination');total=count(response.total)
result.push(...next);if(page>=count(response.pages)){requireFact(result.length===total&&newSet(result.map(i=>i.workItemKey)).size===total,'Duplicate or missing work rows');returnresult}
check(`${b.case}: immutable FBA batch and business number`,batch.appointment.batchKey===item.batchKey&&batch.appointment.appointmentNo===b.appointmentNo&&item.batchNo===b.appointmentNo)
assert.deepEqual(sort(batch.appointment.items.map(source)),sort(b.sources.map(source)),'FBA per-source quantities must match producer evidence')
check(`${b.case}: original private dispatch identity`,item.batchKey===`DISPATCH:${dispatch.id}`&&item.batchNo===dispatch.dispatchNo&&dispatch.dispatchNo===b.dispatchNo)
assert.deepEqual(sort(dispatch.items.map(p=>({planPalletId:id(p.planPalletId),packageCount:p.packageCount}))),sort(b.pallets),'Private original pallet allocation drift')
assert.deepEqual(sort(trip.dispatches.map(d=>({dispatchNo:d.dispatchNo,customerId:id(d.customerId),packageCount:d.packageCount}))),sort(t.dispatches),'Shared trip original dispatch membership drift')
for(constcontaineroft.containerIds)check(`${t.case}: shared transport counted once per container`,(awaitrows(container,detail.item.calendarDate||undefined)).filter(i=>i.type==='TRANSPORT'&&i.workItemKey===detail.item.workItemKey).length===1)
}
for(constroffixture.retired){
check('retired item excluded from active scope',!(awaitrows(r.containerBookingId)).some(i=>i.workItemKey===r.workItemKey))
check('retired item retains history and read-only actions',old.history.some(h=>h.action==='REPLACED')&&old.item.allowedActions.every(a=>['VIEW_HISTORY','VIEW_DETAIL'].includes(a.code)))
for(constnameofr.replacementCases)check('original requirement restored or explicitly replaced',old.relatedItems.some(i=>i.workItemKey===resolved.get(name).item.workItemKey))
check('workflow sample is unfinished and exposes followup',before.item.executionStatus!=='COMPLETED'&&before.item.allowedActions.some(a=>a.code==='SAVE_FOLLOWUP'))
check('followup resolves the active platform Auth subject owner',result.item.owner?.id===w.ownerId&&typeofresult.item.owner.name==='string'&&result.item.owner.name.length>0&&result.item.followupDate===w.followupDate)
assert.deepEqual(awaitdata('GET',path),saved,'Idempotent replay wrote history or version')
check('changed payload under same key rejected',refused(awaitcontext.request('admin','POST',`${path}/commands`,{...command,payload:{...command.payload,note:'变更内容应拒绝'}}),409))
check('stale version rejected',refused(awaitcontext.request('admin','POST',`${path}/commands`,{...command,idempotencyKey:`AW-${config.runId}-STALE`}),409))
check('explicit customer requirement is editable',before.item.type==='DELIVERY'&&saved.requirement&&saved.item.allowedActions.some(a=>a.code==='SAVE_REQUIREMENT'))
check('no booking does not mean executed',updated.item.planStatus==='NOT_REQUIRED'&&updated.item.executionStatus===before.item.executionStatus&&updated.item.actual==null)
if(process.argv[1]&&import.meta.url===pathToFileURL(resolve(process.argv[1])).href){execute().then(result=>{console.log(JSON.stringify(result,null,2));if(result.success===false)process.exitCode=1}).catch(()=>{console.error('Appointment work acceptance not started: verify explicit TEST configuration, current-run fixture and unused report directory.');process.exitCode=1})}