test: harden carrier node HTTP acceptance
This commit is contained in:
@@ -4,39 +4,49 @@ import path from 'node:path'
|
||||
import test from 'node:test'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
import { markerTrackingNo, ownsCarrierQuery } from './phase3-carrier-schedule-queries.mjs'
|
||||
import { currentOutboundFixture, ownsCarrierQuery } from './phase3-carrier-schedule-queries.mjs'
|
||||
|
||||
const here = path.dirname(fileURLToPath(import.meta.url))
|
||||
const source = fs.readFileSync(path.join(here, 'phase3-carrier-schedule-queries.mjs'), 'utf8')
|
||||
|
||||
test('marker ownership requires explicit module ownership and the exact current marker', () => {
|
||||
assert.equal(ownsCarrierQuery({ queryId: '1', marker: 'M', ownedByModule: true }, 'M'), true)
|
||||
assert.equal(ownsCarrierQuery({ queryId: '1', marker: 'OLD', ownedByModule: true }, 'M'), false)
|
||||
assert.equal(ownsCarrierQuery({ queryId: '1', marker: 'M', ownedByModule: false }, 'M'), false)
|
||||
assert.equal(ownsCarrierQuery({ marker: 'M', ownedByModule: true }, 'M'), false)
|
||||
function context(marker = 'RUN') {
|
||||
return { marker, createdResources: {
|
||||
phase3Loading: { marker, tenantId: '10001', oceanBookingId: '20001', containerBookingId: '30001', containerNo: 'TSTU1234567' },
|
||||
phase3OutboundDispatch: { marker, tenantId: '10001', containerBookingId: '30001', confirmedStatus: 'WAITING_FOR_LOADING' },
|
||||
} }
|
||||
}
|
||||
|
||||
test('outbound fixture requires exact current marker and matching loading/outbound container', () => {
|
||||
assert.deepEqual(currentOutboundFixture(context()), {
|
||||
marker: 'RUN', customerId: '10001', oceanBookingId: '20001', containerBookingId: '30001', trackingNo: 'TSTU1234567',
|
||||
})
|
||||
const old = context(); old.createdResources.phase3OutboundDispatch.marker = 'OLD'
|
||||
assert.equal(currentOutboundFixture(old), null)
|
||||
const mismatch = context(); mismatch.createdResources.phase3OutboundDispatch.containerBookingId = 'OTHER'
|
||||
assert.equal(currentOutboundFixture(mismatch), null)
|
||||
})
|
||||
|
||||
test('default tracking number is deterministic marker data while explicit samples are opt-in', () => {
|
||||
const first = markerTrackingNo('RUN-20260821-001', '')
|
||||
const second = markerTrackingNo('RUN-20260821-001', '')
|
||||
assert.equal(first, second)
|
||||
assert.match(first, /^TSTU\d{7}$/)
|
||||
assert.equal(markerTrackingNo('RUN', ' zcsu-test-only '), 'ZCSU-TEST-ONLY')
|
||||
test('carrier query ownership requires explicit outbound-confirm marker registration', () => {
|
||||
assert.equal(ownsCarrierQuery({ queryId: '1', marker: 'RUN', ownedByModule: true,
|
||||
triggerSource: 'OUTBOUND_CONFIRM' }, 'RUN'), true)
|
||||
assert.equal(ownsCarrierQuery({ queryId: '1', marker: 'RUN', ownedByModule: true,
|
||||
triggerSource: 'MANUAL' }, 'RUN'), false)
|
||||
assert.equal(ownsCarrierQuery({ queryId: '1', marker: 'OLD', ownedByModule: true,
|
||||
triggerSource: 'OUTBOUND_CONFIRM' }, 'RUN'), false)
|
||||
})
|
||||
|
||||
test('phase3 contract creates and mutates only its marker-owned container query', () => {
|
||||
assert.match(source, /carrierCode:\s*'ZIM',\s*trackingType:\s*'CONTAINER_NO'/)
|
||||
assert.match(source, /phase3CarrierScheduleQuery\s*=\s*\{[\s\S]*queryId,[\s\S]*marker:\s*context\.marker,[\s\S]*ownedByModule:\s*true/)
|
||||
assert.match(source, /\/manual-nodes/)
|
||||
assert.match(source, /'Idempotency-Key'/)
|
||||
assert.match(source, /expectedVersion:\s*Number\(initialTask\.version\)/)
|
||||
assert.match(source, /actualAt:\s*null/)
|
||||
assert.match(source, /A0409/)
|
||||
assert.match(source, /nodeSnapshot\(detail\)[\s\S]*nodeSnapshot\(manualDetail\)/)
|
||||
assert.doesNotMatch(source, /\/manual-results/)
|
||||
assert.doesNotMatch(source, /\/attempts|\/scheduler|\/internal|\/pda/)
|
||||
assert.doesNotMatch(source, /BILL_OF_LADING/)
|
||||
assert.doesNotMatch(source, /createManualSchedule|portScheduleId|\/api\/platform\/v1\/port-schedules/)
|
||||
test('phase3 script only discovers the current outbound task and blocks missing prerequisites', () => {
|
||||
assert.match(source, /phase3Loading/)
|
||||
assert.match(source, /phase3OutboundDispatch/)
|
||||
assert.match(source, /缺少本轮phase3出仓fixture,禁止借历史Query验收/)
|
||||
assert.match(source, /deploymentBlocker:\s*true/)
|
||||
assert.match(source, /triggerSource === 'OUTBOUND_CONFIRM'/)
|
||||
assert.match(source, /DEPARTED_WAREHOUSE/)
|
||||
assert.match(source, /providerEventId/)
|
||||
assert.match(source, /\^\\d\{16,/)
|
||||
assert.doesNotMatch(source, /request\(context,\s*'POST',\s*BASE/)
|
||||
assert.doesNotMatch(source, /manual-nodes|manual-results|BILL_OF_LADING/)
|
||||
assert.doesNotMatch(source, /records\[0\]/)
|
||||
})
|
||||
|
||||
test('carrier capability assertion freezes five automated providers and COSCO only gap', () => {
|
||||
|
||||
Reference in New Issue
Block a user