Files
gplan-2/game/tests/unit/data_config/counter_prefix_fatal_test.gd
T
DKChan 33e1f11057 test(卡② T7补漏): 补齐 §9 正向验收主力 V1/V2/V6 与全 Vn 标注 + V1/V4 变异验证
前批合回时漏建卡② §9 逐需求点「正向验收主力」断言(四桶机制),仅靠迁移旧测+V12 兜底——
V12 formed/rules 输出面不作判据,adventure 桶跨战持久若坏不会红,核心缺陷消解无回归网。本批补:
- V1 冒烟新段:同一 RunLedger 两 begin_battle 各真实 request_dig,断 adv_twin_digs 经 ctx 就地写宿主字典跨战累积=2
- V2:start_adventure 后 adventure 桶置空(feat_vouchers)
- V6 冒烟新段:次战新编排器 fx_counters_battle 天然空、battle 桶 insurance_used 读 0
- V3/V4/V5/V7/V8/V9/V10 补〔无状态化 Vn〕尾缀使 §9 可追溯
- 变异验证:V1 断 adventure 桶引用改新建空字典→3 条红;V4 断 level 桶不共享→红(证回归网真拦得住)
2026-10-21 02:45:57 +08:00

72 lines
3.5 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.
# 致命类用例(独立进程,期望退出码 1)
# 卡② V9/E1——计数器前缀合法性 + 引用闭合加载期致命双断言:
# ①向 feats.tres 注入 kind=counter_add 但 counter_id 前缀非法(meta_ 出域)的行 → validate_trigger_row 须拦;
# ②注入读点(when fact=counter id)指向无同名写入行的悬空 id → config_db_cross_validator 引用闭合须拦。
# 任一违规被放行即回归(退出码 2)。两夹具目录各跑一次 load_tables,均须拒绝。
# 运行:godot --headless --path game --script res://tests/unit/data_config/counter_prefix_fatal_test.gd
extends SceneTree
const ConfigDBScript := preload("res://core/config_db.gd")
const Kit := preload("res://tests/unit/test_kit.gd")
const SRC_DIR := "res://data/tables"
const BAD_PREFIX_DIR := "user://counter_fixture_prefix"
const BAD_REF_DIR := "user://counter_fixture_ref"
# 注入探针:非法前缀写入行(meta_probe 无 meta_ 合法归桶 → counter_id_legal false)
const PROBE_PREFIX := ' {\n "feat_id": "prefix_probe",\n "display_name": "前缀探针",\n "rarity": "common",\n "triggers": [ { "on": "dig_reveal", "when": [], "do": { "kind": "counter_add", "counter_id": "meta_probe", "value": 1 } } ],\n "desc": "夹具探针——非法前缀"\n},\n'
# 注入探针:悬空读点(when counter id=pain_layer 单数,全表无同名写入行 → 引用闭合拦)
const PROBE_REF := ' {\n "feat_id": "ref_probe",\n "display_name": "引用探针",\n "rarity": "common",\n "triggers": [ { "on": "dig_reveal", "when": [ { "fact": "counter", "id": "pain_layer", "op": "lt", "value": 1 } ], "do": { "kind": "grant_ap", "mode": "queue", "value": 1 } } ],\n "desc": "夹具探针——悬空读点"\n},\n'
func _inject(dir: String, probe: String) -> bool:
var path := dir + "/feats.tres"
var f := FileAccess.open(path, FileAccess.READ)
if f == null:
push_error("注入失败:读不到 %s" % path)
return false
var s := f.get_as_text()
f.close()
var anchor := "rows = ["
var idx := s.find(anchor)
if idx < 0:
push_error("注入失败:锚点 '%s' 未找到(len=%d)" % [anchor, s.length()])
return false
var cut := idx + anchor.length()
s = s.substr(0, cut) + "\n" + probe + s.substr(cut)
var w := FileAccess.open(path, FileAccess.WRITE)
if w == null:
push_error("注入失败:写不开 %s" % path)
return false
w.store_string(s)
w.close()
return true
func _assert_rejected(bad_dir: String, probe: String, label: String) -> bool:
# 返回 true=正确拒绝;false=放行或夹具失败(调用方据此退出 2)
if not Kit.copy_tables(SRC_DIR, bad_dir) or not _inject(bad_dir, probe):
push_error("[%s] 夹具目录准备失败" % label)
return false
var db = ConfigDBScript.new()
var ok: bool = db.load_tables(bad_dir, false)
if ok:
push_error("[%s] 违规表被放行——加载期校验失守(回归)" % label)
return false
if db.diagnostics_count("error") < 1:
push_error("[%s] 加载被拒但零 error 诊断——校验通道静默化(回归)" % label)
return false
print("[%s] 正确拒绝(error 诊断在案)" % label)
return true
func _init() -> void:
if not _assert_rejected(BAD_PREFIX_DIR, PROBE_PREFIX, "counter_prefix_fatal_test/①非法前缀"):
quit(2)
return
if not _assert_rejected(BAD_REF_DIR, PROBE_REF, "counter_prefix_fatal_test/②悬空读点"):
quit(2)
return
print("[counter_prefix_fatal_test] 双断言均正确拒绝(前缀合法性 + 引用闭合)〔无状态化 V9〕")
quit(1)