This commit is contained in:
2026-09-09 23:46:21 +08:00
parent 107374bec5
commit 3e4b9d0a9a
10 changed files with 2886 additions and 103 deletions
@@ -3,6 +3,13 @@ import { readFileSync } from 'node:fs'
import test from 'node:test'
const sql = readFileSync(new URL('../../deploy/sql/头程数据库统一增量-MySQL8.sql', import.meta.url), 'utf8')
const overseasSql = readFileSync(new URL('../../deploy/sql/海外区域统一增量-MySQL8.sql', import.meta.url), 'utf8')
const lastlegBaseline = readFileSync(new URL('../../lastleg-service/src/main/resources/db/lastleg.sql', import.meta.url), 'utf8')
const lastlegPermissionSeed = readFileSync(new URL('../../iam/src/main/resources/db/lastleg-permissions.sql', import.meta.url), 'utf8')
const phase5DeliveryPermissionSeed = readFileSync(new URL('../../iam/src/main/resources/db/phase5-delivery-permissions.sql', import.meta.url), 'utf8')
const overseasWarehousePermissions = readFileSync(new URL('../../../apps/admin-web/src/modules/overseas-warehouse/permissions.ts', import.meta.url), 'utf8')
const overseasBusinessPermissions = readFileSync(new URL('../../../apps/admin-web/src/modules/overseas-business/permissions.ts', import.meta.url), 'utf8')
const overseasMasterDataPermissions = readFileSync(new URL('../../../apps/admin-web/src/modules/overseas-master-data/permissions.ts', import.meta.url), 'utf8')
const iamSeed = readFileSync(new URL('../../iam/src/main/resources/db/phase1-admin-rbac.sql', import.meta.url), 'utf8')
const oceanBookingSchema = readFileSync(new URL('../../firstleg/src/main/resources/db/phase3-ocean-booking-schema.sql', import.meta.url), 'utf8')
const truckAppointmentSchema = readFileSync(new URL('../../firstleg/src/main/resources/db/phase3-truck-appointment-schema.sql', import.meta.url), 'utf8')
@@ -50,6 +57,81 @@ test('国内统一初始化支持真实空库且不越界创建海外业务库',
)
})
test('国内统一初始化在注释门禁前创建订单申报快照表', () => {
for (const table of ['fl_order_declaration_snapshot', 'fl_order_declaration_event']) {
const createIndex = sql.indexOf(`CREATE TABLE IF NOT EXISTS ${table} (`)
const commentIndex = sql.indexOf(`CALL queue_table_comment('baiyue_firstleg', '${table}'`)
assert.ok(createIndex >= 0, `missing domestic baseline table: ${table}`)
assert.ok(commentIndex >= 0, `missing domestic table comment gate: ${table}`)
assert.ok(createIndex < commentIndex, `${table} must exist before the table-comment gate runs`)
}
})
test('海外统一初始化内联空库基线且不依赖模块 SQL', () => {
assert.match(overseasSql, /BEGIN INLINE EMPTY-DATABASE BASELINE: LASTLEG/)
assert.match(overseasSql, /BEGIN INLINE EMPTY-DATABASE BASELINE: OVERSEAS WAREHOUSE/)
assert.match(overseasSql, /CREATE DATABASE IF NOT EXISTS baiyue_lastleg/)
assert.match(overseasSql, /CREATE DATABASE IF NOT EXISTS baiyue_lastlag_warehouse/)
assert.match(overseasSql, /CREATE TABLE IF NOT EXISTS ll_order \(/)
assert.match(overseasSql, /CREATE TABLE IF NOT EXISTS wh_location \(/)
assert.ok(
overseasSql.indexOf('CREATE TABLE IF NOT EXISTS ll_order (') <
overseasSql.indexOf('CREATE TABLE IF NOT EXISTS ll_order_source_pallet ('),
'll_order must exist before the source-pallet foreign key is created',
)
assert.ok(
overseasSql.indexOf('CREATE DATABASE IF NOT EXISTS baiyue_lastlag_warehouse') <
overseasSql.indexOf('CREATE TABLE IF NOT EXISTS wh_location ('),
'the overseas warehouse schema must be selected before its baseline tables are created',
)
})
test('海外空库基线为固定平台管理员提供完整version0授权投影', () => {
const authorityBlock = lastlegBaseline.match(
/SET @platform_admin_overseas_authorities = JSON_ARRAY\(([\s\S]*?)\n\);/,
)?.[1]
assert.ok(authorityBlock, 'missing platform_admin overseas authority snapshot')
const authorities = [...authorityBlock.matchAll(/'([^']+)'/g)].map((match) => match[1])
assert.equal(authorities.length, 109)
assert.equal(new Set(authorities).size, authorities.length, 'baseline authorities must not contain duplicates')
assert.equal(authorities.filter((item) => item.startsWith('platform:finance:')).length, 34)
assert.equal(authorities.filter((item) => item.startsWith('platform:overseas-business:')).length, 11)
assert.equal(authorities.filter((item) => item.startsWith('platform:overseas-master-data:')).length, 15)
assert.equal(authorities.filter((item) => item.startsWith('platform:overseas-warehouse:')).length, 49)
for (const authority of authorities) {
assert.ok(sql.includes(`'${authority}'`), `authority is absent from the domestic IAM baseline: ${authority}`)
}
for (const source of [overseasWarehousePermissions, overseasBusinessPermissions, overseasMasterDataPermissions]) {
const declared = [...source.matchAll(/'((?:platform:overseas-warehouse|platform:overseas-business|platform:overseas-master-data):[^']+)'/g)]
.map((match) => match[1])
for (const authority of declared) {
assert.ok(
[lastlegPermissionSeed, phase5DeliveryPermissionSeed].some((seed) => seed.includes(`'${authority}'`)),
`Admin permission is absent from the IAM source seed: ${authority}`,
)
assert.ok(authorities.includes(authority), `Admin permission is absent from the fixed-admin overseas snapshot: ${authority}`)
}
}
for (const required of [
'platform:overseas-warehouse:last-mile-order:list',
'platform:overseas-warehouse:inbound-order:list',
'platform:overseas-warehouse:dispatch:list',
'platform:overseas-business:purchase:list',
'platform:overseas-master-data:quote:list',
'platform:finance:fee-source:review',
]) assert.ok(authorities.includes(required), `missing fixed-admin overseas authority: ${required}`)
assert.match(lastlegBaseline, /SET @platform_admin_overseas_roles = JSON_ARRAY\('PLATFORM_ADMIN'\)/)
assert.doesNotMatch(lastlegBaseline, /\('AUTHORIZATION','1000001',0,NULL,0,JSON_ARRAY\(\),JSON_ARRAY\(\)/)
assert.doesNotMatch(overseasSql, /\('AUTHORIZATION','1000001',0,NULL,0,JSON_ARRAY\(\),JSON_ARRAY\(\)/)
const inline = overseasSql.match(
/-- BEGIN INLINE EMPTY-DATABASE BASELINE: LASTLEG\r?\n([\s\S]*?)\r?\n\r?\n-- END INLINE EMPTY-DATABASE BASELINE: LASTLEG/,
)?.[1]
assert.ok(inline, 'missing inline Lastleg baseline')
assert.equal(inline.replace(/\r\n/g, '\n').trim(), lastlegBaseline.replace(/\r\n/g, '\n').trim())
})
test('国内统一初始化补齐入库费用人工调整基线字段', () => {
assert.match(sql, /baseline_chargeable_quantity DECIMAL\(18,6\) NOT NULL/)
assert.match(sql, /SET baseline_chargeable_quantity = chargeable_quantity[\s\S]*?WHERE baseline_chargeable_quantity IS NULL/)