feat(dispatch): unify whole vehicle scheduling, source ownership and staged execution

This commit is contained in:
2026-10-19 23:40:42 +08:00
parent e0677e7ae7
commit 9dd34791f7
346 changed files with 29245 additions and 12602 deletions
@@ -4,7 +4,7 @@ import { mkdtempSync, readFileSync, unlinkSync, rmdirSync } from 'node:fs'
import { join, resolve } from 'node:path'
import { tmpdir } from 'node:os'
import { PRIVATE_DIRECTORY, privateCredentialsPath, parseUiFixtureArguments, uiFixturePlan,
createPrivateCredentialStore, publicUiEvidence, uiInquiryBody, runUiFixture } from './fleet-capacity-pool-ui-fixture-test-env.mjs'
createPrivateCredentialStore, publicUiEvidence, uiInquiryBody, runUiFixture, applyGrayUiTransportWindow, grayUiSchedule } from './fleet-capacity-pool-ui-fixture-test-env.mjs'
const credentials = join(PRIVATE_DIRECTORY, 'offline-contract-example.json')
const execute = ['--execute', '--environment', 'TEST', '--run-id', 'ui-contract', '--warehouse-id', '10',
@@ -112,3 +112,34 @@ test('plan lists minimal independent identities and explicitly excludes full acc
assert.match(plan.boundary, /completed-order fabrication/)
assert.match(plan.boundary, /Retain business samples and UI accounts/)
})
test('UI fixture prepares one shared native main and an explicitly planned 18-of-30 capacity without fake deliveries or loading', () => {
const source = readFileSync(new URL('./fleet-capacity-pool-ui-fixture-test-env.mjs', import.meta.url), 'utf8')
assert.match(source, /fixture\.members\.every\(member => member\.dispatchNo === fixture\.dispatchNo\)/)
assert.match(source, /return-to-review/)
assert.match(source, /request\('PUT', dispatchPath, uiPlanBody\)/)
assert.match(source, /\['submit-review', 'dispatch-review', 'loading-review'\]/)
assert.match(source, /testPlannedCapacity\(plan\.cargo, detail\.trip\.stops\)\.map\(row => \(\{ \.\.\.row, palletSpaces: 9 \}\)\)/)
assert.match(source, /proof\.planEvidence = \{ actual: false/)
assert.match(source, /dispatch\.documents\?\.outbounds\?\.length === 0/)
assert.match(source, /dispatch\.documents\?\.deliveries\?\.length === 0/)
for (const old of ['controlledPalletMeasurements(', "request('PUT', `${tripPath}/plan`", "member.deliveryNo", "dispatch.pickedPackageCount", "dispatch.shippedPackageCount"]) assert.equal(source.includes(old), false, old)
assert.equal(source.includes('/loading-complete'), false)
assert.equal(source.includes('/depart`'), false)
})
test('native GRAY delivery window preserves per-customer group identity and never adds a retired top-level ETA', () => {
const schedule = grayUiSchedule(Date.parse('2030-01-01T00:00:00Z'))
const body = { recordVersion: '0', idempotencyKey: 'same-command', cargoHash: 'real-cargo', loadingCompletionHash: 'real-load',
groups: [{ groupKey: 'A:FBA:1', plannedDeliveryAt: 'old', fees: [{ amount: 30 }] }, { groupKey: 'B:FBA:1', plannedDeliveryAt: 'old', fees: [] }] }
const applied = applyGrayUiTransportWindow('POST', '/api/platform/v1/last-leg/dispatches/DS-1/transfer-delivery', body, schedule)
assert.equal(applied.recordVersion, '0'); assert.equal(applied.idempotencyKey, body.idempotencyKey)
assert.equal(Object.hasOwn(applied, 'plannedDeliveryAt'), false)
assert.deepEqual(applied.groups.map(group => group.groupKey), body.groups.map(group => group.groupKey))
assert.ok(applied.groups.every(group => group.plannedDeliveryAt === new Date(schedule.plannedDeliveryAt).toISOString()))
assert.deepEqual(applied.groups[0].fees, body.groups[0].fees)
assert.equal(body.groups[0].plannedDeliveryAt, 'old')
assert.throws(() => applyGrayUiTransportWindow('POST', '/api/platform/v1/last-leg/dispatches/DS-1/transfer-delivery', { plannedDeliveryAt: 'old' }, schedule), /NATIVE_DELIVERY_WINDOW_REQUIRED/)
})