@furongjun1999/dsh-memory 0.9.6 → 0.9.8
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/README.md +150 -662
- package/codebuddy/CODEBUDDY.md +333 -204
- package/data/policy.json +38 -38
- package/docs/README.md +18 -0
- package/docs/discipline/harnesses.yaml +11 -3
- package/docs/discipline/templates/compact.txt.tmpl +20 -18
- package/docs/discipline/templates/full.md.tmpl +63 -61
- package/docs/discipline/templates/rules.mdc.tmpl +5 -3
- package/docs/discipline/templates/skill.md.tmpl +25 -23
- package/docs/discipline/templates/spec.txt.tmpl +2 -2
- package/docs/discipline/templates/zcode-user.md.tmpl +1 -1
- package/dsh/cordis.yml.example +139 -139
- package/lib/hooks.d.ts +19 -0
- package/lib/hooks.js +30 -7
- package/lib/index.js +18 -3
- package/lib/init.js +19 -4
- package/lib/lib/hook_audit.js +64 -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/sustain.py +10 -1
- 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 +9 -3
- 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_n184_keys_concurrent_provision.py +1 -1
- 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_read_scope_b27.py +2 -2
- package/md_cg/test_retr_s5.py +312 -312
- package/md_cg/test_s1_ast_judge.py +109 -109
- package/md_cg/test_security_audit_v21.py +249 -249
- 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_bad_stamp.py +178 -0
- 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 +932 -908
- package/src/index.ts +21 -6
- package/src/init.ts +16 -4
- package/src/lib/hook_audit.ts +48 -2
- package/src/lib/mdcg_client.ts +469 -469
- package/src/lib/prompt_safety.ts +17 -3
- package/src/tools.ts +23 -1
- package/zcode/AGENTS.md +333 -204
|
@@ -1,919 +1,919 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
'''写返回体判据守卫(issue #109 相邻面):committed 必须可机器判定。
|
|
3
|
-
|
|
4
|
-
背景:`mdcg_remember` 工具面的**同一个返回体**在闸门短路分支给 `committed=False`,
|
|
5
|
-
成功分支此前**不给 `committed`** ⇒ 按 `committed` 判「是否落盘」的调用方会把**成功**
|
|
6
|
-
读成**未提交**;而按 `ok` 判的调用方会把**待审**读成**已提交**(#109 报的那一面)。
|
|
7
|
-
两面同源:**工具面的 committed 不是恒在的判据键**。
|
|
8
|
-
|
|
9
|
-
权威依据:`md_cg/protocol.py:57-59` 的 `WRITE_TRIO` 铁律(write 任一形态必含
|
|
10
|
-
ok/id/committed——「客户端据此判定『是否落盘』而非猜测」)与
|
|
11
|
-
`docs/mdcg/灵枢记忆动词协议_v1.0-draft.md:28/:31-32/:43`。
|
|
12
|
-
|
|
13
|
-
本守卫只钉**可判据面**:committed 恒在且与落盘事实一致;pending 态用 committed 可判。
|
|
14
|
-
不改写入语义。
|
|
15
|
-
|
|
16
|
-
运行:python -X utf8 -m md_cg.test_write_return_shape
|
|
17
|
-
python -X utf8 -m md_cg.test_write_return_shape --mutate
|
|
18
|
-
'''
|
|
19
|
-
import argparse
|
|
20
|
-
import ast as _ast
|
|
21
|
-
import io
|
|
22
|
-
import json
|
|
23
|
-
import os
|
|
24
|
-
import shutil
|
|
25
|
-
import sys
|
|
26
|
-
import tempfile
|
|
27
|
-
|
|
28
|
-
_SANDBOX = tempfile.mkdtemp(prefix='write_shape_sandbox_')
|
|
29
|
-
os.environ['MDCG_AUX_ROOT'] = _SANDBOX
|
|
30
|
-
os.environ['MDCG_ROOT'] = os.path.join(_SANDBOX, 'root')
|
|
31
|
-
os.environ['MDCG_MASTER_KEY'] = os.urandom(32).hex()
|
|
32
|
-
os.environ.pop('MDCG_TEST_LIVE_ROOT', None)
|
|
33
|
-
_pol = os.path.join(_SANDBOX, 'policy.json')
|
|
34
|
-
with io.open(_pol, 'w', encoding='utf-8') as _f:
|
|
35
|
-
json.dump({'forbidden': ['FORBIDDEN_WORD'], 'required': ['PASSED']}, _f)
|
|
36
|
-
os.environ['MDCG_POLICY_FILE'] = _pol
|
|
37
|
-
|
|
38
|
-
from . import mcp_server, protocol # noqa: E402
|
|
39
|
-
from .mdcos import MdCGOS # noqa: E402
|
|
40
|
-
|
|
41
|
-
_HERE = os.path.dirname(os.path.abspath(__file__))
|
|
42
|
-
_PASS = []
|
|
43
|
-
_FAIL = []
|
|
44
|
-
_RUN = [0]
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
def ok(cond, msg, extra=''):
|
|
48
|
-
(_PASS if cond else _FAIL).append(msg)
|
|
49
|
-
print((' PASS ' if cond else ' FAIL ') + msg
|
|
50
|
-
+ ((' <- ' + str(extra)) if (extra and not cond) else ''))
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
def _lib(tag):
|
|
54
|
-
_RUN[0] += 1
|
|
55
|
-
return MdCGOS(os.path.join(_SANDBOX, '%s_r%d' % (tag, _RUN[0])), autoflush=0)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
BODY = '# 功能名:%s' + chr(10) + chr(10) + '# 生效条件:PASSED' + chr(10)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
def _args(text, nid):
|
|
62
|
-
return {'content_kind': 'text', 'content': text, 'layer': 'knowledge',
|
|
63
|
-
'node_id': nid, 'verification_basis': 'test'}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
def tool_write(cg, text, nid):
|
|
67
|
-
return mcp_server.call_tool(cg, 'mdcg_remember', _args(text, nid))
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
def verb_write(cg, text, nid):
|
|
71
|
-
a = dict(op='write')
|
|
72
|
-
a.update(_args(text, nid))
|
|
73
|
-
return mcp_server.call_tool(cg, 'cg', a)
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
def g_tool_success():
|
|
77
|
-
cg = _lib('toolok')
|
|
78
|
-
o = tool_write(cg, BODY % '初版', 'w1')
|
|
79
|
-
ok(o.get('ok') is True, 'G1a 工具面首次写入 ok=True', o.get('ok'))
|
|
80
|
-
ok('committed' in o, 'G1b 工具面成功返回体含 committed(三键铁律)', sorted(o))
|
|
81
|
-
ok(o.get('committed') is True, 'G1c 工具面成功 => committed is True', o.get('committed'))
|
|
82
|
-
ok('初版' in ((cg.get('w1') or {}).get('content') or ''),
|
|
83
|
-
'G1d 与落盘事实一致(正文确在盘上)')
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
def g_tool_pending():
|
|
87
|
-
cg = _lib('toolpend')
|
|
88
|
-
tool_write(cg, BODY % '初版', 'w2')
|
|
89
|
-
o = tool_write(cg, BODY % '改写版', 'w2')
|
|
90
|
-
ok('committed' in o, 'G2a pending 返回体含 committed', sorted(o))
|
|
91
|
-
ok(o.get('committed') is False, 'G2b pending => committed is False', o.get('committed'))
|
|
92
|
-
ok(bool(o.get('moved_to')), 'G2c 未 committed 必给去向(moved_to)', o.get('moved_to'))
|
|
93
|
-
ok('改写版' not in ((cg.get('w2') or {}).get('content') or ''),
|
|
94
|
-
'G2d 与落盘事实一致(新正文未落盘)')
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
def g_machine_decidable():
|
|
98
|
-
cg = _lib('decide')
|
|
99
|
-
a = tool_write(cg, BODY % 'A', 'w3')
|
|
100
|
-
b = tool_write(cg, BODY % 'B', 'w3')
|
|
101
|
-
ok(a.get('committed') is True and b.get('committed') is False,
|
|
102
|
-
'G3a 「已提交 / 待审」两态仅凭 committed 即可机器区分(不依赖 ok)',
|
|
103
|
-
(a.get('committed'), b.get('committed')))
|
|
104
|
-
ok(a.get('ok') is True and b.get('ok') is True,
|
|
105
|
-
'G3b 两态 ok 相同 => 印证「只判 ok 必然误判」(#109 要害;本守卫不以 ok 作判据)')
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
def g_verb_face():
|
|
109
|
-
cg = _lib('verb')
|
|
110
|
-
a = verb_write(cg, BODY % 'VA', 'v1')
|
|
111
|
-
b = verb_write(cg, BODY % 'VB', 'v1')
|
|
112
|
-
for tag, o, want in (('G4a verb 成功', a, True), ('G4b verb 待审', b, False)):
|
|
113
|
-
miss = [k for k in protocol.WRITE_TRIO if k not in o]
|
|
114
|
-
ok(not miss and o.get('committed') is want,
|
|
115
|
-
'%s => 含三键且 committed is %s' % (tag, want), (miss, o.get('committed')))
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
def _scan_ok_without_committed(src):
|
|
119
|
-
'''找出 return {"ok": True ...} 且同一字典字面量内无 committed 的返回。'''
|
|
120
|
-
bad = []
|
|
121
|
-
lines = src.split(chr(10))
|
|
122
|
-
for n, l in enumerate(lines):
|
|
123
|
-
if 'return {' not in l:
|
|
124
|
-
continue
|
|
125
|
-
if '\"ok\": True' not in l and "'ok': True" not in l:
|
|
126
|
-
continue
|
|
127
|
-
head = chr(10).join(lines[n:n + 6]).split('}')[0]
|
|
128
|
-
if 'committed' not in head:
|
|
129
|
-
bad.append('第 %d 行' % (n + 1))
|
|
130
|
-
return bad
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
def _write_shapes():
|
|
134
|
-
'''协议里 write 的声明形态表(判据真源,不在本文件另立一份)。'''
|
|
135
|
-
return protocol.VERB_SPECS['write']['shapes']
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
def _required_of(name):
|
|
139
|
-
return tuple(_write_shapes()[name].get('required') or ())
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
def _static_violations(keys):
|
|
143
|
-
'''静态面判据(只有键名):①三键齐 ②命中至少一个声明形态 ③不构成任何形态的**降级**。
|
|
144
|
-
|
|
145
|
-
返回 (违规列表, 命中的最具体形态名)。「最具体」=required 键数最多——
|
|
146
|
-
于是「自治出单」不会被更松的 committed 形态吞掉:形态判定可判据、不靠猜。
|
|
147
|
-
|
|
148
|
-
★**降级判据**(2026-10-12 加):形态声明里的 `fingerprint` 是「本形态的特征键集
|
|
149
|
-
(不含那条最容易漏的键)」。若某返回体**命中特征键却没满足 required**,说明它
|
|
150
|
-
本该是本形态、却缺了必需键 —— 缺的那一个键(如 verdict)会让它退回去命中更松的
|
|
151
|
-
形态(committed),**判据静默失效**。故此处显式判红。
|
|
152
|
-
'''
|
|
153
|
-
ks = set(keys)
|
|
154
|
-
bad = []
|
|
155
|
-
miss = [k for k in protocol.WRITE_TRIO if k not in ks]
|
|
156
|
-
if miss:
|
|
157
|
-
bad.append('缺三键%s' % miss)
|
|
158
|
-
hit = [n for n in _write_shapes() if set(_required_of(n)) <= ks]
|
|
159
|
-
if not hit:
|
|
160
|
-
bad.append('不属任何声明形态')
|
|
161
|
-
best = max(hit, key=lambda n: len(_required_of(n))) if hit else None
|
|
162
|
-
for name, spec in _write_shapes().items():
|
|
163
|
-
fp = tuple(spec.get('fingerprint') or ())
|
|
164
|
-
if fp and set(fp) <= ks and name not in hit:
|
|
165
|
-
missing = [k for k in _required_of(name) if k not in ks]
|
|
166
|
-
bad.append('降级:命中 %s 的特征键却缺 %s' % (name, missing))
|
|
167
|
-
return bad, best
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
def _runtime_violations(body):
|
|
171
|
-
'''运行面判据(有真值):静态面 + 「未 committed 必给去向(moved_to/gate)」。'''
|
|
172
|
-
bad, best = _static_violations(body)
|
|
173
|
-
if body.get('committed') is not True and not (body.get('moved_to')
|
|
174
|
-
or body.get('gate')):
|
|
175
|
-
bad.append('未 committed 但无去向(moved_to/gate 皆缺)')
|
|
176
|
-
return bad, best
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
def _dict_returns_in_block(path, tool):
|
|
180
|
-
'''AST 取工具面分支块内的**字典字面量**返回:(行号, 键列表, 源码片段)。
|
|
181
|
-
|
|
182
|
-
用 AST 而非正则:单引号/换行/多行字典都要认出(正则漏提=假绿灯)。
|
|
183
|
-
命名返回(return out / return res)不是字面量——其键集由运行面判据覆盖。
|
|
184
|
-
'''
|
|
185
|
-
import ast
|
|
186
|
-
src = io.open(path, encoding='utf-8').read()
|
|
187
|
-
tree = ast.parse(src)
|
|
188
|
-
out = []
|
|
189
|
-
for node in ast.walk(tree):
|
|
190
|
-
if not isinstance(node, ast.If) or not isinstance(node.test, ast.Compare):
|
|
191
|
-
continue
|
|
192
|
-
c = node.test
|
|
193
|
-
if not (isinstance(c.left, ast.Name) and c.left.id == "name"
|
|
194
|
-
and len(c.comparators) == 1
|
|
195
|
-
and isinstance(c.comparators[0], ast.Constant)
|
|
196
|
-
and c.comparators[0].value == tool):
|
|
197
|
-
continue
|
|
198
|
-
for sub in ast.walk(node):
|
|
199
|
-
if not isinstance(sub, ast.Return):
|
|
200
|
-
continue
|
|
201
|
-
# 生效条件:返回体是字典字面量时直接取;若是**包了一层调用**
|
|
202
|
-
# (如 return _am.apply_dedup({...}, _pr)),则递归看它的 args——
|
|
203
|
-
# 被包一层的字典仍是「工具分支块内的字典返回」,而按 ast.Dict 硬匹配
|
|
204
|
-
# 会**静默看不见它**(不报错,表现为锚点漂移)。issue #552。
|
|
205
|
-
cand = []
|
|
206
|
-
if isinstance(sub.value, ast.Dict):
|
|
207
|
-
cand.append(sub.value)
|
|
208
|
-
elif isinstance(sub.value, ast.Call):
|
|
209
|
-
for arg in list(sub.value.args) + [kw.value for kw in sub.value.keywords]:
|
|
210
|
-
if isinstance(arg, ast.Dict):
|
|
211
|
-
cand.append(arg)
|
|
212
|
-
for d in cand:
|
|
213
|
-
ks = [k.value for k in d.keys if isinstance(k, ast.Constant)]
|
|
214
|
-
out.append((d.lineno, ks, ast.get_source_segment(src, d) or ''))
|
|
215
|
-
return sorted(out)
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
def g_declared_shapes_full():
|
|
219
|
-
'''G6 按声明形态**全量**校验工具面(静态 AST 面)。
|
|
220
|
-
|
|
221
|
-
每个字典字面量返回都必须 ①三键齐 ②命中声明形态;并按锚串钉住**具体形态**
|
|
222
|
-
(锚串不在 ⇒ 判红:实现改了却没同步本表=判据漂移,不静默放行)。
|
|
223
|
-
'''
|
|
224
|
-
src_path = os.path.join(_HERE, 'mcp_server.py')
|
|
225
|
-
found = _dict_returns_in_block(src_path, 'mdcg_remember')
|
|
226
|
-
ok(len(found) >= 3,
|
|
227
|
-
'G6a 工具面分支块内字典返回数 >= 3(实测 %d 个)' % len(found),
|
|
228
|
-
[r[0] for r in found])
|
|
229
|
-
anchors = {
|
|
230
|
-
'autonomy_forbidden': {'must': protocol.WRITE_TRIO + ('moved_to',)},
|
|
231
|
-
'conflict_deferred': {'must': protocol.WRITE_TRIO + ('moved_to', 'verdict'),
|
|
232
|
-
'best': 'gate_short_circuit'},
|
|
233
|
-
'review_queue': {'must': _required_of('autonomy_ticket'),
|
|
234
|
-
'best': 'autonomy_ticket',
|
|
235
|
-
# ★2026-10-12 设计者裁定:verdict **键必在场**、值取盲区标记
|
|
236
|
-
# None(`no` 从 ('verdict',) 改为「不许有值」由 G6e' 判)。
|
|
237
|
-
'no_value': ('verdict',)},
|
|
238
|
-
}
|
|
239
|
-
seen = {}
|
|
240
|
-
for ln, keys, seg in found:
|
|
241
|
-
bad, best = _static_violations(keys)
|
|
242
|
-
ok(not bad, 'G6b 行 %d 满足三键铁律且属声明形态(形态=%s)' % (ln, best),
|
|
243
|
-
(bad, sorted(keys)))
|
|
244
|
-
for name, spec in anchors.items():
|
|
245
|
-
if name in seg:
|
|
246
|
-
seen[name] = ln
|
|
247
|
-
miss = [k for k in spec['must'] if k not in keys]
|
|
248
|
-
ok(not miss, 'G6c 行 %d 是 %s 形态且含必需键' % (ln, name), miss)
|
|
249
|
-
if spec.get('best'):
|
|
250
|
-
ok(best == spec['best'],
|
|
251
|
-
'G6d 行 %d(%s)命中的最具体形态 == %s'
|
|
252
|
-
% (ln, name, spec['best']), best)
|
|
253
|
-
for k in spec.get('no', ()):
|
|
254
|
-
ok(k not in keys,
|
|
255
|
-
'G6e 行 %d(%s)不得含 %s(无该判据不许编造)'
|
|
256
|
-
% (ln, name, k), sorted(keys))
|
|
257
|
-
# ★2026-10-12 裁定新增:键**必在场**,但值必须是盲区标记 None。
|
|
258
|
-
for k in spec.get('no_value', ()):
|
|
259
|
-
ok(k in keys,
|
|
260
|
-
'G6e\u2032 行 %d(%s)必须含 %s 键(盲区声明:键必在场)'
|
|
261
|
-
% (ln, name, k), sorted(keys))
|
|
262
|
-
vals = _literal_values_of(seg)
|
|
263
|
-
ok(k in vals and vals[k] is None,
|
|
264
|
-
'G6e\u2033 行 %d(%s)的 %s 值必须是盲区标记 None'
|
|
265
|
-
'(该路径无 audit 裁决,不许编造有值裁决)'
|
|
266
|
-
% (ln, name, k), vals.get(k, '<缺键>'))
|
|
267
|
-
for name in anchors:
|
|
268
|
-
ok(name in seen,
|
|
269
|
-
'G6f 锚点 %s 仍存在于工具面分支块(锚点漂移即判红)' % name,
|
|
270
|
-
sorted(seen))
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
def g_runtime_shapes():
|
|
274
|
-
'''G7 运行面:逐分支真跑,按声明形态全量校验。'''
|
|
275
|
-
cg = _lib('shapes')
|
|
276
|
-
a = tool_write(cg, BODY % '初版', 's1')
|
|
277
|
-
bad, best = _runtime_violations(a)
|
|
278
|
-
ok(not bad, 'G7a 成功分支满足全量校验(形态=%s)' % best, bad)
|
|
279
|
-
ok(best == 'committed', 'G7b 成功分支最具体形态 == committed', best)
|
|
280
|
-
|
|
281
|
-
b = tool_write(cg, BODY % '改写版', 's1')
|
|
282
|
-
bad, best = _runtime_violations(b)
|
|
283
|
-
ok(not bad, 'G7c 自治出单分支满足全量校验(形态=%s)' % best, bad)
|
|
284
|
-
ok(best == 'autonomy_ticket',
|
|
285
|
-
'G7d 自治出单分支最具体形态 == autonomy_ticket(不并入 gate_short_circuit)',
|
|
286
|
-
best)
|
|
287
|
-
ok('verdict' in b and b.get('verdict') is None,
|
|
288
|
-
'G7e 自治出单分支 verdict **键必在场且值为盲区标记 None**'
|
|
289
|
-
'(2026-10-12 裁定:该路径无 audit 裁决 ⇒ 留显式标记,不编造有值裁决)',
|
|
290
|
-
(sorted(b), b.get('verdict', '<缺键>')))
|
|
291
|
-
ok(b.get('committed') is False and b.get('moved_to') == 'review_queue',
|
|
292
|
-
'G7f 自治出单 = 未落盘 + 去向 review_queue + 可轮询 pid',
|
|
293
|
-
(b.get('committed'), b.get('moved_to'), b.get('pid')))
|
|
294
|
-
|
|
295
|
-
# on_conflict 必须显式给 defer:工具面缺省是 reject(抛 ConsistencyError),
|
|
296
|
-
# 只有 defer 才会让 cg.add 返回 None 并走冲突 DEFER 出口(本批新增的去向词)。
|
|
297
|
-
_ca = _args('# 功能名:冲突体' + chr(10) * 2
|
|
298
|
-
+ '# 生效条件:超时 30s 允许并发' + chr(10)
|
|
299
|
-
+ '# 不适用条件:超时' + chr(10), 's2')
|
|
300
|
-
_ca['on_conflict'] = 'defer'
|
|
301
|
-
c = mcp_server.call_tool(cg, 'mdcg_remember', _ca)
|
|
302
|
-
bad, best = _runtime_violations(c)
|
|
303
|
-
ok(not bad, 'G7g 冲突 DEFER 分支满足全量校验(形态=%s)' % best, bad)
|
|
304
|
-
ok(c.get('moved_to') == 'conflict_deferred',
|
|
305
|
-
'G7h 冲突 DEFER 去向词 == conflict_deferred(未落盘也未入队)',
|
|
306
|
-
(c.get('moved_to'), c.get('committed'), sorted(c)))
|
|
307
|
-
ok(c.get('committed') is False and 'pid' not in c,
|
|
308
|
-
'G7i 冲突 DEFER:committed is False 且不给 pid(未入队 ⇒ 不轮询)', sorted(c))
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
def g_autonomy_forbidden_and_guest():
|
|
312
|
-
'''G8 自治禁止(plan 档)+ 无权限(guest)两面。'''
|
|
313
|
-
from unittest.mock import patch
|
|
314
|
-
from . import autonomy_modes as _am
|
|
315
|
-
# 纪律(autonomy_modes.py:124):档位 env 名只在唯一入口模块写字面量 ——
|
|
316
|
-
# 本守卫经 AUTONOMY_ENV_KEYS 取键(同 test_autonomy_modes 的 _ENV_MODE 口径),
|
|
317
|
-
# 绝不在此处再写一处带引号的档位 env 字面量。
|
|
318
|
-
with patch.dict(os.environ, {_am.AUTONOMY_ENV_KEYS['mode']: 'plan'}):
|
|
319
|
-
cg = _lib('forbid')
|
|
320
|
-
tool_write(cg, BODY % '初版', 'f1')
|
|
321
|
-
o = tool_write(cg, BODY % '改写版', 'f1')
|
|
322
|
-
bad, best = _runtime_violations(o)
|
|
323
|
-
ok(not bad, 'G8a 自治禁止分支满足全量校验(形态=%s)' % best, bad)
|
|
324
|
-
ok(o.get('moved_to') == 'autonomy_forbidden'
|
|
325
|
-
and o.get('committed') is False,
|
|
326
|
-
'G8b plan 档 => moved_to=autonomy_forbidden + committed False',
|
|
327
|
-
(o.get('moved_to'), o.get('committed')))
|
|
328
|
-
from .mdcos import MdCGSecure
|
|
329
|
-
from .security import AccessDenied, Principal
|
|
330
|
-
root = os.path.join(_SANDBOX, 'guest_root')
|
|
331
|
-
master = bytes(range(32))
|
|
332
|
-
owner = Principal(tenant='t', actor='owner', session='s', clearance='secret',
|
|
333
|
-
role='designer', can_write=True, can_admin=True)
|
|
334
|
-
cg2 = MdCGSecure(root, master_key=master, principal=owner)
|
|
335
|
-
guest = MdCGSecure(root, master_key=master, principal=Principal(
|
|
336
|
-
tenant='t', actor='guest', session='g', clearance='public',
|
|
337
|
-
role='guest', can_write=False))
|
|
338
|
-
try:
|
|
339
|
-
raised = None
|
|
340
|
-
try:
|
|
341
|
-
mcp_server.call_tool(guest, 'mdcg_remember', _args(BODY % 'guest', 'gx'))
|
|
342
|
-
except Exception as exc: # noqa: BLE001
|
|
343
|
-
raised = exc
|
|
344
|
-
ok(isinstance(raised, AccessDenied),
|
|
345
|
-
'G8c 无权限分支=异常面(抛 AccessDenied),不返回形状不全的 dict',
|
|
346
|
-
type(raised).__name__ if raised else None)
|
|
347
|
-
finally:
|
|
348
|
-
guest.close()
|
|
349
|
-
cg2.close()
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
def g_gated_envelope_exempt():
|
|
353
|
-
'''G9 gated=true 分支的**显式豁免**判据(双向钉,防静默两面)。
|
|
354
|
-
|
|
355
|
-
该分支委托 mdcos.remember_gated,返回**闸门裁决信封**(ok/gate/verdict/
|
|
356
|
-
written),不含 id/committed ⇒ 不在三键面。本判据不断言它「合规」,而是钉:
|
|
357
|
-
① 现状确实缺三键(记录下来,不假装已覆盖);
|
|
358
|
-
② 它仍给出机器可判的裁决/落盘判据(gate|verdict|written);
|
|
359
|
-
③ 若将来补上三键 ⇒ 必须同时满足声明形态(改善也不许无声明)。
|
|
360
|
-
'''
|
|
361
|
-
cg = _lib('gatedenv')
|
|
362
|
-
o = mcp_server.call_tool(cg, 'mdcg_remember',
|
|
363
|
-
dict(_args(BODY % 'gated', 'ge1'), gated=True))
|
|
364
|
-
trio_complete = all(k in o for k in protocol.WRITE_TRIO)
|
|
365
|
-
ok(not trio_complete,
|
|
366
|
-
'G9a gated 分支现状不在三键面(实测键=%s)——显式记录,未假装覆盖'
|
|
367
|
-
% sorted(o), sorted(o))
|
|
368
|
-
ok(any(k in o for k in ('gate', 'verdict', 'written')),
|
|
369
|
-
'G9b gated 分支仍给出机器可判的裁决/落盘判据(gate|verdict|written)',
|
|
370
|
-
sorted(o))
|
|
371
|
-
if trio_complete:
|
|
372
|
-
bad, best = _runtime_violations(o)
|
|
373
|
-
ok(not bad,
|
|
374
|
-
'G9c gated 分支已补三键 => 必须满足声明形态(形态=%s)' % best, bad)
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
def g_tool_face_binding_declared():
|
|
378
|
-
'''G10 声明面:mdcg_remember 已绑定 write 动词(题1 的声明落地)。'''
|
|
379
|
-
bind = getattr(protocol, 'TOOL_FACE_BINDINGS', {}).get('mdcg_remember')
|
|
380
|
-
ok(bool(bind), 'G10a 协议声明了工具面 mdcg_remember → 动词绑定', bind)
|
|
381
|
-
ok(bool(bind) and bind.get('verb') == 'write',
|
|
382
|
-
'G10b 绑定动词 == write(受 WRITE_TRIO 铁律约束)', bind)
|
|
383
|
-
rep = protocol.audit()
|
|
384
|
-
ok(rep.get('ok') is True and not rep.get('shape_errors'),
|
|
385
|
-
'G10c 协议静态对账 ok=True 且零 shape_errors', rep.get('shape_errors'))
|
|
386
|
-
ok('autonomy_ticket' in protocol.VERB_SPECS['write']['shapes'],
|
|
387
|
-
'G10d write 声明形态含 autonomy_ticket(题3b 落地)')
|
|
388
|
-
ok('verdict' in _required_of('autonomy_ticket'),
|
|
389
|
-
'G10e autonomy_ticket.required **含** verdict(2026-10-12 裁定:该路径无 audit 裁决'
|
|
390
|
-
' ⇒ 值取盲区标记 None,但**键必在场**——缺席是歧义源)',
|
|
391
|
-
_required_of('autonomy_ticket'))
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
def g_source_no_silent_gap():
|
|
396
|
-
src = io.open(os.path.join(_HERE, 'mcp_server.py'), encoding='utf-8').read()
|
|
397
|
-
i = src.find('if name == \"mdcg_remember\":')
|
|
398
|
-
j = src.find('if name == \"mdcg_recall\":')
|
|
399
|
-
block = src[i:j] if (i >= 0 and j > i) else ''
|
|
400
|
-
ok(bool(block), 'G5a 定位到 mdcg_remember 工具面分支块', (i, j))
|
|
401
|
-
bad = _scan_ok_without_committed(block)
|
|
402
|
-
ok(not bad,
|
|
403
|
-
'G5b 工具面分支内不存在「ok:True 却不给 committed」的返回(防静默回退)', bad)
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
#: protocol.gate_short_circuit(任一 before 闸门短路)的必需键集——本批补齐的判据面。
|
|
407
|
-
_GATE_REQ = protocol.WRITE_TRIO + ('moved_to', 'verdict', 'hint')
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
def _scan_gate_missing(src, markers=('moved_to', 'gate')):
|
|
411
|
-
'''按 protocol 形状表核对写面返回体(**AST 级**,避免内层字典 `}` 误切)。
|
|
412
|
-
|
|
413
|
-
`markers`:认定「本返回属闸门短路类」的键。默认 `moved_to`/`gate`(写链/引擎面);
|
|
414
|
-
工具面额外加 `verdict`——因为那里最初的缺口正是**连 moved_to 都没有**的那一态。
|
|
415
|
-
形状判定(按返回字典键集):
|
|
416
|
-
· 含 `gate` ⇒ gate_gated:需 WRITE_TRIO + (gate, verdict)
|
|
417
|
-
· 含 `moved_to` ⇒ gate_short_circuit:需 WRITE_TRIO + (moved_to, verdict, hint)
|
|
418
|
-
· 其余 ⇒ 落盘形态:需 WRITE_TRIO
|
|
419
|
-
豁免:字面量之后补键的既有写法(如 `out["hint"] = ...`)视为满足(源码全文出现该赋值即豁免)。
|
|
420
|
-
'''
|
|
421
|
-
bad = []
|
|
422
|
-
try:
|
|
423
|
-
tree = _ast.parse(src)
|
|
424
|
-
except SyntaxError as exc:
|
|
425
|
-
return ['源码解析失败:%s' % exc]
|
|
426
|
-
late = set()
|
|
427
|
-
for k in ('hint',):
|
|
428
|
-
if ('["%s"] = ' % k) in src or ("['%s'] = " % k) in src:
|
|
429
|
-
late.add(k)
|
|
430
|
-
for node in _ast.walk(tree):
|
|
431
|
-
if not isinstance(node, _ast.Return) or not isinstance(node.value, _ast.Dict):
|
|
432
|
-
continue
|
|
433
|
-
keys = set()
|
|
434
|
-
for k in node.value.keys:
|
|
435
|
-
if isinstance(k, _ast.Constant) and isinstance(k.value, str):
|
|
436
|
-
keys.add(k.value)
|
|
437
|
-
if not (set(markers) & keys):
|
|
438
|
-
continue
|
|
439
|
-
if 'gate' in keys:
|
|
440
|
-
need, shape = protocol.WRITE_TRIO + ('gate', 'verdict'), 'gate_gated'
|
|
441
|
-
elif 'moved_to' in keys:
|
|
442
|
-
need, shape = _GATE_REQ, 'gate_short_circuit'
|
|
443
|
-
else:
|
|
444
|
-
need, shape = protocol.WRITE_TRIO, 'committed'
|
|
445
|
-
miss = [k for k in need if k not in keys and k not in late]
|
|
446
|
-
if miss:
|
|
447
|
-
bad.append('第 %d 行 [%s] 缺 %s' % (node.lineno, shape, ','.join(miss)))
|
|
448
|
-
return bad
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
def g_autonomy_gate_shape():
|
|
452
|
-
'''自治档位短路的两条分支(出单 / 兜底拒绝)须满足 gate_short_circuit 形状。
|
|
453
|
-
|
|
454
|
-
背景(#109 三处仍开着之二):工具面 `mdcg_remember` 的自治档位分支此前**缺 verdict**,
|
|
455
|
-
不满足 protocol 声明的形状;直写面无校验闸 ⇒ verdict 键必在、值取 None(照
|
|
456
|
-
writepipe.py:758 既有惯例,不编造裁决)。
|
|
457
|
-
'''
|
|
458
|
-
from . import autonomy_modes as _am
|
|
459
|
-
env_mode = _am.AUTONOMY_ENV_KEYS['mode']
|
|
460
|
-
cg = _lib('autgate')
|
|
461
|
-
tool_write(cg, BODY % '初版', 'g1') # 先造既有节点(触发 C 改写)
|
|
462
|
-
old = os.environ.get(env_mode)
|
|
463
|
-
try:
|
|
464
|
-
os.environ[env_mode] = 'confirm' # 变更确认档 ⇒ 出单
|
|
465
|
-
o = tool_write(cg, BODY % '改写版', 'g1')
|
|
466
|
-
miss = [k for k in _GATE_REQ if k not in o]
|
|
467
|
-
ok(not miss and o.get('committed') is False
|
|
468
|
-
and o.get('moved_to') == 'review_queue' and o.get('verdict', '缺键') is None,
|
|
469
|
-
'G6a 自治出单分支满足 gate_short_circuit(含 verdict 键且为 None、committed=False)',
|
|
470
|
-
(miss, o.get('committed'), o.get('verdict', '缺键')))
|
|
471
|
-
os.environ[env_mode] = 'plan' # 计划档 ⇒ **A 新增** fail-closed
|
|
472
|
-
o2 = tool_write(cg, BODY % '计划外新增', 'g2') # 新 id ⇒ A 新增(非改写)
|
|
473
|
-
miss2 = [k for k in _GATE_REQ if k not in o2]
|
|
474
|
-
ok(not miss2 and o2.get('committed') is False
|
|
475
|
-
and o2.get('moved_to') == 'autonomy_forbidden',
|
|
476
|
-
'G6b 自治兜底拒绝分支(plan 档 A 新增)同样满足该形状(含 verdict 键、committed=False)',
|
|
477
|
-
(miss2, o2.get('moved_to')))
|
|
478
|
-
finally:
|
|
479
|
-
if old is None:
|
|
480
|
-
os.environ.pop(env_mode, None)
|
|
481
|
-
else:
|
|
482
|
-
os.environ[env_mode] = old
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
def g_gate_source_no_gap():
|
|
486
|
-
'''写动词面三个文件的闸门短路返回,必须含对应形状的必需键。
|
|
487
|
-
|
|
488
|
-
面与标记(避免扫到非写面同名字段):
|
|
489
|
-
· `mcp_server.py`:**只扫 `mdcg_remember` 工具面分支块**;标记含 `verdict`
|
|
490
|
-
——该面最初的缺口正是「连 `moved_to` 都没有」的那一态。
|
|
491
|
-
· `writepipe.py` / `mdcos.py`:整文件按 `moved_to`/`gate` 标记(两文件均写面)。
|
|
492
|
-
'''
|
|
493
|
-
bad = []
|
|
494
|
-
src = io.open(os.path.join(_HERE, 'mcp_server.py'), encoding='utf-8').read()
|
|
495
|
-
i = src.find('if name == "mdcg_remember":')
|
|
496
|
-
j = src.find('if name == "mdcg_recall":')
|
|
497
|
-
block = src[i:j] if (i >= 0 and j > i) else ''
|
|
498
|
-
bad += ['mcp_server.py mdcg_remember 块 %s' % s
|
|
499
|
-
for s in _scan_gate_missing(block,
|
|
500
|
-
markers=('moved_to', 'gate', 'verdict'))]
|
|
501
|
-
for fn, marks in (('writepipe.py', ('moved_to', 'gate')),
|
|
502
|
-
# mdcos 只按 moved_to 标记:其 `remember_gated` 的**内部返回形状**
|
|
503
|
-
# (verdict/bypass/gate/written)契约属 #109 第③项「工具面是否受三键
|
|
504
|
-
# 铁律约束」的**待裁范围**,本判据不替它裁(不误报、也不擅改)。
|
|
505
|
-
('mdcos.py', ('moved_to',))):
|
|
506
|
-
s = io.open(os.path.join(_HERE, fn), encoding='utf-8').read()
|
|
507
|
-
bad += ['%s %s' % (fn, x) for x in _scan_gate_missing(s, markers=marks)]
|
|
508
|
-
ok(not bad,
|
|
509
|
-
'G7 写动词面闸门短路返回均含对应形状的必需键(gate_short_circuit = WRITE_TRIO'
|
|
510
|
-
'+moved_to+verdict+hint;gate_gated = WRITE_TRIO+gate+verdict;防缺键回退)', bad)
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
# ---------------------------------------------------------------- #142(2026-10-12 DSH 端)
|
|
514
|
-
#: #142 定点变异的注入开关(默认全关;只在 --mutate 的自证段打开)。
|
|
515
|
-
_142_MUT = {'oversize_keys': False, 'halt_2pc': False}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
def _ledger_rows(cg):
|
|
519
|
-
'''两段式账本行数(#142② 的覆盖判据用)。'''
|
|
520
|
-
from . import twophase
|
|
521
|
-
p = twophase.log_path(cg)
|
|
522
|
-
if not os.path.isfile(p):
|
|
523
|
-
return 0
|
|
524
|
-
with io.open(p, encoding='utf-8') as f:
|
|
525
|
-
return sum(1 for l in f if l.strip())
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
def g_142_oversize_trio():
|
|
529
|
-
'''#142①:**超限出口**必须满足 WRITE_TRIO 铁律。
|
|
530
|
-
|
|
531
|
-
这是「写返回体形状」此前**未被覆盖的出口**——它不经任何 before 闸,直接在
|
|
532
|
-
execute 入口返回;修前只有 ok/bytes/error/limit/verdict(三键缺二,且不属任何
|
|
533
|
-
声明形态)。判据真源=protocol.WRITE_TRIO + VERB_SPECS['write']['shapes']。
|
|
534
|
-
'''
|
|
535
|
-
from . import writepipe
|
|
536
|
-
cg = _lib('o142')
|
|
537
|
-
big = '# 功能名:超限' + chr(10) + chr(10) + '# 生效条件:PASSED' + chr(10) \
|
|
538
|
-
+ ('x' * (writepipe.MAX_WRITE_BYTES + 8))
|
|
539
|
-
out = writepipe.default_pipeline().execute(cg, _args(big, 'o142_big'))
|
|
540
|
-
if _142_MUT['oversize_keys']: # 变异:还原修前返回体
|
|
541
|
-
out = {k: v for k, v in out.items() if k not in ('id', 'committed')}
|
|
542
|
-
miss = [k for k in protocol.WRITE_TRIO if k not in out]
|
|
543
|
-
ok(not miss, 'H1a 超限出口含三键(ok/id/committed)', sorted(out))
|
|
544
|
-
ok(bool(out.get('id')), 'H1b 超限出口带非空 id(与 ctx 同源)', out.get('id'))
|
|
545
|
-
ok(out.get('committed') is False, 'H1c 超限 => committed is False', out.get('committed'))
|
|
546
|
-
bad, best = _static_violations(sorted(out))
|
|
547
|
-
ok(not bad, 'H1d 超限出口命中协议声明形态(静态判据)', (bad, best))
|
|
548
|
-
ok(best == 'gate_hard_reject', 'H1e 命中 gate_hard_reject(硬拒+结构化 error)', best)
|
|
549
|
-
src = io.open(os.path.join(_HERE, 'writepipe.py'), encoding='utf-8').read()
|
|
550
|
-
ok('return {"ok": False, "error": "content 超过写入硬上限' not in src,
|
|
551
|
-
'H1f 源码级:修前的无三键超限出口字面量已不存在',
|
|
552
|
-
'(若本项红说明被回退)')
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
def g_142_halt_2pc():
|
|
556
|
-
'''#142②:**短路出口零两段式覆盖**——现状如实钉住 + 口径冲突标注(本件未改)。
|
|
557
|
-
|
|
558
|
-
实测:audit REJECT / 缺必需要素等短路出口落 **0** 条两段式记录(twophase 只覆盖
|
|
559
|
-
「全放行」与 gated 两段);但 `md_cg/test_twophase.py:9/⑧2` 把「未落盘的分支
|
|
560
|
-
(闸门拒绝 / 入队)**不产生 intent**——没打算写就不记账」钉成不变量,而该守卫
|
|
561
|
-
文件**不在本件写面**(task-35:写面仅 writepipe.py + 本批守卫)⇒ 本件**回退了**
|
|
562
|
-
「短路补记账」的改法(回退前 test_twophase 34/1,⑧2 红),改为在此如实钉现状。
|
|
563
|
-
若将来裁定「短路也要落账」,本组断言会转红——那正是升级断言的信号。
|
|
564
|
-
'''
|
|
565
|
-
from . import writepipe
|
|
566
|
-
cg = _lib('h142')
|
|
567
|
-
cases = [
|
|
568
|
-
('audit REJECT·禁表词',
|
|
569
|
-
_args('# 功能名:禁' + chr(10) * 2 + '# 生效条件:PASSED' + chr(10)
|
|
570
|
-
+ '内容 FORBIDDEN_WORD 在此', 'h_rej')),
|
|
571
|
-
('audit REJECT·缺必需要素',
|
|
572
|
-
_args('# 功能名:缺' + chr(10) * 2 + '正文无必需要素词', 'h_miss')),
|
|
573
|
-
('gated 闸(自记账)', dict(_args(BODY % '遗忘闸', 'h_gated'), gated=True)),
|
|
574
|
-
]
|
|
575
|
-
for label, a in cases:
|
|
576
|
-
before = _ledger_rows(cg)
|
|
577
|
-
writepipe.default_pipeline().execute(cg, a)
|
|
578
|
-
delta = _ledger_rows(cg) - before
|
|
579
|
-
want = 2 if label.startswith('gated') else 0
|
|
580
|
-
ok(delta == want,
|
|
581
|
-
'H2 %s ⇒ 账本 +%d(现状口径:短路不记账 / gated 自记一对)' % (label, want),
|
|
582
|
-
'delta=%d(期望 %d)' % (delta, want))
|
|
583
|
-
rep = cg.reconcile_writes()
|
|
584
|
-
ok(rep.get('unpaired') == 0, 'H2d 两段式对账零悬空(unpaired=0)', rep)
|
|
585
|
-
print(' [需裁定] ②:短路出口零账(本件未改,因与 test_twophase ⑧2 的不变量冲突)——改法已写进 _team/writepipe/report.md,待 Lead/设计者裁定')
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
def g_142_two_path_divergence():
|
|
589
|
-
'''#142④:两条写通路(mdcg_remember 直写 vs cg(op=write) 走 writepipe)结论相反。
|
|
590
|
-
|
|
591
|
-
**本守卫只如实记录现状**:统一判据的改动点落在 `mcp_server.py:3571` 分支
|
|
592
|
-
(本件**只读**,见 task-35 写面约束)⇒ 不在本守卫红绿面内。若 Lead 后续统一了
|
|
593
|
-
通路,H3a 会转红——那正是「把断言升级为『两通路一致』」的信号。
|
|
594
|
-
'''
|
|
595
|
-
cg = _lib('twopath142')
|
|
596
|
-
text = ('# 功能名:同一内容' + chr(10) * 2 + '# 生效条件:PASSED' + chr(10)
|
|
597
|
-
+ '内容 FORBIDDEN_WORD 在此')
|
|
598
|
-
o_t = mcp_server.call_tool(cg, 'mdcg_remember', _args(text, 'tp_tool'))
|
|
599
|
-
o_v = mcp_server.call_tool(cg, 'cg', dict(op='write', **_args(text, 'tp_verb')))
|
|
600
|
-
ok(bool(o_t.get('committed')) != bool(o_v.get('committed')),
|
|
601
|
-
'H3a 现状:同一内容两通路结论相反(报告已记录;统一需改 mcp_server)',
|
|
602
|
-
(o_t.get('committed'), o_v.get('committed')))
|
|
603
|
-
ok(not [k for k in protocol.WRITE_TRIO if k not in o_t]
|
|
604
|
-
and not [k for k in protocol.WRITE_TRIO if k not in o_v],
|
|
605
|
-
'H3b 两通路返回体各自满足三键铁律(形状面已覆盖)',
|
|
606
|
-
(sorted(o_t), sorted(o_v)))
|
|
607
|
-
print(' [需协调] 统一判据的改动点在 mcp_server.py:3571(本件只读)——'
|
|
608
|
-
'现状:工具面落盘 / 动词面 REJECT')
|
|
609
|
-
|
|
610
|
-
_CASES = (g_tool_success, g_tool_pending, g_machine_decidable, g_verb_face,
|
|
611
|
-
g_source_no_silent_gap,
|
|
612
|
-
# issue #109 三题(2026-10-10 裁定)新增判据组:
|
|
613
|
-
g_tool_face_binding_declared, # G10 声明面:工具面绑定 + autonomy_ticket 落地
|
|
614
|
-
g_declared_shapes_full, # G6 静态面:按声明形态全量校验工具面
|
|
615
|
-
g_runtime_shapes, # G7 运行面:成功/自治出单/冲突 DEFER 逐分支
|
|
616
|
-
g_autonomy_forbidden_and_guest, # G8 自治禁止(plan 档)+ 无权限(异常面)
|
|
617
|
-
g_gated_envelope_exempt, # G9 gated 分支显式豁免(双向钉)
|
|
618
|
-
# PR #113(2026-10-12 合并,经设计者裁定收束 verdict 语义):
|
|
619
|
-
g_autonomy_gate_shape, # 自治短路两分支满足 gate_short_circuit(verdict 键必在)
|
|
620
|
-
g_gate_source_no_gap, # 三写面源码级:闸门短路返回必含对应形状必需键
|
|
621
|
-
# #142(2026-10-12 DSH 端)新增判据组:
|
|
622
|
-
g_142_oversize_trio, # H1 超限出口(此前未覆盖的出口)三键+声明形态
|
|
623
|
-
g_142_halt_2pc, # H2 短路出口两段式覆盖(恰一对 intent/outcome)
|
|
624
|
-
g_142_two_path_divergence) # H3 两通路相反结论(现状记录·待 Lead 协调)
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
def _run_all():
|
|
628
|
-
del _PASS[:]
|
|
629
|
-
del _FAIL[:]
|
|
630
|
-
for fn in _CASES:
|
|
631
|
-
try:
|
|
632
|
-
fn()
|
|
633
|
-
except Exception as exc: # noqa: BLE001
|
|
634
|
-
ok(False, '%s 组抛异常:%s: %s' % (fn.__name__, type(exc).__name__, exc))
|
|
635
|
-
return list(_FAIL)
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
_SYN = (
|
|
639
|
-
('M0 合成合规源码(同一字典内含 committed)',
|
|
640
|
-
'return {"ok": True, "id": nid, "committed": True}', False),
|
|
641
|
-
('M1 合成缺 committed(本轮修掉的那一态)',
|
|
642
|
-
'return {"ok": True, "id": nid}', True),
|
|
643
|
-
('M2 合成 committed 换行后仍在同一字典内',
|
|
644
|
-
'return {"ok": True, "id": nid,' + chr(10) + ' "committed": True}', False),
|
|
645
|
-
('M3 合成 committed 落在字典之外(应判红)',
|
|
646
|
-
'return {"ok": True, "id": nid}' + chr(10) + 'x = {"committed": True}', True),
|
|
647
|
-
)
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
def _syn_shape_report(src):
|
|
651
|
-
'''对**合成源码**跑本批新增的静态形态判据(不读盘、不定点改真实源码)。
|
|
652
|
-
|
|
653
|
-
返回 [(违规列表, 最具体形态, 键列表)] —— 一个 return 一行。
|
|
654
|
-
'''
|
|
655
|
-
import ast as _ast
|
|
656
|
-
import textwrap as _tw
|
|
657
|
-
tree = _ast.parse(_tw.dedent(src))
|
|
658
|
-
rows = []
|
|
659
|
-
for node in _ast.walk(tree):
|
|
660
|
-
if isinstance(node, _ast.Return) and isinstance(node.value, _ast.Dict):
|
|
661
|
-
ks = [k.value for k in node.value.keys if isinstance(k, _ast.Constant)]
|
|
662
|
-
bad, best = _static_violations(ks)
|
|
663
|
-
rows.append((bad, best, ks))
|
|
664
|
-
return rows
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
#: 新增判据的定点变异表:每行 = (名称, 合成源码, 期望特征)。
|
|
668
|
-
#: 期望特征键:violations_red(静态面应否报违规)/ best(应为的最具体形态)/
|
|
669
|
-
#: fabricated_verdict(「autonomy_ticket 形态下 verdict 被编造成有值」
|
|
670
|
-
#: 应否被检出 —— ★2026-10-12 设计者裁定后,**verdict 键必在场、值取 None
|
|
671
|
-
#: 是盲区声明**;仍被禁止的只是**编造一个有值的裁决**)。
|
|
672
|
-
_SYN_SHAPES = (
|
|
673
|
-
('V0 改前的冲突 DEFER 体(只有 ok/id/verdict/reason)=本批修掉的那一态',
|
|
674
|
-
'return {"ok": False, "id": nid, "verdict": "DEFER", "reason": "x"}',
|
|
675
|
-
{'violations_red': True}),
|
|
676
|
-
('V1 改后的冲突 DEFER 体(三键 + moved_to + verdict + hint)',
|
|
677
|
-
'return {"ok": False, "id": nid, "committed": False,'
|
|
678
|
-
' "moved_to": "conflict_deferred", "verdict": "DEFER", "hint": "h"}',
|
|
679
|
-
{'violations_red': False, 'best': 'gate_short_circuit'}),
|
|
680
|
-
('V2 自治出单体(真实键集,含 verdict: None =盲区声明)',
|
|
681
|
-
'return {"ok": True, "id": nid, "committed": False,'
|
|
682
|
-
' "moved_to": "review_queue", "pid": p, "mutation": m,'
|
|
683
|
-
' "autonomy": a, "verdict": None, "hint": "h"}',
|
|
684
|
-
{'violations_red': False, 'best': 'autonomy_ticket',
|
|
685
|
-
'fabricated_verdict': False}),
|
|
686
|
-
('V2b 自治出单体**缺 verdict 键**(盲区未声明 ⇒ 静态面应判红)',
|
|
687
|
-
'return {"ok": True, "id": nid, "committed": False,'
|
|
688
|
-
' "moved_to": "review_queue", "pid": p, "mutation": m,'
|
|
689
|
-
' "autonomy": a, "hint": "h"}',
|
|
690
|
-
{'violations_red': True}),
|
|
691
|
-
('V3 自治出单体被**编造有值裁决**(verdict: "DEFER" ⇒ 应被检出)',
|
|
692
|
-
'return {"ok": True, "id": nid, "committed": False,'
|
|
693
|
-
' "moved_to": "review_queue", "pid": p, "mutation": m,'
|
|
694
|
-
' "autonomy": a, "verdict": "DEFER", "hint": "h"}',
|
|
695
|
-
{'violations_red': False, 'best': 'autonomy_ticket',
|
|
696
|
-
'fabricated_verdict': True}),
|
|
697
|
-
('V4 自治出单体丢掉 autonomy(形态降级 ⇒ 最具体形态退化为 committed)',
|
|
698
|
-
'return {"ok": True, "id": nid, "committed": False,'
|
|
699
|
-
' "moved_to": "review_queue", "pid": p, "hint": "h"}',
|
|
700
|
-
{'violations_red': False, 'best': 'committed',
|
|
701
|
-
'body': {'ok': True, 'id': 'x', 'committed': False,
|
|
702
|
-
'moved_to': 'review_queue', 'pid': 'prop_x', 'hint': 'h'},
|
|
703
|
-
'runtime_red': False}),
|
|
704
|
-
('V5 三键齐但未 committed 且无去向(运行面应判红)',
|
|
705
|
-
'return {"ok": False, "id": nid, "committed": False, "verdict": "DEFER"}',
|
|
706
|
-
{'violations_red': False,
|
|
707
|
-
'body': {'ok': False, 'id': 'x', 'committed': False, 'verdict': 'DEFER'},
|
|
708
|
-
'runtime_red': True}),
|
|
709
|
-
)
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
def _literal_values(src):
|
|
713
|
-
'''从源码片段里的字典字面量取 {键: 值}(值只认字面常量;名字→哨兵 `'<expr>'`)。
|
|
714
|
-
|
|
715
|
-
输入既可是**合成源码**(`return {...}`),也可是**真实源码里的一个返回片段**
|
|
716
|
-
(G6 的 `seg`,形如 `{"ok": True, ...}`)。故先试 `return` 包裹,失败则当表达式解析。
|
|
717
|
-
'''
|
|
718
|
-
import ast as _ast
|
|
719
|
-
import textwrap as _tw
|
|
720
|
-
text = _tw.dedent(src).strip()
|
|
721
|
-
for candidate in (text, 'return ' + text, 'x = ' + text):
|
|
722
|
-
try:
|
|
723
|
-
tree = _ast.parse(candidate)
|
|
724
|
-
except SyntaxError:
|
|
725
|
-
continue
|
|
726
|
-
for node in _ast.walk(tree):
|
|
727
|
-
d = node.value if (isinstance(node, (_ast.Return, _ast.Assign))
|
|
728
|
-
and isinstance(node.value, _ast.Dict)) else (
|
|
729
|
-
node if isinstance(node, _ast.Dict) else None)
|
|
730
|
-
if d is None:
|
|
731
|
-
continue
|
|
732
|
-
out = {}
|
|
733
|
-
for k, v in zip(d.keys, d.values):
|
|
734
|
-
if isinstance(k, _ast.Constant) and isinstance(k.value, str):
|
|
735
|
-
out[k.value] = v.value if isinstance(v, _ast.Constant) else '<expr>'
|
|
736
|
-
if out:
|
|
737
|
-
return out
|
|
738
|
-
return {}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
#: G6 的片段级取值:对真实源码里的返回片段做同样的事(供 `no_value` 判据用)。
|
|
742
|
-
_literal_values_of = _literal_values
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
def _fabricated_verdict(ks):
|
|
746
|
-
'''autonomy_ticket 形态下 verdict 是否为**编造的有值裁决**。
|
|
747
|
-
|
|
748
|
-
判据(2026-10-12 设计者裁定):该形态 required 含 verdict,取值必须是盲区
|
|
749
|
-
标记 None;**任何非 None 值都是编造**(该路径无 audit 裁决可透出)。
|
|
750
|
-
'''
|
|
751
|
-
return ('verdict' in ks and ks['verdict'] is not None) if isinstance(ks, dict) \
|
|
752
|
-
else False
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
def _run_shape_mutations():
|
|
756
|
-
print('!! 新增判据定点变异自证(G6/G7 静态+运行面)')
|
|
757
|
-
bad = 0
|
|
758
|
-
for name, src, expect in _SYN_SHAPES:
|
|
759
|
-
rows = _syn_shape_report(src)
|
|
760
|
-
got_red = bool(rows) and bool(rows[0][0])
|
|
761
|
-
got_best = rows[0][1] if rows else None
|
|
762
|
-
ks = rows[0][2] if rows else []
|
|
763
|
-
got_fv = _fabricated_verdict(_literal_values(src))
|
|
764
|
-
# 运行面判据吃**显式真实值的 body**(键集 fromkeys 会把值全变 None,
|
|
765
|
-
# 那是假读:committed=None 既非 True 也非 False,moved_to=None 会被
|
|
766
|
-
# 误当「无去向」)。故用表里给的 body;未给则跳过该项。
|
|
767
|
-
|
|
768
|
-
_body = expect.get('body')
|
|
769
|
-
rt_bad = _runtime_violations(_body)[0] if _body is not None else []
|
|
770
|
-
got_rt = bool(rt_bad)
|
|
771
|
-
checks = []
|
|
772
|
-
if 'violations_red' in expect:
|
|
773
|
-
checks.append(('静态面判红=%s' % expect['violations_red'],
|
|
774
|
-
got_red == expect['violations_red']))
|
|
775
|
-
if 'best' in expect:
|
|
776
|
-
checks.append(('最具体形态=%s' % expect['best'],
|
|
777
|
-
got_best == expect['best']))
|
|
778
|
-
if 'fabricated_verdict' in expect:
|
|
779
|
-
checks.append(('autonomy_ticket 编造有值裁决被检出=%s'
|
|
780
|
-
% expect['fabricated_verdict'],
|
|
781
|
-
got_fv == expect['fabricated_verdict']))
|
|
782
|
-
if 'runtime_red' in expect:
|
|
783
|
-
checks.append(('运行面判红=%s' % expect['runtime_red'],
|
|
784
|
-
got_rt == expect['runtime_red']))
|
|
785
|
-
good = all(v for _l, v in checks)
|
|
786
|
-
if not good:
|
|
787
|
-
bad += 1
|
|
788
|
-
print(' %s %s' % ('PASS' if good else 'FAIL', name))
|
|
789
|
-
for label, v in checks:
|
|
790
|
-
print(' %s %s' % ('ok ' if v else 'MISS', label))
|
|
791
|
-
if not good:
|
|
792
|
-
print(' 实际:red=%s best=%s keys=%s runtime_bad=%s'
|
|
793
|
-
% (got_red, got_best, sorted(ks), rt_bad))
|
|
794
|
-
print('')
|
|
795
|
-
return bad
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
#: 本批(gate_short_circuit 形状)的合成变异:喂 `_scan_gate_missing`,判别力必须成立。
|
|
799
|
-
_SYN_GATE = (
|
|
800
|
-
('M4 合成合规(三键 + moved_to + verdict + hint)',
|
|
801
|
-
'return {"ok": False, "id": nid, "committed": False,'
|
|
802
|
-
' "moved_to": "conflict_deferred", "verdict": "DEFER", "hint": "x"}', False),
|
|
803
|
-
('M5 合成缺 verdict(本批修掉的那一态)',
|
|
804
|
-
'return {"ok": True, "id": nid, "committed": False,'
|
|
805
|
-
' "moved_to": "review_queue", "hint": "x"}', True),
|
|
806
|
-
('M6 合成缺 hint(形状要求的下一步说明)',
|
|
807
|
-
'return {"ok": False, "id": nid, "committed": False,'
|
|
808
|
-
' "moved_to": "x", "verdict": None}', True),
|
|
809
|
-
('M7 合成缺 committed(原冲突 DEFER 分支那一态)',
|
|
810
|
-
'return {"ok": False, "id": nid, "verdict": "DEFER", "reason": "r"}', True),
|
|
811
|
-
)
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
def _run_142_mutations():
|
|
815
|
-
'''#142 的两条定点变异(都作用于**被验实现**,不是断言侧)。'''
|
|
816
|
-
print('!! #142 定点变异自证(短路两段式 / 超限三键)')
|
|
817
|
-
bad = 0
|
|
818
|
-
from . import twophase
|
|
819
|
-
_p0, _f0 = list(_PASS), list(_FAIL)
|
|
820
|
-
# ---- M5:注入「短路出口补两段式账」的改法(=本件曾尝试、后回退的那一版)
|
|
821
|
-
# ⇒ H2 必须判红(证明「现状口径」这条断言有判别力) ----
|
|
822
|
-
from . import writepipe
|
|
823
|
-
_oe = writepipe.WritePipeline.execute
|
|
824
|
-
|
|
825
|
-
def _me(self, cg, a):
|
|
826
|
-
out = _oe(self, cg, a)
|
|
827
|
-
if isinstance(out, dict) and out.get('committed') is False:
|
|
828
|
-
_t = twophase.begin(cg, out.get('id') or '', a.get('content', ''),
|
|
829
|
-
actor='mut5:halt')
|
|
830
|
-
twophase.commit(cg, _t, status=twophase.STATUS_ABORTED,
|
|
831
|
-
reason='halted_by=mut5')
|
|
832
|
-
return out
|
|
833
|
-
|
|
834
|
-
writepipe.WritePipeline.execute = _me
|
|
835
|
-
del _PASS[:]
|
|
836
|
-
del _FAIL[:]
|
|
837
|
-
try:
|
|
838
|
-
g_142_halt_2pc()
|
|
839
|
-
except Exception as exc: # noqa: BLE001
|
|
840
|
-
ok(False, '变异段抛异常:%s: %s' % (type(exc).__name__, exc))
|
|
841
|
-
red2 = [m for m in _FAIL if m.startswith('H2')]
|
|
842
|
-
writepipe.WritePipeline.execute = _oe
|
|
843
|
-
good2 = len(red2) >= 1
|
|
844
|
-
bad += 0 if good2 else 1
|
|
845
|
-
print(' %s M5 注入「短路补记账」改法 ⇒ H2 判红 %d 条%s'
|
|
846
|
-
% ('PASS' if good2 else 'FAIL', len(red2),
|
|
847
|
-
(':' + '; '.join(red2[:2])) if red2 else ''))
|
|
848
|
-
# ---- M6:超限出口还原修前(缺 id/committed)⇒ H1 必须判红 ----
|
|
849
|
-
_142_MUT['oversize_keys'] = True
|
|
850
|
-
del _PASS[:]
|
|
851
|
-
del _FAIL[:]
|
|
852
|
-
try:
|
|
853
|
-
g_142_oversize_trio()
|
|
854
|
-
except Exception as exc: # noqa: BLE001
|
|
855
|
-
ok(False, '变异段抛异常:%s: %s' % (type(exc).__name__, exc))
|
|
856
|
-
red1 = [m for m in _FAIL if m.startswith('H1')]
|
|
857
|
-
_142_MUT['oversize_keys'] = False
|
|
858
|
-
good1 = len(red1) >= 2
|
|
859
|
-
bad += 0 if good1 else 1
|
|
860
|
-
print(' %s M6 超限出口缺 id/committed(还原修前)⇒ H1 判红 %d 条%s'
|
|
861
|
-
% ('PASS' if good1 else 'FAIL', len(red1),
|
|
862
|
-
(':' + '; '.join(red1[:3])) if red1 else ''))
|
|
863
|
-
del _PASS[:]
|
|
864
|
-
del _FAIL[:]
|
|
865
|
-
_PASS.extend(_p0)
|
|
866
|
-
_FAIL.extend(_f0)
|
|
867
|
-
print('')
|
|
868
|
-
return bad
|
|
869
|
-
|
|
870
|
-
def _run_mutations():
|
|
871
|
-
print('!! 定点变异自证:给 G5b 判据体喂合成源码,判别力必须成立')
|
|
872
|
-
bad = 0
|
|
873
|
-
for name, src, expect_red in _SYN:
|
|
874
|
-
got = _scan_ok_without_committed(src)
|
|
875
|
-
good = (bool(got) == expect_red)
|
|
876
|
-
if not good:
|
|
877
|
-
bad += 1
|
|
878
|
-
print(' %s %s' % ('PASS' if good else 'FAIL', name))
|
|
879
|
-
if not good:
|
|
880
|
-
print(' 预期有红=%s 实际=%s' % (expect_red, got))
|
|
881
|
-
print('')
|
|
882
|
-
bad += _run_shape_mutations()
|
|
883
|
-
print('!! 定点变异自证:给 G7 判据体喂合成源码,判别力必须成立')
|
|
884
|
-
for name, src, expect_red in _SYN_GATE:
|
|
885
|
-
# AST 判据要求 return 处于函数体内 ⇒ 合成样本统一包一层 def
|
|
886
|
-
wrapped = 'def _f():' + chr(10) + chr(10).join(
|
|
887
|
-
' ' + l for l in src.split(chr(10)))
|
|
888
|
-
got = _scan_gate_missing(wrapped, markers=('moved_to', 'gate', 'verdict'))
|
|
889
|
-
good = (bool(got) == expect_red)
|
|
890
|
-
if not good:
|
|
891
|
-
bad += 1
|
|
892
|
-
print(' %s %s' % ('PASS' if good else 'FAIL', name))
|
|
893
|
-
if not good:
|
|
894
|
-
print(' 预期有红=%s 实际=%s' % (expect_red, got))
|
|
895
|
-
print('')
|
|
896
|
-
bad += _run_142_mutations()
|
|
897
|
-
return bad
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
def main() -> int:
|
|
901
|
-
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
902
|
-
ap = argparse.ArgumentParser(description='写返回体判据守卫(issue #109 相邻面)')
|
|
903
|
-
ap.add_argument('--mutate', action='store_true', help='定点变异自证')
|
|
904
|
-
a = ap.parse_args()
|
|
905
|
-
reds = _run_all()
|
|
906
|
-
print('')
|
|
907
|
-
print('SUMMARY: 写返回体判据守卫:%d 通过,%d 失败' % (len(_PASS), len(reds)))
|
|
908
|
-
if reds:
|
|
909
|
-
print('失败判据:' + '; '.join(reds))
|
|
910
|
-
rc = 1 if reds else 0
|
|
911
|
-
if a.mutate:
|
|
912
|
-
rc = 1 if (_run_mutations() or reds) else 0
|
|
913
|
-
print('SUMMARY: 定点变异自证:%s' % ('全部按预期' if rc == 0 else '存在偏差'))
|
|
914
|
-
shutil.rmtree(_SANDBOX, ignore_errors=True)
|
|
915
|
-
return rc
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
if __name__ == '__main__':
|
|
919
|
-
sys.exit(main())
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''写返回体判据守卫(issue #109 相邻面):committed 必须可机器判定。
|
|
3
|
+
|
|
4
|
+
背景:`mdcg_remember` 工具面的**同一个返回体**在闸门短路分支给 `committed=False`,
|
|
5
|
+
成功分支此前**不给 `committed`** ⇒ 按 `committed` 判「是否落盘」的调用方会把**成功**
|
|
6
|
+
读成**未提交**;而按 `ok` 判的调用方会把**待审**读成**已提交**(#109 报的那一面)。
|
|
7
|
+
两面同源:**工具面的 committed 不是恒在的判据键**。
|
|
8
|
+
|
|
9
|
+
权威依据:`md_cg/protocol.py:57-59` 的 `WRITE_TRIO` 铁律(write 任一形态必含
|
|
10
|
+
ok/id/committed——「客户端据此判定『是否落盘』而非猜测」)与
|
|
11
|
+
`docs/mdcg/灵枢记忆动词协议_v1.0-draft.md:28/:31-32/:43`。
|
|
12
|
+
|
|
13
|
+
本守卫只钉**可判据面**:committed 恒在且与落盘事实一致;pending 态用 committed 可判。
|
|
14
|
+
不改写入语义。
|
|
15
|
+
|
|
16
|
+
运行:python -X utf8 -m md_cg.test_write_return_shape
|
|
17
|
+
python -X utf8 -m md_cg.test_write_return_shape --mutate
|
|
18
|
+
'''
|
|
19
|
+
import argparse
|
|
20
|
+
import ast as _ast
|
|
21
|
+
import io
|
|
22
|
+
import json
|
|
23
|
+
import os
|
|
24
|
+
import shutil
|
|
25
|
+
import sys
|
|
26
|
+
import tempfile
|
|
27
|
+
|
|
28
|
+
_SANDBOX = tempfile.mkdtemp(prefix='write_shape_sandbox_')
|
|
29
|
+
os.environ['MDCG_AUX_ROOT'] = _SANDBOX
|
|
30
|
+
os.environ['MDCG_ROOT'] = os.path.join(_SANDBOX, 'root')
|
|
31
|
+
os.environ['MDCG_MASTER_KEY'] = os.urandom(32).hex()
|
|
32
|
+
os.environ.pop('MDCG_TEST_LIVE_ROOT', None)
|
|
33
|
+
_pol = os.path.join(_SANDBOX, 'policy.json')
|
|
34
|
+
with io.open(_pol, 'w', encoding='utf-8') as _f:
|
|
35
|
+
json.dump({'forbidden': ['FORBIDDEN_WORD'], 'required': ['PASSED']}, _f)
|
|
36
|
+
os.environ['MDCG_POLICY_FILE'] = _pol
|
|
37
|
+
|
|
38
|
+
from . import mcp_server, protocol # noqa: E402
|
|
39
|
+
from .mdcos import MdCGOS # noqa: E402
|
|
40
|
+
|
|
41
|
+
_HERE = os.path.dirname(os.path.abspath(__file__))
|
|
42
|
+
_PASS = []
|
|
43
|
+
_FAIL = []
|
|
44
|
+
_RUN = [0]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def ok(cond, msg, extra=''):
|
|
48
|
+
(_PASS if cond else _FAIL).append(msg)
|
|
49
|
+
print((' PASS ' if cond else ' FAIL ') + msg
|
|
50
|
+
+ ((' <- ' + str(extra)) if (extra and not cond) else ''))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _lib(tag):
|
|
54
|
+
_RUN[0] += 1
|
|
55
|
+
return MdCGOS(os.path.join(_SANDBOX, '%s_r%d' % (tag, _RUN[0])), autoflush=0)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
BODY = '# 功能名:%s' + chr(10) + chr(10) + '# 生效条件:PASSED' + chr(10)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _args(text, nid):
|
|
62
|
+
return {'content_kind': 'text', 'content': text, 'layer': 'knowledge',
|
|
63
|
+
'node_id': nid, 'verification_basis': 'test'}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def tool_write(cg, text, nid):
|
|
67
|
+
return mcp_server.call_tool(cg, 'mdcg_remember', _args(text, nid))
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def verb_write(cg, text, nid):
|
|
71
|
+
a = dict(op='write')
|
|
72
|
+
a.update(_args(text, nid))
|
|
73
|
+
return mcp_server.call_tool(cg, 'cg', a)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def g_tool_success():
|
|
77
|
+
cg = _lib('toolok')
|
|
78
|
+
o = tool_write(cg, BODY % '初版', 'w1')
|
|
79
|
+
ok(o.get('ok') is True, 'G1a 工具面首次写入 ok=True', o.get('ok'))
|
|
80
|
+
ok('committed' in o, 'G1b 工具面成功返回体含 committed(三键铁律)', sorted(o))
|
|
81
|
+
ok(o.get('committed') is True, 'G1c 工具面成功 => committed is True', o.get('committed'))
|
|
82
|
+
ok('初版' in ((cg.get('w1') or {}).get('content') or ''),
|
|
83
|
+
'G1d 与落盘事实一致(正文确在盘上)')
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def g_tool_pending():
|
|
87
|
+
cg = _lib('toolpend')
|
|
88
|
+
tool_write(cg, BODY % '初版', 'w2')
|
|
89
|
+
o = tool_write(cg, BODY % '改写版', 'w2')
|
|
90
|
+
ok('committed' in o, 'G2a pending 返回体含 committed', sorted(o))
|
|
91
|
+
ok(o.get('committed') is False, 'G2b pending => committed is False', o.get('committed'))
|
|
92
|
+
ok(bool(o.get('moved_to')), 'G2c 未 committed 必给去向(moved_to)', o.get('moved_to'))
|
|
93
|
+
ok('改写版' not in ((cg.get('w2') or {}).get('content') or ''),
|
|
94
|
+
'G2d 与落盘事实一致(新正文未落盘)')
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def g_machine_decidable():
|
|
98
|
+
cg = _lib('decide')
|
|
99
|
+
a = tool_write(cg, BODY % 'A', 'w3')
|
|
100
|
+
b = tool_write(cg, BODY % 'B', 'w3')
|
|
101
|
+
ok(a.get('committed') is True and b.get('committed') is False,
|
|
102
|
+
'G3a 「已提交 / 待审」两态仅凭 committed 即可机器区分(不依赖 ok)',
|
|
103
|
+
(a.get('committed'), b.get('committed')))
|
|
104
|
+
ok(a.get('ok') is True and b.get('ok') is True,
|
|
105
|
+
'G3b 两态 ok 相同 => 印证「只判 ok 必然误判」(#109 要害;本守卫不以 ok 作判据)')
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def g_verb_face():
|
|
109
|
+
cg = _lib('verb')
|
|
110
|
+
a = verb_write(cg, BODY % 'VA', 'v1')
|
|
111
|
+
b = verb_write(cg, BODY % 'VB', 'v1')
|
|
112
|
+
for tag, o, want in (('G4a verb 成功', a, True), ('G4b verb 待审', b, False)):
|
|
113
|
+
miss = [k for k in protocol.WRITE_TRIO if k not in o]
|
|
114
|
+
ok(not miss and o.get('committed') is want,
|
|
115
|
+
'%s => 含三键且 committed is %s' % (tag, want), (miss, o.get('committed')))
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def _scan_ok_without_committed(src):
|
|
119
|
+
'''找出 return {"ok": True ...} 且同一字典字面量内无 committed 的返回。'''
|
|
120
|
+
bad = []
|
|
121
|
+
lines = src.split(chr(10))
|
|
122
|
+
for n, l in enumerate(lines):
|
|
123
|
+
if 'return {' not in l:
|
|
124
|
+
continue
|
|
125
|
+
if '\"ok\": True' not in l and "'ok': True" not in l:
|
|
126
|
+
continue
|
|
127
|
+
head = chr(10).join(lines[n:n + 6]).split('}')[0]
|
|
128
|
+
if 'committed' not in head:
|
|
129
|
+
bad.append('第 %d 行' % (n + 1))
|
|
130
|
+
return bad
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _write_shapes():
|
|
134
|
+
'''协议里 write 的声明形态表(判据真源,不在本文件另立一份)。'''
|
|
135
|
+
return protocol.VERB_SPECS['write']['shapes']
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def _required_of(name):
|
|
139
|
+
return tuple(_write_shapes()[name].get('required') or ())
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _static_violations(keys):
|
|
143
|
+
'''静态面判据(只有键名):①三键齐 ②命中至少一个声明形态 ③不构成任何形态的**降级**。
|
|
144
|
+
|
|
145
|
+
返回 (违规列表, 命中的最具体形态名)。「最具体」=required 键数最多——
|
|
146
|
+
于是「自治出单」不会被更松的 committed 形态吞掉:形态判定可判据、不靠猜。
|
|
147
|
+
|
|
148
|
+
★**降级判据**(2026-10-12 加):形态声明里的 `fingerprint` 是「本形态的特征键集
|
|
149
|
+
(不含那条最容易漏的键)」。若某返回体**命中特征键却没满足 required**,说明它
|
|
150
|
+
本该是本形态、却缺了必需键 —— 缺的那一个键(如 verdict)会让它退回去命中更松的
|
|
151
|
+
形态(committed),**判据静默失效**。故此处显式判红。
|
|
152
|
+
'''
|
|
153
|
+
ks = set(keys)
|
|
154
|
+
bad = []
|
|
155
|
+
miss = [k for k in protocol.WRITE_TRIO if k not in ks]
|
|
156
|
+
if miss:
|
|
157
|
+
bad.append('缺三键%s' % miss)
|
|
158
|
+
hit = [n for n in _write_shapes() if set(_required_of(n)) <= ks]
|
|
159
|
+
if not hit:
|
|
160
|
+
bad.append('不属任何声明形态')
|
|
161
|
+
best = max(hit, key=lambda n: len(_required_of(n))) if hit else None
|
|
162
|
+
for name, spec in _write_shapes().items():
|
|
163
|
+
fp = tuple(spec.get('fingerprint') or ())
|
|
164
|
+
if fp and set(fp) <= ks and name not in hit:
|
|
165
|
+
missing = [k for k in _required_of(name) if k not in ks]
|
|
166
|
+
bad.append('降级:命中 %s 的特征键却缺 %s' % (name, missing))
|
|
167
|
+
return bad, best
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def _runtime_violations(body):
|
|
171
|
+
'''运行面判据(有真值):静态面 + 「未 committed 必给去向(moved_to/gate)」。'''
|
|
172
|
+
bad, best = _static_violations(body)
|
|
173
|
+
if body.get('committed') is not True and not (body.get('moved_to')
|
|
174
|
+
or body.get('gate')):
|
|
175
|
+
bad.append('未 committed 但无去向(moved_to/gate 皆缺)')
|
|
176
|
+
return bad, best
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def _dict_returns_in_block(path, tool):
|
|
180
|
+
'''AST 取工具面分支块内的**字典字面量**返回:(行号, 键列表, 源码片段)。
|
|
181
|
+
|
|
182
|
+
用 AST 而非正则:单引号/换行/多行字典都要认出(正则漏提=假绿灯)。
|
|
183
|
+
命名返回(return out / return res)不是字面量——其键集由运行面判据覆盖。
|
|
184
|
+
'''
|
|
185
|
+
import ast
|
|
186
|
+
src = io.open(path, encoding='utf-8').read()
|
|
187
|
+
tree = ast.parse(src)
|
|
188
|
+
out = []
|
|
189
|
+
for node in ast.walk(tree):
|
|
190
|
+
if not isinstance(node, ast.If) or not isinstance(node.test, ast.Compare):
|
|
191
|
+
continue
|
|
192
|
+
c = node.test
|
|
193
|
+
if not (isinstance(c.left, ast.Name) and c.left.id == "name"
|
|
194
|
+
and len(c.comparators) == 1
|
|
195
|
+
and isinstance(c.comparators[0], ast.Constant)
|
|
196
|
+
and c.comparators[0].value == tool):
|
|
197
|
+
continue
|
|
198
|
+
for sub in ast.walk(node):
|
|
199
|
+
if not isinstance(sub, ast.Return):
|
|
200
|
+
continue
|
|
201
|
+
# 生效条件:返回体是字典字面量时直接取;若是**包了一层调用**
|
|
202
|
+
# (如 return _am.apply_dedup({...}, _pr)),则递归看它的 args——
|
|
203
|
+
# 被包一层的字典仍是「工具分支块内的字典返回」,而按 ast.Dict 硬匹配
|
|
204
|
+
# 会**静默看不见它**(不报错,表现为锚点漂移)。issue #552。
|
|
205
|
+
cand = []
|
|
206
|
+
if isinstance(sub.value, ast.Dict):
|
|
207
|
+
cand.append(sub.value)
|
|
208
|
+
elif isinstance(sub.value, ast.Call):
|
|
209
|
+
for arg in list(sub.value.args) + [kw.value for kw in sub.value.keywords]:
|
|
210
|
+
if isinstance(arg, ast.Dict):
|
|
211
|
+
cand.append(arg)
|
|
212
|
+
for d in cand:
|
|
213
|
+
ks = [k.value for k in d.keys if isinstance(k, ast.Constant)]
|
|
214
|
+
out.append((d.lineno, ks, ast.get_source_segment(src, d) or ''))
|
|
215
|
+
return sorted(out)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def g_declared_shapes_full():
|
|
219
|
+
'''G6 按声明形态**全量**校验工具面(静态 AST 面)。
|
|
220
|
+
|
|
221
|
+
每个字典字面量返回都必须 ①三键齐 ②命中声明形态;并按锚串钉住**具体形态**
|
|
222
|
+
(锚串不在 ⇒ 判红:实现改了却没同步本表=判据漂移,不静默放行)。
|
|
223
|
+
'''
|
|
224
|
+
src_path = os.path.join(_HERE, 'mcp_server.py')
|
|
225
|
+
found = _dict_returns_in_block(src_path, 'mdcg_remember')
|
|
226
|
+
ok(len(found) >= 3,
|
|
227
|
+
'G6a 工具面分支块内字典返回数 >= 3(实测 %d 个)' % len(found),
|
|
228
|
+
[r[0] for r in found])
|
|
229
|
+
anchors = {
|
|
230
|
+
'autonomy_forbidden': {'must': protocol.WRITE_TRIO + ('moved_to',)},
|
|
231
|
+
'conflict_deferred': {'must': protocol.WRITE_TRIO + ('moved_to', 'verdict'),
|
|
232
|
+
'best': 'gate_short_circuit'},
|
|
233
|
+
'review_queue': {'must': _required_of('autonomy_ticket'),
|
|
234
|
+
'best': 'autonomy_ticket',
|
|
235
|
+
# ★2026-10-12 设计者裁定:verdict **键必在场**、值取盲区标记
|
|
236
|
+
# None(`no` 从 ('verdict',) 改为「不许有值」由 G6e' 判)。
|
|
237
|
+
'no_value': ('verdict',)},
|
|
238
|
+
}
|
|
239
|
+
seen = {}
|
|
240
|
+
for ln, keys, seg in found:
|
|
241
|
+
bad, best = _static_violations(keys)
|
|
242
|
+
ok(not bad, 'G6b 行 %d 满足三键铁律且属声明形态(形态=%s)' % (ln, best),
|
|
243
|
+
(bad, sorted(keys)))
|
|
244
|
+
for name, spec in anchors.items():
|
|
245
|
+
if name in seg:
|
|
246
|
+
seen[name] = ln
|
|
247
|
+
miss = [k for k in spec['must'] if k not in keys]
|
|
248
|
+
ok(not miss, 'G6c 行 %d 是 %s 形态且含必需键' % (ln, name), miss)
|
|
249
|
+
if spec.get('best'):
|
|
250
|
+
ok(best == spec['best'],
|
|
251
|
+
'G6d 行 %d(%s)命中的最具体形态 == %s'
|
|
252
|
+
% (ln, name, spec['best']), best)
|
|
253
|
+
for k in spec.get('no', ()):
|
|
254
|
+
ok(k not in keys,
|
|
255
|
+
'G6e 行 %d(%s)不得含 %s(无该判据不许编造)'
|
|
256
|
+
% (ln, name, k), sorted(keys))
|
|
257
|
+
# ★2026-10-12 裁定新增:键**必在场**,但值必须是盲区标记 None。
|
|
258
|
+
for k in spec.get('no_value', ()):
|
|
259
|
+
ok(k in keys,
|
|
260
|
+
'G6e\u2032 行 %d(%s)必须含 %s 键(盲区声明:键必在场)'
|
|
261
|
+
% (ln, name, k), sorted(keys))
|
|
262
|
+
vals = _literal_values_of(seg)
|
|
263
|
+
ok(k in vals and vals[k] is None,
|
|
264
|
+
'G6e\u2033 行 %d(%s)的 %s 值必须是盲区标记 None'
|
|
265
|
+
'(该路径无 audit 裁决,不许编造有值裁决)'
|
|
266
|
+
% (ln, name, k), vals.get(k, '<缺键>'))
|
|
267
|
+
for name in anchors:
|
|
268
|
+
ok(name in seen,
|
|
269
|
+
'G6f 锚点 %s 仍存在于工具面分支块(锚点漂移即判红)' % name,
|
|
270
|
+
sorted(seen))
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def g_runtime_shapes():
|
|
274
|
+
'''G7 运行面:逐分支真跑,按声明形态全量校验。'''
|
|
275
|
+
cg = _lib('shapes')
|
|
276
|
+
a = tool_write(cg, BODY % '初版', 's1')
|
|
277
|
+
bad, best = _runtime_violations(a)
|
|
278
|
+
ok(not bad, 'G7a 成功分支满足全量校验(形态=%s)' % best, bad)
|
|
279
|
+
ok(best == 'committed', 'G7b 成功分支最具体形态 == committed', best)
|
|
280
|
+
|
|
281
|
+
b = tool_write(cg, BODY % '改写版', 's1')
|
|
282
|
+
bad, best = _runtime_violations(b)
|
|
283
|
+
ok(not bad, 'G7c 自治出单分支满足全量校验(形态=%s)' % best, bad)
|
|
284
|
+
ok(best == 'autonomy_ticket',
|
|
285
|
+
'G7d 自治出单分支最具体形态 == autonomy_ticket(不并入 gate_short_circuit)',
|
|
286
|
+
best)
|
|
287
|
+
ok('verdict' in b and b.get('verdict') is None,
|
|
288
|
+
'G7e 自治出单分支 verdict **键必在场且值为盲区标记 None**'
|
|
289
|
+
'(2026-10-12 裁定:该路径无 audit 裁决 ⇒ 留显式标记,不编造有值裁决)',
|
|
290
|
+
(sorted(b), b.get('verdict', '<缺键>')))
|
|
291
|
+
ok(b.get('committed') is False and b.get('moved_to') == 'review_queue',
|
|
292
|
+
'G7f 自治出单 = 未落盘 + 去向 review_queue + 可轮询 pid',
|
|
293
|
+
(b.get('committed'), b.get('moved_to'), b.get('pid')))
|
|
294
|
+
|
|
295
|
+
# on_conflict 必须显式给 defer:工具面缺省是 reject(抛 ConsistencyError),
|
|
296
|
+
# 只有 defer 才会让 cg.add 返回 None 并走冲突 DEFER 出口(本批新增的去向词)。
|
|
297
|
+
_ca = _args('# 功能名:冲突体' + chr(10) * 2
|
|
298
|
+
+ '# 生效条件:超时 30s 允许并发' + chr(10)
|
|
299
|
+
+ '# 不适用条件:超时' + chr(10), 's2')
|
|
300
|
+
_ca['on_conflict'] = 'defer'
|
|
301
|
+
c = mcp_server.call_tool(cg, 'mdcg_remember', _ca)
|
|
302
|
+
bad, best = _runtime_violations(c)
|
|
303
|
+
ok(not bad, 'G7g 冲突 DEFER 分支满足全量校验(形态=%s)' % best, bad)
|
|
304
|
+
ok(c.get('moved_to') == 'conflict_deferred',
|
|
305
|
+
'G7h 冲突 DEFER 去向词 == conflict_deferred(未落盘也未入队)',
|
|
306
|
+
(c.get('moved_to'), c.get('committed'), sorted(c)))
|
|
307
|
+
ok(c.get('committed') is False and 'pid' not in c,
|
|
308
|
+
'G7i 冲突 DEFER:committed is False 且不给 pid(未入队 ⇒ 不轮询)', sorted(c))
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
def g_autonomy_forbidden_and_guest():
|
|
312
|
+
'''G8 自治禁止(plan 档)+ 无权限(guest)两面。'''
|
|
313
|
+
from unittest.mock import patch
|
|
314
|
+
from . import autonomy_modes as _am
|
|
315
|
+
# 纪律(autonomy_modes.py:124):档位 env 名只在唯一入口模块写字面量 ——
|
|
316
|
+
# 本守卫经 AUTONOMY_ENV_KEYS 取键(同 test_autonomy_modes 的 _ENV_MODE 口径),
|
|
317
|
+
# 绝不在此处再写一处带引号的档位 env 字面量。
|
|
318
|
+
with patch.dict(os.environ, {_am.AUTONOMY_ENV_KEYS['mode']: 'plan'}):
|
|
319
|
+
cg = _lib('forbid')
|
|
320
|
+
tool_write(cg, BODY % '初版', 'f1')
|
|
321
|
+
o = tool_write(cg, BODY % '改写版', 'f1')
|
|
322
|
+
bad, best = _runtime_violations(o)
|
|
323
|
+
ok(not bad, 'G8a 自治禁止分支满足全量校验(形态=%s)' % best, bad)
|
|
324
|
+
ok(o.get('moved_to') == 'autonomy_forbidden'
|
|
325
|
+
and o.get('committed') is False,
|
|
326
|
+
'G8b plan 档 => moved_to=autonomy_forbidden + committed False',
|
|
327
|
+
(o.get('moved_to'), o.get('committed')))
|
|
328
|
+
from .mdcos import MdCGSecure
|
|
329
|
+
from .security import AccessDenied, Principal
|
|
330
|
+
root = os.path.join(_SANDBOX, 'guest_root')
|
|
331
|
+
master = bytes(range(32))
|
|
332
|
+
owner = Principal(tenant='t', actor='owner', session='s', clearance='secret',
|
|
333
|
+
role='designer', can_write=True, can_admin=True)
|
|
334
|
+
cg2 = MdCGSecure(root, master_key=master, principal=owner)
|
|
335
|
+
guest = MdCGSecure(root, master_key=master, principal=Principal(
|
|
336
|
+
tenant='t', actor='guest', session='g', clearance='public',
|
|
337
|
+
role='guest', can_write=False))
|
|
338
|
+
try:
|
|
339
|
+
raised = None
|
|
340
|
+
try:
|
|
341
|
+
mcp_server.call_tool(guest, 'mdcg_remember', _args(BODY % 'guest', 'gx'))
|
|
342
|
+
except Exception as exc: # noqa: BLE001
|
|
343
|
+
raised = exc
|
|
344
|
+
ok(isinstance(raised, AccessDenied),
|
|
345
|
+
'G8c 无权限分支=异常面(抛 AccessDenied),不返回形状不全的 dict',
|
|
346
|
+
type(raised).__name__ if raised else None)
|
|
347
|
+
finally:
|
|
348
|
+
guest.close()
|
|
349
|
+
cg2.close()
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
def g_gated_envelope_exempt():
|
|
353
|
+
'''G9 gated=true 分支的**显式豁免**判据(双向钉,防静默两面)。
|
|
354
|
+
|
|
355
|
+
该分支委托 mdcos.remember_gated,返回**闸门裁决信封**(ok/gate/verdict/
|
|
356
|
+
written),不含 id/committed ⇒ 不在三键面。本判据不断言它「合规」,而是钉:
|
|
357
|
+
① 现状确实缺三键(记录下来,不假装已覆盖);
|
|
358
|
+
② 它仍给出机器可判的裁决/落盘判据(gate|verdict|written);
|
|
359
|
+
③ 若将来补上三键 ⇒ 必须同时满足声明形态(改善也不许无声明)。
|
|
360
|
+
'''
|
|
361
|
+
cg = _lib('gatedenv')
|
|
362
|
+
o = mcp_server.call_tool(cg, 'mdcg_remember',
|
|
363
|
+
dict(_args(BODY % 'gated', 'ge1'), gated=True))
|
|
364
|
+
trio_complete = all(k in o for k in protocol.WRITE_TRIO)
|
|
365
|
+
ok(not trio_complete,
|
|
366
|
+
'G9a gated 分支现状不在三键面(实测键=%s)——显式记录,未假装覆盖'
|
|
367
|
+
% sorted(o), sorted(o))
|
|
368
|
+
ok(any(k in o for k in ('gate', 'verdict', 'written')),
|
|
369
|
+
'G9b gated 分支仍给出机器可判的裁决/落盘判据(gate|verdict|written)',
|
|
370
|
+
sorted(o))
|
|
371
|
+
if trio_complete:
|
|
372
|
+
bad, best = _runtime_violations(o)
|
|
373
|
+
ok(not bad,
|
|
374
|
+
'G9c gated 分支已补三键 => 必须满足声明形态(形态=%s)' % best, bad)
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
def g_tool_face_binding_declared():
|
|
378
|
+
'''G10 声明面:mdcg_remember 已绑定 write 动词(题1 的声明落地)。'''
|
|
379
|
+
bind = getattr(protocol, 'TOOL_FACE_BINDINGS', {}).get('mdcg_remember')
|
|
380
|
+
ok(bool(bind), 'G10a 协议声明了工具面 mdcg_remember → 动词绑定', bind)
|
|
381
|
+
ok(bool(bind) and bind.get('verb') == 'write',
|
|
382
|
+
'G10b 绑定动词 == write(受 WRITE_TRIO 铁律约束)', bind)
|
|
383
|
+
rep = protocol.audit()
|
|
384
|
+
ok(rep.get('ok') is True and not rep.get('shape_errors'),
|
|
385
|
+
'G10c 协议静态对账 ok=True 且零 shape_errors', rep.get('shape_errors'))
|
|
386
|
+
ok('autonomy_ticket' in protocol.VERB_SPECS['write']['shapes'],
|
|
387
|
+
'G10d write 声明形态含 autonomy_ticket(题3b 落地)')
|
|
388
|
+
ok('verdict' in _required_of('autonomy_ticket'),
|
|
389
|
+
'G10e autonomy_ticket.required **含** verdict(2026-10-12 裁定:该路径无 audit 裁决'
|
|
390
|
+
' ⇒ 值取盲区标记 None,但**键必在场**——缺席是歧义源)',
|
|
391
|
+
_required_of('autonomy_ticket'))
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
def g_source_no_silent_gap():
|
|
396
|
+
src = io.open(os.path.join(_HERE, 'mcp_server.py'), encoding='utf-8').read()
|
|
397
|
+
i = src.find('if name == \"mdcg_remember\":')
|
|
398
|
+
j = src.find('if name == \"mdcg_recall\":')
|
|
399
|
+
block = src[i:j] if (i >= 0 and j > i) else ''
|
|
400
|
+
ok(bool(block), 'G5a 定位到 mdcg_remember 工具面分支块', (i, j))
|
|
401
|
+
bad = _scan_ok_without_committed(block)
|
|
402
|
+
ok(not bad,
|
|
403
|
+
'G5b 工具面分支内不存在「ok:True 却不给 committed」的返回(防静默回退)', bad)
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
#: protocol.gate_short_circuit(任一 before 闸门短路)的必需键集——本批补齐的判据面。
|
|
407
|
+
_GATE_REQ = protocol.WRITE_TRIO + ('moved_to', 'verdict', 'hint')
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
def _scan_gate_missing(src, markers=('moved_to', 'gate')):
|
|
411
|
+
'''按 protocol 形状表核对写面返回体(**AST 级**,避免内层字典 `}` 误切)。
|
|
412
|
+
|
|
413
|
+
`markers`:认定「本返回属闸门短路类」的键。默认 `moved_to`/`gate`(写链/引擎面);
|
|
414
|
+
工具面额外加 `verdict`——因为那里最初的缺口正是**连 moved_to 都没有**的那一态。
|
|
415
|
+
形状判定(按返回字典键集):
|
|
416
|
+
· 含 `gate` ⇒ gate_gated:需 WRITE_TRIO + (gate, verdict)
|
|
417
|
+
· 含 `moved_to` ⇒ gate_short_circuit:需 WRITE_TRIO + (moved_to, verdict, hint)
|
|
418
|
+
· 其余 ⇒ 落盘形态:需 WRITE_TRIO
|
|
419
|
+
豁免:字面量之后补键的既有写法(如 `out["hint"] = ...`)视为满足(源码全文出现该赋值即豁免)。
|
|
420
|
+
'''
|
|
421
|
+
bad = []
|
|
422
|
+
try:
|
|
423
|
+
tree = _ast.parse(src)
|
|
424
|
+
except SyntaxError as exc:
|
|
425
|
+
return ['源码解析失败:%s' % exc]
|
|
426
|
+
late = set()
|
|
427
|
+
for k in ('hint',):
|
|
428
|
+
if ('["%s"] = ' % k) in src or ("['%s'] = " % k) in src:
|
|
429
|
+
late.add(k)
|
|
430
|
+
for node in _ast.walk(tree):
|
|
431
|
+
if not isinstance(node, _ast.Return) or not isinstance(node.value, _ast.Dict):
|
|
432
|
+
continue
|
|
433
|
+
keys = set()
|
|
434
|
+
for k in node.value.keys:
|
|
435
|
+
if isinstance(k, _ast.Constant) and isinstance(k.value, str):
|
|
436
|
+
keys.add(k.value)
|
|
437
|
+
if not (set(markers) & keys):
|
|
438
|
+
continue
|
|
439
|
+
if 'gate' in keys:
|
|
440
|
+
need, shape = protocol.WRITE_TRIO + ('gate', 'verdict'), 'gate_gated'
|
|
441
|
+
elif 'moved_to' in keys:
|
|
442
|
+
need, shape = _GATE_REQ, 'gate_short_circuit'
|
|
443
|
+
else:
|
|
444
|
+
need, shape = protocol.WRITE_TRIO, 'committed'
|
|
445
|
+
miss = [k for k in need if k not in keys and k not in late]
|
|
446
|
+
if miss:
|
|
447
|
+
bad.append('第 %d 行 [%s] 缺 %s' % (node.lineno, shape, ','.join(miss)))
|
|
448
|
+
return bad
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
def g_autonomy_gate_shape():
|
|
452
|
+
'''自治档位短路的两条分支(出单 / 兜底拒绝)须满足 gate_short_circuit 形状。
|
|
453
|
+
|
|
454
|
+
背景(#109 三处仍开着之二):工具面 `mdcg_remember` 的自治档位分支此前**缺 verdict**,
|
|
455
|
+
不满足 protocol 声明的形状;直写面无校验闸 ⇒ verdict 键必在、值取 None(照
|
|
456
|
+
writepipe.py:758 既有惯例,不编造裁决)。
|
|
457
|
+
'''
|
|
458
|
+
from . import autonomy_modes as _am
|
|
459
|
+
env_mode = _am.AUTONOMY_ENV_KEYS['mode']
|
|
460
|
+
cg = _lib('autgate')
|
|
461
|
+
tool_write(cg, BODY % '初版', 'g1') # 先造既有节点(触发 C 改写)
|
|
462
|
+
old = os.environ.get(env_mode)
|
|
463
|
+
try:
|
|
464
|
+
os.environ[env_mode] = 'confirm' # 变更确认档 ⇒ 出单
|
|
465
|
+
o = tool_write(cg, BODY % '改写版', 'g1')
|
|
466
|
+
miss = [k for k in _GATE_REQ if k not in o]
|
|
467
|
+
ok(not miss and o.get('committed') is False
|
|
468
|
+
and o.get('moved_to') == 'review_queue' and o.get('verdict', '缺键') is None,
|
|
469
|
+
'G6a 自治出单分支满足 gate_short_circuit(含 verdict 键且为 None、committed=False)',
|
|
470
|
+
(miss, o.get('committed'), o.get('verdict', '缺键')))
|
|
471
|
+
os.environ[env_mode] = 'plan' # 计划档 ⇒ **A 新增** fail-closed
|
|
472
|
+
o2 = tool_write(cg, BODY % '计划外新增', 'g2') # 新 id ⇒ A 新增(非改写)
|
|
473
|
+
miss2 = [k for k in _GATE_REQ if k not in o2]
|
|
474
|
+
ok(not miss2 and o2.get('committed') is False
|
|
475
|
+
and o2.get('moved_to') == 'autonomy_forbidden',
|
|
476
|
+
'G6b 自治兜底拒绝分支(plan 档 A 新增)同样满足该形状(含 verdict 键、committed=False)',
|
|
477
|
+
(miss2, o2.get('moved_to')))
|
|
478
|
+
finally:
|
|
479
|
+
if old is None:
|
|
480
|
+
os.environ.pop(env_mode, None)
|
|
481
|
+
else:
|
|
482
|
+
os.environ[env_mode] = old
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
def g_gate_source_no_gap():
|
|
486
|
+
'''写动词面三个文件的闸门短路返回,必须含对应形状的必需键。
|
|
487
|
+
|
|
488
|
+
面与标记(避免扫到非写面同名字段):
|
|
489
|
+
· `mcp_server.py`:**只扫 `mdcg_remember` 工具面分支块**;标记含 `verdict`
|
|
490
|
+
——该面最初的缺口正是「连 `moved_to` 都没有」的那一态。
|
|
491
|
+
· `writepipe.py` / `mdcos.py`:整文件按 `moved_to`/`gate` 标记(两文件均写面)。
|
|
492
|
+
'''
|
|
493
|
+
bad = []
|
|
494
|
+
src = io.open(os.path.join(_HERE, 'mcp_server.py'), encoding='utf-8').read()
|
|
495
|
+
i = src.find('if name == "mdcg_remember":')
|
|
496
|
+
j = src.find('if name == "mdcg_recall":')
|
|
497
|
+
block = src[i:j] if (i >= 0 and j > i) else ''
|
|
498
|
+
bad += ['mcp_server.py mdcg_remember 块 %s' % s
|
|
499
|
+
for s in _scan_gate_missing(block,
|
|
500
|
+
markers=('moved_to', 'gate', 'verdict'))]
|
|
501
|
+
for fn, marks in (('writepipe.py', ('moved_to', 'gate')),
|
|
502
|
+
# mdcos 只按 moved_to 标记:其 `remember_gated` 的**内部返回形状**
|
|
503
|
+
# (verdict/bypass/gate/written)契约属 #109 第③项「工具面是否受三键
|
|
504
|
+
# 铁律约束」的**待裁范围**,本判据不替它裁(不误报、也不擅改)。
|
|
505
|
+
('mdcos.py', ('moved_to',))):
|
|
506
|
+
s = io.open(os.path.join(_HERE, fn), encoding='utf-8').read()
|
|
507
|
+
bad += ['%s %s' % (fn, x) for x in _scan_gate_missing(s, markers=marks)]
|
|
508
|
+
ok(not bad,
|
|
509
|
+
'G7 写动词面闸门短路返回均含对应形状的必需键(gate_short_circuit = WRITE_TRIO'
|
|
510
|
+
'+moved_to+verdict+hint;gate_gated = WRITE_TRIO+gate+verdict;防缺键回退)', bad)
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
# ---------------------------------------------------------------- #142(2026-10-12 DSH 端)
|
|
514
|
+
#: #142 定点变异的注入开关(默认全关;只在 --mutate 的自证段打开)。
|
|
515
|
+
_142_MUT = {'oversize_keys': False, 'halt_2pc': False}
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
def _ledger_rows(cg):
|
|
519
|
+
'''两段式账本行数(#142② 的覆盖判据用)。'''
|
|
520
|
+
from . import twophase
|
|
521
|
+
p = twophase.log_path(cg)
|
|
522
|
+
if not os.path.isfile(p):
|
|
523
|
+
return 0
|
|
524
|
+
with io.open(p, encoding='utf-8') as f:
|
|
525
|
+
return sum(1 for l in f if l.strip())
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
def g_142_oversize_trio():
|
|
529
|
+
'''#142①:**超限出口**必须满足 WRITE_TRIO 铁律。
|
|
530
|
+
|
|
531
|
+
这是「写返回体形状」此前**未被覆盖的出口**——它不经任何 before 闸,直接在
|
|
532
|
+
execute 入口返回;修前只有 ok/bytes/error/limit/verdict(三键缺二,且不属任何
|
|
533
|
+
声明形态)。判据真源=protocol.WRITE_TRIO + VERB_SPECS['write']['shapes']。
|
|
534
|
+
'''
|
|
535
|
+
from . import writepipe
|
|
536
|
+
cg = _lib('o142')
|
|
537
|
+
big = '# 功能名:超限' + chr(10) + chr(10) + '# 生效条件:PASSED' + chr(10) \
|
|
538
|
+
+ ('x' * (writepipe.MAX_WRITE_BYTES + 8))
|
|
539
|
+
out = writepipe.default_pipeline().execute(cg, _args(big, 'o142_big'))
|
|
540
|
+
if _142_MUT['oversize_keys']: # 变异:还原修前返回体
|
|
541
|
+
out = {k: v for k, v in out.items() if k not in ('id', 'committed')}
|
|
542
|
+
miss = [k for k in protocol.WRITE_TRIO if k not in out]
|
|
543
|
+
ok(not miss, 'H1a 超限出口含三键(ok/id/committed)', sorted(out))
|
|
544
|
+
ok(bool(out.get('id')), 'H1b 超限出口带非空 id(与 ctx 同源)', out.get('id'))
|
|
545
|
+
ok(out.get('committed') is False, 'H1c 超限 => committed is False', out.get('committed'))
|
|
546
|
+
bad, best = _static_violations(sorted(out))
|
|
547
|
+
ok(not bad, 'H1d 超限出口命中协议声明形态(静态判据)', (bad, best))
|
|
548
|
+
ok(best == 'gate_hard_reject', 'H1e 命中 gate_hard_reject(硬拒+结构化 error)', best)
|
|
549
|
+
src = io.open(os.path.join(_HERE, 'writepipe.py'), encoding='utf-8').read()
|
|
550
|
+
ok('return {"ok": False, "error": "content 超过写入硬上限' not in src,
|
|
551
|
+
'H1f 源码级:修前的无三键超限出口字面量已不存在',
|
|
552
|
+
'(若本项红说明被回退)')
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
def g_142_halt_2pc():
|
|
556
|
+
'''#142②:**短路出口零两段式覆盖**——现状如实钉住 + 口径冲突标注(本件未改)。
|
|
557
|
+
|
|
558
|
+
实测:audit REJECT / 缺必需要素等短路出口落 **0** 条两段式记录(twophase 只覆盖
|
|
559
|
+
「全放行」与 gated 两段);但 `md_cg/test_twophase.py:9/⑧2` 把「未落盘的分支
|
|
560
|
+
(闸门拒绝 / 入队)**不产生 intent**——没打算写就不记账」钉成不变量,而该守卫
|
|
561
|
+
文件**不在本件写面**(task-35:写面仅 writepipe.py + 本批守卫)⇒ 本件**回退了**
|
|
562
|
+
「短路补记账」的改法(回退前 test_twophase 34/1,⑧2 红),改为在此如实钉现状。
|
|
563
|
+
若将来裁定「短路也要落账」,本组断言会转红——那正是升级断言的信号。
|
|
564
|
+
'''
|
|
565
|
+
from . import writepipe
|
|
566
|
+
cg = _lib('h142')
|
|
567
|
+
cases = [
|
|
568
|
+
('audit REJECT·禁表词',
|
|
569
|
+
_args('# 功能名:禁' + chr(10) * 2 + '# 生效条件:PASSED' + chr(10)
|
|
570
|
+
+ '内容 FORBIDDEN_WORD 在此', 'h_rej')),
|
|
571
|
+
('audit REJECT·缺必需要素',
|
|
572
|
+
_args('# 功能名:缺' + chr(10) * 2 + '正文无必需要素词', 'h_miss')),
|
|
573
|
+
('gated 闸(自记账)', dict(_args(BODY % '遗忘闸', 'h_gated'), gated=True)),
|
|
574
|
+
]
|
|
575
|
+
for label, a in cases:
|
|
576
|
+
before = _ledger_rows(cg)
|
|
577
|
+
writepipe.default_pipeline().execute(cg, a)
|
|
578
|
+
delta = _ledger_rows(cg) - before
|
|
579
|
+
want = 2 if label.startswith('gated') else 0
|
|
580
|
+
ok(delta == want,
|
|
581
|
+
'H2 %s ⇒ 账本 +%d(现状口径:短路不记账 / gated 自记一对)' % (label, want),
|
|
582
|
+
'delta=%d(期望 %d)' % (delta, want))
|
|
583
|
+
rep = cg.reconcile_writes()
|
|
584
|
+
ok(rep.get('unpaired') == 0, 'H2d 两段式对账零悬空(unpaired=0)', rep)
|
|
585
|
+
print(' [需裁定] ②:短路出口零账(本件未改,因与 test_twophase ⑧2 的不变量冲突)——改法已写进 _team/writepipe/report.md,待 Lead/设计者裁定')
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
def g_142_two_path_divergence():
|
|
589
|
+
'''#142④:两条写通路(mdcg_remember 直写 vs cg(op=write) 走 writepipe)结论相反。
|
|
590
|
+
|
|
591
|
+
**本守卫只如实记录现状**:统一判据的改动点落在 `mcp_server.py:3571` 分支
|
|
592
|
+
(本件**只读**,见 task-35 写面约束)⇒ 不在本守卫红绿面内。若 Lead 后续统一了
|
|
593
|
+
通路,H3a 会转红——那正是「把断言升级为『两通路一致』」的信号。
|
|
594
|
+
'''
|
|
595
|
+
cg = _lib('twopath142')
|
|
596
|
+
text = ('# 功能名:同一内容' + chr(10) * 2 + '# 生效条件:PASSED' + chr(10)
|
|
597
|
+
+ '内容 FORBIDDEN_WORD 在此')
|
|
598
|
+
o_t = mcp_server.call_tool(cg, 'mdcg_remember', _args(text, 'tp_tool'))
|
|
599
|
+
o_v = mcp_server.call_tool(cg, 'cg', dict(op='write', **_args(text, 'tp_verb')))
|
|
600
|
+
ok(bool(o_t.get('committed')) != bool(o_v.get('committed')),
|
|
601
|
+
'H3a 现状:同一内容两通路结论相反(报告已记录;统一需改 mcp_server)',
|
|
602
|
+
(o_t.get('committed'), o_v.get('committed')))
|
|
603
|
+
ok(not [k for k in protocol.WRITE_TRIO if k not in o_t]
|
|
604
|
+
and not [k for k in protocol.WRITE_TRIO if k not in o_v],
|
|
605
|
+
'H3b 两通路返回体各自满足三键铁律(形状面已覆盖)',
|
|
606
|
+
(sorted(o_t), sorted(o_v)))
|
|
607
|
+
print(' [需协调] 统一判据的改动点在 mcp_server.py:3571(本件只读)——'
|
|
608
|
+
'现状:工具面落盘 / 动词面 REJECT')
|
|
609
|
+
|
|
610
|
+
_CASES = (g_tool_success, g_tool_pending, g_machine_decidable, g_verb_face,
|
|
611
|
+
g_source_no_silent_gap,
|
|
612
|
+
# issue #109 三题(2026-10-10 裁定)新增判据组:
|
|
613
|
+
g_tool_face_binding_declared, # G10 声明面:工具面绑定 + autonomy_ticket 落地
|
|
614
|
+
g_declared_shapes_full, # G6 静态面:按声明形态全量校验工具面
|
|
615
|
+
g_runtime_shapes, # G7 运行面:成功/自治出单/冲突 DEFER 逐分支
|
|
616
|
+
g_autonomy_forbidden_and_guest, # G8 自治禁止(plan 档)+ 无权限(异常面)
|
|
617
|
+
g_gated_envelope_exempt, # G9 gated 分支显式豁免(双向钉)
|
|
618
|
+
# PR #113(2026-10-12 合并,经设计者裁定收束 verdict 语义):
|
|
619
|
+
g_autonomy_gate_shape, # 自治短路两分支满足 gate_short_circuit(verdict 键必在)
|
|
620
|
+
g_gate_source_no_gap, # 三写面源码级:闸门短路返回必含对应形状必需键
|
|
621
|
+
# #142(2026-10-12 DSH 端)新增判据组:
|
|
622
|
+
g_142_oversize_trio, # H1 超限出口(此前未覆盖的出口)三键+声明形态
|
|
623
|
+
g_142_halt_2pc, # H2 短路出口两段式覆盖(恰一对 intent/outcome)
|
|
624
|
+
g_142_two_path_divergence) # H3 两通路相反结论(现状记录·待 Lead 协调)
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
def _run_all():
|
|
628
|
+
del _PASS[:]
|
|
629
|
+
del _FAIL[:]
|
|
630
|
+
for fn in _CASES:
|
|
631
|
+
try:
|
|
632
|
+
fn()
|
|
633
|
+
except Exception as exc: # noqa: BLE001
|
|
634
|
+
ok(False, '%s 组抛异常:%s: %s' % (fn.__name__, type(exc).__name__, exc))
|
|
635
|
+
return list(_FAIL)
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
_SYN = (
|
|
639
|
+
('M0 合成合规源码(同一字典内含 committed)',
|
|
640
|
+
'return {"ok": True, "id": nid, "committed": True}', False),
|
|
641
|
+
('M1 合成缺 committed(本轮修掉的那一态)',
|
|
642
|
+
'return {"ok": True, "id": nid}', True),
|
|
643
|
+
('M2 合成 committed 换行后仍在同一字典内',
|
|
644
|
+
'return {"ok": True, "id": nid,' + chr(10) + ' "committed": True}', False),
|
|
645
|
+
('M3 合成 committed 落在字典之外(应判红)',
|
|
646
|
+
'return {"ok": True, "id": nid}' + chr(10) + 'x = {"committed": True}', True),
|
|
647
|
+
)
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
def _syn_shape_report(src):
|
|
651
|
+
'''对**合成源码**跑本批新增的静态形态判据(不读盘、不定点改真实源码)。
|
|
652
|
+
|
|
653
|
+
返回 [(违规列表, 最具体形态, 键列表)] —— 一个 return 一行。
|
|
654
|
+
'''
|
|
655
|
+
import ast as _ast
|
|
656
|
+
import textwrap as _tw
|
|
657
|
+
tree = _ast.parse(_tw.dedent(src))
|
|
658
|
+
rows = []
|
|
659
|
+
for node in _ast.walk(tree):
|
|
660
|
+
if isinstance(node, _ast.Return) and isinstance(node.value, _ast.Dict):
|
|
661
|
+
ks = [k.value for k in node.value.keys if isinstance(k, _ast.Constant)]
|
|
662
|
+
bad, best = _static_violations(ks)
|
|
663
|
+
rows.append((bad, best, ks))
|
|
664
|
+
return rows
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
#: 新增判据的定点变异表:每行 = (名称, 合成源码, 期望特征)。
|
|
668
|
+
#: 期望特征键:violations_red(静态面应否报违规)/ best(应为的最具体形态)/
|
|
669
|
+
#: fabricated_verdict(「autonomy_ticket 形态下 verdict 被编造成有值」
|
|
670
|
+
#: 应否被检出 —— ★2026-10-12 设计者裁定后,**verdict 键必在场、值取 None
|
|
671
|
+
#: 是盲区声明**;仍被禁止的只是**编造一个有值的裁决**)。
|
|
672
|
+
_SYN_SHAPES = (
|
|
673
|
+
('V0 改前的冲突 DEFER 体(只有 ok/id/verdict/reason)=本批修掉的那一态',
|
|
674
|
+
'return {"ok": False, "id": nid, "verdict": "DEFER", "reason": "x"}',
|
|
675
|
+
{'violations_red': True}),
|
|
676
|
+
('V1 改后的冲突 DEFER 体(三键 + moved_to + verdict + hint)',
|
|
677
|
+
'return {"ok": False, "id": nid, "committed": False,'
|
|
678
|
+
' "moved_to": "conflict_deferred", "verdict": "DEFER", "hint": "h"}',
|
|
679
|
+
{'violations_red': False, 'best': 'gate_short_circuit'}),
|
|
680
|
+
('V2 自治出单体(真实键集,含 verdict: None =盲区声明)',
|
|
681
|
+
'return {"ok": True, "id": nid, "committed": False,'
|
|
682
|
+
' "moved_to": "review_queue", "pid": p, "mutation": m,'
|
|
683
|
+
' "autonomy": a, "verdict": None, "hint": "h"}',
|
|
684
|
+
{'violations_red': False, 'best': 'autonomy_ticket',
|
|
685
|
+
'fabricated_verdict': False}),
|
|
686
|
+
('V2b 自治出单体**缺 verdict 键**(盲区未声明 ⇒ 静态面应判红)',
|
|
687
|
+
'return {"ok": True, "id": nid, "committed": False,'
|
|
688
|
+
' "moved_to": "review_queue", "pid": p, "mutation": m,'
|
|
689
|
+
' "autonomy": a, "hint": "h"}',
|
|
690
|
+
{'violations_red': True}),
|
|
691
|
+
('V3 自治出单体被**编造有值裁决**(verdict: "DEFER" ⇒ 应被检出)',
|
|
692
|
+
'return {"ok": True, "id": nid, "committed": False,'
|
|
693
|
+
' "moved_to": "review_queue", "pid": p, "mutation": m,'
|
|
694
|
+
' "autonomy": a, "verdict": "DEFER", "hint": "h"}',
|
|
695
|
+
{'violations_red': False, 'best': 'autonomy_ticket',
|
|
696
|
+
'fabricated_verdict': True}),
|
|
697
|
+
('V4 自治出单体丢掉 autonomy(形态降级 ⇒ 最具体形态退化为 committed)',
|
|
698
|
+
'return {"ok": True, "id": nid, "committed": False,'
|
|
699
|
+
' "moved_to": "review_queue", "pid": p, "hint": "h"}',
|
|
700
|
+
{'violations_red': False, 'best': 'committed',
|
|
701
|
+
'body': {'ok': True, 'id': 'x', 'committed': False,
|
|
702
|
+
'moved_to': 'review_queue', 'pid': 'prop_x', 'hint': 'h'},
|
|
703
|
+
'runtime_red': False}),
|
|
704
|
+
('V5 三键齐但未 committed 且无去向(运行面应判红)',
|
|
705
|
+
'return {"ok": False, "id": nid, "committed": False, "verdict": "DEFER"}',
|
|
706
|
+
{'violations_red': False,
|
|
707
|
+
'body': {'ok': False, 'id': 'x', 'committed': False, 'verdict': 'DEFER'},
|
|
708
|
+
'runtime_red': True}),
|
|
709
|
+
)
|
|
710
|
+
|
|
711
|
+
|
|
712
|
+
def _literal_values(src):
|
|
713
|
+
'''从源码片段里的字典字面量取 {键: 值}(值只认字面常量;名字→哨兵 `'<expr>'`)。
|
|
714
|
+
|
|
715
|
+
输入既可是**合成源码**(`return {...}`),也可是**真实源码里的一个返回片段**
|
|
716
|
+
(G6 的 `seg`,形如 `{"ok": True, ...}`)。故先试 `return` 包裹,失败则当表达式解析。
|
|
717
|
+
'''
|
|
718
|
+
import ast as _ast
|
|
719
|
+
import textwrap as _tw
|
|
720
|
+
text = _tw.dedent(src).strip()
|
|
721
|
+
for candidate in (text, 'return ' + text, 'x = ' + text):
|
|
722
|
+
try:
|
|
723
|
+
tree = _ast.parse(candidate)
|
|
724
|
+
except SyntaxError:
|
|
725
|
+
continue
|
|
726
|
+
for node in _ast.walk(tree):
|
|
727
|
+
d = node.value if (isinstance(node, (_ast.Return, _ast.Assign))
|
|
728
|
+
and isinstance(node.value, _ast.Dict)) else (
|
|
729
|
+
node if isinstance(node, _ast.Dict) else None)
|
|
730
|
+
if d is None:
|
|
731
|
+
continue
|
|
732
|
+
out = {}
|
|
733
|
+
for k, v in zip(d.keys, d.values):
|
|
734
|
+
if isinstance(k, _ast.Constant) and isinstance(k.value, str):
|
|
735
|
+
out[k.value] = v.value if isinstance(v, _ast.Constant) else '<expr>'
|
|
736
|
+
if out:
|
|
737
|
+
return out
|
|
738
|
+
return {}
|
|
739
|
+
|
|
740
|
+
|
|
741
|
+
#: G6 的片段级取值:对真实源码里的返回片段做同样的事(供 `no_value` 判据用)。
|
|
742
|
+
_literal_values_of = _literal_values
|
|
743
|
+
|
|
744
|
+
|
|
745
|
+
def _fabricated_verdict(ks):
|
|
746
|
+
'''autonomy_ticket 形态下 verdict 是否为**编造的有值裁决**。
|
|
747
|
+
|
|
748
|
+
判据(2026-10-12 设计者裁定):该形态 required 含 verdict,取值必须是盲区
|
|
749
|
+
标记 None;**任何非 None 值都是编造**(该路径无 audit 裁决可透出)。
|
|
750
|
+
'''
|
|
751
|
+
return ('verdict' in ks and ks['verdict'] is not None) if isinstance(ks, dict) \
|
|
752
|
+
else False
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
def _run_shape_mutations():
|
|
756
|
+
print('!! 新增判据定点变异自证(G6/G7 静态+运行面)')
|
|
757
|
+
bad = 0
|
|
758
|
+
for name, src, expect in _SYN_SHAPES:
|
|
759
|
+
rows = _syn_shape_report(src)
|
|
760
|
+
got_red = bool(rows) and bool(rows[0][0])
|
|
761
|
+
got_best = rows[0][1] if rows else None
|
|
762
|
+
ks = rows[0][2] if rows else []
|
|
763
|
+
got_fv = _fabricated_verdict(_literal_values(src))
|
|
764
|
+
# 运行面判据吃**显式真实值的 body**(键集 fromkeys 会把值全变 None,
|
|
765
|
+
# 那是假读:committed=None 既非 True 也非 False,moved_to=None 会被
|
|
766
|
+
# 误当「无去向」)。故用表里给的 body;未给则跳过该项。
|
|
767
|
+
|
|
768
|
+
_body = expect.get('body')
|
|
769
|
+
rt_bad = _runtime_violations(_body)[0] if _body is not None else []
|
|
770
|
+
got_rt = bool(rt_bad)
|
|
771
|
+
checks = []
|
|
772
|
+
if 'violations_red' in expect:
|
|
773
|
+
checks.append(('静态面判红=%s' % expect['violations_red'],
|
|
774
|
+
got_red == expect['violations_red']))
|
|
775
|
+
if 'best' in expect:
|
|
776
|
+
checks.append(('最具体形态=%s' % expect['best'],
|
|
777
|
+
got_best == expect['best']))
|
|
778
|
+
if 'fabricated_verdict' in expect:
|
|
779
|
+
checks.append(('autonomy_ticket 编造有值裁决被检出=%s'
|
|
780
|
+
% expect['fabricated_verdict'],
|
|
781
|
+
got_fv == expect['fabricated_verdict']))
|
|
782
|
+
if 'runtime_red' in expect:
|
|
783
|
+
checks.append(('运行面判红=%s' % expect['runtime_red'],
|
|
784
|
+
got_rt == expect['runtime_red']))
|
|
785
|
+
good = all(v for _l, v in checks)
|
|
786
|
+
if not good:
|
|
787
|
+
bad += 1
|
|
788
|
+
print(' %s %s' % ('PASS' if good else 'FAIL', name))
|
|
789
|
+
for label, v in checks:
|
|
790
|
+
print(' %s %s' % ('ok ' if v else 'MISS', label))
|
|
791
|
+
if not good:
|
|
792
|
+
print(' 实际:red=%s best=%s keys=%s runtime_bad=%s'
|
|
793
|
+
% (got_red, got_best, sorted(ks), rt_bad))
|
|
794
|
+
print('')
|
|
795
|
+
return bad
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
#: 本批(gate_short_circuit 形状)的合成变异:喂 `_scan_gate_missing`,判别力必须成立。
|
|
799
|
+
_SYN_GATE = (
|
|
800
|
+
('M4 合成合规(三键 + moved_to + verdict + hint)',
|
|
801
|
+
'return {"ok": False, "id": nid, "committed": False,'
|
|
802
|
+
' "moved_to": "conflict_deferred", "verdict": "DEFER", "hint": "x"}', False),
|
|
803
|
+
('M5 合成缺 verdict(本批修掉的那一态)',
|
|
804
|
+
'return {"ok": True, "id": nid, "committed": False,'
|
|
805
|
+
' "moved_to": "review_queue", "hint": "x"}', True),
|
|
806
|
+
('M6 合成缺 hint(形状要求的下一步说明)',
|
|
807
|
+
'return {"ok": False, "id": nid, "committed": False,'
|
|
808
|
+
' "moved_to": "x", "verdict": None}', True),
|
|
809
|
+
('M7 合成缺 committed(原冲突 DEFER 分支那一态)',
|
|
810
|
+
'return {"ok": False, "id": nid, "verdict": "DEFER", "reason": "r"}', True),
|
|
811
|
+
)
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
def _run_142_mutations():
|
|
815
|
+
'''#142 的两条定点变异(都作用于**被验实现**,不是断言侧)。'''
|
|
816
|
+
print('!! #142 定点变异自证(短路两段式 / 超限三键)')
|
|
817
|
+
bad = 0
|
|
818
|
+
from . import twophase
|
|
819
|
+
_p0, _f0 = list(_PASS), list(_FAIL)
|
|
820
|
+
# ---- M5:注入「短路出口补两段式账」的改法(=本件曾尝试、后回退的那一版)
|
|
821
|
+
# ⇒ H2 必须判红(证明「现状口径」这条断言有判别力) ----
|
|
822
|
+
from . import writepipe
|
|
823
|
+
_oe = writepipe.WritePipeline.execute
|
|
824
|
+
|
|
825
|
+
def _me(self, cg, a):
|
|
826
|
+
out = _oe(self, cg, a)
|
|
827
|
+
if isinstance(out, dict) and out.get('committed') is False:
|
|
828
|
+
_t = twophase.begin(cg, out.get('id') or '', a.get('content', ''),
|
|
829
|
+
actor='mut5:halt')
|
|
830
|
+
twophase.commit(cg, _t, status=twophase.STATUS_ABORTED,
|
|
831
|
+
reason='halted_by=mut5')
|
|
832
|
+
return out
|
|
833
|
+
|
|
834
|
+
writepipe.WritePipeline.execute = _me
|
|
835
|
+
del _PASS[:]
|
|
836
|
+
del _FAIL[:]
|
|
837
|
+
try:
|
|
838
|
+
g_142_halt_2pc()
|
|
839
|
+
except Exception as exc: # noqa: BLE001
|
|
840
|
+
ok(False, '变异段抛异常:%s: %s' % (type(exc).__name__, exc))
|
|
841
|
+
red2 = [m for m in _FAIL if m.startswith('H2')]
|
|
842
|
+
writepipe.WritePipeline.execute = _oe
|
|
843
|
+
good2 = len(red2) >= 1
|
|
844
|
+
bad += 0 if good2 else 1
|
|
845
|
+
print(' %s M5 注入「短路补记账」改法 ⇒ H2 判红 %d 条%s'
|
|
846
|
+
% ('PASS' if good2 else 'FAIL', len(red2),
|
|
847
|
+
(':' + '; '.join(red2[:2])) if red2 else ''))
|
|
848
|
+
# ---- M6:超限出口还原修前(缺 id/committed)⇒ H1 必须判红 ----
|
|
849
|
+
_142_MUT['oversize_keys'] = True
|
|
850
|
+
del _PASS[:]
|
|
851
|
+
del _FAIL[:]
|
|
852
|
+
try:
|
|
853
|
+
g_142_oversize_trio()
|
|
854
|
+
except Exception as exc: # noqa: BLE001
|
|
855
|
+
ok(False, '变异段抛异常:%s: %s' % (type(exc).__name__, exc))
|
|
856
|
+
red1 = [m for m in _FAIL if m.startswith('H1')]
|
|
857
|
+
_142_MUT['oversize_keys'] = False
|
|
858
|
+
good1 = len(red1) >= 2
|
|
859
|
+
bad += 0 if good1 else 1
|
|
860
|
+
print(' %s M6 超限出口缺 id/committed(还原修前)⇒ H1 判红 %d 条%s'
|
|
861
|
+
% ('PASS' if good1 else 'FAIL', len(red1),
|
|
862
|
+
(':' + '; '.join(red1[:3])) if red1 else ''))
|
|
863
|
+
del _PASS[:]
|
|
864
|
+
del _FAIL[:]
|
|
865
|
+
_PASS.extend(_p0)
|
|
866
|
+
_FAIL.extend(_f0)
|
|
867
|
+
print('')
|
|
868
|
+
return bad
|
|
869
|
+
|
|
870
|
+
def _run_mutations():
|
|
871
|
+
print('!! 定点变异自证:给 G5b 判据体喂合成源码,判别力必须成立')
|
|
872
|
+
bad = 0
|
|
873
|
+
for name, src, expect_red in _SYN:
|
|
874
|
+
got = _scan_ok_without_committed(src)
|
|
875
|
+
good = (bool(got) == expect_red)
|
|
876
|
+
if not good:
|
|
877
|
+
bad += 1
|
|
878
|
+
print(' %s %s' % ('PASS' if good else 'FAIL', name))
|
|
879
|
+
if not good:
|
|
880
|
+
print(' 预期有红=%s 实际=%s' % (expect_red, got))
|
|
881
|
+
print('')
|
|
882
|
+
bad += _run_shape_mutations()
|
|
883
|
+
print('!! 定点变异自证:给 G7 判据体喂合成源码,判别力必须成立')
|
|
884
|
+
for name, src, expect_red in _SYN_GATE:
|
|
885
|
+
# AST 判据要求 return 处于函数体内 ⇒ 合成样本统一包一层 def
|
|
886
|
+
wrapped = 'def _f():' + chr(10) + chr(10).join(
|
|
887
|
+
' ' + l for l in src.split(chr(10)))
|
|
888
|
+
got = _scan_gate_missing(wrapped, markers=('moved_to', 'gate', 'verdict'))
|
|
889
|
+
good = (bool(got) == expect_red)
|
|
890
|
+
if not good:
|
|
891
|
+
bad += 1
|
|
892
|
+
print(' %s %s' % ('PASS' if good else 'FAIL', name))
|
|
893
|
+
if not good:
|
|
894
|
+
print(' 预期有红=%s 实际=%s' % (expect_red, got))
|
|
895
|
+
print('')
|
|
896
|
+
bad += _run_142_mutations()
|
|
897
|
+
return bad
|
|
898
|
+
|
|
899
|
+
|
|
900
|
+
def main() -> int:
|
|
901
|
+
sys.stdout.reconfigure(encoding='utf-8', errors='replace')
|
|
902
|
+
ap = argparse.ArgumentParser(description='写返回体判据守卫(issue #109 相邻面)')
|
|
903
|
+
ap.add_argument('--mutate', action='store_true', help='定点变异自证')
|
|
904
|
+
a = ap.parse_args()
|
|
905
|
+
reds = _run_all()
|
|
906
|
+
print('')
|
|
907
|
+
print('SUMMARY: 写返回体判据守卫:%d 通过,%d 失败' % (len(_PASS), len(reds)))
|
|
908
|
+
if reds:
|
|
909
|
+
print('失败判据:' + '; '.join(reds))
|
|
910
|
+
rc = 1 if reds else 0
|
|
911
|
+
if a.mutate:
|
|
912
|
+
rc = 1 if (_run_mutations() or reds) else 0
|
|
913
|
+
print('SUMMARY: 定点变异自证:%s' % ('全部按预期' if rc == 0 else '存在偏差'))
|
|
914
|
+
shutil.rmtree(_SANDBOX, ignore_errors=True)
|
|
915
|
+
return rc
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
if __name__ == '__main__':
|
|
919
|
+
sys.exit(main())
|