@furongjun1999/dsh-memory 0.9.22 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/CHANGELOG.en.md +450 -0
  2. package/CHANGELOG.md +112 -0
  3. package/README.en.md +244 -0
  4. package/README.md +272 -260
  5. package/codebuddy/CODEBUDDY.md +1 -1
  6. package/docs/README.md +2 -0
  7. package/docs/discipline/templates/full.md.tmpl +1 -1
  8. package/docs/discipline/templates/rules.mdc.tmpl +1 -1
  9. package/docs/en/README.md +190 -0
  10. package/docs/en/TRANSLATION.md +78 -0
  11. package/docs/en/TRANSLATION_MANIFEST.json +170 -0
  12. package/docs/en/TRANSLATION_REPORT.md +11 -0
  13. package/docs/en/dev/README.md +10 -0
  14. package/docs/en/dev/coding-testing.md +72 -0
  15. package/docs/en/dev/switch-matrix.md +10 -0
  16. package/docs/en/glossary.md +97 -0
  17. package/docs/en/harnesses/claude.md +100 -0
  18. package/docs/en/harnesses/codebuddy.md +93 -0
  19. package/docs/en/harnesses/codex.md +88 -0
  20. package/docs/en/harnesses/dsh.md +84 -0
  21. package/docs/en/harnesses/zcode.md +42 -0
  22. package/docs/en/mdcg/ccg.md +32 -0
  23. package/docs/en/mdcg/generated-docs.md +20 -0
  24. package/docs/en/mdcg/guardrail-charter.md +170 -0
  25. package/docs/en/mdcg/mcp-tool-names.md +43 -0
  26. package/docs/en/mdcg/multi-harness.md +43 -0
  27. package/docs/en/mdcg/recall-metadata.md +30 -0
  28. package/docs/en/mdcg/world-model-endpoint.md +379 -0
  29. package/docs/en/mdcg/write-aliases.md +130 -0
  30. package/docs/en/ops/README.md +11 -0
  31. package/docs/en/ops/environment-known-issues.md +244 -0
  32. package/docs/en/ops/install.md +72 -0
  33. package/docs/en/ops/operations-troubleshooting.md +86 -0
  34. package/docs/en/ops/permissions-review.md +79 -0
  35. package/docs/en/ops/release-governance.md +49 -0
  36. package/docs/en/ops/tool-name-migration.md +30 -0
  37. package/docs/en/ops/ui-install-troubleshooting.md +53 -0
  38. package/docs/en/standards/ai-coding-standard-checklist.md +71 -0
  39. package/docs/en/standards/ai-coding-standard-lingshu.md +47 -0
  40. package/docs/en/standards/ai-coding-standard.md +185 -0
  41. package/docs/en/ui/minimal.md +62 -0
  42. package/docs/mdcg/cogmap_ops.md +16 -15
  43. package/lib/client.js +29 -3
  44. package/lib/hooks.d.ts +34 -0
  45. package/lib/hooks.js +167 -33
  46. package/lib/index.js +19 -3
  47. package/lib/lib/console_web.mjs +30 -3
  48. package/lib/lib/hook_audit.d.ts +3 -2
  49. package/lib/lib/hook_audit.js +14 -4
  50. package/lib/lib/mdcg_client.d.ts +5 -2
  51. package/lib/lib/mdcg_client.js +8 -4
  52. package/lib/lib/prompt_safety.d.ts +24 -0
  53. package/lib/lib/prompt_safety.js +77 -1
  54. package/lib/lib/token_store.js +5 -2
  55. package/lib/tools.js +5 -3
  56. package/md_cg/bucketindex.py +231 -0
  57. package/md_cg/bucketscope.py +339 -0
  58. package/md_cg/config_registry_bulk.py +19 -10
  59. package/md_cg/config_validate.py +14 -2
  60. package/md_cg/detrerank.py +137 -0
  61. package/md_cg/fsutil.py +215 -25
  62. package/md_cg/govern/__init__.py +23 -0
  63. package/md_cg/iface/__init__.py +46 -0
  64. package/md_cg/iface/_verify.py +609 -0
  65. package/md_cg/iface/contracts.py +337 -0
  66. package/md_cg/judgment_manifest.py +14 -0
  67. package/md_cg/kernel/__init__.py +27 -0
  68. package/md_cg/mcp_server.py +457 -23
  69. package/md_cg/mdcg.py +1034 -79
  70. package/md_cg/mdcos.py +263 -21
  71. package/md_cg/metacognition.py +66 -13
  72. package/md_cg/mutate_extract_shipped.py +126 -0
  73. package/md_cg/mutate_ledger_e2e.py +100 -0
  74. package/md_cg/nodefile.py +147 -23
  75. package/md_cg/op_table.py +22 -4
  76. package/md_cg/probe_c_ledger_integrity.py +258 -0
  77. package/md_cg/probe_d_retirement_discipline.py +263 -0
  78. package/md_cg/reconcile.py +9 -11
  79. package/md_cg/review_cli.py +6 -1
  80. package/md_cg/rollback.py +16 -1
  81. package/md_cg/run_tests.py +30 -1
  82. package/md_cg/scopeselect.py +214 -0
  83. package/md_cg/scrub.py +160 -23
  84. package/md_cg/security.py +4 -2
  85. package/md_cg/state_extract.py +149 -0
  86. package/md_cg/state_slots.py +58 -10
  87. package/md_cg/structboost.py +179 -0
  88. package/md_cg/test_alternatives_historical.py +162 -0
  89. package/md_cg/test_b2_sensitivity_landing.py +226 -223
  90. package/md_cg/test_b3_merge_keeps_content.py +608 -583
  91. package/md_cg/test_bucket_cards.py +85 -0
  92. package/md_cg/test_bucket_day_order.py +74 -0
  93. package/md_cg/test_bucket_quota.py +79 -0
  94. package/md_cg/test_bucket_recency_guards.py +75 -0
  95. package/md_cg/test_bucket_three_causes.py +83 -0
  96. package/md_cg/test_bucketindex.py +130 -0
  97. package/md_cg/test_bucketscope_early.py +71 -0
  98. package/md_cg/test_cond_term_fold.py +183 -0
  99. package/md_cg/test_cond_term_fold_gate.py +1210 -0
  100. package/md_cg/test_cond_term_neg_scope.py +147 -0
  101. package/md_cg/test_cond_terms_colon.py +348 -0
  102. package/md_cg/test_detrerank.py +157 -0
  103. package/md_cg/test_gate_four_kpi.py +136 -0
  104. package/md_cg/test_generation_guard.py +76 -43
  105. package/md_cg/test_issue192_move_layer_indices_guard.py +48 -0
  106. package/md_cg/test_issue362_neg_condition.py +44 -7
  107. package/md_cg/test_issue39_utf8_stdio.py +572 -572
  108. package/md_cg/test_issue413_preimage_failclosed.py +147 -9
  109. package/md_cg/test_issue444_scrub_evidence_plaintext.py +14 -8
  110. package/md_cg/test_issue677_flush_batch_io.py +139 -0
  111. package/md_cg/test_issue677_info_fast.py +82 -0
  112. package/md_cg/test_issue677_remember_dedupe.py +106 -0
  113. package/md_cg/test_issue712_tokens_sessions_read.py +199 -0
  114. package/md_cg/test_issue722_strict_conditions.py +96 -0
  115. package/md_cg/test_issue730_narrowing_audit.py +121 -0
  116. package/md_cg/test_issue733_verify_override.py +193 -0
  117. package/md_cg/test_issue733_verify_override_and_overwrite_inherit.py +315 -0
  118. package/md_cg/test_issue740_filelock_fd_leak.py +218 -0
  119. package/md_cg/test_issue741_content_hash_same_source.py +158 -0
  120. package/md_cg/test_issue747_slot_contradiction.py +125 -0
  121. package/md_cg/test_issue754_nested_root_guard.py +197 -0
  122. package/md_cg/test_issue757_index_hash_compare.py +85 -0
  123. package/md_cg/test_issue758_disk_hash_single.py +67 -0
  124. package/md_cg/test_issue759_twophase_hash.py +67 -0
  125. package/md_cg/test_issue768_overwrite_time_window_anchor.py +135 -0
  126. package/md_cg/test_issue789_log_plaintext_probe.py +100 -0
  127. package/md_cg/test_issue790_verb_negation.py +77 -0
  128. package/md_cg/test_issue810_root_guard.py +71 -0
  129. package/md_cg/test_issue812_info_index_stale.py +78 -0
  130. package/md_cg/test_issue827_weaken_dedup.py +361 -0
  131. package/md_cg/test_issue829_calibration_positive_gate.py +473 -0
  132. package/md_cg/test_kernel_iface_contracts.py +18 -0
  133. package/md_cg/test_md_cg_no_hive_dep.py +238 -17
  134. package/md_cg/test_n204_n205_n226_n227_n228_n229_exit_gates.py +545 -542
  135. package/md_cg/test_n209_verify_write_face_gates.py +5 -2
  136. package/md_cg/test_neg_condition_hits.py +336 -333
  137. package/md_cg/test_probe_cd_shipped.py +385 -0
  138. package/md_cg/test_recent_tail.py +93 -0
  139. package/md_cg/test_run_tests_entry_gates.py +110 -0
  140. package/md_cg/test_scopeselect.py +70 -0
  141. package/md_cg/test_scopeselect_clock.py +70 -0
  142. package/md_cg/test_scrub_source_line_false_positive.py +64 -0
  143. package/md_cg/test_session_attribution_consistency.py +835 -813
  144. package/md_cg/test_state_extract_shipped.py +162 -0
  145. package/md_cg/test_state_ledger_chain.py +207 -0
  146. package/md_cg/test_state_ledger_e2e.py +145 -0
  147. package/md_cg/test_structboost.py +102 -0
  148. package/md_cg/test_timeboost.py +83 -0
  149. package/md_cg/test_timeboost_relativedate.py +71 -0
  150. package/md_cg/test_topicagg.py +129 -0
  151. package/md_cg/test_twophase.py +286 -286
  152. package/md_cg/timeboost.py +223 -0
  153. package/md_cg/tokens.py +55 -7
  154. package/md_cg/topicagg.py +142 -0
  155. package/md_cg/twophase.py +15 -6
  156. package/md_cg/whitebox_kb/wisdom/code_compose.py +33 -5
  157. package/md_cg/whitebox_kb/wisdom/compose_engine.py +5 -1
  158. package/md_cg/whitebox_kb/wisdom/role_compose.py +271 -268
  159. package/md_cg/writepipe.py +35 -3
  160. package/package.json +4 -1
  161. package/scripts/workspace_index.py +2 -0
  162. package/src/hooks.ts +182 -34
  163. package/src/index.ts +19 -3
  164. package/src/lib/console_web.mjs +30 -3
  165. package/src/lib/hook_audit.ts +15 -5
  166. package/src/lib/mdcg_client.ts +8 -4
  167. package/src/lib/prompt_safety.ts +73 -1
  168. package/src/lib/token_store.ts +5 -2
  169. package/src/tools.ts +5 -3
  170. package/ui/minimal/integrity.json +2 -2
  171. package/ui/minimal/payload/build-ui.mjs +41 -2
  172. package/ui/minimal/payload/lib/client.js +29 -3
  173. package/ui/minimal/payload/lib/lib/console_web.mjs +30 -3
  174. package/ui/minimal/payload/src/lib/console_web.mjs +30 -3
  175. package/ui/minimal/payload/web/app.js +3 -1
  176. package/ui/minimal/payload/web/client.js +30 -3
  177. package/web/app.js +3 -1
  178. package/web/client.js +30 -3
  179. package/zcode/AGENTS.md +1 -1
