优化
This commit is contained in:
@@ -1,24 +1,47 @@
|
||||
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 { matchesManualScheduleScope } from './phase3-carrier-schedule-queries.mjs'
|
||||
import { markerTrackingNo, ownsCarrierQuery } from './phase3-carrier-schedule-queries.mjs'
|
||||
|
||||
const expected = { customerId: '10001', oceanBookingId: '20001', containerBookingId: null }
|
||||
const here = path.dirname(fileURLToPath(import.meta.url))
|
||||
const source = fs.readFileSync(path.join(here, 'phase3-carrier-schedule-queries.mjs'), 'utf8')
|
||||
|
||||
test('does not reuse a schedule from the same booking when the container scope differs', () => {
|
||||
assert.equal(matchesManualScheduleScope({
|
||||
id: '30001', customerId: '10001', oceanBookingId: '20001', containerBookingId: '40001',
|
||||
}, expected), false)
|
||||
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('does not reuse a schedule whose customer scope is unknown', () => {
|
||||
assert.equal(matchesManualScheduleScope({
|
||||
id: '30001', oceanBookingId: '20001', containerBookingId: null,
|
||||
}, expected), 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('reuses a schedule only when customer, booking and container scopes all match', () => {
|
||||
assert.equal(matchesManualScheduleScope({
|
||||
id: '30001', customerId: 10001, oceanBookingId: 20001, containerBookingId: null,
|
||||
}, expected), true)
|
||||
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/)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user