Files
baiyue-firstleg/scripts/admin-test-env-modules/phase3-carrier-schedule-queries.test.mjs
T
2026-08-21 17:58:52 +08:00

48 lines
2.5 KiB
JavaScript

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 { markerTrackingNo, 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)
})
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('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('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/)
})