@@ -0,0 +1,136 @@
1
+ # -*- coding: utf-8 -*-
2
+ """W5 四 KPI 门禁的守卫:门禁自己必须可红可绿。
3
+
4
+ 真源:docs/architecture/灵枢1.0_建设路线_v0.1.md §9 W5「每 KPI 一条可红可绿的检查」。
5
+
6
+ # 功能名:W5 门禁自证守卫
7
+ # 生效条件:改动 scripts/gate_four_kpi.py、或有人怀疑「门禁恒绿」时
8
+ # 子功能:①四条 KPI 齐全且名字与路线稿一字不差
9
+ # ②每条都绑定真实存在的证据模块(防证据路径写错导致永远 INVALID 却不自知)
10
+ # ③变异体必须变红(模块不存在 / 恒真不打印 / 打印 0 条 / 自报失败)
11
+ # ④真证据必须全绿(防门禁恒红,恒红与恒绿同属无判别力)
12
+ # ⑤判据锚点在场(min_pass 下限、正则、fail-closed 的 INVALID 分支)
13
+ # 执行:python -X utf8 -m md_cg.test_gate_four_kpi
14
+ # 验证方式:本文件全绿即通过;任一条红退出码 1
15
+ # 不适用条件:不判 KPI 语义是否"足够好";不替代全量套件
16
+
17
+ 为什么要单独守这个门禁
18
+ 本会话已实证:断言写错对象后,删掉被测判据用例仍 PASS(恒绿)。
19
+ 门禁是「判别的判别」,它一旦恒绿,下游全部结论失效且无人察觉。
20
+ 故本守卫不只跑一遍门禁,而是**要求门禁对变异体必须变红**。
21
+ """
22
+ from __future__ import annotations
23
+
24
+ import io
25
+ import os
26
+ import re
27
+ import sys
28
+ import tempfile
29
+
30
+ HERE = os.path.dirname(os.path.abspath(__file__))
31
+ REPO = os.path.dirname(HERE)
32
+ sys.path.insert(0, REPO)
33
+ sys.path.insert(0, os.path.join(REPO, "scripts"))
34
+
35
+ PASS = 0
36
+ FAIL = 0
37
+ FAILS = []
38
+
39
+
40
+ def check(name, ok, detail=""):
41
+ global PASS, FAIL
42
+ if ok:
43
+ PASS += 1
44
+ print(" PASS %s" % name)
45
+ else:
46
+ FAIL += 1
47
+ FAILS.append(name)
48
+ print(" FAIL %s %s" % (name, detail))
49
+
50
+
51
+ def main():
52
+ import gate_four_kpi as G
53
+
54
+ print("=" * 78)
55
+ print("W5 四 KPI 门禁 · 守卫")
56
+ print("=" * 78)
57
+
58
+ # ---- A 四个 KPI 齐全,名字与路线稿一致 ----
59
+ names = [s["kpi"] for s in G.KPIS]
60
+ want = ["记得住", "查得到", "改得回", "账不丢"]
61
+ check("A1 恰好四个 KPI 且顺序与 §0 原文一致", names == want, "实得 %r" % (names,))
62
+
63
+ src = io.open(os.path.join(REPO, "docs", "architecture",
64
+ "灵枢1.0_建设路线_v0.1.md"), encoding="utf-8").read()
65
+ missing = [n for n in want if n not in src]
66
+ check("A2 四个名字都能在路线稿原文中找到", not missing, "缺:%r" % (missing,))
67
+
68
+ # ---- B 证据模块真实存在 ----
69
+ for spec in G.KPIS:
70
+ mod = spec["evidence"]
71
+ rel = os.path.join(REPO, "md_cg", mod.split(".")[-1] + ".py")
72
+ check("B 证据存在:%s → %s" % (spec["kpi"], mod), os.path.isfile(rel), "缺文件 %s" % rel)
73
+
74
+ # ---- C 每条都有可判参数(防漏填导致空转)----
75
+ for spec in G.KPIS:
76
+ ok = (spec["pattern"] and spec["min_pass"] > 0 and spec["why"].strip())
77
+ check("C 判据参数齐备:%s(min_pass=%s)" % (spec["kpi"], spec["min_pass"]), ok)
78
+
79
+ # ---- D 变异体必须变红(核心)----
80
+ tmp = tempfile.mkdtemp(prefix="kpi_gate_guard_")
81
+ os.environ["PYTHONPATH"] = tmp + os.pathsep + os.environ.get("PYTHONPATH", "")
82
+
83
+ def write_mod(name, body):
84
+ with open(os.path.join(tmp, name + ".py"), "w", encoding="utf-8") as f:
85
+ f.write(body)
86
+ return name
87
+
88
+ m_missing = "zzz_no_such_module_xyz"
89
+ m_pass = write_mod("mut_always_pass", "import sys\nsys.exit(0)\n")
90
+ m_zero = write_mod("mut_zero_assert", "print('0 通过,0 失败')\n")
91
+ m_bad = write_mod("mut_failed", "print('3 通过,2 失败')\nimport sys\nsys.exit(1)\n")
92
+
93
+ cases = [
94
+ ("D1 模块不存在 → INVALID", m_missing, "INVALID"),
95
+ ("D2 恒真但不打印条数 → INVALID", m_pass, "INVALID"),
96
+ ("D3 打印 0 条断言 → INVALID", m_zero, "INVALID"),
97
+ ("D4 自报失败 → FAIL", m_bad, "FAIL"),
98
+ ]
99
+ for label, module, expect in cases:
100
+ spec = dict(G.KPIS[0])
101
+ spec["evidence"] = module
102
+ spec["pattern"] = r"(\d+)\s*通过,\s*(\d+)\s*失败"
103
+ spec["min_pass"] = 4
104
+ r = G.evaluate(spec, timeout=120)
105
+ check("%s(实得 %s)" % (label, r["state"]), r["state"] == expect, r["reason"])
106
+
107
+ # ---- E 反向:真证据必须 PASS(防恒红)----
108
+ ev = G.evaluate(G.KPIS[2], timeout=900) # 改得回:单条最快
109
+ check("E1 真证据应 PASS(防门禁恒红,实得 %s)" % ev["state"], ev["state"] == "PASS", ev["reason"])
110
+
111
+ # ---- F 结构锚点:fail-closed 分支必须在场 ----
112
+ gsrc = io.open(os.path.join(REPO, "scripts", "gate_four_kpi.py"), encoding="utf-8").read()
113
+ for anchor, why in (
114
+ ("INVALID", "解析不出条数/fail-closed 必须用 INVALID 而非 PASS"),
115
+ ("min_pass", "低于断言下限必须判 INVALID(防恒绿)"),
116
+ ("TimeoutExpired", "超时必须不判 PASS"),
117
+ ("len(groups)", "必须真的解析出条数,不能只看退出码"),
118
+ ):
119
+ check("F 结构锚点在场:%s(%s)" % (anchor, why), anchor in gsrc)
120
+
121
+ # ---- G verdict 聚合规则 ----
122
+ rows = [{"state": "PASS"}, {"state": "INVALID"}]
123
+ check("G1 有 INVALID 时整体 INVALID", G.verdict_of(rows) == "INVALID", G.verdict_of(rows))
124
+ rows = [{"state": "INVALID"}, {"state": "FAIL"}]
125
+ check("G2 FAIL 优先于 INVALID", G.verdict_of(rows) == "FAIL", G.verdict_of(rows))
126
+ check("G3 空集判 INVALID(不判 PASS)", G.verdict_of([]) == "INVALID", G.verdict_of([]))
127
+
128
+ print()
129
+ print("===== W5 门禁守卫:%d 通过,%d 失败 =====" % (PASS, FAIL))
130
+ if FAILS:
131
+ print(" 红项:" + ";".join(FAILS))
132
+ return 0 if FAIL == 0 else 1
133
+
134
+
135
+ if __name__ == "__main__":
136
+ sys.exit(main())
@@ -55,7 +55,11 @@ PINNED_INFO_KEYS = frozenset({
55
55
 
56
56
  NEW_INFO_KEYS = ("code_generation", "disk_generation", "stale_on_disk",
57
57
  "restart_required", "hint",
58
- "write_gate") # issue #708:分层写入闸的进程内计数(warn 观察期)
58
+ "write_gate", # issue #708:分层写入闸的进程内计数(warn 观察期)
59
+ # issue #812(2026-11-07):内存索引 vs 落盘索引的偏差面——纯增量扩键。
60
+ # 因由:批量软删 1987 条后 node_count 不降反升,真因是本进程内存索引陈旧;
61
+ # 没有这组键,调用方无法判定「数字到底信哪个」。
62
+ "index_mtime", "node_count_scope")
59
63
 
60
64
  _FAILED = []
61
65
 
@@ -274,12 +278,44 @@ def check_call_site_not_toplevel():
274
278
  % (len(found), ", ".join("%s:%d" % (f[2], f[0]) for f in found)))
