@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,468 +1,468 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# 功能名:负条件判据 neg_condition_hits 的否定作用域与字符归一(issue #362 a/b/c)
|
|
3
|
-
# 生效条件:python -X utf8 -m md_cg.test_issue362_neg_condition [--mutate];被测面=md_cg/mdcg.py 的 neg_condition_hits(否定作用域 _negated_at + 归一 fold_for_match + 摘词面 _strip_variant)与 md_cg/routing.py 的 nfkc_text / fold_variants / 繁简折叠注入单点;直调判据面 + 资格/边界两面端到端
|
|
4
|
-
# 子功能:A 组=#362 a/b 正题(否定句不误拒、全角/大小写 6/6 互通);K 组=非恒真对照(**过度收紧与过度放宽两个方向**:真负条件仍命中、`不适合X` 不被吞、不是A而是B、多次出现、自主题豁免/词长下限/全词分支仍在、不过度归一、归一既定后果留痕);E 组=判据单点(NFKC 实现全仓唯一、fold 走 routing 单点、neg 判据全仓唯一、normalize_domain 零位移);C 组=#362c 机制在位/数据待补;D 组=#362d 取证(**不锁裁定**)
|
|
5
|
-
# 执行:--mutate 时在镜像树里逐条把判据改回缺陷形态/归一退化/过度放宽/过度收紧/单点分裂,守卫必须按指定项转红(多红/少红皆不合格)
|
|
6
|
-
# 验证方式:全部 PASS 即通过(退出码 0);--mutate 下每条变异的红项集合须与预期逐项相符,锚点未命中即 fail-closed(打印 ANCHOR-MISS 并计入不合格)
|
|
7
|
-
# 不适用条件:① #362d 已按 Lead 裁定取**案②零破坏子形态**(证据并入顶层 reason、键集与 state 一字不动),D 组锁 D1–D6;**案①(不覆盖 REJECT)未采**、**案③(`is_boundary_query` 标记表过宽,「…适用吗,还是不适用」这类是非问句被「不适用」误判)为独立小项,本守卫不覆盖**;② #362c(繁简互通)**生产未生效**:仓内无既有繁简映射表,证据三重——(a) 全仓 grep `繁简|简繁|t2s|s2t|opencc|zhconv|traditional|simplified|hant|hans|big5` 仅命中 md_cg/bench_p0.py 的计时变量 t2s 与英文单词 traditional,无映射表;(b) 全仓 grep 常用繁体字 `個|說|會|這|對` 命中 **0**(真表不可能在这些字上零命中),`國` 仅 1 处、在 md_cg/lexicon/char_atoms_clean.json:31152 的 en_raw 注记「楚國|楚国」里,是个案不是表;(c) Python312 下 zhconv/opencc/hanziconv/zhon/langconv 的 find_spec 全为 None,且 .tmp/ 里 lingshu/core/condition_normalize.py 只做图像域同义词归一。故 c 只落机制(C1 注入表证明链路通),**数据待补**,C-BLOCKED 为如实登记的覆盖缺口;③ 不判非 CJK 的其它语种变体归一(希腊/阿拉伯变体等);④ 不判 Rust 侧(无对应实现);⑤ 不判 mdcos/_emit 的呈现面字段(本任务写面只有 mdcg.py/routing.py/本文件)
|
|
8
|
-
"""issue #362 守卫:负条件判据的否定作用域与字符归一(a/b/c)。
|
|
9
|
-
|
|
10
|
-
病象(修前,本守卫 A 组逐条复现):
|
|
11
|
-
a 否定句误拒(8/8):neg=['梅雨季节'] + 「现在**不是**梅雨季节,需要防晒」
|
|
12
|
-
⇒ 命中 ⇒ 资格 REJECT。判据只做空白归一再整条子串匹配,**不看否定作用域**。
|
|
13
|
-
b 全角/大小写不归一(6/6 漏拒):4G单模终端 vs 4G单模终端、PDF 扫描件 vs
|
|
14
|
-
pdf 扫描件——两侧只去空白,无 NFKC/casefold。
|
|
15
|
-
c 繁简不互通(6/6 漏拒):載貨電梯 vs 载货电梯。**本轮挂起**(见顶部不适用条件②)。
|
|
16
|
-
|
|
17
|
-
修法(判据单点,不新造第二份口径):
|
|
18
|
-
· 归一:routing.nfkc_text(NFKC 唯一单点,normalize_domain 同源)→
|
|
19
|
-
routing.fold_variants(+ casefold + 繁简折叠表,表当前为空)→
|
|
20
|
-
mdcg.fold_for_match(再 + 去全部空白)。两侧都过同一条链。
|
|
21
|
-
· 否定作用域(#362a):整条命中后**逐次出现**判 _negated_at——向前最多
|
|
22
|
-
NEG_SCOPE_WINDOW 个字符内存在否定词,且否定词与被否定成分之间**只由
|
|
23
|
-
连接字组成**(不是X / 不是这种X)才算否定;任一出现未被否定即命中。
|
|
24
|
-
刻意**不**取「窗口内出现否定词就算否定」:那会把「不适合梅雨季节的施工」
|
|
25
|
-
(真负条件)一起吞掉——过度收紧方向由 M3 定点变异钉住。
|
|
26
|
-
|
|
27
|
-
#362d(2026-10-14 Lead 裁定,案②零破坏子形态):上面的 §5.2 不变量是 P0-4/P2-2 的
|
|
28
|
-
有意设计,不改;真正缺的是可观测性。故在「抑制确实发生 ∧ 未摘词面原判 REJECT」时,把
|
|
29
|
-
该证据并入既有顶层 reason 串——键集与 state 不动。案①(不覆盖 REJECT)未采,案③
|
|
30
|
-
(is_boundary_query 标记表过宽)列为独立小项、本守卫不覆盖。
|
|
31
|
-
|
|
32
|
-
本守卫的判别力来自四处**非恒真**对照,而不是「修完就绿」:
|
|
33
|
-
K3(过度收紧)不适合X 仍须命中;K5(过度收紧)任一出现未被否定即命中;
|
|
34
|
-
K11(既定后果留痕)罗马数字与德语 sharp s 的改写是 NFKC/casefold 的固有后果,显式钉住;
|
|
35
|
-
D3(新证据不恒真)非边界问句下 reason 必须**不含**那条 REJECT 证据。
|
|
36
|
-
"""
|
|
37
|
-
from __future__ import annotations
|
|
38
|
-
|
|
39
|
-
import inspect
|
|
40
|
-
import json
|
|
41
|
-
import os
|
|
42
|
-
import re
|
|
43
|
-
import shutil
|
|
44
|
-
import subprocess
|
|
45
|
-
import sys
|
|
46
|
-
import tempfile
|
|
47
|
-
import unicodedata
|
|
48
|
-
|
|
49
|
-
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
50
|
-
|
|
51
|
-
_REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
52
|
-
if _REPO not in sys.path:
|
|
53
|
-
sys.path.insert(0, _REPO)
|
|
54
|
-
|
|
55
|
-
_TMP = tempfile.mkdtemp(prefix="iss362_")
|
|
56
|
-
os.environ.update({"MDCG_ROOT": os.path.join(_TMP, "brain"),
|
|
57
|
-
"MDCG_STATE_ROOT": os.path.join(_TMP, "state"),
|
|
58
|
-
"MDCG_AUX_ROOT": os.path.join(_TMP, "aux"),
|
|
59
|
-
"MDCG_DATA_ROOT": os.path.join(_TMP, "data"),
|
|
60
|
-
"MDCG_EXPORT_ROOT": _TMP,
|
|
61
|
-
"MDCG_SUSTAIN": "0", "MDCG_SLEEP": "0"})
|
|
62
|
-
|
|
63
|
-
from md_cg import mdcg as M # noqa: E402
|
|
64
|
-
from md_cg import routing as RT # noqa: E402
|
|
65
|
-
from md_cg.mdcg import MdCG, fold_for_match, neg_condition_hits # noqa: E402
|
|
66
|
-
|
|
67
|
-
FAILS = []
|
|
68
|
-
PASSED = []
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
def _check(name, cond, detail=''):
|
|
72
|
-
if cond:
|
|
73
|
-
print(" PASS " + name)
|
|
74
|
-
PASSED.append(name)
|
|
75
|
-
else:
|
|
76
|
-
print(" FAIL " + name + " " + str(detail)[:260])
|
|
77
|
-
FAILS.append(name)
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
def _note(text):
|
|
81
|
-
print(" NOTE " + text)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
def _scene(q, **ctx):
|
|
85
|
-
d = {"query": q}
|
|
86
|
-
d.update(ctx)
|
|
87
|
-
return json.dumps(d, ensure_ascii=False)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def _hit(neg, q, own='', **ctx):
|
|
91
|
-
return neg_condition_hits(neg, _scene(q, **ctx), own)
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
def _legacy_normalize_domain(raw):
|
|
95
|
-
"""#362 之前的**内联 NFKC** 版 normalize_domain(E6 等价性对照用)。
|
|
96
|
-
|
|
97
|
-
刻意写在 test_*.py 里(E1 的单点扫描排除 test_*.py):守卫需要**引用**那个
|
|
98
|
-
字面量才能断言「真源只有一处」,不能在断言里就把它复制第二份。
|
|
99
|
-
"""
|
|
100
|
-
if not raw:
|
|
101
|
-
return RT.ORPHAN
|
|
102
|
-
s = unicodedata.normalize("NFKC", str(raw)).strip()
|
|
103
|
-
for _ in range(3):
|
|
104
|
-
new = RT._INSTANCE_TAIL.sub("", s)
|
|
105
|
-
if new == s:
|
|
106
|
-
break
|
|
107
|
-
s = new.strip()
|
|
108
|
-
s = RT._SKELETON_TAIL.sub("", s).strip()
|
|
109
|
-
s = re.sub(r"\s+", "_", s)
|
|
110
|
-
return s or RT.ORPHAN
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
#: #362a 的语料条目(与 issue 正文同形)
|
|
114
|
-
NEG = ['梅雨季节']
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
def group_a():
|
|
118
|
-
print("== A 组:#362 a/b 正题(否定句误拒 / 全角大小写不归一)==")
|
|
119
|
-
_check('A1 a·紧邻否定「不是X」不计命中',
|
|
120
|
-
not _hit(NEG, '现在不是梅雨季节,需要防晒'),
|
|
121
|
-
_hit(NEG, '现在不是梅雨季节,需要防晒'))
|
|
122
|
-
_check('A2 a·「不是X」在独立问句里同样不计命中',
|
|
123
|
-
not _hit(NEG, '现在不是梅雨季节'), _hit(NEG, '现在不是梅雨季节'))
|
|
124
|
-
_check('A3 a·「不是这种X」(否定词 + 连接字)不计命中',
|
|
125
|
-
not _hit(NEG, '现在不是这种梅雨季节'),
|
|
126
|
-
_hit(NEG, '现在不是这种梅雨季节'))
|
|
127
|
-
_check('A4 b·全角条目 vs 半角情境', bool(_hit(['4G单模终端'], '4G单模终端怎么配')))
|
|
128
|
-
_check('A5 b·半角条目 vs 全角情境', bool(_hit(['4G单模终端'], '4G单模终端怎么配')))
|
|
129
|
-
_check('A6 b·全角含全角标点条目 vs 半角情境',
|
|
130
|
-
bool(_hit(['USB2.0接口'], 'USB2.0接口')))
|
|
131
|
-
_check('A7 b·半角条目 vs 全角情境', bool(_hit(['USB2.0接口'], 'USB2.0接口')))
|
|
132
|
-
_check('A8 b·大写条目 vs 小写情境', bool(_hit(['PDF 扫描件'], 'pdf 扫描件')))
|
|
133
|
-
_check('A9 b·小写条目 vs 大写情境', bool(_hit(['pdf 扫描件'], 'PDF 扫描件')))
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
def group_k():
|
|
137
|
-
print("== K 组:非恒真对照(过度收紧 / 过度放宽两个方向)==")
|
|
138
|
-
_check('K1 真负条件仍命中(肯定句)', bool(_hit(NEG, '现在是梅雨季节,需要防潮')))
|
|
139
|
-
_check('K2 真负条件仍命中(词面在句中)',
|
|
140
|
-
bool(_hit(NEG, '梅雨季节的施工方案要注意什么')))
|
|
141
|
-
_check('K3 **过度收紧对照**:不适合X 的否定词作用在「适合」上,仍须命中',
|
|
142
|
-
bool(_hit(NEG, '不适合梅雨季节的施工方案')),
|
|
143
|
-
_hit(NEG, '不适合梅雨季节的施工方案'))
|
|
144
|
-
_check('K4 不是A而是B:B 未被否定仍命中',
|
|
145
|
-
bool(_hit(NEG, '现在不是旱季而是梅雨季节')))
|
|
146
|
-
_check('K5 多次出现:任一出现未被否定即命中',
|
|
147
|
-
bool(_hit(NEG, '不是梅雨季节,现在是梅雨季节')))
|
|
148
|
-
_check('K6 自主题豁免仍在(本节点讲的就是它)',
|
|
149
|
-
not _hit(['抓取管线'], '抓取管线的做法', '抓取管线的做法;问抓取管线时')
|
|
150
|
-
and bool(_hit(['抓取管线'], '抓取管线的做法')),
|
|
151
|
-
_hit(['抓取管线'], '抓取管线的做法', '抓取管线的做法;问抓取管线时'))
|
|
152
|
-
_check('K7 词长下限仍在(单字符碎片不是拒绝理由)',
|
|
153
|
-
not _hit(['抓'], '抓取管线的做法'))
|
|
154
|
-
_check('K8a 全词命中分支仍在(词面齐全即命中)',
|
|
155
|
-
bool(_hit(['其它 机器'], '机器 其它')))
|
|
156
|
-
_check('K8b 全词命中分支仍在(缺一词不命中)', not _hit(['其它 机器'], '其它'))
|
|
157
|
-
_check('K9 空列表 / 空条目 / 空白条目 / None 条目不命中',
|
|
158
|
-
not _hit([], '任意问句') and not _hit([''], '任意问句')
|
|
159
|
-
and not _hit([' '], '任意问句') and not _hit([None], '任意问句'))
|
|
160
|
-
_check('K10 **不过度归一**:标点与连字符不被折叠',
|
|
161
|
-
not _hit(['C++'], '用 C 语言写') and not _hit(['A-B'], 'AB 两个字母'),
|
|
162
|
-
(_hit(['C++'], '用 C 语言写'), _hit(['A-B'], 'AB 两个字母')))
|
|
163
|
-
_check('K11 归一的既定后果留痕(NFKC/casefold 使然,刻意保留)',
|
|
164
|
-
bool(_hit(['IV'], 'Ⅳ 是罗马数字')) and bool(_hit(['ß'], 'ss 这种写法')),
|
|
165
|
-
(_hit(['IV'], 'Ⅳ 是罗马数字'), _hit(['ß'], 'ss 这种写法')))
|
|
166
|
-
_check('K12 **过度收紧对照**:正反问 A-not-A(是不是X / 有没有X)不算否定,仍须命中',
|
|
167
|
-
bool(_hit(NEG, '现在是不是梅雨季节'))
|
|
168
|
-
and bool(_hit(['USB2.0接口'], '有没有 USB2.0 接口')),
|
|
169
|
-
(_hit(NEG, '现在是不是梅雨季节'),
|
|
170
|
-
_hit(['USB2.0接口'], '有没有 USB2.0 接口')))
|
|
171
|
-
_check('K13 **反向对照**:真否定照旧被吞(并不是X / 他说不是X)',
|
|
172
|
-
not _hit(NEG, '并不是梅雨季节') and not _hit(NEG, '他说不是梅雨季节'),
|
|
173
|
-
(_hit(NEG, '并不是梅雨季节'), _hit(NEG, '他说不是梅雨季节')))
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
_TEST_PREFIX = 'test_'
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
def _py_sources():
|
|
180
|
-
"""md_cg 下的**非测试** Python 源码(相对路径, 文本)——E 组单点扫描面。
|
|
181
|
-
|
|
182
|
-
为什么排除 test_*.py:守卫必须**引用** normalize(NFKC 那个字面量才能断言它
|
|
183
|
-
全仓唯一(见 _legacy_normalize_domain),把守卫自己算进去会自伤。"""
|
|
184
|
-
out = []
|
|
185
|
-
root = os.path.join(_REPO, "md_cg")
|
|
186
|
-
for dirpath, dirnames, filenames in os.walk(root):
|
|
187
|
-
dirnames[:] = [d for d in dirnames if d != '__pycache__']
|
|
188
|
-
for fn in sorted(filenames):
|
|
189
|
-
if not fn.endswith('.py') or fn.startswith(_TEST_PREFIX):
|
|
190
|
-
continue
|
|
191
|
-
p = os.path.join(dirpath, fn)
|
|
192
|
-
with open(p, encoding='utf-8', errors='replace') as f:
|
|
193
|
-
out.append((os.path.relpath(p, _REPO).replace(os.sep, '/'),
|
|
194
|
-
f.read()))
|
|
195
|
-
return out
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
_NFKC_MARK = 'normalize(' + chr(34) + 'NFKC' + chr(34)
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
def group_e():
|
|
202
|
-
print("== E 组:判据单点(源码面)==")
|
|
203
|
-
sites = []
|
|
204
|
-
for rel, src in _py_sources():
|
|
205
|
-
for i, line in enumerate(src.splitlines(), 1):
|
|
206
|
-
if line.lstrip().startswith('#'):
|
|
207
|
-
continue
|
|
208
|
-
if _NFKC_MARK in line:
|
|
209
|
-
sites.append((rel, i))
|
|
210
|
-
_check('E1 NFKC 归一实现全仓唯一(排除 test_*.py;不得长出第二份口径)',
|
|
211
|
-
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])
|
|
215
|
-
_check('E3 fold_variants 走 nfkc_text 单点',
|
|
216
|
-
'nfkc_text(' in inspect.getsource(RT.fold_variants))
|
|
217
|
-
_check('E4 judge_qualification 的负条件腿走 neg_condition_hits 单点',
|
|
218
|
-
'neg_condition_hits(' in inspect.getsource(MdCG.judge_qualification))
|
|
219
|
-
n_def = sum(len(re.findall(r'def neg_condition_hits', src))
|
|
220
|
-
for _rel, src in _py_sources())
|
|
221
|
-
_check('E5 neg_condition_hits 全仓唯一实现', n_def == 1, n_def)
|
|
222
|
-
cases = ['数学分析知识点内容(按骨架填充)', '工程学 知识点(内力与截面法)',
|
|
223
|
-
'高中物理知识点内容(按骨架填充) 知识点(贝塞尔不等式)',
|
|
224
|
-
None, '', ' 观察 位置 ']
|
|
225
|
-
same = all(RT.normalize_domain(x) == _legacy_normalize_domain(x) for x in cases)
|
|
226
|
-
_check('E6 normalize_domain 行为零位移(与 #362 前的内联 NFKC 逐字一致)', same,
|
|
227
|
-
[(RT.normalize_domain(x), _legacy_normalize_domain(x)) for x in cases])
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
_TRAD_TEST = {'載': '载', '貨': '货', '電': '电', '腎': '肾'}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
def group_c():
|
|
234
|
-
print("== C 组:#362c 机制在位 / 数据待补(按 Lead 裁定:c 本轮挂起)==")
|
|
235
|
-
old = RT.set_trad_to_simp(_TRAD_TEST)
|
|
236
|
-
try:
|
|
237
|
-
r1 = bool(_hit(['載貨電梯'], '载货电梯'))
|
|
238
|
-
r2 = bool(_hit(['载货电梯'], '載貨電梯'))
|
|
239
|
-
r3 = bool(_hit(['腎功能不全患者'], '肾功能不全患者'))
|
|
240
|
-
r4 = bool(_hit(['肾功能不全患者'], '腎功能不全患者'))
|
|
241
|
-
finally:
|
|
242
|
-
RT.set_trad_to_simp(old)
|
|
243
|
-
_check('C1 **非恒真对照**:注入测试用折叠表后,繁简互通链路即通(4/4)',
|
|
244
|
-
r1 and r2 and r3 and r4, (r1, r2, r3, r4))
|
|
245
|
-
_note('C-BLOCKED(待裁定):生产表 routing.TRAD_TO_SIMP 当前为 %r ⇒ #362c 未生效;'
|
|
246
|
-
'原因与三重证据见本文件顶部「不适用条件」②。表一旦有,C1 证明链路是通的。'
|
|
247
|
-
% (RT.trad_to_simp(),))
|
|
248
|
-
_note('C-BLOCKED 复现读数(应为 [],数据待补而非机制缺陷):載貨電梯→%r / 载货电梯→%r'
|
|
249
|
-
% (_hit(['載貨電梯'], '载货电梯'), _hit(['载货电梯'], '載貨電梯')))
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
_NEG_D = '梅雨季节'
|
|
253
|
-
_DOC_D = ('# 功能名:施工窗口选择' + chr(10)
|
|
254
|
-
+ '# 生效条件:问施工安排时' + chr(10)
|
|
255
|
-
+ '# 子功能:md_cg/mdcg.py' + chr(10)
|
|
256
|
-
+ '# 执行:读判据代码' + chr(10)
|
|
257
|
-
+ '# 验证方式:静态检查通过' + chr(10)
|
|
258
|
-
+ '# 不适用条件:%s' % _NEG_D)
|
|
259
|
-
_Q_D = '现在是梅雨季节吗,适用吗,还是不适用'
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
def _node_d():
|
|
263
|
-
return {'frontmatter': {'non_applicable_conditions': [_NEG_D],
|
|
264
|
-
'verification_basis': 'test'},
|
|
265
|
-
'content': _DOC_D}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
def group_d():
|
|
269
|
-
print("== D 组:#362d 案②已落(零破坏子形态)——证据在场 + 键集一字不动 ==")
|
|
270
|
-
plain = MdCG.judge_qualification(_node_d(), _Q_D, None)
|
|
271
|
-
jb = MdCG.judge_with_boundary(_node_d(), _Q_D, None)
|
|
272
|
-
_check('D1 共同前提:未摘词面的资格判定仍是 REJECT(且该问句是边界问句)',
|
|
273
|
-
plain['state'] == 'REJECT' and M.is_boundary_query(_Q_D) is True,
|
|
274
|
-
(plain['state'], M.is_boundary_query(_Q_D)))
|
|
275
|
-
_check('D2 案②证据在场:抑制确实发生 ⇒ 顶层 reason 里看得到「摘词面前原判 REJECT」',
|
|
276
|
-
jb['qualification']['boundary_suppressed'] is True
|
|
277
|
-
and '摘词面前原判 REJECT' in str(jb['reason']),
|
|
278
|
-
(jb['qualification']['boundary_suppressed'], jb['reason']))
|
|
279
|
-
nb = MdCG.judge_with_boundary(_node_d(), '现在是不是梅雨季节', None)
|
|
280
|
-
_check('D3 **非恒真对照**:非边界问句下 reason 不含该证据(证据不恒真)',
|
|
281
|
-
nb['qualification']['boundary_suppressed'] is False
|
|
282
|
-
and '摘词面前原判' not in str(nb['reason']), nb['reason'])
|
|
283
|
-
_check('D4 **零破坏子形态**:顶层/boundary/counts/qualification 键集逐项不变',
|
|
284
|
-
set(jb) == {'qualification', 'boundary', 'counts', 'recallable', 'reason'}
|
|
285
|
-
and set(jb['qualification']) == {'state', 'reason', 'boundary_suppressed'}
|
|
286
|
-
and set(jb['boundary']) == {'hit', 'terms', 'marker', 'reason'}
|
|
287
|
-
and set(jb['counts']) == {'accept', 'reject', 'defer', 'blindspot',
|
|
288
|
-
'boundary_hit'},
|
|
289
|
-
(sorted(jb), sorted(jb['qualification'])))
|
|
290
|
-
_check('D5 §5.2 不变量仍成立:边界命中**不构成**资格否定(state 非 REJECT 且可召回)',
|
|
291
|
-
jb['qualification']['state'] != 'REJECT' and jb['recallable'] is True,
|
|
292
|
-
(jb['qualification']['state'], jb['recallable']))
|
|
293
|
-
_check('D6 非边界问句口径零位移:state ≡ judge_qualification 的 state',
|
|
294
|
-
nb['qualification']['state'] == MdCG.judge_qualification(
|
|
295
|
-
_node_d(), '现在是不是梅雨季节', None)['state'],
|
|
296
|
-
nb['qualification']['state'])
|
|
297
|
-
_note('D7 当前读数(证据):judge_qualification=%s;judge_with_boundary=%s'
|
|
298
|
-
' boundary_suppressed=%s recallable=%s counts=%s'
|
|
299
|
-
% (plain['state'], jb['qualification']['state'],
|
|
300
|
-
jb['qualification']['boundary_suppressed'], jb['recallable'],
|
|
301
|
-
jb['counts']))
|
|
302
|
-
_note('D7 **覆盖缺口(如实登记)**:reason 已带证据,但 mdcos.search_rrf 与 MdCG._emit'
|
|
303
|
-
' 都只取 qualification/counts,**不主动透出**该串;透出需改 md_cg/mdcos.py'
|
|
304
|
-
'(不在本轮写面),交后续轮次或维护者。')
|
|
305
|
-
_note('D7 三案(Lead 2026-10-14 已裁:取 ②):① 不覆盖 REJECT ⇒ 破 §5.2 不变量 +'
|
|
306
|
-
' 转红 test_boundary_hit B1c/B2c/B3b/B4/B5b 与 test_p2_six_elements(两文件不在'
|
|
307
|
-
' 写面)+ 重开「问它何时不适用⇒它被否」的自否定 ⇒ 未采;② 零破坏子形态 ⇒'
|
|
308
|
-
' 本组 D2–D6 锁住;③ 报告例「…适用吗,还是不适用」是**是非问句**,被'
|
|
309
|
-
' BOUNDARY_QUERY_MARKERS 的「不适用」误判成边界问句 ⇒ **标记表过宽**,'
|
|
310
|
-
' Lead 列为独立小项,本守卫不覆盖。')
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
# ---- 定点变异表(镜像树里逐条把判据打回缺陷态/退化/过度收紧/过度放宽/单点分裂)
|
|
314
|
-
# 每条 (标签, 目标文件, ((现实现锚点, 改后), ...), 期望转红的检查 ID 集合)。
|
|
315
|
-
# 锚点缺失 → ANCHOR-MISS → fail-closed;红项集合与期望**逐项相符**才算合格。
|
|
316
|
-
_Q = chr(34)
|
|
317
|
-
_MUTATIONS = (
|
|
318
|
-
('M1 缺陷回退:整条命中后不判否定作用域(#362a 修前形态)', 'md_cg/mdcg.py',
|
|
319
|
-
((' if any(not _negated_at(scene_norm, k)'
|
|
320
|
-
+ chr(10) + ' for k in _occurrences(scene_norm, item)):',
|
|
321
|
-
' if True:'),),
|
|
322
|
-
('A1', 'A2', 'A3', 'K13')),
|
|
323
|
-
('M2 过度放宽:否定作用域窗口缩到 2(「不是这种X」不再算紧邻)', 'md_cg/mdcg.py',
|
|
324
|
-
(('NEG_SCOPE_WINDOW = 6', 'NEG_SCOPE_WINDOW = 2'),),
|
|
325
|
-
('A3',)),
|
|
326
|
-
('M3 过度收紧:不看紧邻连接字(窗口内出现否定词即算否定)', 'md_cg/mdcg.py',
|
|
327
|
-
((' if all(ch in NEG_LINK_CHARS for ch in s[j + len(cue):i]):',
|
|
328
|
-
' if True:'),),
|
|
329
|
-
('K3', 'K4')),
|
|
330
|
-
('M4 过度收紧:要求**每次**出现都被否定(任一未被否定即命中 → 全部)', 'md_cg/mdcg.py',
|
|
331
|
-
((' if any(not _negated_at(scene_norm, k)',
|
|
332
|
-
' if all(not _negated_at(scene_norm, k)'),),
|
|
333
|
-
('K5',)),
|
|
334
|
-
('M5 归一退化:fold_for_match 退回只做去空白(#362b 修前形态)', 'md_cg/mdcg.py',
|
|
335
|
-
((' return compact_exact_text(routing.fold_variants(text))',
|
|
336
|
-
' return compact_exact_text(text)'),),
|
|
337
|
-
('A4', 'A5', 'A6', 'A7', 'A8', 'A9', 'C1', 'E2', 'K11')),
|
|
338
|
-
('M6 判据退化:全词命中 all → any(单个通用词即整片否决)', 'md_cg/mdcg.py',
|
|
339
|
-
((' if words and all(w in scene_norm for w in words):',
|
|
340
|
-
' if words and any(w in scene_norm for w in words):'),),
|
|
341
|
-
('K8b',)),
|
|
342
|
-
('M7 单点分裂:fold_for_match 自写一份内联 NFKC(不走 routing 单点)', 'md_cg/mdcg.py',
|
|
343
|
-
((' return compact_exact_text(routing.fold_variants(text))',
|
|
344
|
-
' return compact_exact_text(' + chr(10)
|
|
345
|
-
+ ' __import__(' + _Q + 'unicodedata' + _Q + ').normalize(' + _Q + 'NFKC' + _Q + ', str(text))).casefold()'),),
|
|
346
|
-
('C1', 'E1', 'E2')),
|
|
347
|
-
('M8 案②回退:摘掉 reason 里的「未摘词面原判 REJECT」证据(可观测性缺失)',
|
|
348
|
-
'md_cg/mdcg.py',
|
|
349
|
-
((' why += (";**摘词面前原判 %s**(查询逐字含本节点的拒绝域条目,该 REJECT "'
|
|
350
|
-
+ chr(10) + ' "被边界问句的摘词面抑制;边界命中使其可召回可展示)"'
|
|
351
|
-
+ chr(10) + ' % STATE_REJECT)',
|
|
352
|
-
' why += ' + _Q + _Q),),
|
|
353
|
-
('D2',)),
|
|
354
|
-
('M9 过度收紧:取消正反问(A-not-A)豁免 ⇒「是不是X」被当成否定', 'md_cg/mdcg.py',
|
|
355
|
-
((' if j >= 1 and j + 1 < len(s) and s[j - 1] == s[j + 1]:',
|
|
356
|
-
' if False:'),),
|
|
357
|
-
('K12',)),
|
|
358
|
-
)
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
def _mirror_build():
|
|
362
|
-
"""镜像树:md_cg/scripts/根级 .py 拷到临时树——**绝不在真实工作树里改源**。"""
|
|
363
|
-
dst = tempfile.mkdtemp(prefix='iss362_mut_')
|
|
364
|
-
for name in ('md_cg', 'scripts'):
|
|
365
|
-
src = os.path.join(_REPO, name)
|
|
366
|
-
if os.path.isdir(src):
|
|
367
|
-
shutil.copytree(src, os.path.join(dst, name),
|
|
368
|
-
ignore=shutil.ignore_patterns('__pycache__', '*.pyc'))
|
|
369
|
-
for name in sorted(os.listdir(_REPO)):
|
|
370
|
-
p = os.path.join(_REPO, name)
|
|
371
|
-
if os.path.isfile(p) and (name.endswith('.py')
|
|
372
|
-
or name in ('README.md', 'pyproject.toml',
|
|
373
|
-
'package.json')):
|
|
374
|
-
shutil.copy2(p, os.path.join(dst, name))
|
|
375
|
-
return dst
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
def _run_in(tree):
|
|
379
|
-
env = dict(os.environ)
|
|
380
|
-
env['PYTHONPATH'] = tree
|
|
381
|
-
env['PYTHONUTF8'] = '1'
|
|
382
|
-
env['PYTHONDONTWRITEBYTECODE'] = '1'
|
|
383
|
-
for k in ('MDCG_ROOT', 'MDCG_STATE_ROOT', 'MDCG_AUX_ROOT',
|
|
384
|
-
'MDCG_DATA_ROOT', 'MDCG_EXPORT_ROOT', 'MDCG_INGEST_ROOT'):
|
|
385
|
-
env.pop(k, None)
|
|
386
|
-
pr = subprocess.run([sys.executable, '-X', 'utf8', '-m',
|
|
387
|
-
'md_cg.test_issue362_neg_condition'],
|
|
388
|
-
capture_output=True, text=True, encoding='utf-8',
|
|
389
|
-
errors='replace', cwd=tree, env=env, timeout=1800)
|
|
390
|
-
out = (pr.stdout or '') + (pr.stderr or '')
|
|
391
|
-
reds = [ln.split('FAIL ', 1)[1].strip()
|
|
392
|
-
for ln in out.splitlines() if ln.strip().startswith('FAIL ')]
|
|
393
|
-
return pr.returncode, reds, out
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
def _apply_text(text, rel, pairs):
|
|
397
|
-
"""按目标文件**实际行尾**折算锚点后逐条替换;任一锚点命中数 != 1 返回 (None, 原因)。"""
|
|
398
|
-
eol = (chr(13) + chr(10)) if (chr(13) + chr(10)) in text else chr(10)
|
|
399
|
-
for old, new in pairs:
|
|
400
|
-
o = old.replace(chr(10), eol)
|
|
401
|
-
n = new.replace(chr(10), eol)
|
|
402
|
-
if text.count(o) != 1:
|
|
403
|
-
return None, '锚点在 %s 里命中 %d 次' % (rel, text.count(o))
|
|
404
|
-
text = text.replace(o, n, 1)
|
|
405
|
-
return text, ''
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
def _mutate():
|
|
409
|
-
print('!! 定点变异自证:逐条把判据改回缺陷形态/判据退化/过度放宽/过度收紧/单点分裂,守卫必须按指定项转红')
|
|
410
|
-
tree = _mirror_build()
|
|
411
|
-
bad = []
|
|
412
|
-
try:
|
|
413
|
-
rc, reds, out = _run_in(tree)
|
|
414
|
-
print(' 未变异镜像基线:rc=%d 红项=%d(必须 rc=0 且 0 红)' % (rc, len(reds)))
|
|
415
|
-
if rc != 0 or reds:
|
|
416
|
-
bad.append('未变异镜像基线即红')
|
|
417
|
-
print(chr(10).join(out.splitlines()[-25:]))
|
|
418
|
-
for desc, rel, pairs, exp in _MUTATIONS:
|
|
419
|
-
p = os.path.join(tree, rel)
|
|
420
|
-
with open(p, encoding='utf-8', newline='') as f:
|
|
421
|
-
bak = f.read()
|
|
422
|
-
mut, why = _apply_text(bak, rel, pairs)
|
|
423
|
-
if mut is None:
|
|
424
|
-
bad.append('%s —— %s' % (desc, why))
|
|
425
|
-
print(' ANCHOR-MISS ' + desc + ' ' + why)
|
|
426
|
-
continue
|
|
427
|
-
with open(p, 'w', encoding='utf-8', newline='') as f:
|
|
428
|
-
f.write(mut)
|
|
429
|
-
for root, dd, ff in os.walk(tree):
|
|
430
|
-
if os.path.basename(root) == '__pycache__':
|
|
431
|
-
shutil.rmtree(root, ignore_errors=True)
|
|
432
|
-
rc2, reds2, out2 = _run_in(tree)
|
|
433
|
-
with open(p, 'w', encoding='utf-8', newline='') as f:
|
|
434
|
-
f.write(bak)
|
|
435
|
-
hit = sorted({r.split(' ')[0] for r in reds2})
|
|
436
|
-
if rc2 != 0 and hit == sorted(exp):
|
|
437
|
-
print(' OK %s 红项=%d 指定命中=%s' % (desc, len(reds2), hit))
|
|
438
|
-
else:
|
|
439
|
-
bad.append(desc)
|
|
440
|
-
print(' MISMATCH %s 实际红项=%s 期望=%s rc=%d'
|
|
441
|
-
% (desc, hit, sorted(exp), rc2))
|
|
442
|
-
for r in reds2[:12]:
|
|
443
|
-
print(' FAIL ' + r)
|
|
444
|
-
print('定点变异自证:%s(%d 条不合格)'
|
|
445
|
-
% ('PASS' if not bad else 'FAIL', len(bad)))
|
|
446
|
-
for b in bad:
|
|
447
|
-
print(' 不合格:' + b)
|
|
448
|
-
return len(bad)
|
|
449
|
-
finally:
|
|
450
|
-
shutil.rmtree(tree, ignore_errors=True)
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
def main():
|
|
454
|
-
group_a()
|
|
455
|
-
group_k()
|
|
456
|
-
group_e()
|
|
457
|
-
group_c()
|
|
458
|
-
group_d()
|
|
459
|
-
print('=' * 68)
|
|
460
|
-
print('#362 负条件判据守卫:%d 通过,%d 失败' % (len(PASSED), len(FAILS)))
|
|
461
|
-
for f in FAILS:
|
|
462
|
-
print(' 红项:' + f)
|
|
463
|
-
_bad = _mutate() if '--mutate' in sys.argv else 0
|
|
464
|
-
return 1 if (FAILS or _bad) else 0
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
if __name__ == '__main__':
|
|
468
|
-
sys.exit(main())
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# 功能名:负条件判据 neg_condition_hits 的否定作用域与字符归一(issue #362 a/b/c)
|
|
3
|
+
# 生效条件:python -X utf8 -m md_cg.test_issue362_neg_condition [--mutate];被测面=md_cg/mdcg.py 的 neg_condition_hits(否定作用域 _negated_at + 归一 fold_for_match + 摘词面 _strip_variant)与 md_cg/routing.py 的 nfkc_text / fold_variants / 繁简折叠注入单点;直调判据面 + 资格/边界两面端到端
|
|
4
|
+
# 子功能:A 组=#362 a/b 正题(否定句不误拒、全角/大小写 6/6 互通);K 组=非恒真对照(**过度收紧与过度放宽两个方向**:真负条件仍命中、`不适合X` 不被吞、不是A而是B、多次出现、自主题豁免/词长下限/全词分支仍在、不过度归一、归一既定后果留痕);E 组=判据单点(NFKC 实现全仓唯一、fold 走 routing 单点、neg 判据全仓唯一、normalize_domain 零位移);C 组=#362c 机制在位/数据待补;D 组=#362d 取证(**不锁裁定**)
|
|
5
|
+
# 执行:--mutate 时在镜像树里逐条把判据改回缺陷形态/归一退化/过度放宽/过度收紧/单点分裂,守卫必须按指定项转红(多红/少红皆不合格)
|
|
6
|
+
# 验证方式:全部 PASS 即通过(退出码 0);--mutate 下每条变异的红项集合须与预期逐项相符,锚点未命中即 fail-closed(打印 ANCHOR-MISS 并计入不合格)
|
|
7
|
+
# 不适用条件:① #362d 已按 Lead 裁定取**案②零破坏子形态**(证据并入顶层 reason、键集与 state 一字不动),D 组锁 D1–D6;**案①(不覆盖 REJECT)未采**、**案③(`is_boundary_query` 标记表过宽,「…适用吗,还是不适用」这类是非问句被「不适用」误判)为独立小项,本守卫不覆盖**;② #362c(繁简互通)**生产未生效**:仓内无既有繁简映射表,证据三重——(a) 全仓 grep `繁简|简繁|t2s|s2t|opencc|zhconv|traditional|simplified|hant|hans|big5` 仅命中 md_cg/bench_p0.py 的计时变量 t2s 与英文单词 traditional,无映射表;(b) 全仓 grep 常用繁体字 `個|說|會|這|對` 命中 **0**(真表不可能在这些字上零命中),`國` 仅 1 处、在 md_cg/lexicon/char_atoms_clean.json:31152 的 en_raw 注记「楚國|楚国」里,是个案不是表;(c) Python312 下 zhconv/opencc/hanziconv/zhon/langconv 的 find_spec 全为 None,且 .tmp/ 里 lingshu/core/condition_normalize.py 只做图像域同义词归一。故 c 只落机制(C1 注入表证明链路通),**数据待补**,C-BLOCKED 为如实登记的覆盖缺口;③ 不判非 CJK 的其它语种变体归一(希腊/阿拉伯变体等);④ 不判 Rust 侧(无对应实现);⑤ 不判 mdcos/_emit 的呈现面字段(本任务写面只有 mdcg.py/routing.py/本文件)
|
|
8
|
+
"""issue #362 守卫:负条件判据的否定作用域与字符归一(a/b/c)。
|
|
9
|
+
|
|
10
|
+
病象(修前,本守卫 A 组逐条复现):
|
|
11
|
+
a 否定句误拒(8/8):neg=['梅雨季节'] + 「现在**不是**梅雨季节,需要防晒」
|
|
12
|
+
⇒ 命中 ⇒ 资格 REJECT。判据只做空白归一再整条子串匹配,**不看否定作用域**。
|
|
13
|
+
b 全角/大小写不归一(6/6 漏拒):4G单模终端 vs 4G单模终端、PDF 扫描件 vs
|
|
14
|
+
pdf 扫描件——两侧只去空白,无 NFKC/casefold。
|
|
15
|
+
c 繁简不互通(6/6 漏拒):載貨電梯 vs 载货电梯。**本轮挂起**(见顶部不适用条件②)。
|
|
16
|
+
|
|
17
|
+
修法(判据单点,不新造第二份口径):
|
|
18
|
+
· 归一:routing.nfkc_text(NFKC 唯一单点,normalize_domain 同源)→
|
|
19
|
+
routing.fold_variants(+ casefold + 繁简折叠表,表当前为空)→
|
|
20
|
+
mdcg.fold_for_match(再 + 去全部空白)。两侧都过同一条链。
|
|
21
|
+
· 否定作用域(#362a):整条命中后**逐次出现**判 _negated_at——向前最多
|
|
22
|
+
NEG_SCOPE_WINDOW 个字符内存在否定词,且否定词与被否定成分之间**只由
|
|
23
|
+
连接字组成**(不是X / 不是这种X)才算否定;任一出现未被否定即命中。
|
|
24
|
+
刻意**不**取「窗口内出现否定词就算否定」:那会把「不适合梅雨季节的施工」
|
|
25
|
+
(真负条件)一起吞掉——过度收紧方向由 M3 定点变异钉住。
|
|
26
|
+
|
|
27
|
+
#362d(2026-10-14 Lead 裁定,案②零破坏子形态):上面的 §5.2 不变量是 P0-4/P2-2 的
|
|
28
|
+
有意设计,不改;真正缺的是可观测性。故在「抑制确实发生 ∧ 未摘词面原判 REJECT」时,把
|
|
29
|
+
该证据并入既有顶层 reason 串——键集与 state 不动。案①(不覆盖 REJECT)未采,案③
|
|
30
|
+
(is_boundary_query 标记表过宽)列为独立小项、本守卫不覆盖。
|
|
31
|
+
|
|
32
|
+
本守卫的判别力来自四处**非恒真**对照,而不是「修完就绿」:
|
|
33
|
+
K3(过度收紧)不适合X 仍须命中;K5(过度收紧)任一出现未被否定即命中;
|
|
34
|
+
K11(既定后果留痕)罗马数字与德语 sharp s 的改写是 NFKC/casefold 的固有后果,显式钉住;
|
|
35
|
+
D3(新证据不恒真)非边界问句下 reason 必须**不含**那条 REJECT 证据。
|
|
36
|
+
"""
|
|
37
|
+
from __future__ import annotations
|
|
38
|
+
|
|
39
|
+
import inspect
|
|
40
|
+
import json
|
|
41
|
+
import os
|
|
42
|
+
import re
|
|
43
|
+
import shutil
|
|
44
|
+
import subprocess
|
|
45
|
+
import sys
|
|
46
|
+
import tempfile
|
|
47
|
+
import unicodedata
|
|
48
|
+
|
|
49
|
+
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
50
|
+
|
|
51
|
+
_REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
52
|
+
if _REPO not in sys.path:
|
|
53
|
+
sys.path.insert(0, _REPO)
|
|
54
|
+
|
|
55
|
+
_TMP = tempfile.mkdtemp(prefix="iss362_")
|
|
56
|
+
os.environ.update({"MDCG_ROOT": os.path.join(_TMP, "brain"),
|
|
57
|
+
"MDCG_STATE_ROOT": os.path.join(_TMP, "state"),
|
|
58
|
+
"MDCG_AUX_ROOT": os.path.join(_TMP, "aux"),
|
|
59
|
+
"MDCG_DATA_ROOT": os.path.join(_TMP, "data"),
|
|
60
|
+
"MDCG_EXPORT_ROOT": _TMP,
|
|
61
|
+
"MDCG_SUSTAIN": "0", "MDCG_SLEEP": "0"})
|
|
62
|
+
|
|
63
|
+
from md_cg import mdcg as M # noqa: E402
|
|
64
|
+
from md_cg import routing as RT # noqa: E402
|
|
65
|
+
from md_cg.mdcg import MdCG, fold_for_match, neg_condition_hits # noqa: E402
|
|
66
|
+
|
|
67
|
+
FAILS = []
|
|
68
|
+
PASSED = []
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _check(name, cond, detail=''):
|
|
72
|
+
if cond:
|
|
73
|
+
print(" PASS " + name)
|
|
74
|
+
PASSED.append(name)
|
|
75
|
+
else:
|
|
76
|
+
print(" FAIL " + name + " " + str(detail)[:260])
|
|
77
|
+
FAILS.append(name)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _note(text):
|
|
81
|
+
print(" NOTE " + text)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def _scene(q, **ctx):
|
|
85
|
+
d = {"query": q}
|
|
86
|
+
d.update(ctx)
|
|
87
|
+
return json.dumps(d, ensure_ascii=False)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _hit(neg, q, own='', **ctx):
|
|
91
|
+
return neg_condition_hits(neg, _scene(q, **ctx), own)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def _legacy_normalize_domain(raw):
|
|
95
|
+
"""#362 之前的**内联 NFKC** 版 normalize_domain(E6 等价性对照用)。
|
|
96
|
+
|
|
97
|
+
刻意写在 test_*.py 里(E1 的单点扫描排除 test_*.py):守卫需要**引用**那个
|
|
98
|
+
字面量才能断言「真源只有一处」,不能在断言里就把它复制第二份。
|
|
99
|
+
"""
|
|
100
|
+
if not raw:
|
|
101
|
+
return RT.ORPHAN
|
|
102
|
+
s = unicodedata.normalize("NFKC", str(raw)).strip()
|
|
103
|
+
for _ in range(3):
|
|
104
|
+
new = RT._INSTANCE_TAIL.sub("", s)
|
|
105
|
+
if new == s:
|
|
106
|
+
break
|
|
107
|
+
s = new.strip()
|
|
108
|
+
s = RT._SKELETON_TAIL.sub("", s).strip()
|
|
109
|
+
s = re.sub(r"\s+", "_", s)
|
|
110
|
+
return s or RT.ORPHAN
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
#: #362a 的语料条目(与 issue 正文同形)
|
|
114
|
+
NEG = ['梅雨季节']
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def group_a():
|
|
118
|
+
print("== A 组:#362 a/b 正题(否定句误拒 / 全角大小写不归一)==")
|
|
119
|
+
_check('A1 a·紧邻否定「不是X」不计命中',
|
|
120
|
+
not _hit(NEG, '现在不是梅雨季节,需要防晒'),
|
|
121
|
+
_hit(NEG, '现在不是梅雨季节,需要防晒'))
|
|
122
|
+
_check('A2 a·「不是X」在独立问句里同样不计命中',
|
|
123
|
+
not _hit(NEG, '现在不是梅雨季节'), _hit(NEG, '现在不是梅雨季节'))
|
|
124
|
+
_check('A3 a·「不是这种X」(否定词 + 连接字)不计命中',
|
|
125
|
+
not _hit(NEG, '现在不是这种梅雨季节'),
|
|
126
|
+
_hit(NEG, '现在不是这种梅雨季节'))
|
|
127
|
+
_check('A4 b·全角条目 vs 半角情境', bool(_hit(['4G单模终端'], '4G单模终端怎么配')))
|
|
128
|
+
_check('A5 b·半角条目 vs 全角情境', bool(_hit(['4G单模终端'], '4G单模终端怎么配')))
|
|
129
|
+
_check('A6 b·全角含全角标点条目 vs 半角情境',
|
|
130
|
+
bool(_hit(['USB2.0接口'], 'USB2.0接口')))
|
|
131
|
+
_check('A7 b·半角条目 vs 全角情境', bool(_hit(['USB2.0接口'], 'USB2.0接口')))
|
|
132
|
+
_check('A8 b·大写条目 vs 小写情境', bool(_hit(['PDF 扫描件'], 'pdf 扫描件')))
|
|
133
|
+
_check('A9 b·小写条目 vs 大写情境', bool(_hit(['pdf 扫描件'], 'PDF 扫描件')))
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def group_k():
|
|
137
|
+
print("== K 组:非恒真对照(过度收紧 / 过度放宽两个方向)==")
|
|
138
|
+
_check('K1 真负条件仍命中(肯定句)', bool(_hit(NEG, '现在是梅雨季节,需要防潮')))
|
|
139
|
+
_check('K2 真负条件仍命中(词面在句中)',
|
|
140
|
+
bool(_hit(NEG, '梅雨季节的施工方案要注意什么')))
|
|
141
|
+
_check('K3 **过度收紧对照**:不适合X 的否定词作用在「适合」上,仍须命中',
|
|
142
|
+
bool(_hit(NEG, '不适合梅雨季节的施工方案')),
|
|
143
|
+
_hit(NEG, '不适合梅雨季节的施工方案'))
|
|
144
|
+
_check('K4 不是A而是B:B 未被否定仍命中',
|
|
145
|
+
bool(_hit(NEG, '现在不是旱季而是梅雨季节')))
|
|
146
|
+
_check('K5 多次出现:任一出现未被否定即命中',
|
|
147
|
+
bool(_hit(NEG, '不是梅雨季节,现在是梅雨季节')))
|
|
148
|
+
_check('K6 自主题豁免仍在(本节点讲的就是它)',
|
|
149
|
+
not _hit(['抓取管线'], '抓取管线的做法', '抓取管线的做法;问抓取管线时')
|
|
150
|
+
and bool(_hit(['抓取管线'], '抓取管线的做法')),
|
|
151
|
+
_hit(['抓取管线'], '抓取管线的做法', '抓取管线的做法;问抓取管线时'))
|
|
152
|
+
_check('K7 词长下限仍在(单字符碎片不是拒绝理由)',
|
|
153
|
+
not _hit(['抓'], '抓取管线的做法'))
|
|
154
|
+
_check('K8a 全词命中分支仍在(词面齐全即命中)',
|
|
155
|
+
bool(_hit(['其它 机器'], '机器 其它')))
|
|
156
|
+
_check('K8b 全词命中分支仍在(缺一词不命中)', not _hit(['其它 机器'], '其它'))
|
|
157
|
+
_check('K9 空列表 / 空条目 / 空白条目 / None 条目不命中',
|
|
158
|
+
not _hit([], '任意问句') and not _hit([''], '任意问句')
|
|
159
|
+
and not _hit([' '], '任意问句') and not _hit([None], '任意问句'))
|
|
160
|
+
_check('K10 **不过度归一**:标点与连字符不被折叠',
|
|
161
|
+
not _hit(['C++'], '用 C 语言写') and not _hit(['A-B'], 'AB 两个字母'),
|
|
162
|
+
(_hit(['C++'], '用 C 语言写'), _hit(['A-B'], 'AB 两个字母')))
|
|
163
|
+
_check('K11 归一的既定后果留痕(NFKC/casefold 使然,刻意保留)',
|
|
164
|
+
bool(_hit(['IV'], 'Ⅳ 是罗马数字')) and bool(_hit(['ß'], 'ss 这种写法')),
|
|
165
|
+
(_hit(['IV'], 'Ⅳ 是罗马数字'), _hit(['ß'], 'ss 这种写法')))
|
|
166
|
+
_check('K12 **过度收紧对照**:正反问 A-not-A(是不是X / 有没有X)不算否定,仍须命中',
|
|
167
|
+
bool(_hit(NEG, '现在是不是梅雨季节'))
|
|
168
|
+
and bool(_hit(['USB2.0接口'], '有没有 USB2.0 接口')),
|
|
169
|
+
(_hit(NEG, '现在是不是梅雨季节'),
|
|
170
|
+
_hit(['USB2.0接口'], '有没有 USB2.0 接口')))
|
|
171
|
+
_check('K13 **反向对照**:真否定照旧被吞(并不是X / 他说不是X)',
|
|
172
|
+
not _hit(NEG, '并不是梅雨季节') and not _hit(NEG, '他说不是梅雨季节'),
|
|
173
|
+
(_hit(NEG, '并不是梅雨季节'), _hit(NEG, '他说不是梅雨季节')))
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
_TEST_PREFIX = 'test_'
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _py_sources():
|
|
180
|
+
"""md_cg 下的**非测试** Python 源码(相对路径, 文本)——E 组单点扫描面。
|
|
181
|
+
|
|
182
|
+
为什么排除 test_*.py:守卫必须**引用** normalize(NFKC 那个字面量才能断言它
|
|
183
|
+
全仓唯一(见 _legacy_normalize_domain),把守卫自己算进去会自伤。"""
|
|
184
|
+
out = []
|
|
185
|
+
root = os.path.join(_REPO, "md_cg")
|
|
186
|
+
for dirpath, dirnames, filenames in os.walk(root):
|
|
187
|
+
dirnames[:] = [d for d in dirnames if d != '__pycache__']
|
|
188
|
+
for fn in sorted(filenames):
|
|
189
|
+
if not fn.endswith('.py') or fn.startswith(_TEST_PREFIX):
|
|
190
|
+
continue
|
|
191
|
+
p = os.path.join(dirpath, fn)
|
|
192
|
+
with open(p, encoding='utf-8', errors='replace') as f:
|
|
193
|
+
out.append((os.path.relpath(p, _REPO).replace(os.sep, '/'),
|
|
194
|
+
f.read()))
|
|
195
|
+
return out
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
_NFKC_MARK = 'normalize(' + chr(34) + 'NFKC' + chr(34)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def group_e():
|
|
202
|
+
print("== E 组:判据单点(源码面)==")
|
|
203
|
+
sites = []
|
|
204
|
+
for rel, src in _py_sources():
|
|
205
|
+
for i, line in enumerate(src.splitlines(), 1):
|
|
206
|
+
if line.lstrip().startswith('#'):
|
|
207
|
+
continue
|
|
208
|
+
if _NFKC_MARK in line:
|
|
209
|
+
sites.append((rel, i))
|
|
210
|
+
_check('E1 NFKC 归一实现全仓唯一(排除 test_*.py;不得长出第二份口径)',
|
|
211
|
+
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])
|
|
215
|
+
_check('E3 fold_variants 走 nfkc_text 单点',
|
|
216
|
+
'nfkc_text(' in inspect.getsource(RT.fold_variants))
|
|
217
|
+
_check('E4 judge_qualification 的负条件腿走 neg_condition_hits 单点',
|
|
218
|
+
'neg_condition_hits(' in inspect.getsource(MdCG.judge_qualification))
|
|
219
|
+
n_def = sum(len(re.findall(r'def neg_condition_hits', src))
|
|
220
|
+
for _rel, src in _py_sources())
|
|
221
|
+
_check('E5 neg_condition_hits 全仓唯一实现', n_def == 1, n_def)
|
|
222
|
+
cases = ['数学分析知识点内容(按骨架填充)', '工程学 知识点(内力与截面法)',
|
|
223
|
+
'高中物理知识点内容(按骨架填充) 知识点(贝塞尔不等式)',
|
|
224
|
+
None, '', ' 观察 位置 ']
|
|
225
|
+
same = all(RT.normalize_domain(x) == _legacy_normalize_domain(x) for x in cases)
|
|
226
|
+
_check('E6 normalize_domain 行为零位移(与 #362 前的内联 NFKC 逐字一致)', same,
|
|
227
|
+
[(RT.normalize_domain(x), _legacy_normalize_domain(x)) for x in cases])
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
_TRAD_TEST = {'載': '载', '貨': '货', '電': '电', '腎': '肾'}
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def group_c():
|
|
234
|
+
print("== C 组:#362c 机制在位 / 数据待补(按 Lead 裁定:c 本轮挂起)==")
|
|
235
|
+
old = RT.set_trad_to_simp(_TRAD_TEST)
|
|
236
|
+
try:
|
|
237
|
+
r1 = bool(_hit(['載貨電梯'], '载货电梯'))
|
|
238
|
+
r2 = bool(_hit(['载货电梯'], '載貨電梯'))
|
|
239
|
+
r3 = bool(_hit(['腎功能不全患者'], '肾功能不全患者'))
|
|
240
|
+
r4 = bool(_hit(['肾功能不全患者'], '腎功能不全患者'))
|
|
241
|
+
finally:
|
|
242
|
+
RT.set_trad_to_simp(old)
|
|
243
|
+
_check('C1 **非恒真对照**:注入测试用折叠表后,繁简互通链路即通(4/4)',
|
|
244
|
+
r1 and r2 and r3 and r4, (r1, r2, r3, r4))
|
|
245
|
+
_note('C-BLOCKED(待裁定):生产表 routing.TRAD_TO_SIMP 当前为 %r ⇒ #362c 未生效;'
|
|
246
|
+
'原因与三重证据见本文件顶部「不适用条件」②。表一旦有,C1 证明链路是通的。'
|
|
247
|
+
% (RT.trad_to_simp(),))
|
|
248
|
+
_note('C-BLOCKED 复现读数(应为 [],数据待补而非机制缺陷):載貨電梯→%r / 载货电梯→%r'
|
|
249
|
+
% (_hit(['載貨電梯'], '载货电梯'), _hit(['载货电梯'], '載貨電梯')))
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
_NEG_D = '梅雨季节'
|
|
253
|
+
_DOC_D = ('# 功能名:施工窗口选择' + chr(10)
|
|
254
|
+
+ '# 生效条件:问施工安排时' + chr(10)
|
|
255
|
+
+ '# 子功能:md_cg/mdcg.py' + chr(10)
|
|
256
|
+
+ '# 执行:读判据代码' + chr(10)
|
|
257
|
+
+ '# 验证方式:静态检查通过' + chr(10)
|
|
258
|
+
+ '# 不适用条件:%s' % _NEG_D)
|
|
259
|
+
_Q_D = '现在是梅雨季节吗,适用吗,还是不适用'
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def _node_d():
|
|
263
|
+
return {'frontmatter': {'non_applicable_conditions': [_NEG_D],
|
|
264
|
+
'verification_basis': 'test'},
|
|
265
|
+
'content': _DOC_D}
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
def group_d():
|
|
269
|
+
print("== D 组:#362d 案②已落(零破坏子形态)——证据在场 + 键集一字不动 ==")
|
|
270
|
+
plain = MdCG.judge_qualification(_node_d(), _Q_D, None)
|
|
271
|
+
jb = MdCG.judge_with_boundary(_node_d(), _Q_D, None)
|
|
272
|
+
_check('D1 共同前提:未摘词面的资格判定仍是 REJECT(且该问句是边界问句)',
|
|
273
|
+
plain['state'] == 'REJECT' and M.is_boundary_query(_Q_D) is True,
|
|
274
|
+
(plain['state'], M.is_boundary_query(_Q_D)))
|
|
275
|
+
_check('D2 案②证据在场:抑制确实发生 ⇒ 顶层 reason 里看得到「摘词面前原判 REJECT」',
|
|
276
|
+
jb['qualification']['boundary_suppressed'] is True
|
|
277
|
+
and '摘词面前原判 REJECT' in str(jb['reason']),
|
|
278
|
+
(jb['qualification']['boundary_suppressed'], jb['reason']))
|
|
279
|
+
nb = MdCG.judge_with_boundary(_node_d(), '现在是不是梅雨季节', None)
|
|
280
|
+
_check('D3 **非恒真对照**:非边界问句下 reason 不含该证据(证据不恒真)',
|
|
281
|
+
nb['qualification']['boundary_suppressed'] is False
|
|
282
|
+
and '摘词面前原判' not in str(nb['reason']), nb['reason'])
|
|
283
|
+
_check('D4 **零破坏子形态**:顶层/boundary/counts/qualification 键集逐项不变',
|
|
284
|
+
set(jb) == {'qualification', 'boundary', 'counts', 'recallable', 'reason'}
|
|
285
|
+
and set(jb['qualification']) == {'state', 'reason', 'boundary_suppressed'}
|
|
286
|
+
and set(jb['boundary']) == {'hit', 'terms', 'marker', 'reason'}
|
|
287
|
+
and set(jb['counts']) == {'accept', 'reject', 'defer', 'blindspot',
|
|
288
|
+
'boundary_hit'},
|
|
289
|
+
(sorted(jb), sorted(jb['qualification'])))
|
|
290
|
+
_check('D5 §5.2 不变量仍成立:边界命中**不构成**资格否定(state 非 REJECT 且可召回)',
|
|
291
|
+
jb['qualification']['state'] != 'REJECT' and jb['recallable'] is True,
|
|
292
|
+
(jb['qualification']['state'], jb['recallable']))
|
|
293
|
+
_check('D6 非边界问句口径零位移:state ≡ judge_qualification 的 state',
|
|
294
|
+
nb['qualification']['state'] == MdCG.judge_qualification(
|
|
295
|
+
_node_d(), '现在是不是梅雨季节', None)['state'],
|
|
296
|
+
nb['qualification']['state'])
|
|
297
|
+
_note('D7 当前读数(证据):judge_qualification=%s;judge_with_boundary=%s'
|
|
298
|
+
' boundary_suppressed=%s recallable=%s counts=%s'
|
|
299
|
+
% (plain['state'], jb['qualification']['state'],
|
|
300
|
+
jb['qualification']['boundary_suppressed'], jb['recallable'],
|
|
301
|
+
jb['counts']))
|
|
302
|
+
_note('D7 **覆盖缺口(如实登记)**:reason 已带证据,但 mdcos.search_rrf 与 MdCG._emit'
|
|
303
|
+
' 都只取 qualification/counts,**不主动透出**该串;透出需改 md_cg/mdcos.py'
|
|
304
|
+
'(不在本轮写面),交后续轮次或维护者。')
|
|
305
|
+
_note('D7 三案(Lead 2026-10-14 已裁:取 ②):① 不覆盖 REJECT ⇒ 破 §5.2 不变量 +'
|
|
306
|
+
' 转红 test_boundary_hit B1c/B2c/B3b/B4/B5b 与 test_p2_six_elements(两文件不在'
|
|
307
|
+
' 写面)+ 重开「问它何时不适用⇒它被否」的自否定 ⇒ 未采;② 零破坏子形态 ⇒'
|
|
308
|
+
' 本组 D2–D6 锁住;③ 报告例「…适用吗,还是不适用」是**是非问句**,被'
|
|
309
|
+
' BOUNDARY_QUERY_MARKERS 的「不适用」误判成边界问句 ⇒ **标记表过宽**,'
|
|
310
|
+
' Lead 列为独立小项,本守卫不覆盖。')
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
# ---- 定点变异表(镜像树里逐条把判据打回缺陷态/退化/过度收紧/过度放宽/单点分裂)
|
|
314
|
+
# 每条 (标签, 目标文件, ((现实现锚点, 改后), ...), 期望转红的检查 ID 集合)。
|
|
315
|
+
# 锚点缺失 → ANCHOR-MISS → fail-closed;红项集合与期望**逐项相符**才算合格。
|
|
316
|
+
_Q = chr(34)
|
|
317
|
+
_MUTATIONS = (
|
|
318
|
+
('M1 缺陷回退:整条命中后不判否定作用域(#362a 修前形态)', 'md_cg/mdcg.py',
|
|
319
|
+
((' if any(not _negated_at(scene_norm, k)'
|
|
320
|
+
+ chr(10) + ' for k in _occurrences(scene_norm, item)):',
|
|
321
|
+
' if True:'),),
|
|
322
|
+
('A1', 'A2', 'A3', 'K13')),
|
|
323
|
+
('M2 过度放宽:否定作用域窗口缩到 2(「不是这种X」不再算紧邻)', 'md_cg/mdcg.py',
|
|
324
|
+
(('NEG_SCOPE_WINDOW = 6', 'NEG_SCOPE_WINDOW = 2'),),
|
|
325
|
+
('A3',)),
|
|
326
|
+
('M3 过度收紧:不看紧邻连接字(窗口内出现否定词即算否定)', 'md_cg/mdcg.py',
|
|
327
|
+
((' if all(ch in NEG_LINK_CHARS for ch in s[j + len(cue):i]):',
|
|
328
|
+
' if True:'),),
|
|
329
|
+
('K3', 'K4')),
|
|
330
|
+
('M4 过度收紧:要求**每次**出现都被否定(任一未被否定即命中 → 全部)', 'md_cg/mdcg.py',
|
|
331
|
+
((' if any(not _negated_at(scene_norm, k)',
|
|
332
|
+
' if all(not _negated_at(scene_norm, k)'),),
|
|
333
|
+
('K5',)),
|
|
334
|
+
('M5 归一退化:fold_for_match 退回只做去空白(#362b 修前形态)', 'md_cg/mdcg.py',
|
|
335
|
+
((' return compact_exact_text(routing.fold_variants(text))',
|
|
336
|
+
' return compact_exact_text(text)'),),
|
|
337
|
+
('A4', 'A5', 'A6', 'A7', 'A8', 'A9', 'C1', 'E2', 'K11')),
|
|
338
|
+
('M6 判据退化:全词命中 all → any(单个通用词即整片否决)', 'md_cg/mdcg.py',
|
|
339
|
+
((' if words and all(w in scene_norm for w in words):',
|
|
340
|
+
' if words and any(w in scene_norm for w in words):'),),
|
|
341
|
+
('K8b',)),
|
|
342
|
+
('M7 单点分裂:fold_for_match 自写一份内联 NFKC(不走 routing 单点)', 'md_cg/mdcg.py',
|
|
343
|
+
((' return compact_exact_text(routing.fold_variants(text))',
|
|
344
|
+
' return compact_exact_text(' + chr(10)
|
|
345
|
+
+ ' __import__(' + _Q + 'unicodedata' + _Q + ').normalize(' + _Q + 'NFKC' + _Q + ', str(text))).casefold()'),),
|
|
346
|
+
('C1', 'E1', 'E2')),
|
|
347
|
+
('M8 案②回退:摘掉 reason 里的「未摘词面原判 REJECT」证据(可观测性缺失)',
|
|
348
|
+
'md_cg/mdcg.py',
|
|
349
|
+
((' why += (";**摘词面前原判 %s**(查询逐字含本节点的拒绝域条目,该 REJECT "'
|
|
350
|
+
+ chr(10) + ' "被边界问句的摘词面抑制;边界命中使其可召回可展示)"'
|
|
351
|
+
+ chr(10) + ' % STATE_REJECT)',
|
|
352
|
+
' why += ' + _Q + _Q),),
|
|
353
|
+
('D2',)),
|
|
354
|
+
('M9 过度收紧:取消正反问(A-not-A)豁免 ⇒「是不是X」被当成否定', 'md_cg/mdcg.py',
|
|
355
|
+
((' if j >= 1 and j + 1 < len(s) and s[j - 1] == s[j + 1]:',
|
|
356
|
+
' if False:'),),
|
|
357
|
+
('K12',)),
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
def _mirror_build():
|
|
362
|
+
"""镜像树:md_cg/scripts/根级 .py 拷到临时树——**绝不在真实工作树里改源**。"""
|
|
363
|
+
dst = tempfile.mkdtemp(prefix='iss362_mut_')
|
|
364
|
+
for name in ('md_cg', 'scripts'):
|
|
365
|
+
src = os.path.join(_REPO, name)
|
|
366
|
+
if os.path.isdir(src):
|
|
367
|
+
shutil.copytree(src, os.path.join(dst, name),
|
|
368
|
+
ignore=shutil.ignore_patterns('__pycache__', '*.pyc'))
|
|
369
|
+
for name in sorted(os.listdir(_REPO)):
|
|
370
|
+
p = os.path.join(_REPO, name)
|
|
371
|
+
if os.path.isfile(p) and (name.endswith('.py')
|
|
372
|
+
or name in ('README.md', 'pyproject.toml',
|
|
373
|
+
'package.json')):
|
|
374
|
+
shutil.copy2(p, os.path.join(dst, name))
|
|
375
|
+
return dst
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
def _run_in(tree):
|
|
379
|
+
env = dict(os.environ)
|
|
380
|
+
env['PYTHONPATH'] = tree
|
|
381
|
+
env['PYTHONUTF8'] = '1'
|
|
382
|
+
env['PYTHONDONTWRITEBYTECODE'] = '1'
|
|
383
|
+
for k in ('MDCG_ROOT', 'MDCG_STATE_ROOT', 'MDCG_AUX_ROOT',
|
|
384
|
+
'MDCG_DATA_ROOT', 'MDCG_EXPORT_ROOT', 'MDCG_INGEST_ROOT'):
|
|
385
|
+
env.pop(k, None)
|
|
386
|
+
pr = subprocess.run([sys.executable, '-X', 'utf8', '-m',
|
|
387
|
+
'md_cg.test_issue362_neg_condition'],
|
|
388
|
+
capture_output=True, text=True, encoding='utf-8',
|
|
389
|
+
errors='replace', cwd=tree, env=env, timeout=1800)
|
|
390
|
+
out = (pr.stdout or '') + (pr.stderr or '')
|
|
391
|
+
reds = [ln.split('FAIL ', 1)[1].strip()
|
|
392
|
+
for ln in out.splitlines() if ln.strip().startswith('FAIL ')]
|
|
393
|
+
return pr.returncode, reds, out
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
def _apply_text(text, rel, pairs):
|
|
397
|
+
"""按目标文件**实际行尾**折算锚点后逐条替换;任一锚点命中数 != 1 返回 (None, 原因)。"""
|
|
398
|
+
eol = (chr(13) + chr(10)) if (chr(13) + chr(10)) in text else chr(10)
|
|
399
|
+
for old, new in pairs:
|
|
400
|
+
o = old.replace(chr(10), eol)
|
|
401
|
+
n = new.replace(chr(10), eol)
|
|
402
|
+
if text.count(o) != 1:
|
|
403
|
+
return None, '锚点在 %s 里命中 %d 次' % (rel, text.count(o))
|
|
404
|
+
text = text.replace(o, n, 1)
|
|
405
|
+
return text, ''
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
def _mutate():
|
|
409
|
+
print('!! 定点变异自证:逐条把判据改回缺陷形态/判据退化/过度放宽/过度收紧/单点分裂,守卫必须按指定项转红')
|
|
410
|
+
tree = _mirror_build()
|
|
411
|
+
bad = []
|
|
412
|
+
try:
|
|
413
|
+
rc, reds, out = _run_in(tree)
|
|
414
|
+
print(' 未变异镜像基线:rc=%d 红项=%d(必须 rc=0 且 0 红)' % (rc, len(reds)))
|
|
415
|
+
if rc != 0 or reds:
|
|
416
|
+
bad.append('未变异镜像基线即红')
|
|
417
|
+
print(chr(10).join(out.splitlines()[-25:]))
|
|
418
|
+
for desc, rel, pairs, exp in _MUTATIONS:
|
|
419
|
+
p = os.path.join(tree, rel)
|
|
420
|
+
with open(p, encoding='utf-8', newline='') as f:
|
|
421
|
+
bak = f.read()
|
|
422
|
+
mut, why = _apply_text(bak, rel, pairs)
|
|
423
|
+
if mut is None:
|
|
424
|
+
bad.append('%s —— %s' % (desc, why))
|
|
425
|
+
print(' ANCHOR-MISS ' + desc + ' ' + why)
|
|
426
|
+
continue
|
|
427
|
+
with open(p, 'w', encoding='utf-8', newline='') as f:
|
|
428
|
+
f.write(mut)
|
|
429
|
+
for root, dd, ff in os.walk(tree):
|
|
430
|
+
if os.path.basename(root) == '__pycache__':
|
|
431
|
+
shutil.rmtree(root, ignore_errors=True)
|
|
432
|
+
rc2, reds2, out2 = _run_in(tree)
|
|
433
|
+
with open(p, 'w', encoding='utf-8', newline='') as f:
|
|
434
|
+
f.write(bak)
|
|
435
|
+
hit = sorted({r.split(' ')[0] for r in reds2})
|
|
436
|
+
if rc2 != 0 and hit == sorted(exp):
|
|
437
|
+
print(' OK %s 红项=%d 指定命中=%s' % (desc, len(reds2), hit))
|
|
438
|
+
else:
|
|
439
|
+
bad.append(desc)
|
|
440
|
+
print(' MISMATCH %s 实际红项=%s 期望=%s rc=%d'
|
|
441
|
+
% (desc, hit, sorted(exp), rc2))
|
|
442
|
+
for r in reds2[:12]:
|
|
443
|
+
print(' FAIL ' + r)
|
|
444
|
+
print('定点变异自证:%s(%d 条不合格)'
|
|
445
|
+
% ('PASS' if not bad else 'FAIL', len(bad)))
|
|
446
|
+
for b in bad:
|
|
447
|
+
print(' 不合格:' + b)
|
|
448
|
+
return len(bad)
|
|
449
|
+
finally:
|
|
450
|
+
shutil.rmtree(tree, ignore_errors=True)
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
def main():
|
|
454
|
+
group_a()
|
|
455
|
+
group_k()
|
|
456
|
+
group_e()
|
|
457
|
+
group_c()
|
|
458
|
+
group_d()
|
|
459
|
+
print('=' * 68)
|
|
460
|
+
print('#362 负条件判据守卫:%d 通过,%d 失败' % (len(PASSED), len(FAILS)))
|
|
461
|
+
for f in FAILS:
|
|
462
|
+
print(' 红项:' + f)
|
|
463
|
+
_bad = _mutate() if '--mutate' in sys.argv else 0
|
|
464
|
+
return 1 if (FAILS or _bad) else 0
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
if __name__ == '__main__':
|
|
468
|
+
sys.exit(main())
|