@furongjun1999/dsh-memory 0.9.6 → 0.9.7
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.
- package/data/policy.json +38 -38
- package/docs/discipline/templates/spec.txt.tmpl +1 -1
- package/dsh/cordis.yml.example +139 -139
- package/lib/hooks.d.ts +19 -0
- package/lib/hooks.js +29 -6
- package/lib/index.js +11 -2
- package/lib/lib/hook_audit.js +38 -2
- package/lib/lib/prompt_safety.js +14 -3
- package/lib/tools.d.ts +7 -0
- package/lib/tools.js +22 -1
- package/md_cg/_guard_kit.py +121 -121
- package/md_cg/anchor.py +114 -114
- package/md_cg/audit.py +15 -2
- package/md_cg/chain.py +3 -2
- package/md_cg/config_registry_guard.py +487 -487
- package/md_cg/conformance.py +747 -747
- package/md_cg/consolidate.py +1793 -1793
- package/md_cg/crypto.py +794 -794
- package/md_cg/hyperedge.py +262 -262
- package/md_cg/interface_schema.py +146 -146
- package/md_cg/lifecycle.py +426 -426
- package/md_cg/mdcos.py +12 -8
- package/md_cg/predict.py +1103 -1103
- package/md_cg/protect.py +654 -654
- package/md_cg/provenance.py +606 -606
- package/md_cg/queue_health.py +130 -130
- package/md_cg/refine.py +613 -613
- package/md_cg/retrieve.py +128 -128
- package/md_cg/revise.py +140 -140
- package/md_cg/rollback.py +657 -657
- package/md_cg/rollback_cli.py +124 -124
- package/md_cg/rotate.py +346 -346
- package/md_cg/routing.py +490 -490
- package/md_cg/self_surface.py +50 -50
- package/md_cg/semantic/canonical.py +144 -144
- package/md_cg/semantic/zh_en_atoms.py +141 -141
- package/md_cg/sources.py +1091 -1091
- package/md_cg/stg.py +3 -2
- package/md_cg/test_audit_rotate_parity.py +279 -279
- package/md_cg/test_autonomy_modes.py +2013 -2013
- package/md_cg/test_cn_recall_grams.py +206 -206
- package/md_cg/test_code_kind_forbidden.py +101 -0
- package/md_cg/test_condaccept.py +156 -156
- package/md_cg/test_condgate.py +141 -141
- package/md_cg/test_heartbeat_ledger.py +557 -557
- package/md_cg/test_i50e_readside_protection.py +658 -658
- package/md_cg/test_issue111_gate_order.py +76 -76
- package/md_cg/test_issue111_scoring_contract.py +86 -86
- package/md_cg/test_issue121_calibration_bounds.py +293 -293
- package/md_cg/test_issue145_sleep_no_silent_rollback.py +167 -167
- package/md_cg/test_issue147_pack_id_escape.py +378 -378
- package/md_cg/test_issue148_merge_downgrade_leak.py +192 -192
- package/md_cg/test_issue149_accel_default_face.py +248 -248
- package/md_cg/test_issue150_empty_query_terms.py +328 -328
- package/md_cg/test_issue151_153_157_write_cache_index.py +151 -151
- package/md_cg/test_issue152_sealed_postings.py +309 -309
- package/md_cg/test_issue153b_index_generation_invalidation.py +142 -142
- package/md_cg/test_issue157b_index_remainder.py +344 -344
- package/md_cg/test_issue189_conclusion_bidirectional.py +223 -223
- package/md_cg/test_issue191_import_trust.py +382 -382
- package/md_cg/test_issue193_write_scope.py +378 -378
- package/md_cg/test_issue212_writeface_gaps.py +349 -349
- package/md_cg/test_issue214_reject_sensitivity.py +266 -266
- package/md_cg/test_issue215_condition_source_gap.py +272 -272
- package/md_cg/test_issue216_clash_routes.py +214 -214
- package/md_cg/test_issue217_slot_routes.py +248 -248
- package/md_cg/test_issue218_postcondition_value_blind.py +222 -222
- package/md_cg/test_issue258_pack_sensitivity.py +468 -468
- package/md_cg/test_issue265_coldverify_multiproc.py +438 -438
- package/md_cg/test_issue274_read_node_id_none.py +341 -341
- package/md_cg/test_issue275_layer_param.py +250 -250
- package/md_cg/test_issue277_node_id_traversal.py +384 -384
- package/md_cg/test_issue278_neg_separated_tension.py +271 -271
- package/md_cg/test_issue278_neg_window.py +294 -294
- package/md_cg/test_issue278_negative_layering.py +83 -83
- package/md_cg/test_issue284_skip_not_pass.py +291 -291
- package/md_cg/test_issue294_flywheel_sensitivity.py +573 -573
- package/md_cg/test_issue301_baseline_corpus_gate.py +245 -245
- package/md_cg/test_issue303_design_boundaries.py +262 -262
- package/md_cg/test_issue315_merge_branch_sensitivity.py +383 -383
- package/md_cg/test_issue319_tenant_unregistered_bypass.py +256 -256
- package/md_cg/test_issue321_mcp_deep_json.py +304 -304
- package/md_cg/test_issue322_node_write_lock.py +727 -727
- package/md_cg/test_issue324_write_size_fields.py +214 -214
- package/md_cg/test_issue325_audit_poison.py +229 -229
- package/md_cg/test_issue326_ingest_auto_whitelist.py +331 -331
- package/md_cg/test_issue326_key_perms.py +355 -355
- package/md_cg/test_issue326_twin_parser_parity.py +323 -323
- package/md_cg/test_issue326_vm_call_frame.py +569 -569
- package/md_cg/test_issue345_writelimit_effective_sens.py +233 -233
- package/md_cg/test_issue346_overwrite_sensitivity_gate.py +424 -424
- package/md_cg/test_issue348_insight_verify_op.py +199 -199
- package/md_cg/test_issue348_merge_rmw_lock.py +345 -345
- package/md_cg/test_issue350_casefold_collision.py +235 -235
- package/md_cg/test_issue351_ingest_root_fallback.py +201 -201
- package/md_cg/test_issue352_imgaudit.py +418 -418
- package/md_cg/test_issue352_pathsjson.py +537 -537
- package/md_cg/test_issue352_refindex.py +412 -412
- package/md_cg/test_issue352_rollback.py +604 -604
- package/md_cg/test_issue354_p2_writelimit_toctou.py +327 -327
- package/md_cg/test_issue354_rust_index_containment.py +571 -571
- package/md_cg/test_issue354_rust_wal_containment.py +606 -606
- package/md_cg/test_issue358_truncation_observable.py +247 -247
- package/md_cg/test_issue360_tidy_private_excerpt.py +195 -195
- package/md_cg/test_issue361_blindspot_not_silent_drop.py +494 -494
- package/md_cg/test_issue362_neg_condition.py +468 -468
- package/md_cg/test_issue363_lexical_idf.py +275 -275
- package/md_cg/test_issue370_readcache_assembly.py +488 -488
- package/md_cg/test_issue376_heartbeat_failed.py +293 -293
- package/md_cg/test_issue377_layer_protect_stamp.py +324 -324
- package/md_cg/test_issue378_protected_floor.py +310 -310
- package/md_cg/test_issue383_state_event_write_gate.py +462 -462
- package/md_cg/test_issue397_sens_eff_wiring.py +435 -435
- package/md_cg/test_issue398_toolface_op_parity.py +511 -511
- package/md_cg/test_issue399_hive_json_shape.py +317 -317
- package/md_cg/test_issue401_wisdom_codegen.py +295 -295
- package/md_cg/test_issue404_heal_receipt.py +389 -389
- package/md_cg/test_issue409_compact_index_completeness.py +509 -509
- package/md_cg/test_issue410_verify_demote_write.py +366 -366
- package/md_cg/test_issue411_scrub_idempotence.py +575 -575
- package/md_cg/test_issue412_discipline_producer_parity.py +311 -311
- package/md_cg/test_issue413_preimage_failclosed.py +239 -239
- package/md_cg/test_issue413_preimage_twin.py +339 -339
- package/md_cg/test_issue415_deps_gate_probe.py +357 -357
- package/md_cg/test_issue416_entry_key_subset.py +525 -525
- package/md_cg/test_issue417_twophase_merge_landed.py +423 -423
- package/md_cg/test_issue425_ingest_library_path.py +331 -331
- package/md_cg/test_issue426c_enqueue_not_silent.py +346 -346
- package/md_cg/test_issue426e_restore_overwrite_live.py +310 -310
- package/md_cg/test_issue426f_paths_gbk_failclosed.py +301 -301
- package/md_cg/test_issue427_serve_status_shape.py +191 -191
- package/md_cg/test_issue431_432_468_protect_single_point.py +322 -322
- package/md_cg/test_issue433_outlook_threshold_single_point.py +278 -278
- package/md_cg/test_issue434_435_float_gate.py +90 -90
- package/md_cg/test_issue439_sibling_sensitivity_inherit.py +448 -448
- package/md_cg/test_issue43_default_policy.py +874 -874
- package/md_cg/test_issue444_scrub_evidence_plaintext.py +281 -281
- package/md_cg/test_issue445_metacognition_ledger_gate.py +454 -454
- package/md_cg/test_issue446_453_403_verified_evidence.py +382 -382
- package/md_cg/test_issue450_sensitivity_fallback_reason.py +51 -51
- package/md_cg/test_issue450_writegate_unknown_sens.py +203 -203
- package/md_cg/test_issue451_audit_actor.py +313 -313
- package/md_cg/test_issue452_ingest_root_sensitivity.py +299 -299
- package/md_cg/test_issue463_ghost_prune_guard.py +259 -259
- package/md_cg/test_issue466_basis_registry.py +469 -469
- package/md_cg/test_issue467_identity_sensitivity_parity.py +360 -360
- package/md_cg/test_issue469_scrub_override_passthrough.py +126 -126
- package/md_cg/test_issue470_wal_event_durable.py +427 -427
- package/md_cg/test_issue471_identity_readable.py +136 -136
- package/md_cg/test_issue472_audit_chain.py +90 -90
- package/md_cg/test_issue472_prune_ledger.py +105 -105
- package/md_cg/test_issue472_rollback_degraded.py +81 -81
- package/md_cg/test_issue491_compose_sandbox.py +460 -460
- package/md_cg/test_issue498_merge_trace_stale_index.py +280 -280
- package/md_cg/test_issue511_scoreboard_bad_files.py +256 -256
- package/md_cg/test_issue521_rotate_lock_suffix.py +110 -110
- package/md_cg/test_issue524_orphan_noise_no_demote.py +88 -88
- package/md_cg/test_issue525_read_null_semantics.py +52 -52
- package/md_cg/test_issue547_append_jsonl_whitelist.py +114 -114
- package/md_cg/test_issue547_audit_durable.py +96 -96
- package/md_cg/test_issue557_r2_write_entries_size_gate.py +83 -83
- package/md_cg/test_issue559_refine_prefix.py +69 -69
- package/md_cg/test_issue562_retired_faces.py +150 -0
- package/md_cg/test_issue71_queue_backlog.py +376 -376
- package/md_cg/test_issue72_coldverify_controlled_drain.py +420 -420
- package/md_cg/test_issue82_credential_rules.py +271 -271
- package/md_cg/test_issue91_verifier_sandbox.py +314 -314
- package/md_cg/test_issue93_remember_redaction.py +282 -282
- package/md_cg/test_logref.py +1141 -1141
- package/md_cg/test_md_access_parity.py +330 -330
- package/md_cg/test_md_cg_no_hive_dep.py +139 -139
- package/md_cg/test_mutation_residue.py +119 -119
- package/md_cg/test_mutation_rollback.py +835 -835
- package/md_cg/test_n123_derive_expiry_chain.py +210 -210
- package/md_cg/test_n209_verify_write_face_gates.py +466 -466
- package/md_cg/test_n62_tenant_bind_failclosed.py +200 -200
- package/md_cg/test_neg_tail_honesty.py +733 -733
- package/md_cg/test_p21_tokens.py +294 -294
- package/md_cg/test_p27_docindex.py +792 -792
- package/md_cg/test_p28_refcheck.py +1053 -1053
- package/md_cg/test_p2_six_elements.py +476 -476
- package/md_cg/test_p33_ccg_wiring.py +300 -300
- package/md_cg/test_p3_legacy_closure.py +438 -438
- package/md_cg/test_p40_refine_worklist.py +244 -244
- package/md_cg/test_p4_freshness.py +781 -781
- package/md_cg/test_p9c_dedup_hints.py +288 -288
- package/md_cg/test_policy_required_ccg.py +444 -444
- package/md_cg/test_retr_s5.py +312 -312
- package/md_cg/test_s1_ast_judge.py +109 -109
- package/md_cg/test_state_event_op.py +521 -521
- package/md_cg/test_stgidx_index_parity.py +1024 -1024
- package/md_cg/test_sustain_bounded.py +652 -652
- package/md_cg/test_trust_edge_reachability.py +405 -405
- package/md_cg/test_w7_redlines.py +659 -659
- package/md_cg/test_write_return_shape.py +919 -919
- package/md_cg/test_writepipe.py +228 -228
- package/md_cg/trust.py +1114 -1114
- package/md_cg/twophase.py +303 -303
- package/md_cg/whitebox.py +536 -536
- package/md_cg/whitebox_kb/wisdom/compose_engine.py +1634 -1634
- package/md_cg/whitebox_kb/wisdom/core/condition_vm.py +318 -318
- package/md_cg/whitebox_kb/wisdom/core/parser.py +1082 -1082
- package/md_cg/whitebox_kb/wisdom/md_access.py +490 -490
- package/md_cg/whitebox_kb/wisdom/migrate_wisdom.py +497 -497
- package/md_cg/whitebox_kb/wisdom/mini_python.py +995 -995
- package/md_cg/whitebox_kb/wisdom/net_units.py +2900 -2900
- package/md_cg/whitebox_kb/wisdom/semantic_translate.py +4060 -4060
- package/md_cg/writepipe.py +1337 -1337
- package/package.json +3 -2
- package/scripts/workspace_index.py +328 -0
- package/src/hooks.ts +30 -6
- package/src/index.ts +14 -5
- package/src/lib/hook_audit.ts +282 -256
- package/src/lib/mdcg_client.ts +469 -469
- package/src/lib/prompt_safety.ts +17 -3
- package/src/tools.ts +23 -1
|
@@ -1,222 +1,222 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""issue #218 守卫:postcondition_terms 两条出口的回传面(判据一字未动)。
|
|
3
|
-
|
|
4
|
-
# 功能名:index_key_hits 的 post/reject 分支回传面结构化(post_source/reject_source)
|
|
5
|
-
# 生效条件:改动 md_cg/mdcg.py 的 index_key_hits、或改动 nodefile.CCG_CONTRACT_ROLES
|
|
6
|
-
# 旁的 #218 登记注释之后必跑
|
|
7
|
-
# 子功能:① 判据未变(hit/post/reject/why 逐位不变,只新增字段)② 生产同源词项下的
|
|
8
|
-
# 真值表被如实钉住 ③ **更正报告 §1.2**(compiler 确实走 term 分支)④ declared
|
|
9
|
-
# 分支值盲(5 个不同取值 -> 1 种输出)⑤ post_source 使分支机器可读 ⑥ 判别力
|
|
10
|
-
# 执行:python -X utf8 -m md_cg.test_issue218_postcondition_value_blind
|
|
11
|
-
# 验证方式:末行「通过 N / 失败 M」;红基线:撤掉 post_source 新增 ⇒ ②③⑤⑥ 转红
|
|
12
|
-
# 不适用条件:本守卫**不主张** declared 分支应被取消或收紧——那是行为变更,属设计
|
|
13
|
-
# 裁定(issue #218 自己倾向选项 (a)「零行为变更 + 诚实归类」);不改阈值;
|
|
14
|
-
# 不测生产语料上「验证方式」取值的实际分布
|
|
15
|
-
|
|
16
|
-
## 缺陷现场(issue #218)
|
|
17
|
-
post = e.get(POSTCONDITION_TERMS_KEY) or []
|
|
18
|
-
if post:
|
|
19
|
-
if any(t in " ".join(post) for t in (terms or [])): # 出口 1:term
|
|
20
|
-
hits["post"] = True; hits["why"].append("postcondition_terms:term")
|
|
21
|
-
elif is_postcondition_query(q): # 出口 2:declared
|
|
22
|
-
hits["post"] = True; hits["why"].append("postcondition_terms:declared")
|
|
23
|
-
|
|
24
|
-
## 复核结论(与报告一处重要不同,本守卫按实测钉)
|
|
25
|
-
报告 §1.1 表中「查询 A = compiler 是怎么实现的」一行报 post=False,并据此在 §1.2
|
|
26
|
-
**更正上游 #181**(#181 称「仅 compiler 走 term 分支」)。本件实测**不可复现该更正**:
|
|
27
|
-
|
|
28
|
-
· 生产同源词项 = expand_query_terms(查询)(mdcg.search :4042 即此调用),
|
|
29
|
-
它对查询 A 返回 ['compiler 是怎么实现的', 'compiler', '是怎么实现的', ...]
|
|
30
|
-
—— **裸词 compiler 在其中**;
|
|
31
|
-
· 节点侧 postcondition_terms = ['compiler']," ".join(post) = 'compiler';
|
|
32
|
-
· 故 'compiler' in 'compiler' 为真 ⇒ 走 term 分支。
|
|
33
|
-
· 同一代码在报告所称分支 origin/level0000x(5e9c313e)上**逐字相同**(已核对),
|
|
34
|
-
故该读数在作者自身分支上亦不可复现——应源于探针取的 terms 非生产口径。
|
|
35
|
-
|
|
36
|
-
⇒ **#181 的读数是对的**;报告 §1.2 的「更正」不成立。
|
|
37
|
-
报告真正成立的是:declared 出口**值盲**——但那是**刻意设计**(见下)。
|
|
38
|
-
|
|
39
|
-
## 两条出口的真实语义
|
|
40
|
-
· term —— **值敏感**,但可达性取决于**查询**是否含该值(不是值的质量);
|
|
41
|
-
· declared —— **值盲**:验证方式问句 + 该行切分后非空即命中,任意非空取值同输出。
|
|
42
|
-
代码 docstring 明写这是设计(「声明了验证方式即召回」),与 rejection_terms 的
|
|
43
|
-
边界问句同构。故它不是缺陷,而是**未在回传面登记的语义**。
|
|
44
|
-
"""
|
|
45
|
-
from __future__ import annotations
|
|
46
|
-
|
|
47
|
-
import io
|
|
48
|
-
import os
|
|
49
|
-
import sys
|
|
50
|
-
|
|
51
|
-
_HERE = os.path.dirname(os.path.abspath(__file__))
|
|
52
|
-
sys.path.insert(0, os.path.dirname(_HERE))
|
|
53
|
-
if hasattr(sys.stdout, "reconfigure"):
|
|
54
|
-
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
55
|
-
|
|
56
|
-
from md_cg import nodefile # noqa: E402
|
|
57
|
-
from md_cg.mdcg import (expand_query_terms, is_postcondition_query, # noqa: E402
|
|
58
|
-
index_key_hits)
|
|
59
|
-
|
|
60
|
-
_PASS, _FAIL = [], []
|
|
61
|
-
QA = "compiler 是怎么实现的" # 普通问句(is_postcondition_query=False)
|
|
62
|
-
QB = "这个结论是怎么验证的" # 验证方式问句(=True)
|
|
63
|
-
VALS = ["measurement", "compiler", "textbook", "任意乱写的值", "zzz", "x", "无"]
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
def ok(cond, msg, extra=''):
|
|
67
|
-
(_PASS if cond else _FAIL).append(msg)
|
|
68
|
-
print((' PASS ' if cond else ' FAIL ') + msg
|
|
69
|
-
+ ((' <- ' + str(extra)) if (extra and not cond) else ''))
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
def _entry(v):
|
|
73
|
-
return {nodefile.POSTCONDITION_TERMS_KEY:
|
|
74
|
-
nodefile.ccg_element_terms("# 验证方式:%s\n" % v,
|
|
75
|
-
nodefile.POSTCONDITION_FIELD)}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
def _hit(v, q):
|
|
79
|
-
return index_key_hits(_entry(v), expand_query_terms(q), q)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
def j0_judgement_unchanged():
|
|
83
|
-
ok(is_postcondition_query(QA) is False, 'J0a 查询 A 非验证方式问句')
|
|
84
|
-
ok(is_postcondition_query(QB) is True, 'J0b 查询 B 是验证方式问句')
|
|
85
|
-
ok(nodefile.ELEMENT_TERM_MIN == 2, 'J0c ELEMENT_TERM_MIN 仍为 2',
|
|
86
|
-
nodefile.ELEMENT_TERM_MIN)
|
|
87
|
-
src = io.open(os.path.join(_HERE, "mdcg.py"), encoding="utf-8").read()
|
|
88
|
-
ok('if any(t in " ".join(post) for t in (terms or [])):' in src,
|
|
89
|
-
'J0d term 出口判据原文未变')
|
|
90
|
-
ok("elif is_postcondition_query(q):" in src,
|
|
91
|
-
'J0e declared 出口判据原文未变(本件未取消它)')
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
def j1_truth_table():
|
|
95
|
-
"""生产同源词项下的真值表——本守卫的核心事实表。"""
|
|
96
|
-
seen_a, seen_b = {}, {}
|
|
97
|
-
for v in VALS:
|
|
98
|
-
a, b = _hit(v, QA), _hit(v, QB)
|
|
99
|
-
seen_a.setdefault((a["post"], a["post_source"]), []).append(v)
|
|
100
|
-
seen_b.setdefault((b["post"], b["post_source"]), []).append(v)
|
|
101
|
-
print(' DATA J1 %-12s A: post=%-5s src=%-9s | B: post=%-5s src=%s'
|
|
102
|
-
% (v, a["post"], a["post_source"], b["post"], b["post_source"]))
|
|
103
|
-
# A(普通问句)上取值可分:>=2 种输出。
|
|
104
|
-
ok(len(seen_a) >= 2,
|
|
105
|
-
'J1z 普通问句 A 上取值可分(>=2 种可观测输出)', len(seen_a))
|
|
106
|
-
# B(验证方式问句)上:除「切分后为空/过短」(x / 无)这一桶外,
|
|
107
|
-
# 其余**全部**取值落进同一个桶 ⇒ 值盲。
|
|
108
|
-
empty_bucket = [k for k, v in seen_b.items() if k == (False, None)]
|
|
109
|
-
ok(len(seen_b) == 2 and len(empty_bucket) == 1,
|
|
110
|
-
'J1za B 上只有两桶:一个 declared 桶 + 一个「切分后为空」桶',
|
|
111
|
-
sorted(seen_b))
|
|
112
|
-
ok(len(seen_b[(True, "declared")]) == 5,
|
|
113
|
-
'J1zb B 上 5 个不同取值全落进同一个 declared 桶(值盲)',
|
|
114
|
-
seen_b.get((True, "declared")))
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
def j2_term_reachable_on_ordinary_query():
|
|
118
|
-
"""**更正报告 §1.2**:compiler 在普通问句 A 上确实走 term 分支(#181 是对的)。"""
|
|
119
|
-
h = _hit("compiler", QA)
|
|
120
|
-
ok(h["post"] is True,
|
|
121
|
-
'J2a compiler + 普通问句 A ⇒ post=True(报告报 False,实测为 True)', h)
|
|
122
|
-
ok(h["post_source"] == "term",
|
|
123
|
-
'J2b 其出口是 term(值命中)——即 #181「仅 compiler 走 term 分支」成立',
|
|
124
|
-
h["post_source"])
|
|
125
|
-
ok("compiler" in expand_query_terms(QA),
|
|
126
|
-
'J2c 机制:生产同源词项 expand_query_terms(A) 含裸词 compiler',
|
|
127
|
-
expand_query_terms(QA))
|
|
128
|
-
ok(_hit("measurement", QA)["post"] is False,
|
|
129
|
-
'J2d 对照:查询 A 不含 measurement ⇒ 该值不命中(A 上是值敏感的)')
|
|
130
|
-
ok(_hit("textbook", QA)["post"] is False,
|
|
131
|
-
'J2e 对照:查询 A 不含 textbook ⇒ 不命中')
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
def j3_declared_is_value_blind():
|
|
135
|
-
"""declared 出口值盲(**刻意设计**,本守卫如实钉住、不主张取消)。"""
|
|
136
|
-
blind = [v for v in VALS if _hit(v, QB)["post_source"] == "declared"]
|
|
137
|
-
ok(len(blind) >= 4,
|
|
138
|
-
'J3a 验证方式问句 B 上多个不同取值同走 declared', blind)
|
|
139
|
-
outs = {( _hit(v, QB)["post"], _hit(v, QB)["post_source"]) for v in blind}
|
|
140
|
-
ok(len(outs) == 1,
|
|
141
|
-
'J3b 这些取值在 B 上产生**同一**可观测输出(值盲)', outs)
|
|
142
|
-
ok(_hit("任意乱写的值", QB)["post"] is True
|
|
143
|
-
and _hit("textbook", QB)["post"] is True,
|
|
144
|
-
'J3c 乱写的值与 textbook 在 B 上不可区分(报告的 §1.1 核心主张,成立)')
|
|
145
|
-
ok(_hit("x", QB)["post"] is False,
|
|
146
|
-
'J3d 例外:切分后词长 < ELEMENT_TERM_MIN 的取值不命中("x" 被剔)')
|
|
147
|
-
ok(_hit("无", QB)["post"] is False,
|
|
148
|
-
'J3e 例外:哨兵值「无」切分后为空,同样不命中')
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
def j4_source_field_is_the_new_observable():
|
|
152
|
-
"""post_source 使「是哪一条出口」机器可读——本件真正修的那一半。"""
|
|
153
|
-
a = _hit("compiler", QA)
|
|
154
|
-
b = _hit("任意乱写的值", QB)
|
|
155
|
-
ok(a["post_source"] == "term", 'J4a 值命中 ⇒ post_source="term"', a["post_source"])
|
|
156
|
-
ok(b["post_source"] == "declared",
|
|
157
|
-
'J4b 仅声明命中 ⇒ post_source="declared"', b["post_source"])
|
|
158
|
-
ok(a["post"] == b["post"] is True,
|
|
159
|
-
'J4c 两者 post 都是 True —— 修复前**仅凭 post 无法区分**(本字段的存在理由)')
|
|
160
|
-
ok("post_source" in a and "reject_source" in a,
|
|
161
|
-
'J4d 两字段都在回传体上(含未命中时)', sorted(a))
|
|
162
|
-
ent = {nodefile.REJECTION_TERMS_KEY: ["其它会话"]}
|
|
163
|
-
r = index_key_hits(ent, ["其它会话"], "何时不适用")
|
|
164
|
-
ok(r["reject_source"] == "declared", 'J4e reject 出口同样有结构化来源', r)
|
|
165
|
-
r2 = index_key_hits({}, ["x"], "普通问句")
|
|
166
|
-
ok(r2["post_source"] is None and r2["reject_source"] is None,
|
|
167
|
-
'J4f 未命中时来源为 None(不谎报出口)', r2)
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
def j5_existing_vocabulary():
|
|
171
|
-
"""报告选项 (c) 建议「设词表校验」——**词表已有真源**,不需新造。"""
|
|
172
|
-
ok(isinstance(nodefile.VERIFICATION_BASIS, tuple)
|
|
173
|
-
and "measurement" in nodefile.VERIFICATION_BASIS
|
|
174
|
-
and "textbook" in nodefile.VERIFICATION_BASIS,
|
|
175
|
-
'J5a VERIFICATION_BASIS 已是「验证方式」取值的受控词集',
|
|
176
|
-
nodefile.VERIFICATION_BASIS)
|
|
177
|
-
ok("compiler" in nodefile.VERIFICATION_BASIS,
|
|
178
|
-
'J5b 其中含 compiler(与 #181 所述 term 分支的示例值同源)')
|
|
179
|
-
src = io.open(os.path.join(_HERE, "nodefile.py"), encoding="utf-8").read()
|
|
180
|
-
ok("# ---- issue #218" in src,
|
|
181
|
-
'J5c CCG_CONTRACT_ROLES 旁已登记召回面语义(选项 (a) 的落地形态)')
|
|
182
|
-
ok("post_source" in src, 'J5d 登记注释指向 post_source 字段')
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
def j6_discriminator():
|
|
186
|
-
"""判别力对照:只读 post 的消费者无法区分两条出口。"""
|
|
187
|
-
a, b = _hit("compiler", QA), _hit("任意乱写的值", QB)
|
|
188
|
-
legacy = {k: (a[k], b[k]) for k in ("hit", "post", "reject")}
|
|
189
|
-
ok(legacy["post"] == (True, True) and legacy["reject"] == (False, False),
|
|
190
|
-
'J6a 只看 hit/post/reject:两个语义不同的命中**完全相同**', legacy)
|
|
191
|
-
ok(a["why"] != b["why"],
|
|
192
|
-
'J6b why 其实已带分支信息——但它只被守卫消费(检索/裁决面读不到)',
|
|
193
|
-
(a["why"], b["why"]))
|
|
194
|
-
ok(a["post_source"] != b["post_source"],
|
|
195
|
-
'J6c post_source 是第一个**结构化**且可被消费者读取的分支读数')
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
_CASES = (j0_judgement_unchanged, j1_truth_table,
|
|
199
|
-
j2_term_reachable_on_ordinary_query, j3_declared_is_value_blind,
|
|
200
|
-
j4_source_field_is_the_new_observable, j5_existing_vocabulary,
|
|
201
|
-
j6_discriminator)
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
def _run_all():
|
|
205
|
-
del _PASS[:], _FAIL[:]
|
|
206
|
-
for fn in _CASES:
|
|
207
|
-
print(chr(10) + '== %s' % fn.__name__)
|
|
208
|
-
try:
|
|
209
|
-
fn()
|
|
210
|
-
except Exception as exc: # noqa: BLE001
|
|
211
|
-
import traceback
|
|
212
|
-
_FAIL.append('%s 抛异常' % fn.__name__)
|
|
213
|
-
print(' FAIL %s 抛异常:%s: %s' % (fn.__name__, type(exc).__name__, exc))
|
|
214
|
-
traceback.print_exc()
|
|
215
|
-
print(chr(10) + '通过 %d / 失败 %d' % (len(_PASS), len(_FAIL)))
|
|
216
|
-
for m in _FAIL:
|
|
217
|
-
print(' - ' + m)
|
|
218
|
-
return 1 if _FAIL else 0
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if __name__ == '__main__':
|
|
222
|
-
raise SystemExit(_run_all())
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""issue #218 守卫:postcondition_terms 两条出口的回传面(判据一字未动)。
|
|
3
|
+
|
|
4
|
+
# 功能名:index_key_hits 的 post/reject 分支回传面结构化(post_source/reject_source)
|
|
5
|
+
# 生效条件:改动 md_cg/mdcg.py 的 index_key_hits、或改动 nodefile.CCG_CONTRACT_ROLES
|
|
6
|
+
# 旁的 #218 登记注释之后必跑
|
|
7
|
+
# 子功能:① 判据未变(hit/post/reject/why 逐位不变,只新增字段)② 生产同源词项下的
|
|
8
|
+
# 真值表被如实钉住 ③ **更正报告 §1.2**(compiler 确实走 term 分支)④ declared
|
|
9
|
+
# 分支值盲(5 个不同取值 -> 1 种输出)⑤ post_source 使分支机器可读 ⑥ 判别力
|
|
10
|
+
# 执行:python -X utf8 -m md_cg.test_issue218_postcondition_value_blind
|
|
11
|
+
# 验证方式:末行「通过 N / 失败 M」;红基线:撤掉 post_source 新增 ⇒ ②③⑤⑥ 转红
|
|
12
|
+
# 不适用条件:本守卫**不主张** declared 分支应被取消或收紧——那是行为变更,属设计
|
|
13
|
+
# 裁定(issue #218 自己倾向选项 (a)「零行为变更 + 诚实归类」);不改阈值;
|
|
14
|
+
# 不测生产语料上「验证方式」取值的实际分布
|
|
15
|
+
|
|
16
|
+
## 缺陷现场(issue #218)
|
|
17
|
+
post = e.get(POSTCONDITION_TERMS_KEY) or []
|
|
18
|
+
if post:
|
|
19
|
+
if any(t in " ".join(post) for t in (terms or [])): # 出口 1:term
|
|
20
|
+
hits["post"] = True; hits["why"].append("postcondition_terms:term")
|
|
21
|
+
elif is_postcondition_query(q): # 出口 2:declared
|
|
22
|
+
hits["post"] = True; hits["why"].append("postcondition_terms:declared")
|
|
23
|
+
|
|
24
|
+
## 复核结论(与报告一处重要不同,本守卫按实测钉)
|
|
25
|
+
报告 §1.1 表中「查询 A = compiler 是怎么实现的」一行报 post=False,并据此在 §1.2
|
|
26
|
+
**更正上游 #181**(#181 称「仅 compiler 走 term 分支」)。本件实测**不可复现该更正**:
|
|
27
|
+
|
|
28
|
+
· 生产同源词项 = expand_query_terms(查询)(mdcg.search :4042 即此调用),
|
|
29
|
+
它对查询 A 返回 ['compiler 是怎么实现的', 'compiler', '是怎么实现的', ...]
|
|
30
|
+
—— **裸词 compiler 在其中**;
|
|
31
|
+
· 节点侧 postcondition_terms = ['compiler']," ".join(post) = 'compiler';
|
|
32
|
+
· 故 'compiler' in 'compiler' 为真 ⇒ 走 term 分支。
|
|
33
|
+
· 同一代码在报告所称分支 origin/level0000x(5e9c313e)上**逐字相同**(已核对),
|
|
34
|
+
故该读数在作者自身分支上亦不可复现——应源于探针取的 terms 非生产口径。
|
|
35
|
+
|
|
36
|
+
⇒ **#181 的读数是对的**;报告 §1.2 的「更正」不成立。
|
|
37
|
+
报告真正成立的是:declared 出口**值盲**——但那是**刻意设计**(见下)。
|
|
38
|
+
|
|
39
|
+
## 两条出口的真实语义
|
|
40
|
+
· term —— **值敏感**,但可达性取决于**查询**是否含该值(不是值的质量);
|
|
41
|
+
· declared —— **值盲**:验证方式问句 + 该行切分后非空即命中,任意非空取值同输出。
|
|
42
|
+
代码 docstring 明写这是设计(「声明了验证方式即召回」),与 rejection_terms 的
|
|
43
|
+
边界问句同构。故它不是缺陷,而是**未在回传面登记的语义**。
|
|
44
|
+
"""
|
|
45
|
+
from __future__ import annotations
|
|
46
|
+
|
|
47
|
+
import io
|
|
48
|
+
import os
|
|
49
|
+
import sys
|
|
50
|
+
|
|
51
|
+
_HERE = os.path.dirname(os.path.abspath(__file__))
|
|
52
|
+
sys.path.insert(0, os.path.dirname(_HERE))
|
|
53
|
+
if hasattr(sys.stdout, "reconfigure"):
|
|
54
|
+
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
55
|
+
|
|
56
|
+
from md_cg import nodefile # noqa: E402
|
|
57
|
+
from md_cg.mdcg import (expand_query_terms, is_postcondition_query, # noqa: E402
|
|
58
|
+
index_key_hits)
|
|
59
|
+
|
|
60
|
+
_PASS, _FAIL = [], []
|
|
61
|
+
QA = "compiler 是怎么实现的" # 普通问句(is_postcondition_query=False)
|
|
62
|
+
QB = "这个结论是怎么验证的" # 验证方式问句(=True)
|
|
63
|
+
VALS = ["measurement", "compiler", "textbook", "任意乱写的值", "zzz", "x", "无"]
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def ok(cond, msg, extra=''):
|
|
67
|
+
(_PASS if cond else _FAIL).append(msg)
|
|
68
|
+
print((' PASS ' if cond else ' FAIL ') + msg
|
|
69
|
+
+ ((' <- ' + str(extra)) if (extra and not cond) else ''))
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _entry(v):
|
|
73
|
+
return {nodefile.POSTCONDITION_TERMS_KEY:
|
|
74
|
+
nodefile.ccg_element_terms("# 验证方式:%s\n" % v,
|
|
75
|
+
nodefile.POSTCONDITION_FIELD)}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _hit(v, q):
|
|
79
|
+
return index_key_hits(_entry(v), expand_query_terms(q), q)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def j0_judgement_unchanged():
|
|
83
|
+
ok(is_postcondition_query(QA) is False, 'J0a 查询 A 非验证方式问句')
|
|
84
|
+
ok(is_postcondition_query(QB) is True, 'J0b 查询 B 是验证方式问句')
|
|
85
|
+
ok(nodefile.ELEMENT_TERM_MIN == 2, 'J0c ELEMENT_TERM_MIN 仍为 2',
|
|
86
|
+
nodefile.ELEMENT_TERM_MIN)
|
|
87
|
+
src = io.open(os.path.join(_HERE, "mdcg.py"), encoding="utf-8").read()
|
|
88
|
+
ok('if any(t in " ".join(post) for t in (terms or [])):' in src,
|
|
89
|
+
'J0d term 出口判据原文未变')
|
|
90
|
+
ok("elif is_postcondition_query(q):" in src,
|
|
91
|
+
'J0e declared 出口判据原文未变(本件未取消它)')
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def j1_truth_table():
|
|
95
|
+
"""生产同源词项下的真值表——本守卫的核心事实表。"""
|
|
96
|
+
seen_a, seen_b = {}, {}
|
|
97
|
+
for v in VALS:
|
|
98
|
+
a, b = _hit(v, QA), _hit(v, QB)
|
|
99
|
+
seen_a.setdefault((a["post"], a["post_source"]), []).append(v)
|
|
100
|
+
seen_b.setdefault((b["post"], b["post_source"]), []).append(v)
|
|
101
|
+
print(' DATA J1 %-12s A: post=%-5s src=%-9s | B: post=%-5s src=%s'
|
|
102
|
+
% (v, a["post"], a["post_source"], b["post"], b["post_source"]))
|
|
103
|
+
# A(普通问句)上取值可分:>=2 种输出。
|
|
104
|
+
ok(len(seen_a) >= 2,
|
|
105
|
+
'J1z 普通问句 A 上取值可分(>=2 种可观测输出)', len(seen_a))
|
|
106
|
+
# B(验证方式问句)上:除「切分后为空/过短」(x / 无)这一桶外,
|
|
107
|
+
# 其余**全部**取值落进同一个桶 ⇒ 值盲。
|
|
108
|
+
empty_bucket = [k for k, v in seen_b.items() if k == (False, None)]
|
|
109
|
+
ok(len(seen_b) == 2 and len(empty_bucket) == 1,
|
|
110
|
+
'J1za B 上只有两桶:一个 declared 桶 + 一个「切分后为空」桶',
|
|
111
|
+
sorted(seen_b))
|
|
112
|
+
ok(len(seen_b[(True, "declared")]) == 5,
|
|
113
|
+
'J1zb B 上 5 个不同取值全落进同一个 declared 桶(值盲)',
|
|
114
|
+
seen_b.get((True, "declared")))
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def j2_term_reachable_on_ordinary_query():
|
|
118
|
+
"""**更正报告 §1.2**:compiler 在普通问句 A 上确实走 term 分支(#181 是对的)。"""
|
|
119
|
+
h = _hit("compiler", QA)
|
|
120
|
+
ok(h["post"] is True,
|
|
121
|
+
'J2a compiler + 普通问句 A ⇒ post=True(报告报 False,实测为 True)', h)
|
|
122
|
+
ok(h["post_source"] == "term",
|
|
123
|
+
'J2b 其出口是 term(值命中)——即 #181「仅 compiler 走 term 分支」成立',
|
|
124
|
+
h["post_source"])
|
|
125
|
+
ok("compiler" in expand_query_terms(QA),
|
|
126
|
+
'J2c 机制:生产同源词项 expand_query_terms(A) 含裸词 compiler',
|
|
127
|
+
expand_query_terms(QA))
|
|
128
|
+
ok(_hit("measurement", QA)["post"] is False,
|
|
129
|
+
'J2d 对照:查询 A 不含 measurement ⇒ 该值不命中(A 上是值敏感的)')
|
|
130
|
+
ok(_hit("textbook", QA)["post"] is False,
|
|
131
|
+
'J2e 对照:查询 A 不含 textbook ⇒ 不命中')
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def j3_declared_is_value_blind():
|
|
135
|
+
"""declared 出口值盲(**刻意设计**,本守卫如实钉住、不主张取消)。"""
|
|
136
|
+
blind = [v for v in VALS if _hit(v, QB)["post_source"] == "declared"]
|
|
137
|
+
ok(len(blind) >= 4,
|
|
138
|
+
'J3a 验证方式问句 B 上多个不同取值同走 declared', blind)
|
|
139
|
+
outs = {( _hit(v, QB)["post"], _hit(v, QB)["post_source"]) for v in blind}
|
|
140
|
+
ok(len(outs) == 1,
|
|
141
|
+
'J3b 这些取值在 B 上产生**同一**可观测输出(值盲)', outs)
|
|
142
|
+
ok(_hit("任意乱写的值", QB)["post"] is True
|
|
143
|
+
and _hit("textbook", QB)["post"] is True,
|
|
144
|
+
'J3c 乱写的值与 textbook 在 B 上不可区分(报告的 §1.1 核心主张,成立)')
|
|
145
|
+
ok(_hit("x", QB)["post"] is False,
|
|
146
|
+
'J3d 例外:切分后词长 < ELEMENT_TERM_MIN 的取值不命中("x" 被剔)')
|
|
147
|
+
ok(_hit("无", QB)["post"] is False,
|
|
148
|
+
'J3e 例外:哨兵值「无」切分后为空,同样不命中')
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def j4_source_field_is_the_new_observable():
|
|
152
|
+
"""post_source 使「是哪一条出口」机器可读——本件真正修的那一半。"""
|
|
153
|
+
a = _hit("compiler", QA)
|
|
154
|
+
b = _hit("任意乱写的值", QB)
|
|
155
|
+
ok(a["post_source"] == "term", 'J4a 值命中 ⇒ post_source="term"', a["post_source"])
|
|
156
|
+
ok(b["post_source"] == "declared",
|
|
157
|
+
'J4b 仅声明命中 ⇒ post_source="declared"', b["post_source"])
|
|
158
|
+
ok(a["post"] == b["post"] is True,
|
|
159
|
+
'J4c 两者 post 都是 True —— 修复前**仅凭 post 无法区分**(本字段的存在理由)')
|
|
160
|
+
ok("post_source" in a and "reject_source" in a,
|
|
161
|
+
'J4d 两字段都在回传体上(含未命中时)', sorted(a))
|
|
162
|
+
ent = {nodefile.REJECTION_TERMS_KEY: ["其它会话"]}
|
|
163
|
+
r = index_key_hits(ent, ["其它会话"], "何时不适用")
|
|
164
|
+
ok(r["reject_source"] == "declared", 'J4e reject 出口同样有结构化来源', r)
|
|
165
|
+
r2 = index_key_hits({}, ["x"], "普通问句")
|
|
166
|
+
ok(r2["post_source"] is None and r2["reject_source"] is None,
|
|
167
|
+
'J4f 未命中时来源为 None(不谎报出口)', r2)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def j5_existing_vocabulary():
|
|
171
|
+
"""报告选项 (c) 建议「设词表校验」——**词表已有真源**,不需新造。"""
|
|
172
|
+
ok(isinstance(nodefile.VERIFICATION_BASIS, tuple)
|
|
173
|
+
and "measurement" in nodefile.VERIFICATION_BASIS
|
|
174
|
+
and "textbook" in nodefile.VERIFICATION_BASIS,
|
|
175
|
+
'J5a VERIFICATION_BASIS 已是「验证方式」取值的受控词集',
|
|
176
|
+
nodefile.VERIFICATION_BASIS)
|
|
177
|
+
ok("compiler" in nodefile.VERIFICATION_BASIS,
|
|
178
|
+
'J5b 其中含 compiler(与 #181 所述 term 分支的示例值同源)')
|
|
179
|
+
src = io.open(os.path.join(_HERE, "nodefile.py"), encoding="utf-8").read()
|
|
180
|
+
ok("# ---- issue #218" in src,
|
|
181
|
+
'J5c CCG_CONTRACT_ROLES 旁已登记召回面语义(选项 (a) 的落地形态)')
|
|
182
|
+
ok("post_source" in src, 'J5d 登记注释指向 post_source 字段')
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def j6_discriminator():
|
|
186
|
+
"""判别力对照:只读 post 的消费者无法区分两条出口。"""
|
|
187
|
+
a, b = _hit("compiler", QA), _hit("任意乱写的值", QB)
|
|
188
|
+
legacy = {k: (a[k], b[k]) for k in ("hit", "post", "reject")}
|
|
189
|
+
ok(legacy["post"] == (True, True) and legacy["reject"] == (False, False),
|
|
190
|
+
'J6a 只看 hit/post/reject:两个语义不同的命中**完全相同**', legacy)
|
|
191
|
+
ok(a["why"] != b["why"],
|
|
192
|
+
'J6b why 其实已带分支信息——但它只被守卫消费(检索/裁决面读不到)',
|
|
193
|
+
(a["why"], b["why"]))
|
|
194
|
+
ok(a["post_source"] != b["post_source"],
|
|
195
|
+
'J6c post_source 是第一个**结构化**且可被消费者读取的分支读数')
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
_CASES = (j0_judgement_unchanged, j1_truth_table,
|
|
199
|
+
j2_term_reachable_on_ordinary_query, j3_declared_is_value_blind,
|
|
200
|
+
j4_source_field_is_the_new_observable, j5_existing_vocabulary,
|
|
201
|
+
j6_discriminator)
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
def _run_all():
|
|
205
|
+
del _PASS[:], _FAIL[:]
|
|
206
|
+
for fn in _CASES:
|
|
207
|
+
print(chr(10) + '== %s' % fn.__name__)
|
|
208
|
+
try:
|
|
209
|
+
fn()
|
|
210
|
+
except Exception as exc: # noqa: BLE001
|
|
211
|
+
import traceback
|
|
212
|
+
_FAIL.append('%s 抛异常' % fn.__name__)
|
|
213
|
+
print(' FAIL %s 抛异常:%s: %s' % (fn.__name__, type(exc).__name__, exc))
|
|
214
|
+
traceback.print_exc()
|
|
215
|
+
print(chr(10) + '通过 %d / 失败 %d' % (len(_PASS), len(_FAIL)))
|
|
216
|
+
for m in _FAIL:
|
|
217
|
+
print(' - ' + m)
|
|
218
|
+
return 1 if _FAIL else 0
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
if __name__ == '__main__':
|
|
222
|
+
raise SystemExit(_run_all())
|