weideyouni commited on
Commit
9da90d4
·
verified ·
1 Parent(s): 7ce950d

HOLO sync 1394655

Browse files
Files changed (1) hide show
  1. tests/test_v89_bayes_mech_matching.py +174 -0
tests/test_v89_bayes_mech_matching.py ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """test_v89_bayes_mech_matching.py · V89 贝叶斯内核机制匹配套件
3
+
4
+ 五组:
5
+ 一、15 模块注册表(15/唯一/层 4-5-6/基座实现 6)
6
+ 二、机制匹配表(15 行全覆盖/锚 ⊆ 25 轴 import 对账/import 证据真解析/
7
+ 三态合法)
8
+ 三、基座既有贝叶斯族 8 符号统一账(真 import 可调零复制)
9
+ 四、18 分仓+主仓适配图(19 行/服务合法/无空仓/主仓驻地 15 全量)
10
+ 五、后验校验包(机制锚定先验/共轭方向性/三分流/实测锚真跑)
11
+ """
12
+
13
+ import os
14
+ import sys
15
+ import unittest
16
+
17
+ HERE = os.path.dirname(os.path.abspath(__file__))
18
+ ROOT = os.path.dirname(HERE)
19
+ sys.path.insert(0, ROOT)
20
+ # [V89 落盘最小修正] F1 落点在包内 holoaeon/bayes_reasoning.py;按包路径导入
21
+ # 以让包内相对 import 生效(红线口径:包内禁 `from holoaeon.*` 绝对导入)。
22
+
23
+ from holoaeon import bayes_reasoning as br # noqa: E402
24
+
25
+
26
+ class T1Registry(unittest.TestCase):
27
+ def test_modules_15_unique(self):
28
+ self.assertEqual(len(br.B_MODULES), 15)
29
+ self.assertEqual(len(set(m["id"] for m in br.B_MODULES)), 15)
30
+
31
+ def test_layers_4_5_6(self):
32
+ counts = {ly: sum(1 for m in br.B_MODULES if m["layer"] == ly)
33
+ for ly in ("light", "structure", "heavy")}
34
+ self.assertEqual(counts, {"light": 4, "structure": 5, "heavy": 6})
35
+
36
+ def test_implemented_six_on_base(self):
37
+ impl = sorted(m["id"] for m in br.B_MODULES if m["implemented"])
38
+ self.assertEqual(impl, sorted(br.B_IMPLEMENTED_ON_BASE))
39
+ self.assertEqual(impl, ["B01", "B04", "B07", "B10", "B12", "B13"])
40
+
41
+
42
+ class T2MechMatch(unittest.TestCase):
43
+ def test_match_rows_cover_all_modules(self):
44
+ self.assertEqual(len(br.MECH_MATCH), 15)
45
+ self.assertEqual({r["b"] for r in br.MECH_MATCH},
46
+ {m["id"] for m in br.B_MODULES})
47
+
48
+ def test_anchors_within_25_axis(self):
49
+ from holoaeon import meridian_link as ml
50
+ axis = {m["id"] for m in ml.KERNEL_MECHANISMS}
51
+ self.assertEqual(len(axis), 25)
52
+ anchors = {a for r in br.MECH_MATCH for a in r["anchors"]}
53
+ self.assertTrue(anchors <= axis)
54
+ self.assertTrue(anchors) # 非空
55
+
56
+ def test_every_module_has_anchor(self):
57
+ self.assertTrue(all(r["anchors"] for r in br.MECH_MATCH))
58
+
59
+ def test_states_legal(self):
60
+ self.assertTrue(all(r["state"] in
61
+ ("import-evidenced", "semantic-anchor",
62
+ "pending-implementation")
63
+ for r in br.MECH_MATCH))
64
+
65
+ def test_import_evidence_resolvable(self):
66
+ for r in br.MECH_MATCH:
67
+ if r["state"] == "import-evidenced":
68
+ self.assertTrue(r["symbols"],
69
+ "{} 缺 import 符号".format(r["b"]))
70
+ for s in r["symbols"]:
71
+ self.assertTrue(br._resolve(s),
72
+ "{} 符号不可解析: {}".format(r["b"], s))
73
+
74
+ def test_b13_dual_kalman(self):
75
+ r = next(x for x in br.MECH_MATCH if x["b"] == "B13")
76
+ self.assertEqual(r["anchors"], ["R5"])
77
+ self.assertEqual(len(r["symbols"]), 2) # kalman_fuse + kalman_state
78
+
79
+
80
+ class T3BaseAssets(unittest.TestCase):
81
+ def test_assets_8_resolvable(self):
82
+ self.assertEqual(len(br.BASE_BAYES_ASSETS), 8)
83
+ for a in br.BASE_BAYES_ASSETS:
84
+ self.assertTrue(br._resolve(a["symbol"]),
85
+ "不可解析: " + a["symbol"])
86
+
87
+ def test_assets_mechanisms_in_axis(self):
88
+ from holoaeon import meridian_link as ml
89
+ axis = {m["id"] for m in ml.KERNEL_MECHANISMS}
90
+ self.assertTrue({a["mech"] for a in br.BASE_BAYES_ASSETS} <= axis)
91
+
92
+ def test_guard_and_kalman_callable(self):
93
+ from holoaeon.packs.topology_resonance_pack import (bayesian_guard,
94
+ kalman_state)
95
+ self.assertTrue(callable(bayesian_guard))
96
+ self.assertTrue(callable(kalman_state))
97
+
98
+
99
+ class T4RepoAdapters(unittest.TestCase):
100
+ def test_adapter_rows_19(self):
101
+ rows = br.repo_adapter_map()
102
+ self.assertEqual(len(rows), 19)
103
+ self.assertEqual(len(set(r["repo"] for r in rows)), 19)
104
+
105
+ def test_adapter_from_forge_bureau(self):
106
+ """适配图 import 对账 C18_NUMBERING——指针纪律"""
107
+ from holoaeon.forge_bureau import C18_NUMBERING
108
+ rows = br.repo_adapter_map()
109
+ repos = {r["repo"] for r in rows}
110
+ for c in C18_NUMBERING:
111
+ self.assertIn(c["repo"], repos)
112
+
113
+ def test_services_legal_and_nonempty(self):
114
+ b_ids = {m["id"] for m in br.B_MODULES}
115
+ for r in br.repo_adapter_map():
116
+ self.assertTrue(r["services"])
117
+ self.assertTrue(set(r["services"]) <= b_ids)
118
+
119
+ def test_main_repo_resident_full_15(self):
120
+ main = next(r for r in br.repo_adapter_map()
121
+ if r["repo_id"] == "MAIN")
122
+ self.assertTrue(main["kernel_resident"])
123
+ self.assertEqual(len(main["services"]), 15)
124
+
125
+ def test_c15_risk_gets_b15_arbitration(self):
126
+ c15 = br.REPO_SERVICES["C15"]
127
+ self.assertIn("B15", c15)
128
+
129
+
130
+ class T5PosteriorPackage(unittest.TestCase):
131
+ def test_package_shape(self):
132
+ pkg = br.posterior_package("T5", {"sigma": 0.8})
133
+ for k in ("query_id", "prior_score", "posterior_score",
134
+ "confidence_level", "decision", "update_policy"):
135
+ self.assertIn(k, pkg)
136
+
137
+ def test_mechanism_prior_not_feature_vector(self):
138
+ """去特征向量化:先验只吃机制量化证据键"""
139
+ pr = br.mechanism_prior({"sigma_c1": 0.9, "order_x2": 0.8})
140
+ self.assertGreaterEqual(pr["alpha0"], 2.0 + 0.4 + 0.6)
141
+ self.assertEqual(pr["evidence_used"],
142
+ ["order_x2=0.8", "sigma_c1=0.9"])
143
+
144
+ def test_feedback_directional(self):
145
+ good = br.posterior_package("g", {"x": 0.9}, n_success=6)
146
+ bad = br.posterior_package("b", {"x": 0.1})
147
+ self.assertGreater(good["posterior_score"], bad["posterior_score"])
148
+
149
+ def test_three_way_tiers(self):
150
+ """标定口径:三强证据→hot;单中证据→warm((2,2) 基座拉回中位,
151
+ 弱证据不虚称 high——诚实贝叶斯);负证据→cold"""
152
+ tiers = {
153
+ br.posterior_package("t", {"e1": 0.9, "e2": 0.9, "e3": 0.9})
154
+ ["update_policy"]["tier"],
155
+ br.posterior_package("t", {"x": 0.6})["update_policy"]["tier"],
156
+ br.posterior_package("t", {"x": 0.2})["update_policy"]["tier"],
157
+ }
158
+ self.assertEqual(tiers, {"hot", "warm", "cold"})
159
+
160
+ def test_live_anchor_evidence_real(self):
161
+ live = br.live_anchor_evidence()
162
+ self.assertIsInstance(live["sigma_c1"], float)
163
+ self.assertIsInstance(live["order_x2"], float)
164
+ pkg = br.posterior_package("live", live)
165
+ self.assertTrue(0.0 < pkg["posterior_score"] < 1.0)
166
+
167
+ def test_gate_pass(self):
168
+ r = br.check_bayes_reasoning()
169
+ self.assertEqual(r["verdict"], "PASS")
170
+ self.assertEqual(r["failed"], 0)
171
+
172
+
173
+ if __name__ == "__main__":
174
+ unittest.main(verbosity=2)