275
279
 
276
280
 
277
- # 五:键集对拍——对临时 root 上真起的 MCP 服务调 cg(op=info)
281
+ # issue #677(B,2026-11-04):`info` 拆快/慢后的新契约——
282
+ # 缺省 = **快照**(内存态 + 轻诊断,不含 health_os 慢面);
283
+ # `full=true` = 旧全集(含 PINNED_INFO_KEYS 里 health_os 的键)。
284
+ # 本守卫从「逐字钉死 20 键」改为「两条腿」:快照键必须齐、且快照 ⊂ full;full 必须含旧 20 键。
285
+ FAST_INFO_KEYS = set(NEW_INFO_KEYS) | {
286
+ "surface", "tools", "whoami", "node_count", "flush_state", "full",
287
+ "audit_kinds", "ccg_contract", "external_verifiers",
288
+ "write_policy", "write_gate", "theory", "links",
289
+ }
290
+ #: 快照模式**新增**的键(除 NEW_INFO_KEYS 外)——只允许这三个出现在 full 的「多出」里。
291
+ FAST_ONLY_KEYS = {"flush_state", "full", "node_count"}
292
+
293
+ #: issue #812:**只在 full 面**出现的键(快照面不解析 58MB 落盘索引,故不能要求快照齐备)。
294
+ #: 它们仍需登记,否则「full 多出未登记键」会红——这正是扩键流程要的。
295
+ #: 只在 full=true 时出现的 info 键(新增键必须登记,否则「快照缺键/多键」守卫会红)。
296
+ #: `bucket_auto`:桶索引每日自动重建的读数(2026-11-09 引入,info 触发点)。
297
+ FULL_ONLY_INFO_KEYS = {"index_node_count", "index_stale", "index_stale_error",
298
+ "bucket_auto"}
299
+
300
+
301
+ def _parse_info(stdout, rid):
302
+ for line in stdout.splitlines():
303
+ line = line.strip()
304
+ if not line:
305
+ continue
306
+ try:
307
+ obj = json.loads(line)
308
+ except ValueError:
309
+ continue
310
+ if obj.get("id") == rid and "result" in obj:
311
+ return json.loads(obj["result"]["content"][0]["text"])
312
+ return None
313
+
314
+
315
+ # 五:键集对拍——对临时 root 上真起的 MCP 服务调 cg(op=info)(快照 + full 两条腿)
278
316
  def check_info_keys(tmp):
