Files
ChronicleOfTheImmortalClan/tests/audit.test.ts
T
thzxx 9b0f36c70a v0.1.35b: 兼容层铲除——迁移链/版本戳/死表死代码/normalize 兼容批/死字段
【A+I】migrate.ts 迁移链(CURRENT_SCHEMA/MIGRATIONS/migrateIfNeeded/MigrationError)整链铲除→validateLoadedState 结构校验(seed/family/members 断言);信封统一 payload 单格式(去双格式兜底);APP_ID 保留
【F】schemaVersion 字段全删(domain/creation/save 8 处);SaveMeta.version 记游戏版本字符串
【C】chronicle 死表+saveChronicle 死方法(首行 return+unreachable legacy 僵尸)全删
【D/E】GameEngine __state globalThis 泄漏口+seed 三元(恒不可达)删除;engineFromSnapshot/noAutoCreate 保留(测试便利——非兼容机器)
【B/H】normalizeGameState 兼容批删:老档字段补(28行)/worldGen 重放(18行)/P0-2 占位 def(9行)/worldSim 字段批删;保留 npcs 重注册/headId 修复/d distress 防护;initSim 补 0.1.34 四键(唯一初始源)
【G】domain 收紧 5 兼容 optional(techniqueRank/Progress/tribBoost/worldGen 必填)+pcgen 必写
【测试】删 9 个兼容验证体(audit 0.1.0-era/全残缺矩阵/空 worldSim 兜底);5989 全绿——金钟罩零漂(新档结构全字段,删除不涉世界数值)
2026-08-23 22:35:17 +08:00

110 lines
4.4 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { World, normalizeGameState } from '../src/renderer/game/engine/runtime/World'
import {
marryNpcFamily,
makePeace
} from '../src/renderer/game/engine/runtime/Systems/diplomacy'
import { sendMission, recallAll } from '../src/renderer/game/engine/runtime/Systems/missions'
import { applyEventChoice } from '../src/renderer/game/engine/runtime/Systems/events'
import { GameState } from '../src/renderer/game/types/domain'
import { resetSaveBus, attachLogSink } from './world.helpers'
describe('0.1.3 audit regression', () => {
it('marries a npc family once only (allied lock)', () => {
const w = World.create({ seed: 'hy', surname: '卫', familyName: '卫家', motto: 'm', difficulty: 'normal' })
const npcId = Object.keys(w.state.npcFamilies)[0]!
const npc = w.state.npcFamilies[npcId]
npc.relation = 60
// 姑且让长子成年(18岁可婚)
w.state.members['x3'].bornYear = 1 - 18
expect(marryNpcFamily(w, npcId)).toBe(true)
expect(npc.allied).toBe(true)
expect(marryNpcFamily(w, npcId)).toBe(false)
})
it('or same-mother siblings cannot marry (candidates + direct)', () => {
const w = World.create({ seed: 'kin', surname: '陆', familyName: '陆家', motto: 'm', difficulty: 'normal' })
const a = w.state.members['x3']
const b = w.state.members['x5']
// 人为制造同母异父关系
a.motherId = 'x2'
b.motherId = 'x2'
a.fatherId = undefined
b.fatherId = undefined
expect(w.marriageCandidatesOf(a.id).map((c) => c.id)).not.toContain(b.id)
expect(w.marryTo(a.id, b.id)).toBe(false)
})
it('peace cements relation to a floor above zero', () => {
const w = World.create({ seed: 'peace', surname: '华', familyName: '华家', motto: 'm', difficulty: 'normal' })
const npcId2 = Object.keys(w.state.npcFamilies)[0]!
const npc = w.state.npcFamilies[npcId2]
npc.relation = -80
w.state.family.stones = 900
expect(makePeace(w, npcId2)).toBe(true)
expect(npc.relation).toBeGreaterThanOrEqual(30)
})
it('event negative resource cannot sink stones below zero', () => {
const w = World.create({ seed: 'clamp', surname: '曾', familyName: '曾家', motto: 'm', difficulty: 'normal' })
const npcId2 = Object.keys(w.state.npcFamilies)[0]!
w.state.family.stones = 30
applyEventChoice(w, `ev-raid-${npcId2}`, 1) // 割地求和 -250
expect(w.state.family.stones).toBe(0)
})
it('expedition squad releases members and drops wounded', () => {
const w = World.create({ seed: 'exp', surname: '纪', familyName: '纪家', motto: 'm', difficulty: 'normal' })
resetSaveBus()
attachLogSink(w)
const ok = sendMission(w, 'm-anmoku', ['x1', 'x3'])
expect(ok).toBe(true)
const m = w.state.missions[0]
expect(m.memberIds.length).toBe(2)
// 制造重伤:让一人带伤退出
const c = w.state.members['x3']
c.health = 10
c.state = 'wounded'
w.advanceMonth()
expect(m.memberIds).not.toContain('x3')
expect(w.state.members['x3'].state).toBe('wounded')
// 剩余的 x1 一人 ≥ minMembers=1 可以继续;test recall releases
recallAll(w, m.id)
expect(w.state.members['x1'].state).toBe('idle')
})
it('squad disband when members run short', () => {
const w = World.create({ seed: 'exp2', surname: '窦', familyName: '窦家', motto: 'm', difficulty: 'normal' })
resetSaveBus()
attachLogSink(w)
const ok = sendMission(w, 'm-xuangu', ['x1', 'x3']) // minMembers 1
expect(ok).toBe(true)
const m = w.state.missions[0]
// 两人同时重伤离队
w.state.members['x1'].health = 10
w.state.members['x1'].state = 'wounded'
w.state.members['x3'].health = 10
w.state.members['x3'].state = 'wounded'
w.advanceMonth()
expect(m.done).toBe(true)
expect(m.result).toBe('disband')
})
it('long run 600 months stays sane', () => {
const w = World.create({ seed: 'long', surname: '丁', familyName: '丁家', motto: 'm', difficulty: 'normal' })
resetSaveBus()
attachLogSink(w)
for (let i = 0; i < 600; i++) {
if (w.state.gameOver) break
w.advanceMonth()
}
const s = w.state
expect(Number.isNaN(s.family.stones)).toBe(false)
expect(s.year).toBeGreaterThan(30)
for (const c of Object.values(s.members)) {
expect(Number.isNaN(c.realmProgress)).toBe(false)
expect(Number.isNaN(c.health)).toBe(false)
}
})
})