feat(卡② T5): 计数器引用闭合校验 + V9 负面套件 + manifest 登记
- config_db_cross_validator ⑦ 引用闭合:声明集=feats+treasure 各行 do.counter_id, 读点(when counter id / value_counter / counter_spend counter_id)无同名写入行→加载致命 (判据只做成员判定,不重写前缀规则——契约 6 两落点同源) - 新建 counter_prefix_fatal_test.gd(expect1/negative):①meta_ 非法前缀②悬空读点两断言,均正确拒绝 - run_all.gd manifest 登记负面套件 real 数据 config_db_test 26 全绿(闭合零误伤);insurance_used 经 forgive_seal_miss 行 do.counter_id 声明纳入。
This commit is contained in:
1 parent
d402ea143a
commit
4c5bdbc9aa
4 files changed
+107
No files matched your search
@@ -46,6 +46,7 @@ func _suites() -> Array:
|
||||
# negative=true=负面套件:坏表/违规输入是它的测试目标,输出里必然带 Parse Error,
|
||||
# 脚本错误扫描对它属误伤——豁免只放行这一件,且仅限「错误扫描」一闸(退出码与断言下限照判)。
|
||||
{"path": "res://tests/unit/data_config/reward_dangling_treasure_test.gd", "expect": 1, "negative": true}, # 秘宝双表校验
|
||||
{"path": "res://tests/unit/data_config/counter_prefix_fatal_test.gd", "expect": 1, "negative": true}, # 卡② V9 前缀合法性+引用闭合加载致命
|
||||
{"path": "res://tests/unit/data_config/rng_service_test.gd", "expect": 0},
|
||||
{"path": "res://tests/unit/core/treasure_items_test.gd", "expect": 0}, # 秘宝结构冻结断言面
|
||||
{"path": "res://tests/unit/core/breakpoint_resume_test.gd", "expect": 0}, # 断点往返/续玩确定性/幂等/退出清断点
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
# 致命类用例(独立进程,期望退出码 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] 双断言均正确拒绝(前缀合法性 + 引用闭合)")
|
||||
quit(1)
|
||||
@@ -0,0 +1 @@
|
||||
uid://ckn8u3rt64qmi
|
||||
Reference in new issue
Block a user