This commit is contained in:
2026-09-16 17:15:18 +08:00
parent 854d484142
commit 392f5b7386
6 changed files with 252 additions and 454 deletions
@@ -1,33 +1,34 @@
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
import { readInitialization, table, seedRows, roleAuthorities } from './sql-baseline-contract-helpers.mjs'
const unified = readFileSync(new URL('../deploy/sql/头程数据库统一增量-MySQL8.sql', import.meta.url), 'utf8')
const unified = readInitialization()
const firstleg = readFileSync(new URL('../firstleg/src/main/resources/db/phase2-inbound-schema.sql', import.meta.url), 'utf8')
const iam = readFileSync(new URL('../iam/src/main/resources/db/inbound-hold-permission.sql', import.meta.url), 'utf8')
test('统一增量与 Firstleg 扣货快照和不可变历史结构一致', () => {
for (const source of [unified, firstleg]) {
assert.match(source, /current_hold_reason VARCHAR\(1000\) NULL COMMENT '当前扣货理由快照'/)
assert.match(source, /CREATE TABLE IF NOT EXISTS fl_inbound_hold_record/)
assert.match(source, /hold_action VARCHAR\(16\) NOT NULL COMMENT '动作:HOLD或RELEASE'/)
assert.match(source, /reason VARCHAR\(1000\) NOT NULL/)
assert.match(source, /evidence_file_id BIGINT UNSIGNED NULL/)
assert.match(source, /KEY idx_hold_inbound_time \(tenant_id, inbound_id, operated_at\)/)
test('统一初始化与模块扣货快照和不可变历史结构一致', () => {
const order = table(unified, 'baiyue_firstleg', 'fl_inbound_order')
const history = table(unified, 'baiyue_firstleg', 'fl_inbound_hold_record')
for (const source of [order + history, firstleg]) {
assert.match(source, /current_hold_reason VARCHAR\(1000\)[^\n]*COMMENT '当前扣货理由快照'/i)
assert.match(source, /hold_action VARCHAR\(16\)[^\n]*NOT NULL/i)
assert.match(source, /reason VARCHAR\(1000\)[^\n]*NOT NULL/i)
assert.match(source, /evidence_file_id BIGINT UNSIGNED (?:DEFAULT )?NULL/i)
assert.match(source, /KEY idx_hold_inbound_time \(tenant_id,\s*inbound_id,\s*operated_at\)/i)
}
assert.match(unified, /MODIFY COLUMN current_hold_reason VARCHAR\(1000\) NULL/)
assert.doesNotMatch(unified, /MODIFY COLUMN current_hold_reason/)
})
test('统一增量与 IAM 模块冻结同一独立扣货权限且只默认授予平台管理员', () => {
for (const source of [unified, iam]) {
assert.match(source, /\(5102032, 0, 'PLATFORM', 'BUTTON', 5102030, 'platform:firstleg:inbound:hold'/)
assert.match(source, /role\.role_code='PLATFORM_ADMIN'/)
assert.match(source, /permission\.permission_code='platform:firstleg:inbound:hold'/)
assert.match(source, /入库单扣货权限初始化失败:权限ID、编码或类型冲突/)
assert.match(source, /入库单扣货权限初始化失败:权限资源不完整/)
assert.match(source, /入库单扣货权限初始化失败:平台超级管理员授权不完整/)
test('扣货权限保持独立且仅默认授予平台管理员', () => {
assert.match(iam, /\(5102032, 0, 'PLATFORM', 'BUTTON', 5102030, 'platform:firstleg:inbound:hold'/)
const permission = seedRows(unified, 'iam_permission').find(r => r.permission_code === 'platform:firstleg:inbound:hold')
assert.equal(permission.id, '5102032')
assert.equal(permission.parent_id, '5102030')
assert.equal(permission.permission_type, 'BUTTON')
assert.deepEqual(seedRows(unified, 'iam_role_permission').filter(r => r.permission_id === permission.id).map(r => r.role_id), ['4000001'])
assert.ok(roleAuthorities(unified, 'PLATFORM_ADMIN').has(permission.permission_code))
for (const role of ['ORDER_OPERATOR', 'WAREHOUSE_OPERATOR', 'WAREHOUSE_TALLY']) {
assert.ok(!roleAuthorities(unified, role).has(permission.permission_code), role)
}
const migration = unified.slice(unified.indexOf('CREATE PROCEDURE migrate_inbound_hold_permission()'),
unified.indexOf('DROP PROCEDURE IF EXISTS assert_wallet_event_schema'))
assert.doesNotMatch(migration, /role_code='(?:ORDER_OPERATOR|WAREHOUSE_OPERATOR|WAREHOUSE_TALLY|PLATFORM_CUSTOM_ADMIN)'/)
})