279
- print("\n== 五 键集对拍:cg(op=info) 真调(临时 root) ==")
317
+ print("\n== 五 键集对拍:cg(op=info) 快照/full 两条腿(临时 root) ==")
280
318
  env = _child_env(tmp)
281
- # 本条要验的是**工作区里这套接线**(不是副本),故包来源显式钉到当前树:
282
- # 记忆 root / aux / DSH_HOME 仍是临时目录(隔离),只有代码取自当前树。
283
319
  env["PYTHONPATH"] = REPO
284
320
  lines = [
285
321
  {"jsonrpc": "2.0", "id": 1, "method": "initialize",
@@ -287,7 +323,9 @@ def check_info_keys(tmp):
287
323
  "clientInfo": {"name": "generation-guard", "version": "0"}}},
288
324
  {"jsonrpc": "2.0", "id": 2, "method": "tools/call",
289
325
  "params": {"name": "cg", "arguments": {"op": "info"}}},
290
- {"jsonrpc": "2.0", "id": 3, "method": "shutdown", "params": {}},
326
+ {"jsonrpc": "2.0", "id": 3, "method": "tools/call",
327
+ "params": {"name": "cg", "arguments": {"op": "info", "full": True}}},
328
+ {"jsonrpc": "2.0", "id": 4, "method": "shutdown", "params": {}},
291
329
  ]
