【引擎层 P0】 - GameEngine.restore 双重时钟注册(回档后整月双跑)→ restore 重建内核+回置 rng 状态 - engineFromSnapshot 必崩(globalThis.__state 从未设)→ 修正带 seed 重建 - DEV 性能分支二次执行整月管线 → 只读告警(绝不重跑) - 引擎 advance 遇待决事件死锁 → resolvePending(idx) 通道(自动化/测试推进) 【WorldSim 大修】 - NPC 换代文案垃圾(n-danxin行情降50%)→ 换代快讯专属文案 - secretQi 假闭环(纯写无读)→ 全秘境初始化+missions 统一 consumeSecretQi - 快讯节流自锁(lastNewsMonth 恒 1 月)→ totalTicks%24 - power 月度收敛坍塌(1400±3)→ 换代/年首化+年度成长 - relation 双重拉零(4 家全 0)→ 交还外交年度漂移 - 市场基准 5 处重复 → POOL_BASE 单一权威;灾年 stale 清理;drift 各池独立噪声 - worldsim 能力卡补全 + normalize 兜底(worldSim/stats 子字段) 【UI/动效/存储】 - ModalShell 三条 CSS 规则真正落地(close 定位/body 滚动/footer 独立底排)——0.1.12 声明未实施项 - fx-canvas:resize 监听移除/mistTimer 清零/reduced 联动/soft 档无雾 + drift 走 gate(过滤器) - 档位 density 脱钩修复;顶栏“止”钮补 onClick;版本号三处统一 0.1.15 - importAll 清 chronicle 表;自动推进季度落盘(手动逐次) - 性能:LogFeed memo / Genealogy computeGenealogy memo / Chronicle deps 修正;死码清除(lastPhaseStats/clockFromKernel/哨兵函数等 12 处) - 删除误入库的“p”游离文件 【测试】979 全绿(36 套件);金钟罩三档 0.1.15 基线固化; typecheck/build 通过
118 lines
4.4 KiB
TypeScript
118 lines
4.4 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { World } from '../src/renderer/game/engine/runtime/World'
|
|
import { GameFacade } from '../src/renderer/game/engine/runtime/ApiFacade'
|
|
import { installCoreSystems, buildClock } from '../src/renderer/game/engine/runtime/clocks'
|
|
import { emptyClock } from '../src/renderer/game/engine/runtime/clocks'
|
|
import { CORE_PLUGINS } from '../src/renderer/game/engine/runtime/plugin-bootstrap'
|
|
import { examplePlugin, brokenPlugin } from './helpers/examplePlugin'
|
|
import { stateFingerprint, longRun } from './fingerprint.helper'
|
|
import { findEvent } from '../src/renderer/game/engine/runtime/Systems/events'
|
|
import { resetSaveBus, attachLogSink } from './world.helpers'
|
|
|
|
function baseWorld(seed: string): World {
|
|
const w = World.create({ seed, surname: '夏', familyName: '夏家', motto: 'm', difficulty: 'normal' })
|
|
resetSaveBus()
|
|
attachLogSink(w)
|
|
return w
|
|
}
|
|
|
|
describe('PluginCore 插件协议', () => {
|
|
it('内置三插件常驻且受保护', () => {
|
|
const w = baseWorld('pl-a')
|
|
const list = w.pluginList()
|
|
expect(list.length).toBe(3)
|
|
for (const p of list) {
|
|
expect(p.installed).toBe(true)
|
|
expect(p.enabled).toBe(true)
|
|
expect(p.protected).toBe(true)
|
|
}
|
|
const ids = list.map((p) => p.id)
|
|
expect(ids).toContain('core-systems')
|
|
expect(ids).toContain('core-data')
|
|
expect(ids).toContain('core-events')
|
|
})
|
|
|
|
it('核心插件不可卸载(保护)', () => {
|
|
const w = baseWorld('pl-b')
|
|
const r = w.removePlugin('core-systems')
|
|
expect(r.ok).toBe(false)
|
|
})
|
|
|
|
it('依赖缺失拒绝安装;依赖满足则放行', () => {
|
|
const w = baseWorld('pl-c')
|
|
expect(w.installPlugin(brokenPlugin).ok).toBe(false)
|
|
expect(w.installPlugin(examplePlugin).ok).toBe(true)
|
|
expect(w.pluginList().length).toBe(4)
|
|
})
|
|
|
|
it('示例安装后:消息池注入生效 + 山神庇佑加值;卸载后两清', () => {
|
|
const w = baseWorld('pl-d')
|
|
w.installPlugin(examplePlugin)
|
|
expect(w.eventPoolIds()).toContain('demo-peaks')
|
|
const x5 = w.state.members['x5']
|
|
x5.realm = { major: 'qi', minor: 1 }
|
|
const p0 = x5.realmProgress
|
|
// 推进到跨年触发年首庇佑
|
|
for (let i = 0; i < 13; i++) w.advanceMonth()
|
|
expect(x5.realmProgress).toBeGreaterThan(p0)
|
|
// 事件注入可被解析(findEvent 命中 demo 池 = 注入生效;确定性校验不赌概率)
|
|
expect(findEvent('ev-demo-guardian', w)).toBeTruthy()
|
|
// 卸载
|
|
expect(w.removePlugin('demo-peaks').ok).toBe(true)
|
|
expect(w.eventPoolIds()).not.toContain('demo-peaks')
|
|
expect(w.pluginList().length).toBe(3)
|
|
})
|
|
|
|
it('remove 后时钟钩子计数恢复(真摘钩)', () => {
|
|
const w = baseWorld('pl-e')
|
|
const before = w.clock.subscriptionCount()
|
|
w.installPlugin(examplePlugin)
|
|
const mounted = w.clock.subscriptionCount()
|
|
expect(mounted).toBe(before + 1)
|
|
w.removePlugin('demo-peaks')
|
|
expect(w.clock.subscriptionCount()).toBe(before)
|
|
})
|
|
|
|
it('安装序确定性:同版本两次世界插件列表一致', () => {
|
|
const a = baseWorld('pl-f')
|
|
const b = baseWorld('pl-f')
|
|
expect(JSON.stringify(a.pluginList())).toBe(JSON.stringify(b.pluginList()))
|
|
})
|
|
|
|
it('默认管线金钟罩不受插件层影响', () => {
|
|
expect(stateFingerprint(longRun('bell-seed-1').state)).toBe('a977654a')
|
|
expect(stateFingerprint(longRun('bell-seed-2').state)).toBe('1c41881c')
|
|
expect(stateFingerprint(longRun('bell-seed-3').state)).toBe('ee501983')
|
|
})
|
|
|
|
it('facade 插件查询与 about.plugins', () => {
|
|
const w = baseWorld('pl-g')
|
|
const f = new GameFacade(w, 1)
|
|
const pl = f.query('plugins') as { list: { id: string }[] }
|
|
expect(pl.list.length).toBe(3)
|
|
expect(f.about().plugins).toBe(3)
|
|
})
|
|
|
|
it('订阅可捕获 plugin 生命周期事件', () => {
|
|
const w = baseWorld('pl-h')
|
|
const f = new GameFacade(w, 1)
|
|
const events: string[] = []
|
|
const unsub = f.subscribe((e) => {
|
|
if (e.type === 'plugin') events.push((e as { action: string }).action)
|
|
})
|
|
w.installPlugin(examplePlugin)
|
|
w.removePlugin('demo-peaks')
|
|
expect(events).toContain('install')
|
|
expect(events).toContain('remove')
|
|
unsub()
|
|
})
|
|
|
|
it('buildClock 兼容路径仍完整注册(测试/工具用)', () => {
|
|
const clock = buildClock()
|
|
expect(clock.subscriptionCount()).toBeGreaterThanOrEqual(10)
|
|
const empty = emptyClock()
|
|
expect(empty.subscriptionCount()).toBe(0)
|
|
void installCoreSystems
|
|
})
|
|
})
|