Files
game-code-4/tests/unit/cases/test_offline_contract.gd
T
程基岩(engineering-lead) c534e95458 fix: 首跑错误批次(Godot 4.7.2 引擎实证修复 R1-R14)
本机首次具备引擎自验证能力后的首跑修复。四条命令 + 主场景 180 帧全绿:
- --import exit=0(漂移门 git diff data/build 空)
- --validate-only exit=0 RESULT: PASS
- test_runner exit=0 PASS(584 检查,8/8 用例)
- sim_main exit=0(报告落 tests/sim_reports/report-2026-10-20.json)
- 主场景 --quit-after 180 exit=0 零 ERROR/WARNING(F5 可玩)

预定位错误(team-lead 清单):
- R1 economy_state.gd:596 enthone_ready -> enthrone_ready(单点故障连锁)
- R2 hud_root.gd:142,160 HorizontalAlignment.LEFT -> HORIZONTAL_ALIGNMENT_LEFT
- R3 boss_arena.gd 补 var _pending_hall_index := -1
- R4 hall_band_world.gd:95 删 "_ = ext"(非法语句;--check-only 定位)
- R5 sheet_importer._type_ok 补 object->Dictionary / array->Array(9 条假违规)
- R6 game_state.gd econ==null 防护(防 autoload 崩每帧刷错打满管道挂死)

引擎新暴露错误:
- R7 prestige_model floor() Variant 推断(4.7.2 按错误)连锁编译失败
- R8 gates.gd var pass 保留字;R9 %g/%.*f 格式符 ×6 处
- R10 greedy.gd Dictionary.get() 推断;R11 probe_p1 条件表达式推断
- R12 测试用例 data 参数统一标 BalanceData(无类型参数成员调用返 Variant)
- R13 boss_battle 用例 Dictionary 下标运算显式 float 化
- R14 band_world_root.compute_ranges 返回 Array[Vector2](类型化数组不隐式转换)

测试侧数值修正(根因已核实,实现符合设计):
- gen3 可购断言 merit 1000->2000(800 文书 + 1200 首购)
- 开场伤害断言改"循环至 ACTIVE 即停"(INTRO 结束 tick 不计军列伤)
- 容量断言预算 30->34s(战斗真实给 intro 3s + active 30s)

工程加固:
- EconomyState 红线守卫首次越线才报(sim 长跑日志 6.5MB->1KB)
- stage_world.gd stretch=false(SubViewport 手动尺寸驱动生效)