292
330
  payload = "\n".join(json.dumps(x, ensure_ascii=False) for x in lines) + "\n"
293
331
  r = subprocess.run([sys.executable, "-X", "utf8", "-m", "md_cg.mcp_server"],
@@ -295,50 +333,45 @@ def check_info_keys(tmp):
295
333
  text=True, encoding="utf-8", errors="replace",
296
334
  shell=False, timeout=600)
297
335
  if r.returncode != 0:
298
- _fail("五·键集", "mcp_server 退出码 %s(代校验接线可能把启动打死了):%s"
299
- % (r.returncode, (r.stderr or "")[-700:]))
336
+ _fail("五·键集", "mcp_server 退出码 %s:%s" % (r.returncode, (r.stderr or "")[-700:]))
300
337
  return
301
- info = None
302
- for line in r.stdout.splitlines():
303
- line = line.strip()
304
- if not line:
305
- continue
306
- try:
307
- obj = json.loads(line)
308
- except ValueError:
309
- continue
310
- if obj.get("id") == 2 and "result" in obj:
311
- info = json.loads(obj["result"]["content"][0]["text"])
312
- if info is None:
313
- _fail("五·键集", "没取到 cg(op=info) 响应:stdout=%s" % (r.stdout or "")[:400])
338
+ fast = _parse_info(r.stdout, 2)
339
+ full = _parse_info(r.stdout, 3)
340
+ if fast is None or full is None:
341
+ _fail("五·键集", "没取到 info 响应:stdout=%s" % (r.stdout or "")[:400])
314
342
  return
