test(fleet): close shared trips and verify resource release

This commit is contained in:
2026-10-03 07:51:17 +08:00
parent 2992871975
commit ef1eef3278
3 changed files with 17 additions and 5 deletions
+13 -3
View File
@@ -8,6 +8,7 @@ import { createTestEvidenceReaders } from './fba-core-regression-evidence.mjs'
import { redactEvidence } from './fba-core-regression-test-env.mjs'
import { resolvePickerAccess, createPicker, disablePicker } from './admin-test-env-modules/phase4-overseas-pda.mjs'
import { verifyFleetCrossCustomer } from './admin-test-env-modules/fleet-cross-customer-acceptance.mjs'
import { finishFleetTrip } from './admin-test-env-modules/fleet-trip-fulfillment.mjs'
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..')
const ok = response => response?.http === 200 && String(response.body?.code) === '200'
@@ -33,12 +34,12 @@ export function parseCrossCustomerArguments(args) {
export function crossCustomerPlan(config) {
return { environment: 'TEST', execute: config.execute, runId: config.runId, warehouseId: config.warehouseId || null, destinationWarehouseId: config.destinationWarehouseId || null,
output: `reports/fleet-cross-${config.runId}`, stages: ['two new customers', 'two ordinary transfer receipts', 'two dispatches on one trip',
'unready customer gate rejection', 'shared departure and replay', 'independent receipts'],
'unready customer gate rejection', 'shared departure and replay', 'independent receipts', 'trip completion and separate resource release'],
limits: 'Prerequisite rejection is not mid-transaction rollback. No deployment, configuration change, SQL writes or automatic rerun. Retain business samples; disable temporary PDA in finally.' }
}
export async function runCrossCustomer(config, { env = process.env, outputRoot = ROOT, readers, prepare, verify = verifyFleetCrossCustomer,
contextFactory = options => new AcceptanceRun(options), pickerAccess = resolvePickerAccess, pickerCreate = createPicker, pickerDisable = disablePicker } = {}) {
finish = finishFleetTrip, contextFactory = options => new AcceptanceRun(options), pickerAccess = resolvePickerAccess, pickerCreate = createPicker, pickerDisable = disablePicker } = {}) {
const plan = crossCustomerPlan(config)
if (!config.execute) return plan
if (config.environment !== 'TEST' || env.CHONGCHONG_ENV !== 'test' || !/^[A-Za-z0-9][A-Za-z0-9_-]{0,47}$/.test(config.runId)
@@ -107,7 +108,16 @@ export async function runCrossCustomer(config, { env = process.env, outputRoot =
const fixture = await prepare(context, { execute: true, warehouseId: config.warehouseId, destinationWarehouseId: config.destinationWarehouseId, pdaToken: picker.token, readInventory })
save('fixture.json', fixture)
await verify(context, fixture, { execute: true, readInventory })
report = { success: context.createdResources.fleetCrossCustomer?.status === 'VERIFIED' }
const trip = context.createdResources.fleetTrips?.find(row => row.tripNo === fixture.tripNo)
if (!trip) throw Error('Original fixture trip missing for resource completion')
const beforeClosure = []
for (const member of fixture.members) beforeClosure.push(await readInventory({ marker: context.marker, customerId: member.customerId, warehouseId: config.warehouseId }))
await finish(context, 'fleet-cross-customer-closure', trip)
const afterClosure = []
for (const member of fixture.members) afterClosure.push(await readInventory({ marker: context.marker, customerId: member.customerId, warehouseId: config.warehouseId }))
if (JSON.stringify(beforeClosure) !== JSON.stringify(afterClosure)) throw Error('Trip closure changed customer inventory')
report = { success: context.createdResources.fleetCrossCustomer?.status === 'VERIFIED'
&& trip.closure?.status === 'CARGO_COMPLETED_AND_RESOURCES_RELEASED', closureInventoryUnchanged: true }
} catch (error) {
report = { success: false, error: error instanceof Error ? error.message : 'CROSS_CUSTOMER_FAILED' }
} finally {