test(admin): align phase3 loading producer contract

This commit is contained in:
2026-08-11 17:47:19 +08:00
parent 4561245a71
commit a02dd3a422
3 changed files with 111 additions and 62 deletions
@@ -1,10 +1,23 @@
import assert from 'node:assert/strict'
import fs from 'node:fs'
import { readFileSync } from 'node:fs'
import test from 'node:test'
import { selectCustomsFlow } from './phase3-customs.mjs'
import { buildFinalizeResource } from './phase3-loading-finalize.mjs'
function source(name) {
return readFileSync(new URL(name, import.meta.url), 'utf8')
}
function assertOrder(value, snippets) {
let cursor = -1
for (const snippet of snippets) {
const next = value.indexOf(snippet)
assert.ok(next > cursor, `${snippet} must appear after the previous production step`)
cursor = next
}
}
test('pairs customs source fixture with the matching loading container', () => {
const resources = {
orchestrationFixtures: {
@@ -52,17 +65,37 @@ test('records LOADED and clears the reason only after a real LOADED reread', ()
assert.equal(result.notCleanedReason, null)
})
test('keeps push and claim state transitions in the verified order', () => {
const containerScript = fs.readFileSync(new URL('./phase3-container-loading.mjs', import.meta.url), 'utf8')
const loadingScript = fs.readFileSync(new URL('./phase3-loading.mjs', import.meta.url), 'utf8')
test('container loading follows push, claim, real pick, completed sequence', () => {
const value = source('./phase3-container-loading.mjs')
assert.match(value, /containerDetail\?\.planStatus === 'WAIT_LOADING'/)
assertOrder(value, [
"pushed?.status === 'EDITING'",
"claimedPlan?.status === 'LOADING'",
"const pickResponse = await request",
"finalPlan?.status === 'COMPLETED'",
])
})
assert.match(containerScript, /planStatus === 'WAIT_LOADING'/)
assert.match(containerScript, /pushed\?\.status === 'EDITING'/)
assert.match(containerScript, /claimedPlan\?\.status === 'LOADING'/)
assert.ok(containerScript.indexOf("pushed?.status === 'EDITING'") < containerScript.indexOf("claimedPlan?.status === 'LOADING'"))
test('bridge loading starts through a real PDA batch before preload confirmation', () => {
const value = source('./phase3-loading.mjs')
assertOrder(value, [
"pushedLoadingPlan?.status === 'EDITING'",
"claimedPlan?.status === 'LOADING'",
"const canonicalPick = await request",
"pickedPlan?.status === 'COMPLETED'",
"const confirming = await request",
])
assert.match(value, /confirmed\?\.mainStatus === 'LOADING' && confirmed\?\.preloadPlan\?\.status === 'CONFIRMING'/)
assert.match(value, /confirmed\?\.preloadPlan\?\.status === 'CONFIRMED'/)
assert.doesNotMatch(value, /关联柜次计划进入 LOADING/)
})
assert.match(loadingScript, /pushedLoadingPlan\?\.status === 'EDITING'/)
assert.match(loadingScript, /claimedPlan\?\.status === 'LOADING'/)
assert.ok(loadingScript.indexOf("pushedLoadingPlan?.status === 'EDITING'") < loadingScript.indexOf("claimedPlan?.status === 'LOADING'"))
assert.ok(loadingScript.indexOf("claimedPlan?.status === 'LOADING'") < loadingScript.indexOf("const confirming ="))
test('downstream producers prefer the phase3Loading container fixture', () => {
const ocean = source('./ocean-bookings.mjs')
const customs = source('./phase3-customs.mjs')
const serviceCenter = source('./service-center-flow.mjs')
assert.match(ocean, /context\.createdResources\?\.phase3Loading\s*\|\|\s*context\.createdResources\?\.phase3ContainerLoading/)
assert.match(customs, /createdResources\?\.phase3Loading,\s*\n\s*createdResources\?\.phase3ContainerLoading/)
assert.match(serviceCenter, /context\.createdResources\?\.phase3Loading\s*\|\|\s*context\.createdResources\?\.phase3ContainerLoading/)
assert.match(ocean, /await action\('放舱', 'release'/)
})