315
- keys = set(info)
316
- missing = [k for k in NEW_INFO_KEYS if k not in keys]
317
- if missing:
318
- _fail("五·键集", "缺新键:%s" % missing)
343
+ missing_fast = sorted(FAST_INFO_KEYS - set(fast))
344
+ if missing_fast:
345
+ _fail("五·键集", "快照缺键:%s" % missing_fast)
319
346
  return
320
- extra = sorted(keys - PINNED_INFO_KEYS - set(NEW_INFO_KEYS))
321
- lost = sorted(PINNED_INFO_KEYS - keys)
322
- if extra or lost:
323
- _fail("五·键集", "既有键集被改动:多出 %s / 丢失 %s" % (extra, lost))
347
+ if fast.get("full") is not False:
348
+ _fail("五·键集", "快照模式 full 应为 False,实得 %r" % (fast.get("full"),))
324
349
  return
325
- if info["code_generation"] != info["disk_generation"]:
326
- _fail("五·键集", "刚起的进程自报跨代:code=%s disk=%s"
327
- % (info["code_generation"], info["disk_generation"]))
350
+ if "os" in fast:
351
+ _fail("五·键集", "快照模式不得含 health_os 慢面(os 段)")
328
352
  return
329
- if info["stale_on_disk"] is not False or info["restart_required"] is not False:
330
- _fail("五·键集", "刚起的进程 stale_on_disk/restart_required 应为 False,"
331
- "实得 %r/%r" % (info["stale_on_disk"],
332
- info["restart_required"]))
353
+ if not set(fast) <= set(full):
354
+ _fail("五·键集", "快照键必须 ⊂ full:多出 %s" % sorted(set(fast) - set(full)))
333
355
  return
334
- if "重启常驻 MCP 进程" not in (info["hint"] or ""):
335
- _fail("五·键集", "hint 未含处置指引:%r" % (info["hint"],))
356
+ lost = sorted(PINNED_INFO_KEYS - set(full))
357
+ if lost:
358
+ _fail("五·键集", "full 丢失既有 20 键:%s" % lost)
336
359
  return
337
- _ok("五·键集", "五新键齐备、既有 20 键(18 + #53-B 扩键 bucket_scope + "
338
- "PR #54 扩键 skipped_unreadable)一字未动;"
339
- "代 %s(code==disk,restart_required=False)"
340
- % info["code_generation"])
341
-
360
+ extra = sorted(set(full) - PINNED_INFO_KEYS - set(NEW_INFO_KEYS) - FAST_ONLY_KEYS
361
+ - FULL_ONLY_INFO_KEYS)
362
+ if extra:
363
+ _fail("五·键集", "full 多出未登记键:%s" % extra)
364
+ return
365
+ if full["code_generation"] != full["disk_generation"]:
366
+ _fail("五·键集", "刚起的进程自报跨代:code=%s disk=%s"
367
+ % (full["code_generation"], full["disk_generation"]))
368
+ return
369
+ if full["stale_on_disk"] is not False or full["restart_required"] is not False:
370
+ _fail("五·键集", "stale_on_disk/restart_required 应为 False,实得 %r/%r"
371
+ % (full["stale_on_disk"], full["restart_required"]))
372
+ return
373
+ _ok("五·键集", "快照 %d 键 ⊂ full %d 键;full 含既有 20 键 + 五新键;快照不含 health_os 慢面"
374
+ % (len(fast), len(full)))
342
375
 