知识缺口登记:docs/engineering/2026-10-20-f-engine-first-run-notes.md
sim 首轮数据:主口径 11/14 过(#2/#3/#12/#13/#14 FAIL 待文策渊裁定)
2026-10-20 18:47:07 +08:00

85 lines
4.4 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
extends RefCounted
# 用例:W4 离线契约 v2(systems-spec §2.4/§2.5,用户 2026-10-20 拍板)
# 契约 v2:8h = 6.2 等效小时(效率 77.5%);24h = 12.6h;72h 封顶 = 17.4h(24.2%);
# 长明灯 6 条 × +5% 加法(满 +30%,各档速率硬顶 100%);效率硬顶 ≤ 100%。
# 门 #9 拆三条子检查(a 由 FAIL 转 PASS):9a 契约效率 / 9b 长明灯上限 / 9c 硬顶。
func run(a, data: BalanceData) -> void:
_test_contract_v2(a, data)
_test_gate_offline_v2(a, data)
func _settle(a, data: BalanceData, hours: float, add: float) -> float:
var r: Dictionary = OfflineModel.settle(hours * 3600.0, 1.0, add,
data.tune_num("tune_offline_band1_h", 2.0), data.tune_num("tune_offline_band1_rate", 1.0),
data.tune_num("tune_offline_band2_h", 8.0), data.tune_num("tune_offline_band2_rate", 0.7),
data.tune_num("tune_offline_band3_h", 24.0), data.tune_num("tune_offline_band3_rate", 0.4),
data.tune_num("tune_offline_band4_rate", 0.1),
data.tune_num("tune_offline_cap_h", 72.0))
return float(r["effective_hours"])
# ---- 契约 v2 数值面 ----
func _test_contract_v2(a, data: BalanceData) -> void:
# 衰减表一字不改(systems-spec §2.4:错的是契约不是表)
a.near(data.tune_num("tune_offline_band1_rate", 0.0), 1.0, 1e-9, "0-2h = 100%")
a.near(data.tune_num("tune_offline_band2_rate", 0.0), 0.7, 1e-9, "2-8h = 70%")
a.near(data.tune_num("tune_offline_band3_rate", 0.0), 0.4, 1e-9, "8-24h = 40%")
a.near(data.tune_num("tune_offline_band4_rate", 0.0), 0.1, 1e-9, ">24h = 10%")
a.near(data.tune_num("tune_offline_cap_h", 0.0), 72.0, 1e-9, "72h 封顶")
# 8h = 6.2 等效小时(77.5%)∈ [5.5, 7.0](用户口径)/ [5.5, 6.5](spec 口径,双重满足)
var e8 := _settle(a, data, 8.0, 0.0)
a.near(e8, 6.2, 1e-9, "8h 离线 = 6.2h 等效(契约 v2)")
a.true_(e8 >= 5.5 and e8 <= 7.0, "8h 等效 ∈ [5.5, 7.0](用户构造口径)")
a.true_(e8 >= 5.5 and e8 <= 6.5, "8h 等效 ∈ [5.5, 6.5](systems-spec §2.4 口径)")
a.near(e8 / 8.0, 0.775, 1e-9, "8h 效率 = 77.5%")
# 24h = 12.6h;72h 封顶 = 17.4h(24.2%)
a.near(_settle(a, data, 24.0, 0.0), 12.6, 1e-9, "24h 离线 = 12.6h 等效")
a.near(_settle(a, data, 72.0, 0.0), 17.4, 1e-9, "72h 封顶 = 17.4h 等效")
a.near(_settle(a, data, 72.0, 0.0) / 72.0, 17.4 / 72.0, 1e-9, "72h 效率 ≈ 24.2%")
a.near(_settle(a, data, 100.0, 0.0), 17.4, 1e-9, "100h 也被 72h 硬顶钳到 17.4h")
# 长明灯:数据面 = 6 条 × 0.05 加法(effect_type offline_add)
var lamp := 0.0
var lamp_rows := 0
for u in data.upgrades:
if u.type == "offline":
lamp += u.effect_param
lamp_rows += 1
a.eq(lamp_rows, 6, "长明灯 6 条")
a.near(lamp, 0.30, 1e-9, "长明灯满级 = 加法 +30%(旧 ×2.31 乘性已废止)")
# 长明灯满级:8h = 8.0h,效率恰好 100%(硬顶允许的最大值)
var e8l := _settle(a, data, 8.0, lamp)
a.near(e8l, 8.0, 1e-9, "长明灯满级 8h = 8.0h 等效")
a.near(e8l / 8.0, 1.0, 1e-9, "效率 = 100%(≤ 硬顶,离线不优于在线)")
# + m05(+25%)也不越过硬顶
var m05 := data.meta("meta_05")
var m05_add := 0.0
if m05 != null:
m05_add = m05.effect_param * float(m05.max_rank)
a.near(_settle(a, data, 8.0, lamp + m05_add), 8.0, 1e-9, "+ m05(+25%)仍钳 8.0h")
# 效率硬顶:任意配置/任意时长 ≤ 100%
for dur_h in [1.0, 8.0, 24.0, 72.0]:
for add in [0.0, lamp, lamp + m05_add, 5.0]:
var eff := _settle(a, data, dur_h, add)
a.true_(eff <= dur_h + 1e-9,
"效率硬顶:%sh + 加法 %.2f ⇒ %.2fh ≤ %sh" % [str(dur_h), add, eff, str(dur_h)])
# ---- 门 #9 三条子检查(a 由 FAIL 转 PASS) ----
func _test_gate_offline_v2(a, data: BalanceData) -> void:
var g: Dictionary = SimGates.gate_offline_v2(data)
a.true_(bool(g.get("pass", false)), "门 #9 三条子检查全过(a 由 FAIL 转 PASS)")
a.true_(str(g.get("detail", "")).contains("契约 v2"), "detail 标注契约 v2")
var sub: Dictionary = g.get("sub", {})
var g9a: Dictionary = sub.get("9a", {})
var g9b: Dictionary = sub.get("9b", {})
var g9c: Dictionary = sub.get("9c", {})
a.true_(bool(g9a.get("pass", false)),
"9a PASS:%s" % str(g9a.get("detail", "")))
a.true_(bool(g9b.get("pass", false)),
"9b PASS:%s" % str(g9b.get("detail", "")))
a.true_(bool(g9c.get("pass", false)),
"9c PASS:%s" % str(g9c.get("detail", "")))
a.true_(str(g.get("deferred_beta", "")).contains("β"), "进度口径 β 标记为待 sim 标定")