import assert from 'node:assert/strict' import fs from 'node:fs' import path from 'node:path' import test from 'node:test' import { fileURLToPath } from 'node:url' import { currentOutboundFixture, ownsCarrierQuery, validContainerNo } 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') function context(marker = 'RUN') { return { marker, createdResources: { phase3Loading: { marker, tenantId: '10001', oceanBookingId: '20001', containerBookingId: '30001', containerNo: 'ZCSU7881970' }, 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: 'ZCSU7881970', }) 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('carrier fixture only accepts normalized ISO 6346 physical container numbers', () => { assert.equal(validContainerNo('ZCSU7881970'), true) assert.equal(validContainerNo('zcsu7881970'), false) assert.equal(validContainerNo('ZCSU7881971'), false) assert.equal(validContainerNo('CAB-260901-0001'), false) }) 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 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, /trackingType === 'CONTAINER_NO'/) assert.match(source, /validContainerNo\(task\?\.trackingNo\)/) 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|results)(?=['"`/?])|BILL_OF_LADING/) assert.doesNotMatch(source, /records\[0\]/) }) test('carrier capability assertion freezes five automated providers and COSCO only gap', () => { assert.match(source, /\['MATSON', 'SML', 'ZIM', 'EMC', 'HEDE'\]/) assert.match(source, /AUTOMATED_CARRIERS\.every[\s\S]*automated === true[\s\S]*coverageGap === false/) assert.match(source, /byCode\.get\('COSCO'\)\?\.automated === false/) assert.match(source, /OFFICIAL_API_CREDENTIALS_REQUIRED/) })