import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' import test from 'node:test' const source = readFileSync(new URL('./manual-state-loading-pda.mjs', import.meta.url), 'utf8') test('retains all clickable container, loading-list and PDA workflow states through public APIs', () => { for (const status of ['WAIT_LOADING', 'EDITING', 'LOADING', 'COMPLETED', 'UNASSIGNED', 'IN_PROGRESS', 'AWAITING_REVIEW']) assert.match(source, new RegExp(`['"]${status}['"]`)) for (const endpoint of ['/ocean-bookings', '/smart-loading', '/push-preload', '/inventory-snapshot', '/batch', '/complete', '/loading-plans', '/loading-lists']) assert.match(source, new RegExp(endpoint)) assert.match(source, /requiredStatuses/) assert.match(source, /detailPath/) assert.match(source, /loading-plans\/\$\{fixture\.id\}/) assert.match(source, /loading-lists\/\$\{listFixture\.id\}/) assert.match(source, /prepareInbound/) assert.match(source, /\.\/orders\.mjs/) assert.match(source, /\.\/inbound-measurement\.mjs/) assert.match(source, /context\.request\('POST', CONTAINERS/) assert.match(source, /summary\?\.processStatus === 'WAIT_SPLIT'/) const pushIndex = source.indexOf('`${SMART}/plans/${plan.id}/push-preload`') const transportIndex = source.indexOf('`${CONTAINERS}/${containerId}/transport`') assert.ok(transportIndex >= 0 && pushIndex > transportIndex) const unconfirmedTaskIndex = source.indexOf('`${PDA}/tasks?loadingPlanId=${planId}&warehouseId=${source.warehouseId}`', pushIndex) const confirmIndex = source.indexOf('`${LOADING}/loading-plans/${planId}/confirm`', unconfirmedTaskIndex) const canonicalTaskIndex = source.indexOf('`${PDA}/tasks?loadingPlanId=${planId}&warehouseId=${source.warehouseId}`', unconfirmedTaskIndex + 1) assert.ok(unconfirmedTaskIndex > pushIndex && confirmIndex > unconfirmedTaskIndex && canonicalTaskIndex > confirmIndex) assert.match(source, /计划确认前不生成 PDA 任务/) assert.match(source, /summary\?\.readiness\?\.canConfirm === true/) assert.match(source, /Object\.freeze\(\{ expectedVersion: confirmableVersion \}\)/) assert.match(source, /confirmationStatus === 'CONFIRMED'/) assert.match(source, /readiness\?\.readyForPda === true/) assert.match(source, /id\(task\?\.id\) !== confirmedTaskId/) assert.match(source, /计划确认同键同参精确重放/) assert.doesNotMatch(source, /\/preload\/confirming|\/preload\/confirm\?tenantId=/) assert.match(source, /transported\?\.cabinetNo !== container\?\.cabinetNo/) assert.match(source, /shippingCompanyId: id\(agent\.id\), shippingCompanyName: agent\.name/) assert.match(source, /bookingAgentId: id\(agent\.id\), bookingAgentName: agent\.name/) assert.match(source, /billOfLadingNo: `BL-\$\{value\}`/) const batch = source.slice(source.indexOf('async function pickAll'), source.indexOf('async function complete')) assert.doesNotMatch(batch, /containerNo:/) }) test('does not mutate historical fixtures or remove retained records', () => { assert.doesNotMatch(source, /\bDELETE\b/) assert.doesNotMatch(source, /createdResources\?\.phase3ContainerLoading/) assert.doesNotMatch(source, /orchestrationFixtures\?\./) assert.match(source, /fixtureMarker/) assert.match(source, /context\.marker = originalMarker/) }) test('fails closed when invoked outside the manual matrix wrapper', () => { assert.match(source, /if \(!matrix\?\.pages\)/) assert.match(source, /missing=manualStateMatrix\.pages/) }) test('covers simplified clearance and customs actions through public multipart upload and complete APIs', () => { assert.match(source, /new FormData\(\)/) assert.match(source, /form\.append\('file'/) assert.match(source, /form\.append\('expectedVersion'/) assert.match(source, /form\.append\('operationReason'/) assert.match(source, /'Idempotency-Key'/) assert.match(source, /clearancePath\}\/document\/upload/) assert.match(source, /clearancePath\}\/complete/) assert.match(source, /customsPath\}\/document\/upload\?\$\{warehouse\}/) assert.match(source, /customsPath\}\/complete\?\$\{warehouse\}/) assert.match(source, /matrix\.pages\.containerLoading\.actions/) assert.match(source, /matrix\.pages\.loadingLists\.actions/) assert.doesNotMatch(source, /internal\/file|business-files/) assert.doesNotMatch(source, /\{\s*fileId\s*:/) })