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,22 +1,22 @@
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
import { readInitialization, table } from './sql-baseline-contract-helpers.mjs'
const unified = readFileSync(new URL('../deploy/sql/头程数据库统一增量-MySQL8.sql', import.meta.url), 'utf8')
const firstleg = readFileSync(new URL('../firstleg/src/main/resources/db/phase2-inbound-schema.sql', import.meta.url), 'utf8')
const fee = table(readInitialization(), 'baiyue_firstleg', 'fl_inbound_fee')
test('统一增量与 Firstleg 入库费用计费基准和容差字段一致', () => {
for (const source of [unified, firstleg]) {
assert.match(source, /baseline_chargeable_quantity DECIMAL\(18,6\) NOT NULL/)
assert.match(source, /tolerance_percent DECIMAL\(5,2\) NOT NULL DEFAULT 10\.00/)
assert.match(source, /SET baseline_chargeable_quantity = chargeable_quantity\s+WHERE baseline_chargeable_quantity IS NULL/)
assert.match(source, /MODIFY COLUMN baseline_chargeable_quantity DECIMAL\(18,6\) NOT NULL/)
test('统一初始化与模块入库费用均直接定义计费基准和容差', () => {
for (const source of [fee, firstleg]) {
assert.match(source, /baseline_chargeable_quantity DECIMAL\(18,6\) NOT NULL/i)
assert.match(source, /tolerance_percent DECIMAL\(5,2\) NOT NULL DEFAULT '?10\.00'?/i)
}
assert.doesNotMatch(readInitialization(), /SET baseline_chargeable_quantity = chargeable_quantity|MODIFY COLUMN baseline_chargeable_quantity/)
})
test('统一增量最终检查阻止缺少入库费用计费字段的部署通过', () => {
const finalAssertion = unified.slice(unified.indexOf('CREATE PROCEDURE assert_unified_final_schema()'))
assert.match(finalAssertion, /column_name='baseline_chargeable_quantity'[\s\S]*numeric_precision=18 AND numeric_scale=6/)
assert.match(finalAssertion, /column_name='tolerance_percent'[\s\S]*numeric_precision=5 AND numeric_scale=2/)
assert.match(finalAssertion, /统一迁移失败:入库费用基准计费量或容差字段不完整/)
test('最终建表保留入库费用唯一身份和基准非空约束', () => {
assert.match(fee, /PRIMARY KEY \(id\)/)
assert.match(fee, /UNIQUE KEY/)
assert.match(fee, /baseline_chargeable_quantity decimal\(18,6\) NOT NULL/i)
assert.match(fee, /tolerance_percent decimal\(5,2\) NOT NULL/i)
})