test: strengthen customs and fulfillment acceptance boundaries

This commit is contained in:
2026-09-30 12:58:15 +08:00
parent 125ca34ba4
commit 80632ba409
13 changed files with 1616 additions and 40 deletions
@@ -1,7 +1,33 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { markerSuffix } from './phase3-loading.mjs'
import { loadingBookingCustomerFields, markerSuffix } from './phase3-loading.mjs'
import { withPlatformBookingScope } from './phase3-container-customs-fixture.mjs'
test('normal loading keeps customer scope; explicit platform booking omits both customer fields', () => {
const fields = loadingBookingCustomerFields(undefined, '2100000000000000001', '测试客户')
assert.deepEqual(fields, { customerId: '2100000000000000001', customerName: '测试客户' })
assert.deepEqual(loadingBookingCustomerFields('CUSTOMER', fields.customerId, fields.customerName), fields)
const platform = loadingBookingCustomerFields('PLATFORM', fields.customerId, fields.customerName)
assert.equal(Object.hasOwn(platform, 'customerId'), false)
assert.equal(Object.hasOwn(platform, 'customerName'), false)
assert.throws(() => loadingBookingCustomerFields('MISSPELLED', fields.customerId, fields.customerName), /订舱范围/)
})
test('mixed fixture platform scope restores absence and an existing value after success or failure', async () => {
const absent = { context: {} }
assert.equal(await withPlatformBookingScope(absent, async () => {
assert.equal(absent.context.phase3LoadingBookingScope, 'PLATFORM')
return 'loaded'
}), 'loaded')
assert.equal(Object.hasOwn(absent.context, 'phase3LoadingBookingScope'), false)
const existing = { context: { phase3LoadingBookingScope: 'CUSTOMER' } }
await assert.rejects(withPlatformBookingScope(existing, async () => {
assert.equal(existing.context.phase3LoadingBookingScope, 'PLATFORM')
throw new Error('actual loading failure')
}), /actual loading failure/)
assert.equal(existing.context.phase3LoadingBookingScope, 'CUSTOMER')
})
test('phase3 loading fixture identifiers are deterministic and distinct across marker variants', () => {
const base = 'ADMIN-API-20260824123024536'
@@ -18,6 +44,7 @@ test('phase3 loading uses the collision-safe marker suffix for generated busines
const source = await import('node:fs/promises').then((fs) => fs.readFile(
new URL('./phase3-loading.mjs', import.meta.url), 'utf8'))
assert.match(source, /const suffix = markerSuffix\(context\.marker\)/)
assert.match(source, /const bookingDraft = \{\s*\.\.\.loadingBookingCustomerFields\(context\.context\?\.phase3LoadingBookingScope, tenantId,/)
assert.match(source, /billOfLadingNo: `P3BL-\$\{suffix\}`/)
assert.match(source, /vesselName: `P3VESSEL-\$\{suffix\}`/)
assert.doesNotMatch(source, /suffix = context\.marker\.replace\(\/\\D\/g/)