test: bound A0 location isolation writes

This commit is contained in:
2026-09-01 10:18:19 +08:00
parent cdcf3e0f4f
commit 2c3efad70a
3 changed files with 146 additions and 28 deletions
@@ -0,0 +1,45 @@
import assert from 'node:assert/strict'
import test from 'node:test'
import { planA0LocationIsolation } from '../admin-test-env-acceptance.mjs'
function locations(count) {
return Array.from({ length: count }, (_, index) => ({
id: String(index + 1), locationCode: `L-${String(index + 1).padStart(4, '0')}`,
sharedOverflow: false, version: 0,
}))
}
test('large warehouse is never selected for default mass disable', () => {
const plan = planA0LocationIsolation(locations(614), 1)
assert.equal(plan.enabled, false)
assert.equal(plan.mutationsRequired, 614)
assert.deepEqual(plan.targets, [])
})
test('minimum mutations leave fewer normal locations than required pallets', () => {
const plan = planA0LocationIsolation(locations(3), 3)
assert.equal(plan.enabled, true)
assert.equal(plan.mutationsRequired, 1)
assert.equal(plan.targets.length, 1)
assert.equal(plan.expectedRemainingNormal, 2)
assert.ok(plan.expectedRemainingNormal < plan.requiredSlots)
})
test('natural shortage proves A0 fallback without any location mutation', () => {
const plan = planA0LocationIsolation(locations(1), 2)
assert.equal(plan.enabled, true)
assert.equal(plan.mutationsRequired, 0)
assert.deepEqual(plan.targets, [])
assert.ok(plan.normalCount < plan.requiredSlots)
})
test('shared A0 and duplicate rows never inflate the normal location plan', () => {
const normal = locations(2)
const plan = planA0LocationIsolation([
...normal, normal[0], { id: 'A0', locationCode: 'A0', sharedOverflow: true, version: 0 },
], 2)
assert.equal(plan.normalCount, 2)
assert.equal(plan.mutationsRequired, 1)
assert.deepEqual(plan.targets.map((item) => item.id), ['1'])
})
@@ -511,20 +511,22 @@ test('phase3 loading resolves legal SKIP and PARTIAL exceptions before downstrea
assert.doesNotMatch(loading, /if \(Number\(dynamicCandidate\?\.availablePackageCount\) < 2\) return/)
})
test('phase3 loading fixture forces A0 through reversible public location status APIs', () => {
test('phase3 loading fixture paginates A0 candidates and refuses mass location mutations', () => {
const entry = source('../admin-test-env-acceptance.mjs')
const measurement = source('./inbound-measurement.mjs')
const orders = source('./orders.mjs')
assertOrder(entry, [
'disableAvailableLocationsForA0(warehouseId)',
'this.context.phase3LoadingRequireSharedOverflow = true',
'disableAvailableLocationsForA0(warehouseId, requiredPalletCount)',
'this.context.phase3LoadingRequireSharedOverflow = isolation.forced === true',
"executeModule('inbound-measurement-phase3-loading-fixture'",
'restoreAvailableLocationsAfterA0(warehouseId, disabledLocations)',
'restoreAvailableLocationsAfterA0(warehouseId, isolation)',
])
assert.match(entry, /page=\$\{pageNumber\}&size=\$\{A0_LOCATION_PAGE_SIZE\}/)
assert.match(entry, /A0_MAX_LOCATION_MUTATIONS = 8/)
assert.match(entry, /A0 大仓保护:不批量停用普通库位/)
assert.match(entry, /remainingNormal\.length < isolation\.requiredSlots/)
assert.match(entry, /\/locations\/\$\{encodeURIComponent\(location\.id\)\}\/status/)
assert.match(entry, /\{ status: 'DISABLED', version: Number\(location\.version\) \}/)
assert.match(entry, /\{ status: 'AVAILABLE', version: location\.version \}/)
assert.match(measurement, /phase3LoadingRequireSharedOverflow !== true/)
assert.match(orders, /receivingWarehouseId: id\(master\.receiving\.id\)/)
})