refactor(flight-state): SCHD 日计划收敛为缺失保留合并语义并对齐现行设计文档
按现行 docs/flight-state.md(111 行版,§1-§7)全面对齐 domain 包及其消费方, 删除整套指向已退役长版文档(§5.x-§10)的引用与死代码: - 语义:FlightStateEngine.snapshotState 由"完整快照整体替换"改为 §3.1 合并语义 ——出现 Set/Replace、缺失保留、标量空串显式清空;DELETED 不被日计划恢复(§3.3)。 - 校验:validateMessage 移除从未接线的报文覆盖范围(scope)参数,只保留 §4 步骤 2 的声明数量/航班标识/运营日推导校验;ScheduleBody 删除 scopeStart/scopeEnd。 - 删除死代码:domain/Decision.kt、FlightModel 的 SnapshotPatch/UpsertOutcome、 ProcState.isTerminal/archivable、SnapshotFlag.SEQN_REGRESSION、 ScheduleRecord.seqn(及 wire FlightRecordXml.SEQN);codec 移除未消费 FFID。 - 删除未接线且引用已退役列(fday/last_message_id)的 SqlDialect 方言脚手架, oracle11g README 改为按 V1 现列重建的口径。 - 注释/测试:domain、processing、infra 仓储与 jobs/delivery、配置类及对应测试的 KDoc 章节引用全部对齐现行 flight-state.md/design.md;FlightStateEngineTest 重写为合并语义(62/62 通过)。 V1__flight_state_baseline.sql 保留原样(内容注释仍带旧章节号,改动会破坏 已应用迁移的 Flyway checksum,待重建基线或 V2 净迁移时收敛)。
This commit is contained in:
@@ -10,9 +10,10 @@ import java.time.LocalDate
|
||||
import java.time.ZoneId
|
||||
|
||||
/**
|
||||
* 航班状态引擎(docs/flight-state.md §3.3/§5.2/§5.4/§6.1)不变量:
|
||||
* 快照整体替换(缺失=清除)、DELETED 不被 SCHD 恢复、FLOP 增量保留缺失字段、
|
||||
* §5.2 五项校验整包拒绝语义。
|
||||
* 航班状态引擎(docs/flight-state.md §2–§4)不变量:
|
||||
* 日计划合并(§3.1)——出现 Set/Replace、缺失保留、标量空值显式清空;
|
||||
* DELETED 不被日计划恢复(§3.3);FLOP/ADFT 增量合并(§3.2/§3.3);
|
||||
* 整包校验(§4 步骤 2:声明数量、航班标识、运营日推导)失败整包拒绝。
|
||||
*/
|
||||
class FlightStateEngineTest {
|
||||
|
||||
@@ -20,7 +21,7 @@ class FlightStateEngineTest {
|
||||
private val day = LocalDate.of(2026, 12, 15)
|
||||
|
||||
@Test
|
||||
fun `snapshot replaces scalars and clears absent ones`() {
|
||||
fun `day plan merges scalars overwriting overlaps retaining absent and clearing on explicit empty`() {
|
||||
val current = FlightSnapshot(
|
||||
"121", day, FlightState.ACTIVE, 5,
|
||||
scalars = mapOf("FLNO" to "CA001", "REMC" to "old-note"),
|
||||
@@ -28,25 +29,66 @@ class FlightStateEngineTest {
|
||||
)
|
||||
val next = FlightStateEngine.snapshotState(
|
||||
current,
|
||||
ScheduleRecord("121", scalars = mapOf("FLNO" to "CA002")),
|
||||
ScheduleRecord("121", scalars = mapOf("FLNO" to "CA002", "CNCL" to "")),
|
||||
operationDay = day,
|
||||
keepDeleted = false,
|
||||
)
|
||||
|
||||
assertEquals("CA002", next.scalars["FLNO"])
|
||||
assertFalse(next.scalars.containsKey("REMC")) // 缺失 = Clear(§5.4)
|
||||
assertEquals(emptyList<Map<String, String>>(), next.collections["GTDT"]) // 缺失 = Replace 空集
|
||||
assertEquals(6, next.stateVersion) // 每次成功写入 +1(§4)
|
||||
assertEquals("CA002", next.scalars["FLNO"]) // 重叠字段被覆盖(§3.1)
|
||||
assertEquals("old-note", next.scalars["REMC"]) // 缺失标量保留(§3.1/§7)
|
||||
assertEquals("", next.scalars["CNCL"]) // 空串 = 显式清空(落库置 NULL)
|
||||
assertEquals(listOf(mapOf("GATE" to "G1")), next.collections["GTDT"]) // 缺失集合保留
|
||||
assertEquals(6, next.stateVersion) // 每次成功写入 +1
|
||||
assertEquals(FlightState.ACTIVE, next.state)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `snapshot keeps DELETED state and flags revive conflict by caller`() {
|
||||
fun `day plan replaces collections that are present in the record`() {
|
||||
val current = FlightSnapshot(
|
||||
"121", day, FlightState.ACTIVE, 3,
|
||||
scalars = mapOf("FLNO" to "CA001"),
|
||||
collections = mapOf("GTDT" to listOf(mapOf("GATE" to "G1"))),
|
||||
)
|
||||
val next = FlightStateEngine.snapshotState(
|
||||
current,
|
||||
ScheduleRecord(
|
||||
"121",
|
||||
scalars = mapOf("FLNO" to "CA002"),
|
||||
collections = mapOf("GTDT" to listOf(mapOf("GATE" to "G2"), mapOf("GATE" to "G3"))),
|
||||
),
|
||||
operationDay = day,
|
||||
keepDeleted = false,
|
||||
)
|
||||
|
||||
assertEquals(listOf(mapOf("GATE" to "G2"), mapOf("GATE" to "G3")), next.collections["GTDT"])
|
||||
assertEquals(4, next.stateVersion)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `new flight snapshot carries only its record scalars and full collection key set`() {
|
||||
val next = FlightStateEngine.snapshotState(
|
||||
null,
|
||||
ScheduleRecord("121", mapOf("FLNO" to "CA001"), mapOf("GTDT" to listOf(mapOf("GATE" to "G1")))),
|
||||
operationDay = day,
|
||||
keepDeleted = false,
|
||||
)
|
||||
|
||||
assertEquals(FlightState.ACTIVE, next.state)
|
||||
assertEquals(1L, next.stateVersion)
|
||||
assertEquals("CA001", next.scalars["FLNO"])
|
||||
assertFalse(next.scalars.containsKey("REMC")) // 无历史可保留
|
||||
assertEquals(10, next.collections.size) // 全键输出(§2.2)
|
||||
assertEquals(listOf(mapOf("GATE" to "G1")), next.collections["GTDT"])
|
||||
assertEquals(emptyList<Map<String, String>>(), next.collections["DELY"])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `day plan keeps DELETED state for revive conflict handling`() {
|
||||
val current = FlightSnapshot("121", day, FlightState.DELETED, 3, mapOf(), emptyMap())
|
||||
val next = FlightStateEngine.snapshotState(
|
||||
current, ScheduleRecord("121", mapOf("FLNO" to "CA001")), day, keepDeleted = true,
|
||||
)
|
||||
assertEquals(FlightState.DELETED, next.state) // §5.1 步骤 6:普通 SCHD 不恢复
|
||||
assertEquals(FlightState.DELETED, next.state) // §3.3:日计划不恢复 DELETED
|
||||
assertEquals(4, next.stateVersion)
|
||||
}
|
||||
|
||||
@@ -63,51 +105,54 @@ class FlightStateEngineTest {
|
||||
)
|
||||
|
||||
assertEquals("15DEC261900", next.scalars["ESTT"])
|
||||
assertEquals("CA001", next.scalars["FLNO"]) // 缺失 = 保留(§6.1)
|
||||
assertEquals("CA001", next.scalars["FLNO"]) // 缺失 = 保留(§3.2)
|
||||
assertEquals(listOf(mapOf("GATE" to "G1")), next.collections["GTDT"])
|
||||
assertEquals(2, next.stateVersion)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `validation rejects RECS mismatch and duplicate flid and day outside scope`() {
|
||||
fun `validation accepts valid snapshot and rejects RECS mismatch`() {
|
||||
val ok = FlightStateEngine.validateMessage(
|
||||
1, listOf(ScheduleRecord("121", mapOf("SODT" to "15DEC261723"))), day, day, opDay,
|
||||
1, listOf(ScheduleRecord("121", mapOf("SODT" to "15DEC261723"))), opDay,
|
||||
)
|
||||
assertTrue(ok is SnapshotValidation.Ok)
|
||||
|
||||
val recsMismatch = FlightStateEngine.validateMessage(
|
||||
2, listOf(ScheduleRecord("121", mapOf("SODT" to "15DEC261723"))), day, day, opDay,
|
||||
2, listOf(ScheduleRecord("121", mapOf("SODT" to "15DEC261723"))), opDay,
|
||||
) as SnapshotValidation.Invalid
|
||||
assertTrue(recsMismatch.flags.contains(SnapshotFlag.RECS_DROP))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `validation rejects duplicate flid and non computable operation day`() {
|
||||
val duplicate = FlightStateEngine.validateMessage(
|
||||
2,
|
||||
listOf(
|
||||
ScheduleRecord("121", mapOf("SODT" to "15DEC261723")),
|
||||
ScheduleRecord("121", mapOf("SODT" to "15DEC261723")),
|
||||
),
|
||||
day, day, opDay,
|
||||
opDay,
|
||||
)
|
||||
assertTrue(duplicate is SnapshotValidation.Invalid)
|
||||
|
||||
val outOfScope = FlightStateEngine.validateMessage(
|
||||
1, listOf(ScheduleRecord("121", mapOf("SODT" to "20DEC261723"))), day, day, opDay,
|
||||
val noSodt = FlightStateEngine.validateMessage(
|
||||
1, listOf(ScheduleRecord("121", emptyMap())), opDay,
|
||||
) as SnapshotValidation.Invalid
|
||||
assertTrue(outOfScope.flags.contains(SnapshotFlag.DAY_MISMATCH)) // §5.2 覆盖范围校验
|
||||
assertTrue(noSodt.flags.contains(SnapshotFlag.DAY_MISMATCH)) // 运营日不可计算 → 整包拒绝
|
||||
|
||||
val empty = FlightStateEngine.validateMessage(0, emptyList(), day, day, opDay) as SnapshotValidation.Ok
|
||||
val empty = FlightStateEngine.validateMessage(0, emptyList(), opDay) as SnapshotValidation.Ok
|
||||
assertTrue(empty.flags.contains(SnapshotFlag.EMPTY))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `validation rejects non numeric or oversized flid`() {
|
||||
val bad = FlightStateEngine.validateMessage(
|
||||
1, listOf(ScheduleRecord("ABC", mapOf("SODT" to "15DEC261723"))), day, day, opDay,
|
||||
1, listOf(ScheduleRecord("ABC", mapOf("SODT" to "15DEC261723"))), opDay,
|
||||
)
|
||||
assertTrue(bad is SnapshotValidation.Invalid)
|
||||
val tooLong = FlightStateEngine.validateMessage(
|
||||
1, listOf(ScheduleRecord("1234567890123", mapOf("SODT" to "15DEC261723"))), day, day, opDay,
|
||||
1, listOf(ScheduleRecord("1234567890123", mapOf("SODT" to "15DEC261723"))), opDay,
|
||||
)
|
||||
assertTrue(tooLong is SnapshotValidation.Invalid) // SIS §3.16.2 Number(1-12)
|
||||
assertTrue(tooLong is SnapshotValidation.Invalid) // FLID 数字型 Number(1-12)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user