343
376
  def main():
344
377
  print("代校验守卫(generation guard)——临时目录内进行,不碰工作区与在役库")
@@ -256,3 +256,51 @@ def test_g3_existing_move_behavior_zero_regression(tmp_path):
256
256
  == buckets_before.get("orphan", 0) - 1, "桶归属迁移票数不符"
257
257
  assert lifecycle.state_of(after_entry) == lifecycle.state_of(before_entry)
258
258
  cg.close()
259
+
260
+
261
+ # ---------------------------------------------------------------- 直跑入口
262
+ # 为什么需要(issue #807 同族,2026-11-07 实测):本件的 6 个用例都是
263
+ # `def test_*(tmp_path)`,**没有模块级断言、没有 __main__**。CI 的门禁
264
+ # (scripts/run_tests.py)对 md_cg 组只发 `python -X utf8 -m <module>` ——
265
+ # `-m` 对纯 pytest-style 模块只做 import+define,跑**零个**用例、RC 恒 0。
266
+ # 实测:把 test_g1 的首条断言改成 `assert False` 后,直跑仍 RC=0,而
267
+ # `-m pytest` 下是 1 failed 5 passed。⇒ 本件在门禁里**从未真正执行过**,
268
+ # 是一条假绿守卫。补此入口使其成为 script-style,让直跑真的跑断言。
269
+ #
270
+ # tmp_path 是 pytest 的 fixture,直跑路径下用 tempfile.mkdtemp 等价替代
271
+ # (用例只把它当目录路径用:str(tmp_path) / os.path.join(root, ...))。
272
+ _ENTRY_CASES = (
273
+ ("G1 搬迁携带全部 7 键", test_g1_move_carries_all_seven_keys),
274
+ ("G1b archived lifecycle 键存活", test_g1b_archived_lifecycle_key_survives),
275
+ ("G1c 搬迁条目形态等于重扫", test_g1c_moved_entry_form_equals_rescan),
276
+ ("G1d 上游 verify 面", test_g1d_upstream_verify_face),
277
+ ("G2 旧层残留清零", test_g2_no_old_layer_residue),
278
+ ("G3 既有搬迁行为零回归", test_g3_existing_move_behavior_zero_regression),
279
+ )
280
+
281
+
282
+ def main():
283
+ import tempfile
284
+ import traceback
285
+
286
+ failed = []
287
+ for name, fn in _ENTRY_CASES:
288
+ d = tempfile.mkdtemp(prefix="mdcg_i192_")
289
+ try:
290
+ fn(d)
291
+ print(" PASS %s" % name)
292
+ except Exception as exc: # noqa: BLE001 —— 直跑要报全,不吞
293
+ failed.append(name)
294
+ print(" FAIL %s: %s: %s" % (name, type(exc).__name__, exc))
295
+ traceback.print_exc()
296
+ finally:
297
+ shutil.rmtree(d, ignore_errors=True)
298
+ total = len(_ENTRY_CASES)
299
+ print("")
300
+ print("===== SUMMARY %d/%d 通过 =====" % (total - len(failed), total))
301
+ print("VERDICT=%s" % ("PASS" if not failed else "FAIL"))
302
+ return 0 if not failed else 1
303
+
304
+
305
+ if __name__ == "__main__":
306
+ raise SystemExit(main())
@@ -36,6 +36,7 @@
36
36
  """
37
37
  from __future__ import annotations
38
38
 
39
+ import ast
39
40
  import inspect
40
41
  import json
41
42
  import os
@@ -209,11 +210,43 @@ def group_e():
209
210
  sites.append((rel, i))
210
211
  _check('E1 NFKC 归一实现全仓唯一(排除 test_*.py;不得长出第二份口径)',
211
212
  len(sites) == 1 and sites[0][0] == "md_cg/routing.py", sites)
212
- fold_src = inspect.getsource(fold_for_match)
213
- _check('E2 fold_for_match 走 routing.fold_variants 单点(不新造一份全角/大小写处理)',
214
- 'routing.fold_variants(' in fold_src, fold_src[:160])
213
+ # E2(#753/#755 复核:改 AST 判据)——文本切片会被 docstring/注释骗(假绿或假红):
214
+ # 走 AST 只认**真实调用**:fold_for_match 必须调 fold_for_match_keep,
215
+ # 且 fold_for_match_keep 必须调 routing.fold_variants。
216
+ def _fn_body(fn):
217
+ _tree = ast.parse(inspect.getsource(fn)).body[0]
218
+ _b = _tree.body
219
+ if _b and isinstance(_b[0], ast.Expr) and isinstance(_b[0].value, ast.Constant):
220
+ _b = _b[1:] # 剥 docstring(注释不进 AST,天然免疫)
221
+ return _b
222
+
223
+ def _has_call(body, attr, mod=None):
224
+ for _n in ast.walk(ast.Module(body=body, type_ignores=[])):
225
+ if (isinstance(_n, ast.Call) and isinstance(_n.func, ast.Attribute)
226
+ and _n.func.attr == attr):
227
+ if mod is None:
228
+ return True
229
+ if isinstance(_n.func.value, ast.Name) and _n.func.value.id == mod:
230
+ return True
231
+ return False
232
+
233
+ def _has_name_call(body, name):
234
+ for _n in ast.walk(ast.Module(body=body, type_ignores=[])):
235
+ if isinstance(_n, ast.Call) and isinstance(_n.func, ast.Name) and _n.func.id == name:
236
+ return True
237
+ return False
238
+
239
+ _keep_body = _fn_body(M.fold_for_match_keep)
240
+ _check('E2 fold_for_match 走 routing.fold_variants 单点(#753/#755 后归一收进 fold_for_match_keep)',
241
+ _has_name_call(_fn_body(fold_for_match), 'fold_for_match_keep')
242
+ and _has_call(_keep_body, 'fold_variants', 'routing'),
243
+ (ast.unparse(ast.Module(body=_keep_body, type_ignores=[]))[:160],))
215
244
  _check('E3 fold_variants 走 nfkc_text 单点',
216
245
  'nfkc_text(' in inspect.getsource(RT.fold_variants))
246
+ # E6(#753/#755 复核):归一**顺序**必须与 main 原式一致(fold_accents → fold_variants)。
247
+ # 实测 BMP 有 8 个码点因此分叉(希腊下加点区):「ᾀ」正序 → α、反序 → αι。
248
+ _check('E6 归一顺序 fold_accents → fold_variants(ᾀ → α;反序得 αι)',
249
+ fold_for_match("ᾀ") == "α", fold_for_match("ᾀ"))
217
250
  _check('E4 judge_qualification 的负条件腿走 neg_condition_hits 单点',
218
251
  'neg_condition_hits(' in inspect.getsource(MdCG.judge_qualification))
219
252
  n_def = sum(len(re.findall(r'def neg_condition_hits', src))
@@ -332,18 +365,18 @@ _MUTATIONS = (
332
365
  ' if all(not _negated_at(scene_norm, k)'),),
333
366
  ('K5',)),
334
367
  ('M5 归一退化:fold_for_match 退回只做去空白(#362b 修前形态)', 'md_cg/mdcg.py',
335
- ((' return compact_exact_text(routing.fold_variants(text))',
368
+ ((' return routing.fold_variants(fold_accents(text))',
336
369
  ' return compact_exact_text(text)'),),
337
- ('A4', 'A5', 'A6', 'A7', 'A8', 'A9', 'C1', 'E2', 'K11')),
370
+ ('A4', 'A5', 'A6', 'A7', 'A8', 'A9', 'C1', 'E2', 'E6', 'K11')),
338
371
  ('M6 判据退化:全词命中 all → any(单个通用词即整片否决)', 'md_cg/mdcg.py',
339
372
  ((' if words and all(w in scene_norm for w in words):',
340
373
  ' if words and any(w in scene_norm for w in words):'),),
341
374
  ('K8b',)),
342
375
  ('M7 单点分裂:fold_for_match 自写一份内联 NFKC(不走 routing 单点)', 'md_cg/mdcg.py',
343
- ((' return compact_exact_text(routing.fold_variants(text))',
376
+ ((' return routing.fold_variants(fold_accents(text))',
344
377
  ' return compact_exact_text(' + chr(10)
345
378
  + ' __import__(' + _Q + 'unicodedata' + _Q + ').normalize(' + _Q + 'NFKC' + _Q + ', str(text))).casefold()'),),
346
- ('C1', 'E1', 'E2')),
379
+ ('C1', 'E1', 'E2', 'E6')),
347
380
  ('M8 案②回退:摘掉 reason 里的「未摘词面原判 REJECT」证据(可观测性缺失)',
348
381
  'md_cg/mdcg.py',
349
382
  ((' why += (";**摘词面前原判 %s**(查询逐字含本节点的拒绝域条目,该 REJECT "'
@@ -355,6 +388,10 @@ _MUTATIONS = (
355
388
  ((' if j >= 1 and j + 1 < len(s) and s[j - 1] == s[j + 1]:',
356
389
  ' if False:'),),
357
390
  ('K12',)),
391
+ ('M10 顺序交换:fold_for_match_keep 反序(fold_accents ∘ fold_variants)', 'md_cg/mdcg.py',
392
+ ((' return routing.fold_variants(fold_accents(text))',
393
+ ' return fold_accents(routing.fold_variants(text))'),),
394
+ ('E6',)),
358
395
  )
359
396
 
360
397