@furongjun1999/dsh-memory 0.9.6 → 0.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/policy.json +38 -38
- package/docs/discipline/templates/spec.txt.tmpl +1 -1
- package/dsh/cordis.yml.example +139 -139
- package/lib/hooks.d.ts +19 -0
- package/lib/hooks.js +29 -6
- package/lib/index.js +11 -2
- package/lib/lib/hook_audit.js +38 -2
- package/lib/lib/prompt_safety.js +14 -3
- package/lib/tools.d.ts +7 -0
- package/lib/tools.js +22 -1
- package/md_cg/_guard_kit.py +121 -121
- package/md_cg/anchor.py +114 -114
- package/md_cg/audit.py +15 -2
- package/md_cg/chain.py +3 -2
- package/md_cg/config_registry_guard.py +487 -487
- package/md_cg/conformance.py +747 -747
- package/md_cg/consolidate.py +1793 -1793
- package/md_cg/crypto.py +794 -794
- package/md_cg/hyperedge.py +262 -262
- package/md_cg/interface_schema.py +146 -146
- package/md_cg/lifecycle.py +426 -426
- package/md_cg/mdcos.py +12 -8
- package/md_cg/predict.py +1103 -1103
- package/md_cg/protect.py +654 -654
- package/md_cg/provenance.py +606 -606
- package/md_cg/queue_health.py +130 -130
- package/md_cg/refine.py +613 -613
- package/md_cg/retrieve.py +128 -128
- package/md_cg/revise.py +140 -140
- package/md_cg/rollback.py +657 -657
- package/md_cg/rollback_cli.py +124 -124
- package/md_cg/rotate.py +346 -346
- package/md_cg/routing.py +490 -490
- package/md_cg/self_surface.py +50 -50
- package/md_cg/semantic/canonical.py +144 -144
- package/md_cg/semantic/zh_en_atoms.py +141 -141
- package/md_cg/sources.py +1091 -1091
- package/md_cg/stg.py +3 -2
- package/md_cg/test_audit_rotate_parity.py +279 -279
- package/md_cg/test_autonomy_modes.py +2013 -2013
- package/md_cg/test_cn_recall_grams.py +206 -206
- package/md_cg/test_code_kind_forbidden.py +101 -0
- package/md_cg/test_condaccept.py +156 -156
- package/md_cg/test_condgate.py +141 -141
- package/md_cg/test_heartbeat_ledger.py +557 -557
- package/md_cg/test_i50e_readside_protection.py +658 -658
- package/md_cg/test_issue111_gate_order.py +76 -76
- package/md_cg/test_issue111_scoring_contract.py +86 -86
- package/md_cg/test_issue121_calibration_bounds.py +293 -293
- package/md_cg/test_issue145_sleep_no_silent_rollback.py +167 -167
- package/md_cg/test_issue147_pack_id_escape.py +378 -378
- package/md_cg/test_issue148_merge_downgrade_leak.py +192 -192
- package/md_cg/test_issue149_accel_default_face.py +248 -248
- package/md_cg/test_issue150_empty_query_terms.py +328 -328
- package/md_cg/test_issue151_153_157_write_cache_index.py +151 -151
- package/md_cg/test_issue152_sealed_postings.py +309 -309
- package/md_cg/test_issue153b_index_generation_invalidation.py +142 -142
- package/md_cg/test_issue157b_index_remainder.py +344 -344
- package/md_cg/test_issue189_conclusion_bidirectional.py +223 -223
- package/md_cg/test_issue191_import_trust.py +382 -382
- package/md_cg/test_issue193_write_scope.py +378 -378
- package/md_cg/test_issue212_writeface_gaps.py +349 -349
- package/md_cg/test_issue214_reject_sensitivity.py +266 -266
- package/md_cg/test_issue215_condition_source_gap.py +272 -272
- package/md_cg/test_issue216_clash_routes.py +214 -214
- package/md_cg/test_issue217_slot_routes.py +248 -248
- package/md_cg/test_issue218_postcondition_value_blind.py +222 -222
- package/md_cg/test_issue258_pack_sensitivity.py +468 -468
- package/md_cg/test_issue265_coldverify_multiproc.py +438 -438
- package/md_cg/test_issue274_read_node_id_none.py +341 -341
- package/md_cg/test_issue275_layer_param.py +250 -250
- package/md_cg/test_issue277_node_id_traversal.py +384 -384
- package/md_cg/test_issue278_neg_separated_tension.py +271 -271
- package/md_cg/test_issue278_neg_window.py +294 -294
- package/md_cg/test_issue278_negative_layering.py +83 -83
- package/md_cg/test_issue284_skip_not_pass.py +291 -291
- package/md_cg/test_issue294_flywheel_sensitivity.py +573 -573
- package/md_cg/test_issue301_baseline_corpus_gate.py +245 -245
- package/md_cg/test_issue303_design_boundaries.py +262 -262
- package/md_cg/test_issue315_merge_branch_sensitivity.py +383 -383
- package/md_cg/test_issue319_tenant_unregistered_bypass.py +256 -256
- package/md_cg/test_issue321_mcp_deep_json.py +304 -304
- package/md_cg/test_issue322_node_write_lock.py +727 -727
- package/md_cg/test_issue324_write_size_fields.py +214 -214
- package/md_cg/test_issue325_audit_poison.py +229 -229
- package/md_cg/test_issue326_ingest_auto_whitelist.py +331 -331
- package/md_cg/test_issue326_key_perms.py +355 -355
- package/md_cg/test_issue326_twin_parser_parity.py +323 -323
- package/md_cg/test_issue326_vm_call_frame.py +569 -569
- package/md_cg/test_issue345_writelimit_effective_sens.py +233 -233
- package/md_cg/test_issue346_overwrite_sensitivity_gate.py +424 -424
- package/md_cg/test_issue348_insight_verify_op.py +199 -199
- package/md_cg/test_issue348_merge_rmw_lock.py +345 -345
- package/md_cg/test_issue350_casefold_collision.py +235 -235
- package/md_cg/test_issue351_ingest_root_fallback.py +201 -201
- package/md_cg/test_issue352_imgaudit.py +418 -418
- package/md_cg/test_issue352_pathsjson.py +537 -537
- package/md_cg/test_issue352_refindex.py +412 -412
- package/md_cg/test_issue352_rollback.py +604 -604
- package/md_cg/test_issue354_p2_writelimit_toctou.py +327 -327
- package/md_cg/test_issue354_rust_index_containment.py +571 -571
- package/md_cg/test_issue354_rust_wal_containment.py +606 -606
- package/md_cg/test_issue358_truncation_observable.py +247 -247
- package/md_cg/test_issue360_tidy_private_excerpt.py +195 -195
- package/md_cg/test_issue361_blindspot_not_silent_drop.py +494 -494
- package/md_cg/test_issue362_neg_condition.py +468 -468
- package/md_cg/test_issue363_lexical_idf.py +275 -275
- package/md_cg/test_issue370_readcache_assembly.py +488 -488
- package/md_cg/test_issue376_heartbeat_failed.py +293 -293
- package/md_cg/test_issue377_layer_protect_stamp.py +324 -324
- package/md_cg/test_issue378_protected_floor.py +310 -310
- package/md_cg/test_issue383_state_event_write_gate.py +462 -462
- package/md_cg/test_issue397_sens_eff_wiring.py +435 -435
- package/md_cg/test_issue398_toolface_op_parity.py +511 -511
- package/md_cg/test_issue399_hive_json_shape.py +317 -317
- package/md_cg/test_issue401_wisdom_codegen.py +295 -295
- package/md_cg/test_issue404_heal_receipt.py +389 -389
- package/md_cg/test_issue409_compact_index_completeness.py +509 -509
- package/md_cg/test_issue410_verify_demote_write.py +366 -366
- package/md_cg/test_issue411_scrub_idempotence.py +575 -575
- package/md_cg/test_issue412_discipline_producer_parity.py +311 -311
- package/md_cg/test_issue413_preimage_failclosed.py +239 -239
- package/md_cg/test_issue413_preimage_twin.py +339 -339
- package/md_cg/test_issue415_deps_gate_probe.py +357 -357
- package/md_cg/test_issue416_entry_key_subset.py +525 -525
- package/md_cg/test_issue417_twophase_merge_landed.py +423 -423
- package/md_cg/test_issue425_ingest_library_path.py +331 -331
- package/md_cg/test_issue426c_enqueue_not_silent.py +346 -346
- package/md_cg/test_issue426e_restore_overwrite_live.py +310 -310
- package/md_cg/test_issue426f_paths_gbk_failclosed.py +301 -301
- package/md_cg/test_issue427_serve_status_shape.py +191 -191
- package/md_cg/test_issue431_432_468_protect_single_point.py +322 -322
- package/md_cg/test_issue433_outlook_threshold_single_point.py +278 -278
- package/md_cg/test_issue434_435_float_gate.py +90 -90
- package/md_cg/test_issue439_sibling_sensitivity_inherit.py +448 -448
- package/md_cg/test_issue43_default_policy.py +874 -874
- package/md_cg/test_issue444_scrub_evidence_plaintext.py +281 -281
- package/md_cg/test_issue445_metacognition_ledger_gate.py +454 -454
- package/md_cg/test_issue446_453_403_verified_evidence.py +382 -382
- package/md_cg/test_issue450_sensitivity_fallback_reason.py +51 -51
- package/md_cg/test_issue450_writegate_unknown_sens.py +203 -203
- package/md_cg/test_issue451_audit_actor.py +313 -313
- package/md_cg/test_issue452_ingest_root_sensitivity.py +299 -299
- package/md_cg/test_issue463_ghost_prune_guard.py +259 -259
- package/md_cg/test_issue466_basis_registry.py +469 -469
- package/md_cg/test_issue467_identity_sensitivity_parity.py +360 -360
- package/md_cg/test_issue469_scrub_override_passthrough.py +126 -126
- package/md_cg/test_issue470_wal_event_durable.py +427 -427
- package/md_cg/test_issue471_identity_readable.py +136 -136
- package/md_cg/test_issue472_audit_chain.py +90 -90
- package/md_cg/test_issue472_prune_ledger.py +105 -105
- package/md_cg/test_issue472_rollback_degraded.py +81 -81
- package/md_cg/test_issue491_compose_sandbox.py +460 -460
- package/md_cg/test_issue498_merge_trace_stale_index.py +280 -280
- package/md_cg/test_issue511_scoreboard_bad_files.py +256 -256
- package/md_cg/test_issue521_rotate_lock_suffix.py +110 -110
- package/md_cg/test_issue524_orphan_noise_no_demote.py +88 -88
- package/md_cg/test_issue525_read_null_semantics.py +52 -52
- package/md_cg/test_issue547_append_jsonl_whitelist.py +114 -114
- package/md_cg/test_issue547_audit_durable.py +96 -96
- package/md_cg/test_issue557_r2_write_entries_size_gate.py +83 -83
- package/md_cg/test_issue559_refine_prefix.py +69 -69
- package/md_cg/test_issue562_retired_faces.py +150 -0
- package/md_cg/test_issue71_queue_backlog.py +376 -376
- package/md_cg/test_issue72_coldverify_controlled_drain.py +420 -420
- package/md_cg/test_issue82_credential_rules.py +271 -271
- package/md_cg/test_issue91_verifier_sandbox.py +314 -314
- package/md_cg/test_issue93_remember_redaction.py +282 -282
- package/md_cg/test_logref.py +1141 -1141
- package/md_cg/test_md_access_parity.py +330 -330
- package/md_cg/test_md_cg_no_hive_dep.py +139 -139
- package/md_cg/test_mutation_residue.py +119 -119
- package/md_cg/test_mutation_rollback.py +835 -835
- package/md_cg/test_n123_derive_expiry_chain.py +210 -210
- package/md_cg/test_n209_verify_write_face_gates.py +466 -466
- package/md_cg/test_n62_tenant_bind_failclosed.py +200 -200
- package/md_cg/test_neg_tail_honesty.py +733 -733
- package/md_cg/test_p21_tokens.py +294 -294
- package/md_cg/test_p27_docindex.py +792 -792
- package/md_cg/test_p28_refcheck.py +1053 -1053
- package/md_cg/test_p2_six_elements.py +476 -476
- package/md_cg/test_p33_ccg_wiring.py +300 -300
- package/md_cg/test_p3_legacy_closure.py +438 -438
- package/md_cg/test_p40_refine_worklist.py +244 -244
- package/md_cg/test_p4_freshness.py +781 -781
- package/md_cg/test_p9c_dedup_hints.py +288 -288
- package/md_cg/test_policy_required_ccg.py +444 -444
- package/md_cg/test_retr_s5.py +312 -312
- package/md_cg/test_s1_ast_judge.py +109 -109
- package/md_cg/test_state_event_op.py +521 -521
- package/md_cg/test_stgidx_index_parity.py +1024 -1024
- package/md_cg/test_sustain_bounded.py +652 -652
- package/md_cg/test_trust_edge_reachability.py +405 -405
- package/md_cg/test_w7_redlines.py +659 -659
- package/md_cg/test_write_return_shape.py +919 -919
- package/md_cg/test_writepipe.py +228 -228
- package/md_cg/trust.py +1114 -1114
- package/md_cg/twophase.py +303 -303
- package/md_cg/whitebox.py +536 -536
- package/md_cg/whitebox_kb/wisdom/compose_engine.py +1634 -1634
- package/md_cg/whitebox_kb/wisdom/core/condition_vm.py +318 -318
- package/md_cg/whitebox_kb/wisdom/core/parser.py +1082 -1082
- package/md_cg/whitebox_kb/wisdom/md_access.py +490 -490
- package/md_cg/whitebox_kb/wisdom/migrate_wisdom.py +497 -497
- package/md_cg/whitebox_kb/wisdom/mini_python.py +995 -995
- package/md_cg/whitebox_kb/wisdom/net_units.py +2900 -2900
- package/md_cg/whitebox_kb/wisdom/semantic_translate.py +4060 -4060
- package/md_cg/writepipe.py +1337 -1337
- package/package.json +3 -2
- package/scripts/workspace_index.py +328 -0
- package/src/hooks.ts +30 -6
- package/src/index.ts +14 -5
- package/src/lib/hook_audit.ts +282 -256
- package/src/lib/mdcg_client.ts +469 -469
- package/src/lib/prompt_safety.ts +17 -3
- package/src/tools.ts +23 -1
|
@@ -1,575 +1,575 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# 功能名:scrub 幂等名单不得把**失败**记成「已处置」(issue #411)
|
|
3
|
-
# 生效条件:python -X utf8 -m md_cg.test_issue411_scrub_idempotence [--mutate];被测面=md_cg/scrub.py 的 _actions_ok / decontaminate 写侧 / _handled 读侧
|
|
4
|
-
# 子功能:A 组=走**真实分发面**(cg(op=scrub, action=decontaminate, dry_run=false)):无权身份 ⇒ 盘面零变化 + _scrub.jsonl 该行 ok=False + 下一轮有权限身份仍真正处置;K 组=非恒真对照(三形态枚举 + 反向样本 / 成功轮 ok=True 的过度收紧反证 / dry_run 语义不退化 / _handled 只认 ok / summary 不把失败批次算成功轮);E 组=AST 钉子(_log 的 ok= 只能是 _actions_ok(...))+ 枚举完备性 + writelimit 两处「已核、非本族」登记
|
|
5
|
-
# 执行:三个权限相位(建节点=有权限 / 实修=无权 verifier / 再实修=有权限)各起一个 MdCGSecure 实例,经 mcp_server.call_tool 走 scrub 分发;读 _scrub.jsonl 与节点盘面字节
|
|
6
|
-
# 验证方式:全部 PASS 即通过;--mutate 走镜像树定点变异(含 _guard_kit 两骨架实调),变异后红项必须**恰为**预期集合
|
|
7
|
-
# 不适用条件:①不判 _weaken/_move_layer 自身的权限语义(那是 security 面)②不判 audit 的判据正确性(污染识别另一面)③明文登记:writelimit.py:383 _already_tidied / :373 already_covered **已核、非本族**(理由见 E4)④不改读侧 _handled/summary 的判据形态(#411 的口径是「写侧写真值、读侧照旧只读 ok」这一单点)
|
|
8
|
-
"""issue #411 守卫:失败的处置不得被写进幂等名单。
|
|
9
|
-
|
|
10
|
-
病象(修前):
|
|
11
|
-
scrub.py:171 `if rec.get("op") == "decontaminate" and rec.get("ok"):` ← 幂等判据只看 ok
|
|
12
|
-
scrub.py:738 `_log(cg, "decontaminate", …, ok=True, …)` ← 无条件写 True
|
|
13
|
-
同批失败只以**字符串**留在 `actions` 里(`weaken_failed:<Type>` / `demote_failed:<Type>`
|
|
14
|
-
/ `demote_state:<error>`),于是**无权身份跑一次即可把 (节点, 污染类型) 永久钉成
|
|
15
|
-
「已处置」**,污染此后**永久不再被处置**(幂等名单被失败污染)。
|
|
16
|
-
|
|
17
|
-
处置(单点 + 不变量):
|
|
18
|
-
· 抽 `_actions_ok(actions)`(`ACTION_FAIL_MARKS` 显式三项,**不通配**);
|
|
19
|
-
· **写侧**两处写真值:`:738` 单条 `ok=_actions_ok(done)`;`:762` 批次
|
|
20
|
-
`ok=(n_failed == 0)`(`n_failed` 由同一次 `_actions_ok` 汇总);
|
|
21
|
-
· **读侧** `_handled` / `summary` **一字不改**,照旧只读 `ok` —— 判据收成单点。
|
|
22
|
-
|
|
23
|
-
★**过度收紧方向**(K1/K5 + M3):`_actions_ok` 恒 False 会把**合法成功处置**误判成
|
|
24
|
-
失败,幂等名单永不记账 ⇒ 每轮重复处置。K1 的反向样本(`["weaken"]`/`["demote"]`/
|
|
25
|
-
无冒号的 `"demote_state"`)就是这条的守卫。
|
|
26
|
-
"""
|
|
27
|
-
import ast
|
|
28
|
-
import io
|
|
29
|
-
import inspect
|
|
30
|
-
import json
|
|
31
|
-
import os
|
|
32
|
-
import shutil
|
|
33
|
-
import subprocess
|
|
34
|
-
import sys
|
|
35
|
-
import tempfile
|
|
36
|
-
|
|
37
|
-
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
38
|
-
|
|
39
|
-
_REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
40
|
-
sys.path.insert(0, _REPO)
|
|
41
|
-
_TMP = tempfile.mkdtemp(prefix="iss411_")
|
|
42
|
-
os.environ.update({"MDCG_STATE_ROOT": os.path.join(_TMP, "state"),
|
|
43
|
-
"MDCG_AUX_ROOT": os.path.join(_TMP, "auxstore"),
|
|
44
|
-
"MDCG_DATA_ROOT": os.path.join(_TMP, "data"),
|
|
45
|
-
"MDCG_EXPORT_ROOT": _TMP,
|
|
46
|
-
"MDCG_SUSTAIN": "0", "MDCG_SLEEP": "0"})
|
|
47
|
-
|
|
48
|
-
from md_cg import _guard_kit # noqa: E402
|
|
49
|
-
from md_cg import scrub # noqa: E402
|
|
50
|
-
from md_cg.mdcos import MdCGSecure # noqa: E402
|
|
51
|
-
from md_cg.mcp_server import call_tool # noqa: E402
|
|
52
|
-
from md_cg.security import Principal # noqa: E402
|
|
53
|
-
|
|
54
|
-
FAILS = []
|
|
55
|
-
_RUN = [0]
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def _check(name, cond, detail=""):
|
|
59
|
-
if cond:
|
|
60
|
-
print(" PASS " + name)
|
|
61
|
-
else:
|
|
62
|
-
print(" FAIL " + name + " " + str(detail)[:400])
|
|
63
|
-
FAILS.append(name)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
def _lib(tag):
|
|
67
|
-
_RUN[0] += 1
|
|
68
|
-
root = os.path.join(_TMP, "%s_%d" % (tag, _RUN[0]))
|
|
69
|
-
os.makedirs(root, exist_ok=True)
|
|
70
|
-
return root
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
#: 有权限身份(建节点 / 正向实修)
|
|
74
|
-
P_YES = Principal(role="designer", clearance="private", can_write=True,
|
|
75
|
-
can_admin=True)
|
|
76
|
-
#: 无权身份:可写层只有 rejected ⇒ knowledge 层的 verify/_move_layer 双双 AccessDenied
|
|
77
|
-
P_NO = Principal(role="verifier", clearance="private", can_write=True,
|
|
78
|
-
layers_allow=("rejected",))
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
def _mk_cg(root, principal):
|
|
82
|
-
return MdCGSecure(root, principal=principal, autoflush=1)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
def _seed_expired(root, nid="n_exp"):
|
|
86
|
-
"""建一个`expired`污染节点(severity=high,fix=(weaken, demote))。"""
|
|
87
|
-
import time
|
|
88
|
-
cg = _mk_cg(root, P_YES)
|
|
89
|
-
cg.add(nid, "PASSED 过期条目 ALPHA", layer="knowledge",
|
|
90
|
-
valid_until=time.time() - 86400 * 30, verification_basis="test")
|
|
91
|
-
cg.flush()
|
|
92
|
-
p = os.path.join(root, (cg.get(nid) or {}).get("path") or "")
|
|
93
|
-
cg.close()
|
|
94
|
-
return p
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
def _scrub(root, principal):
|
|
98
|
-
"""走**真实分发面**:cg(op=scrub, action=decontaminate, dry_run=false)。"""
|
|
99
|
-
cg = _mk_cg(root, principal)
|
|
100
|
-
try:
|
|
101
|
-
return call_tool(cg, "cg", {"op": "scrub", "action": "decontaminate",
|
|
102
|
-
"dry_run": False, "min_severity": "medium"})
|
|
103
|
-
finally:
|
|
104
|
-
cg.close()
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
def _sig(root, nid="n_exp"):
|
|
108
|
-
"""节点**处置相关**读数签名(demote 会改层并搬文件,故不能只按固定路径比字节)。"""
|
|
109
|
-
cg = _mk_cg(root, P_YES)
|
|
110
|
-
n = cg.get(nid) or {}
|
|
111
|
-
fm = n.get("frontmatter") or {}
|
|
112
|
-
out = (fm.get("layer"), fm.get("verification_state"),
|
|
113
|
-
fm.get("negative_evidence"), fm.get("confidence"),
|
|
114
|
-
(n.get("content") or "")[:40])
|
|
115
|
-
cg.close()
|
|
116
|
-
return out
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
def _rows(root):
|
|
120
|
-
p = os.path.join(root, scrub.SCRUB_LOG)
|
|
121
|
-
if not os.path.isfile(p):
|
|
122
|
-
return []
|
|
123
|
-
out = []
|
|
124
|
-
with io.open(p, encoding="utf-8") as f:
|
|
125
|
-
for ln in f:
|
|
126
|
-
ln = ln.strip()
|
|
127
|
-
if ln:
|
|
128
|
-
out.append(json.loads(ln))
|
|
129
|
-
return out
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
def _get(row, *path):
|
|
133
|
-
cur = row
|
|
134
|
-
for k in path:
|
|
135
|
-
if isinstance(cur, dict):
|
|
136
|
-
cur = cur.get(k)
|
|
137
|
-
else:
|
|
138
|
-
return None
|
|
139
|
-
return cur
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
# ========================================================= A 组:真实分发面
|
|
143
|
-
print("== A 组:无权身份的失败不得写进幂等名单 ==")
|
|
144
|
-
|
|
145
|
-
_root = _lib("a")
|
|
146
|
-
_p = _seed_expired(_root)
|
|
147
|
-
_b0 = io.open(_p, "rb").read()
|
|
148
|
-
_r1 = _scrub(_root, P_NO)
|
|
149
|
-
_b1 = io.open(_p, "rb").read()
|
|
150
|
-
_rows1 = _rows(_root)
|
|
151
|
-
_dec = [r for r in _rows1 if r.get("op") == "decontaminate"]
|
|
152
|
-
_bat = [r for r in _rows1 if r.get("op") == "decontaminate_batch"]
|
|
153
|
-
_done1 = _get(_r1, "actions") or []
|
|
154
|
-
_done1 = [a.get("done") for a in _done1 if a.get("applied")]
|
|
155
|
-
print(" [读数] A1 done=%s 盘面变化=%s" % (_done1, _b0 != _b1))
|
|
156
|
-
_check("A1 无权身份:两个动作都失败(done 带 weaken_failed:/demote_failed:),盘面零变化",
|
|
157
|
-
bool(_done1) and any(str(d).startswith("weaken_failed:") for d in _done1[0])
|
|
158
|
-
and any(str(d).startswith("demote_failed:") for d in _done1[0])
|
|
159
|
-
and _b0 == _b1, (_done1, _b0 == _b1))
|
|
160
|
-
|
|
161
|
-
print(" [读数] A2 _scrub.jsonl decontaminate 行=%s"
|
|
162
|
-
% [(r.get("kind"), r.get("ok"), r.get("actions")) for r in _dec])
|
|
163
|
-
_check("A2 _scrub.jsonl 该行 ok=False(修前无条件 True:失败被写成已处置)",
|
|
164
|
-
len(_dec) == 1 and _dec[0].get("ok") is False
|
|
165
|
-
and any(str(x).startswith("weaken_failed:") for x in (_dec[0].get("actions") or [])),
|
|
166
|
-
_dec)
|
|
167
|
-
|
|
168
|
-
# 下一轮:有权限身份必须**仍然真正处置**(修前会被幂等名单拦成 skip)
|
|
169
|
-
_sig1 = _sig(_root)
|
|
170
|
-
_r2 = _scrub(_root, P_YES)
|
|
171
|
-
_sig2 = _sig(_root)
|
|
172
|
-
print(" [读数] A3 有权限轮 applied=%s already_handled=%s 盘面签名 %s → %s"
|
|
173
|
-
% (_r2.get("applied"), _r2.get("already_handled"), _sig1, _sig2))
|
|
174
|
-
_check("A3 下一轮有权限身份仍**真正处置**(不是「已处置过(幂等)」)",
|
|
175
|
-
(_r2.get("applied") or 0) >= 1
|
|
176
|
-
and (_r2.get("already_handled") or 0) == 0 and _sig1 != _sig2,
|
|
177
|
-
{k: _r2.get(k) for k in ("applied", "already_handled")})
|
|
178
|
-
|
|
179
|
-
_rows2 = _rows(_root)
|
|
180
|
-
_bat2 = [r for r in _rows2 if r.get("op") == "decontaminate_batch"]
|
|
181
|
-
print(" [读数] A4 批次 ok 序列=%s failed_actions=%s"
|
|
182
|
-
% ([r.get("ok") for r in _bat2], [r.get("failed_actions") for r in _bat2]))
|
|
183
|
-
_check("A4 批次记录与子条一致:失败轮 ok=False/failed_actions=1,成功轮 ok=True/0",
|
|
184
|
-
len(_bat2) == 2 and _bat2[0].get("ok") is False
|
|
185
|
-
and _bat2[0].get("failed_actions") == 1
|
|
186
|
-
and _bat2[1].get("ok") is True
|
|
187
|
-
and _bat2[1].get("failed_actions") == 0, _bat2)
|
|
188
|
-
|
|
189
|
-
_dec2 = [r for r in _rows2 if r.get("op") == "decontaminate"]
|
|
190
|
-
print(" [读数] A5 成功轮 done=%s ok=%s"
|
|
191
|
-
% ([a.get("done") for a in (_r2.get("actions") or []) if a.get("applied")],
|
|
192
|
-
[r.get("ok") for r in _dec2]))
|
|
193
|
-
_check("A5 **过度收紧反证**:有权限身份的成功处置仍得 ok=True(含 demote_state: 不在成功路径上)",
|
|
194
|
-
len(_dec2) == 2 and _dec2[1].get("ok") is True
|
|
195
|
-
and (_r2.get("failed_actions") or 0) == 0, _dec2)
|
|
196
|
-
|
|
197
|
-
# ========================================================= K 组:非恒真对照
|
|
198
|
-
print("== K 组:非恒真对照(含**过度收紧**方向)==")
|
|
199
|
-
|
|
200
|
-
_cases = [
|
|
201
|
-
("全成功", ["weaken", "demote"], True),
|
|
202
|
-
("weaken 失败", ["weaken_failed:AccessDenied"], False),
|
|
203
|
-
("demote 失败", ["demote_failed:ProtectionError"], False),
|
|
204
|
-
("demote_state 失败", ["demote_state:denied"], False),
|
|
205
|
-
("混合:一成一败", ["weaken", "demote_failed:OSError"], False),
|
|
206
|
-
("空列表", [], True),
|
|
207
|
-
("None", None, True),
|
|
208
|
-
("反向:动作名不该被误判(无冒号)", ["weaken_failed"], True),
|
|
209
|
-
("反向:demote_state 无冒号", ["demote_state"], True),
|
|
210
|
-
("反向:名字里含 failed 但不在标记表内的合法动作", ["weaken", "verify_failed_once"], True),
|
|
211
|
-
]
|
|
212
|
-
_got = [(c, scrub._actions_ok(v)) for c, v, _ in _cases]
|
|
213
|
-
_bad = [(c, g, w) for (c, v, w), (c2, g) in zip(_cases, _got) if g != w]
|
|
214
|
-
print(" [读数] K1 _actions_ok 十形态=%s" % _got)
|
|
215
|
-
_check("K1 _actions_ok 三失败形态判 False、成功/空/None 判 True,"
|
|
216
|
-
"且**无冒号的同名字面不被误判**(非恒真 + 不过度收紧)",
|
|
217
|
-
not _bad, _bad)
|
|
218
|
-
|
|
219
|
-
# K2:dry_run 语义不退化(不写 decontaminate 记录、盘面零变化、写批次)
|
|
220
|
-
_kroot = _lib("k2")
|
|
221
|
-
_kp = _seed_expired(_kroot, "k2_exp")
|
|
222
|
-
_kb0 = io.open(_kp, "rb").read()
|
|
223
|
-
_cg = _mk_cg(_kroot, P_YES)
|
|
224
|
-
_rd = call_tool(_cg, "cg", {"op": "scrub", "action": "decontaminate",
|
|
225
|
-
"dry_run": True, "min_severity": "medium"})
|
|
226
|
-
_cg.close()
|
|
227
|
-
_krows = _rows(_kroot)
|
|
228
|
-
print(" [读数] K2 dry_run planned=%s 记录=%s 盘面变化=%s"
|
|
229
|
-
% (_rd.get("planned_dry_run"),
|
|
230
|
-
[r.get("op") for r in _krows], _kb0 != io.open(_kp, "rb").read()))
|
|
231
|
-
_check("K2 dry_run 照旧零副作用(无 decontaminate 记录、盘面零变化、无批次记录)",
|
|
232
|
-
(_rd.get("planned_dry_run") or 0) >= 1
|
|
233
|
-
and not [r for r in _krows if r.get("op") == "decontaminate"]
|
|
234
|
-
and _kb0 == io.open(_kp, "rb").read(), _krows)
|
|
235
|
-
|
|
236
|
-
# K3:_handled 只认 ok(读侧单点未被改宽)
|
|
237
|
-
_kroot3 = _lib("k3")
|
|
238
|
-
_cg3 = _mk_cg(_kroot3, P_YES)
|
|
239
|
-
_cg3.add("k3_a", "PASSED 甲", layer="knowledge", verification_basis="test")
|
|
240
|
-
_cg3.flush()
|
|
241
|
-
scrub._log(_cg3, "decontaminate", node_id="k3_a", kind="expired", ok=False,
|
|
242
|
-
actions=["weaken_failed:AccessDenied"])
|
|
243
|
-
_h_after_fail = sorted(scrub._handled(_cg3))
|
|
244
|
-
scrub._log(_cg3, "decontaminate", node_id="k3_a", kind="expired", ok=True,
|
|
245
|
-
actions=["weaken"])
|
|
246
|
-
_h_after_ok = sorted(scrub._handled(_cg3))
|
|
247
|
-
_cg3.close()
|
|
248
|
-
print(" [读数] K3 ok=False 后名单=%s,ok=True 后名单=%s"
|
|
249
|
-
% (_h_after_fail, _h_after_ok))
|
|
250
|
-
_check("K3 _handled 只认 ok:ok=False 的记录不进幂等名单,ok=True 才进",
|
|
251
|
-
_h_after_fail == [] and _h_after_ok == [("k3_a", "expired")],
|
|
252
|
-
(_h_after_fail, _h_after_ok))
|
|
253
|
-
|
|
254
|
-
# K4:summary 不把失败批次算成成功轮
|
|
255
|
-
_sum = scrub.summary(_cg3) if False else None
|
|
256
|
-
_kroot4 = _lib("k4")
|
|
257
|
-
_cg4 = _mk_cg(_kroot4, P_YES)
|
|
258
|
-
scrub._log(_cg4, "decontaminate_batch", ok=False, applied=1, failed_actions=1)
|
|
259
|
-
scrub._log(_cg4, "decontaminate_batch", ok=True, applied=2, failed_actions=0)
|
|
260
|
-
_s4 = scrub.summary(_cg4)
|
|
261
|
-
_cg4.close()
|
|
262
|
-
print(" [读数] K4 batches=%s decontaminated=%s"
|
|
263
|
-
% (_s4.get("batches"), _s4.get("decontaminated")))
|
|
264
|
-
_check("K4 summary 只把 ok=True 的批次算作成功轮(失败批次不进 batches)",
|
|
265
|
-
_s4.get("batches") == 1 and _s4.get("decontaminated") == 2, _s4)
|
|
266
|
-
|
|
267
|
-
# ========================================================= E 组:AST 钉子 / 枚举 / 族登记
|
|
268
|
-
print("== E 组:AST 钉子 · 枚举完备性 · 族登记 ==")
|
|
269
|
-
|
|
270
|
-
_scrub_src = io.open(os.path.join(_REPO, "md_cg", "scrub.py"),
|
|
271
|
-
encoding="utf-8").read()
|
|
272
|
-
_tree = ast.parse(_scrub_src)
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
# 生效条件:node 为 `_log(...)` 调用节点时返回其**第 2 个位置实参**的字符串值(op),非字面量/缺参返回 None;
|
|
276
|
-
def _op_of_log(node):
|
|
277
|
-
"""取 `_log(cg, op, **rec)` 的 op 字面(第 1 个位置实参是 cg)。"""
|
|
278
|
-
if len(node.args) >= 2 and isinstance(node.args[1], ast.Constant):
|
|
279
|
-
return node.args[1].value
|
|
280
|
-
return None
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
#: #411 的 ok 判据面:**只**覆盖这两条记录(`_handled`/`summary` 消费的就是它们)。
|
|
284
|
-
_TARGET_OPS = ("decontaminate", "decontaminate_batch")
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
def _log_ok_values(tree, ops=_TARGET_OPS):
|
|
288
|
-
"""`_log(` 调用里 `ok=` 实参的 AST 节点列表,**按 op 收窄**到 `ops`。
|
|
289
|
-
|
|
290
|
-
为什么按 op 收窄:`scrub.py` 还有 `calibrate` / `sweep` 两条记录也写 `ok=`
|
|
291
|
-
字面(:911 等),但它们的 ok **不被任何幂等读面消费**、记录里也没有失败标记
|
|
292
|
-
通道 ⇒ 不属本族(登记见 E5)。把 AST 钉子铺到全部 `_log(` 上会顺手改动
|
|
293
|
-
本 issue 范围外的记录、并让「本族」与「全仓」两个面混成一个。
|
|
294
|
-
"""
|
|
295
|
-
out = []
|
|
296
|
-
for node in ast.walk(tree):
|
|
297
|
-
if (isinstance(node, ast.Call) and isinstance(node.func, ast.Name)
|
|
298
|
-
and node.func.id == "_log"):
|
|
299
|
-
# _log(cg, op, **rec):op 是**第 2 个位置实参**(第 1 个是 cg)
|
|
300
|
-
op = (_op_of_log(node))
|
|
301
|
-
if op not in ops:
|
|
302
|
-
continue
|
|
303
|
-
for kw in node.keywords:
|
|
304
|
-
if kw.arg == "ok":
|
|
305
|
-
out.append(kw.value)
|
|
306
|
-
return out
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
_oks = _log_ok_values(_tree)
|
|
310
|
-
_shapes = [ast.unparse(v) for v in _oks]
|
|
311
|
-
print(" [读数] E1 _log(ok=) 实参形态=%s" % _shapes)
|
|
312
|
-
# 判据是**绑定链**而不是「字面里出现某个子串」(后者用变量中转就能逃过):
|
|
313
|
-
# 单条记录 ok=_ok,而 _ok 由 _actions_ok(done) 绑定;
|
|
314
|
-
# 批次记录 ok=(n_failed == 0),而 n_failed 由 `if not _ok: n_failed += 1` 汇总。
|
|
315
|
-
_chain = ("_ok = _actions_ok(done)" in _scrub_src
|
|
316
|
-
and "if not _ok:" in _scrub_src
|
|
317
|
-
and "n_failed += 1" in _scrub_src)
|
|
318
|
-
_check("E1 AST:decontaminate / decontaminate_batch 两条记录的 _log(ok=) 只能是"
|
|
319
|
-
"_ok / n_failed == 0 且其绑定链落在 _actions_ok(...) 上,不得出现字面 "
|
|
320
|
-
"True/False(calibrate/sweep 两条已核非本族,见 E5)",
|
|
321
|
-
len(_oks) == 2 and set(_shapes) == {"_ok", "n_failed == 0"} and _chain
|
|
322
|
-
and not any(isinstance(v, ast.Constant) for v in _oks),
|
|
323
|
-
(_shapes, _chain))
|
|
324
|
-
|
|
325
|
-
_handled_src = inspect.getsource(scrub._handled)
|
|
326
|
-
print(" [读数] E2 _handled 体=%r" % _handled_src.strip()[:120])
|
|
327
|
-
_check("E2 读侧单点:_handled 的过滤只读 ok(不引入第二份 _actions_ok 判据)",
|
|
328
|
-
'rec.get("ok")' in _handled_src and "_actions_ok" not in _handled_src,
|
|
329
|
-
_handled_src.strip()[:160])
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
#: **守卫侧独立字面表**:三处失败形态的已知全集。刻意**不**引用 scrub.ACTION_FAIL_MARKS
|
|
333
|
-
#: —— 引用被测常量会变成自指(把常量改成两项,枚举判据跟着变两项 ⇒ 永远自洽、抓不到漏形态)。
|
|
334
|
-
_KNOWN_FAIL_MARKS = ("weaken_failed:", "demote_failed:", "demote_state:")
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
def _fail_forms_in_src(src):
|
|
338
|
-
"""源码里的失败形态:扫每个 `done.append(...)` 实参中的**字符串字面量**,
|
|
339
|
-
取其命中 ACTION_FAIL_MARKS 前缀的那些(与 scrub._actions_ok 同一判据)。"""
|
|
340
|
-
hits = []
|
|
341
|
-
for node in ast.walk(ast.parse(src)):
|
|
342
|
-
if (isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute)
|
|
343
|
-
and node.func.attr == "append" and node.args):
|
|
344
|
-
arg = node.args[0]
|
|
345
|
-
for sub in ast.walk(arg):
|
|
346
|
-
if isinstance(sub, ast.Constant) and isinstance(sub.value, str) \
|
|
347
|
-
and sub.value.startswith(_KNOWN_FAIL_MARKS):
|
|
348
|
-
hits.append(sub.value)
|
|
349
|
-
# f-string:JoinedStr 的首段常量为前缀字面
|
|
350
|
-
if isinstance(sub, ast.JoinedStr) and sub.values:
|
|
351
|
-
head = sub.values[0]
|
|
352
|
-
if (isinstance(head, ast.Constant)
|
|
353
|
-
and isinstance(head.value, str)
|
|
354
|
-
and head.value.startswith(_KNOWN_FAIL_MARKS)):
|
|
355
|
-
hits.append(head.value)
|
|
356
|
-
return sorted(set(hits))
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
_forms = _fail_forms_in_src(_scrub_src)
|
|
360
|
-
print(" [读数] E3 源码失败形态=%s 常量元组=%s"
|
|
361
|
-
% (_forms, list(scrub.ACTION_FAIL_MARKS)))
|
|
362
|
-
_check("E3 枚举完备:源码里 done.append 的失败形态**恰为**守卫侧独立字面表的"
|
|
363
|
-
"三项,且 scrub.ACTION_FAIL_MARKS 与之逐项相等(多=常量元组冗余会过度收紧;少=漏形态)",
|
|
364
|
-
sorted(_forms) == sorted(_KNOWN_FAIL_MARKS)
|
|
365
|
-
and sorted(scrub.ACTION_FAIL_MARKS) == sorted(_KNOWN_FAIL_MARKS),
|
|
366
|
-
(_forms, list(scrub.ACTION_FAIL_MARKS)))
|
|
367
|
-
|
|
368
|
-
_wl = io.open(os.path.join(_REPO, "md_cg", "writelimit.py"),
|
|
369
|
-
encoding="utf-8").read()
|
|
370
|
-
_wl_tidy = "def _already_tidied(" in _wl and "TIDY_TAG" in _wl
|
|
371
|
-
_wl_cov = 'already_covered' in _wl
|
|
372
|
-
print(" [读数] E4 writelimit 登记:_already_tidied=%s already_covered=%s"
|
|
373
|
-
% (_wl_tidy, _wl_cov))
|
|
374
|
-
_check("E4 **已核、非本族**登记:writelimit.py:383 _already_tidied 与 :373 "
|
|
375
|
-
"already_covered 判的是**落盘条目字段**(tags/lifecycle_state、content_sink "
|
|
376
|
-
"的字面动作名)而非本轮结果,其通路无「无条件写成功」写侧、也不是审计记录 "
|
|
377
|
-
"⇒ 不需要同款不变量(防将来被误当漏点)",
|
|
378
|
-
_wl_tidy and _wl_cov)
|
|
379
|
-
|
|
380
|
-
#: 非本族的 _log(ok= 字面落点(已核、登记,防将来被误当漏点)。
|
|
381
|
-
_ADJACENT_OK_SITES = ("calibrate", "sweep")
|
|
382
|
-
_other = sorted({_op_of_log(n) for n in ast.walk(_tree)
|
|
383
|
-
if isinstance(n, ast.Call) and isinstance(n.func, ast.Name)
|
|
384
|
-
and n.func.id == "_log" and _op_of_log(n)
|
|
385
|
-
and _op_of_log(n) not in _TARGET_OPS})
|
|
386
|
-
print(" [读数] E5 其余 _log op=%s" % _other)
|
|
387
|
-
_check("E5 **已核、非本族**登记:calibrate / sweep 的 _log(ok=True) 不消费于任何幂等"
|
|
388
|
-
"读面(_handled/summary 只读 decontaminate(_batch))、记录里也无失败标记通道"
|
|
389
|
-
"⇒ 不需同款不变量(防将来被误当漏点)",
|
|
390
|
-
set(_other) == set(_ADJACENT_OK_SITES), _other)
|
|
391
|
-
|
|
392
|
-
# ---- _guard_kit 骨架①:枚举完备性(喂合成样本给**本守卫自己的**枚举逻辑)----
|
|
393
|
-
_enum_samples = [
|
|
394
|
-
("weaken 失败形态",
|
|
395
|
-
'def f(exc):\n done.append(f"weaken_failed:{type(exc).__name__}")\n',
|
|
396
|
-
True, "syn1.py"),
|
|
397
|
-
("demote 失败形态",
|
|
398
|
-
'def f(exc):\n done.append(f"demote_failed:{type(exc).__name__}")\n',
|
|
399
|
-
True, "syn2.py"),
|
|
400
|
-
("demote_state 失败形态",
|
|
401
|
-
'def f(st):\n done.append("demote" if st else f"demote_state:{st}")\n',
|
|
402
|
-
True, "syn3.py"),
|
|
403
|
-
("反向:成功动作名",
|
|
404
|
-
'def f():\n done.append("weaken")\n done.append("demote")\n',
|
|
405
|
-
False, "syn4.py"),
|
|
406
|
-
("反向:无冒号的同名字面",
|
|
407
|
-
'def f():\n done.append("weaken_failed")\n done.append("demote_state")\n',
|
|
408
|
-
False, "syn5.py"),
|
|
409
|
-
]
|
|
410
|
-
_eok, _edet = _guard_kit.assert_enumeration_complete(
|
|
411
|
-
lambda texts: [h for src in texts.values() for h in _fail_forms_in_src(src)],
|
|
412
|
-
_enum_samples)
|
|
413
|
-
print(" [读数] 骨架① 枚举完备性:%s" % (_edet.get("样本"),))
|
|
414
|
-
_check("骨架① assert_enumeration_complete:合成样本三形态全命中、反向样本零命中",
|
|
415
|
-
_eok, _edet)
|
|
416
|
-
|
|
417
|
-
shutil.rmtree(_TMP, ignore_errors=True)
|
|
418
|
-
|
|
419
|
-
print("")
|
|
420
|
-
if FAILS:
|
|
421
|
-
print("issue #411 结果:%d 失败 → %s" % (len(FAILS), ", ".join(FAILS)))
|
|
422
|
-
else:
|
|
423
|
-
print("issue #411 结果:全部通过")
|
|
424
|
-
|
|
425
|
-
# ========================================================= 定点变异(镜像树)
|
|
426
|
-
_MUTATIONS = (
|
|
427
|
-
("M1 回退写侧单条:ok=_ok → ok=True(#411 的修前形态)",
|
|
428
|
-
(("md_cg/scrub.py", ["ok=_ok,"], ["ok=True,"]),),
|
|
429
|
-
("A2", "A3", "A5", "E1")),
|
|
430
|
-
("M2 _actions_ok 恒 True(判据摘除,失败重新写成已处置)",
|
|
431
|
-
(("md_cg/scrub.py",
|
|
432
|
-
[" return not any(str(a).startswith(ACTION_FAIL_MARKS)",
|
|
433
|
-
" for a in (actions or ()))"],
|
|
434
|
-
[" return True"]),),
|
|
435
|
-
# A5 也红:失败轮被写成已处置 ⇒ 下一轮被幂等名单拦成 skip、成功轮不再出现。
|
|
436
|
-
# K1 也红:三形态全判成功(判据被摘除)。
|
|
437
|
-
("A2", "A3", "A4", "A5", "K1")),
|
|
438
|
-
("M3 **过度收紧方向**:_actions_ok 恒 False(合法成功被误判成失败)",
|
|
439
|
-
(("md_cg/scrub.py",
|
|
440
|
-
[" return not any(str(a).startswith(ACTION_FAIL_MARKS)",
|
|
441
|
-
" for a in (actions or ()))"],
|
|
442
|
-
[" return False"]),),
|
|
443
|
-
("A4", "A5", "K1")),
|
|
444
|
-
("M4 读侧把 ok 判据拆掉(失败行重新进幂等名单)",
|
|
445
|
-
(("md_cg/scrub.py",
|
|
446
|
-
[' if rec.get("op") == "decontaminate" and rec.get("ok"):'],
|
|
447
|
-
[' if rec.get("op") == "decontaminate":']),),
|
|
448
|
-
# A5/K3 也红:失败行进了幂等名单 ⇒ 下一轮不再真处置,且 K3 的「ok=False 不进名单」被推翻。
|
|
449
|
-
("A3", "A5", "E2", "K3")),
|
|
450
|
-
("M5 回退批次写侧:ok=(n_failed == 0) → ok=True",
|
|
451
|
-
(("md_cg/scrub.py", ["ok=(n_failed == 0), applied=n_applied,"],
|
|
452
|
-
["ok=True, applied=n_applied,"]),),
|
|
453
|
-
("A4", "E1")),
|
|
454
|
-
("M6 常量元组退回交接规格两项(漏 demote_state: 第三种形态)",
|
|
455
|
-
(("md_cg/scrub.py",
|
|
456
|
-
['ACTION_FAIL_MARKS = ("weaken_failed:", "demote_failed:", "demote_state:")'],
|
|
457
|
-
['ACTION_FAIL_MARKS = ("weaken_failed:", "demote_failed:")']),),
|
|
458
|
-
("E3", "K1")),
|
|
459
|
-
)
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
def _mirror_build():
|
|
463
|
-
dst = tempfile.mkdtemp(prefix="iss411_mut_")
|
|
464
|
-
for name in ("md_cg", "scripts", "data"):
|
|
465
|
-
src = os.path.join(_REPO, name)
|
|
466
|
-
if os.path.isdir(src):
|
|
467
|
-
shutil.copytree(src, os.path.join(dst, name),
|
|
468
|
-
ignore=shutil.ignore_patterns("__pycache__", "*.pyc"))
|
|
469
|
-
for name in sorted(os.listdir(_REPO)):
|
|
470
|
-
p = os.path.join(_REPO, name)
|
|
471
|
-
if os.path.isfile(p) and name.endswith(".py"):
|
|
472
|
-
shutil.copy2(p, os.path.join(dst, name))
|
|
473
|
-
return dst
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
def _nl_of(path):
|
|
477
|
-
with io.open(path, "rb") as fh:
|
|
478
|
-
raw = fh.read(8192)
|
|
479
|
-
return "\r\n" if b"\r\n" in raw else "\n"
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
def _run_in(tree):
|
|
483
|
-
env = dict(os.environ)
|
|
484
|
-
env["PYTHONPATH"] = tree
|
|
485
|
-
env["PYTHONUTF8"] = "1"
|
|
486
|
-
env["PYTHONDONTWRITEBYTECODE"] = "1"
|
|
487
|
-
pr = subprocess.run([sys.executable, "-X", "utf8", "-m",
|
|
488
|
-
"md_cg.test_issue411_scrub_idempotence"],
|
|
489
|
-
capture_output=True, text=True, encoding="utf-8",
|
|
490
|
-
errors="replace", cwd=tree, env=env, timeout=1800)
|
|
491
|
-
out = (pr.stdout or "") + (pr.stderr or "")
|
|
492
|
-
reds = [ln.split("FAIL ", 1)[1].strip()
|
|
493
|
-
for ln in out.splitlines() if "FAIL " in ln]
|
|
494
|
-
return pr.returncode, reds, out
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
# ---- _guard_kit 骨架②:回退即红(实跑,不接受推演)----
|
|
498
|
-
def _skeleton_revert():
|
|
499
|
-
ok, det = _guard_kit.assert_revert_reddens(
|
|
500
|
-
_mirror_build,
|
|
501
|
-
[("md_cg/scrub.py", "ok=_ok,", "ok=True,")],
|
|
502
|
-
_run_in, ("A2", "A3", "A5", "E1"), "md_cg/scrub.py", timeout=1800)
|
|
503
|
-
print(" [读数] 骨架② 回退即红:%s" % json.dumps(
|
|
504
|
-
{k: v for k, v in det.items() if k != "输出尾部"}, ensure_ascii=False,
|
|
505
|
-
default=str)[:400])
|
|
506
|
-
_check("骨架② assert_revert_reddens:把 ok=_actions_ok(done) 实退回 ok=True ⇒ "
|
|
507
|
-
"守卫转红且红项**恰为** A2/A3/A5/E1", ok, det)
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
def _mutate():
|
|
511
|
-
print("!! 定点变异自证:把修复点改回改动前形态,守卫必须转红")
|
|
512
|
-
_skeleton_revert()
|
|
513
|
-
tree = _mirror_build()
|
|
514
|
-
try:
|
|
515
|
-
rc, reds, out = _run_in(tree)
|
|
516
|
-
print(" 未变异镜像基线:rc=%d 红项=%d(必须 rc=0 且 0 红)" % (rc, len(reds)))
|
|
517
|
-
if rc != 0 or reds:
|
|
518
|
-
print(chr(10).join(out.splitlines()[-30:]))
|
|
519
|
-
for ln in out.splitlines():
|
|
520
|
-
if "[读数]" in ln:
|
|
521
|
-
print(" 修后读数(未变异镜像):" + ln.strip())
|
|
522
|
-
okc, bad = 0, []
|
|
523
|
-
for desc, edits, exp in _MUTATIONS:
|
|
524
|
-
backups, miss = [], []
|
|
525
|
-
for rel, oldp, newp in edits:
|
|
526
|
-
p = os.path.join(tree, rel)
|
|
527
|
-
nl = _nl_of(p)
|
|
528
|
-
old, new = nl.join(oldp), nl.join(newp)
|
|
529
|
-
with io.open(p, encoding="utf-8", newline="") as fh:
|
|
530
|
-
t = fh.read()
|
|
531
|
-
if t.count(old) != 1:
|
|
532
|
-
miss.append("%s —— 锚点命中 %d 次" % (rel, t.count(old)))
|
|
533
|
-
continue
|
|
534
|
-
backups.append((p, t))
|
|
535
|
-
with io.open(p, "w", encoding="utf-8", newline="") as fh:
|
|
536
|
-
fh.write(t.replace(old, new, 1))
|
|
537
|
-
if miss:
|
|
538
|
-
bad.append("%s —— %s" % (desc, ";".join(miss)))
|
|
539
|
-
print(" ANCHOR-MISS " + desc)
|
|
540
|
-
for p, t in backups:
|
|
541
|
-
with io.open(p, "w", encoding="utf-8", newline="") as fh:
|
|
542
|
-
fh.write(t)
|
|
543
|
-
continue
|
|
544
|
-
rc2, reds2, out2 = _run_in(tree)
|
|
545
|
-
for p, t in backups:
|
|
546
|
-
with io.open(p, "w", encoding="utf-8", newline="") as fh:
|
|
547
|
-
fh.write(t)
|
|
548
|
-
hit = sorted({e for r in reds2 for e in exp if r.startswith(e + " ")})
|
|
549
|
-
if rc2 != 0 and hit == sorted(exp) and len(reds2) == len(exp):
|
|
550
|
-
okc += 1
|
|
551
|
-
print(" OK %s 红项=%d 指定命中=%d/%d"
|
|
552
|
-
% (desc, len(reds2), len(hit), len(exp)))
|
|
553
|
-
else:
|
|
554
|
-
bad.append(desc)
|
|
555
|
-
print(" MISMATCH %s 红项=%d 指定命中=%d/%d rc=%d"
|
|
556
|
-
% (desc, len(reds2), len(hit), len(exp), rc2))
|
|
557
|
-
for r in reds2[:14]:
|
|
558
|
-
print(" FAIL " + r)
|
|
559
|
-
print("定点变异自证:%s(%d 条不合格)"
|
|
560
|
-
% ("PASS" if not bad else "FAIL", len(bad)))
|
|
561
|
-
for b in bad:
|
|
562
|
-
print(" 不合格:" + b)
|
|
563
|
-
finally:
|
|
564
|
-
shutil.rmtree(tree, ignore_errors=True)
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
def main():
|
|
568
|
-
if "--mutate" in sys.argv:
|
|
569
|
-
_mutate()
|
|
570
|
-
return 1 if FAILS else 0
|
|
571
|
-
return 0 if not FAILS else 1
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
if __name__ == "__main__":
|
|
575
|
-
sys.exit(main())
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# 功能名:scrub 幂等名单不得把**失败**记成「已处置」(issue #411)
|
|
3
|
+
# 生效条件:python -X utf8 -m md_cg.test_issue411_scrub_idempotence [--mutate];被测面=md_cg/scrub.py 的 _actions_ok / decontaminate 写侧 / _handled 读侧
|
|
4
|
+
# 子功能:A 组=走**真实分发面**(cg(op=scrub, action=decontaminate, dry_run=false)):无权身份 ⇒ 盘面零变化 + _scrub.jsonl 该行 ok=False + 下一轮有权限身份仍真正处置;K 组=非恒真对照(三形态枚举 + 反向样本 / 成功轮 ok=True 的过度收紧反证 / dry_run 语义不退化 / _handled 只认 ok / summary 不把失败批次算成功轮);E 组=AST 钉子(_log 的 ok= 只能是 _actions_ok(...))+ 枚举完备性 + writelimit 两处「已核、非本族」登记
|
|
5
|
+
# 执行:三个权限相位(建节点=有权限 / 实修=无权 verifier / 再实修=有权限)各起一个 MdCGSecure 实例,经 mcp_server.call_tool 走 scrub 分发;读 _scrub.jsonl 与节点盘面字节
|
|
6
|
+
# 验证方式:全部 PASS 即通过;--mutate 走镜像树定点变异(含 _guard_kit 两骨架实调),变异后红项必须**恰为**预期集合
|
|
7
|
+
# 不适用条件:①不判 _weaken/_move_layer 自身的权限语义(那是 security 面)②不判 audit 的判据正确性(污染识别另一面)③明文登记:writelimit.py:383 _already_tidied / :373 already_covered **已核、非本族**(理由见 E4)④不改读侧 _handled/summary 的判据形态(#411 的口径是「写侧写真值、读侧照旧只读 ok」这一单点)
|
|
8
|
+
"""issue #411 守卫:失败的处置不得被写进幂等名单。
|
|
9
|
+
|
|
10
|
+
病象(修前):
|
|
11
|
+
scrub.py:171 `if rec.get("op") == "decontaminate" and rec.get("ok"):` ← 幂等判据只看 ok
|
|
12
|
+
scrub.py:738 `_log(cg, "decontaminate", …, ok=True, …)` ← 无条件写 True
|
|
13
|
+
同批失败只以**字符串**留在 `actions` 里(`weaken_failed:<Type>` / `demote_failed:<Type>`
|
|
14
|
+
/ `demote_state:<error>`),于是**无权身份跑一次即可把 (节点, 污染类型) 永久钉成
|
|
15
|
+
「已处置」**,污染此后**永久不再被处置**(幂等名单被失败污染)。
|
|
16
|
+
|
|
17
|
+
处置(单点 + 不变量):
|
|
18
|
+
· 抽 `_actions_ok(actions)`(`ACTION_FAIL_MARKS` 显式三项,**不通配**);
|
|
19
|
+
· **写侧**两处写真值:`:738` 单条 `ok=_actions_ok(done)`;`:762` 批次
|
|
20
|
+
`ok=(n_failed == 0)`(`n_failed` 由同一次 `_actions_ok` 汇总);
|
|
21
|
+
· **读侧** `_handled` / `summary` **一字不改**,照旧只读 `ok` —— 判据收成单点。
|
|
22
|
+
|
|
23
|
+
★**过度收紧方向**(K1/K5 + M3):`_actions_ok` 恒 False 会把**合法成功处置**误判成
|
|
24
|
+
失败,幂等名单永不记账 ⇒ 每轮重复处置。K1 的反向样本(`["weaken"]`/`["demote"]`/
|
|
25
|
+
无冒号的 `"demote_state"`)就是这条的守卫。
|
|
26
|
+
"""
|
|
27
|
+
import ast
|
|
28
|
+
import io
|
|
29
|
+
import inspect
|
|
30
|
+
import json
|
|
31
|
+
import os
|
|
32
|
+
import shutil
|
|
33
|
+
import subprocess
|
|
34
|
+
import sys
|
|
35
|
+
import tempfile
|
|
36
|
+
|
|
37
|
+
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
38
|
+
|
|
39
|
+
_REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
40
|
+
sys.path.insert(0, _REPO)
|
|
41
|
+
_TMP = tempfile.mkdtemp(prefix="iss411_")
|
|
42
|
+
os.environ.update({"MDCG_STATE_ROOT": os.path.join(_TMP, "state"),
|
|
43
|
+
"MDCG_AUX_ROOT": os.path.join(_TMP, "auxstore"),
|
|
44
|
+
"MDCG_DATA_ROOT": os.path.join(_TMP, "data"),
|
|
45
|
+
"MDCG_EXPORT_ROOT": _TMP,
|
|
46
|
+
"MDCG_SUSTAIN": "0", "MDCG_SLEEP": "0"})
|
|
47
|
+
|
|
48
|
+
from md_cg import _guard_kit # noqa: E402
|
|
49
|
+
from md_cg import scrub # noqa: E402
|
|
50
|
+
from md_cg.mdcos import MdCGSecure # noqa: E402
|
|
51
|
+
from md_cg.mcp_server import call_tool # noqa: E402
|
|
52
|
+
from md_cg.security import Principal # noqa: E402
|
|
53
|
+
|
|
54
|
+
FAILS = []
|
|
55
|
+
_RUN = [0]
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _check(name, cond, detail=""):
|
|
59
|
+
if cond:
|
|
60
|
+
print(" PASS " + name)
|
|
61
|
+
else:
|
|
62
|
+
print(" FAIL " + name + " " + str(detail)[:400])
|
|
63
|
+
FAILS.append(name)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _lib(tag):
|
|
67
|
+
_RUN[0] += 1
|
|
68
|
+
root = os.path.join(_TMP, "%s_%d" % (tag, _RUN[0]))
|
|
69
|
+
os.makedirs(root, exist_ok=True)
|
|
70
|
+
return root
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
#: 有权限身份(建节点 / 正向实修)
|
|
74
|
+
P_YES = Principal(role="designer", clearance="private", can_write=True,
|
|
75
|
+
can_admin=True)
|
|
76
|
+
#: 无权身份:可写层只有 rejected ⇒ knowledge 层的 verify/_move_layer 双双 AccessDenied
|
|
77
|
+
P_NO = Principal(role="verifier", clearance="private", can_write=True,
|
|
78
|
+
layers_allow=("rejected",))
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _mk_cg(root, principal):
|
|
82
|
+
return MdCGSecure(root, principal=principal, autoflush=1)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _seed_expired(root, nid="n_exp"):
|
|
86
|
+
"""建一个`expired`污染节点(severity=high,fix=(weaken, demote))。"""
|
|
87
|
+
import time
|
|
88
|
+
cg = _mk_cg(root, P_YES)
|
|
89
|
+
cg.add(nid, "PASSED 过期条目 ALPHA", layer="knowledge",
|
|
90
|
+
valid_until=time.time() - 86400 * 30, verification_basis="test")
|
|
91
|
+
cg.flush()
|
|
92
|
+
p = os.path.join(root, (cg.get(nid) or {}).get("path") or "")
|
|
93
|
+
cg.close()
|
|
94
|
+
return p
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _scrub(root, principal):
|
|
98
|
+
"""走**真实分发面**:cg(op=scrub, action=decontaminate, dry_run=false)。"""
|
|
99
|
+
cg = _mk_cg(root, principal)
|
|
100
|
+
try:
|
|
101
|
+
return call_tool(cg, "cg", {"op": "scrub", "action": "decontaminate",
|
|
102
|
+
"dry_run": False, "min_severity": "medium"})
|
|
103
|
+
finally:
|
|
104
|
+
cg.close()
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def _sig(root, nid="n_exp"):
|
|
108
|
+
"""节点**处置相关**读数签名(demote 会改层并搬文件,故不能只按固定路径比字节)。"""
|
|
109
|
+
cg = _mk_cg(root, P_YES)
|
|
110
|
+
n = cg.get(nid) or {}
|
|
111
|
+
fm = n.get("frontmatter") or {}
|
|
112
|
+
out = (fm.get("layer"), fm.get("verification_state"),
|
|
113
|
+
fm.get("negative_evidence"), fm.get("confidence"),
|
|
114
|
+
(n.get("content") or "")[:40])
|
|
115
|
+
cg.close()
|
|
116
|
+
return out
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _rows(root):
|
|
120
|
+
p = os.path.join(root, scrub.SCRUB_LOG)
|
|
121
|
+
if not os.path.isfile(p):
|
|
122
|
+
return []
|
|
123
|
+
out = []
|
|
124
|
+
with io.open(p, encoding="utf-8") as f:
|
|
125
|
+
for ln in f:
|
|
126
|
+
ln = ln.strip()
|
|
127
|
+
if ln:
|
|
128
|
+
out.append(json.loads(ln))
|
|
129
|
+
return out
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _get(row, *path):
|
|
133
|
+
cur = row
|
|
134
|
+
for k in path:
|
|
135
|
+
if isinstance(cur, dict):
|
|
136
|
+
cur = cur.get(k)
|
|
137
|
+
else:
|
|
138
|
+
return None
|
|
139
|
+
return cur
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
# ========================================================= A 组:真实分发面
|
|
143
|
+
print("== A 组:无权身份的失败不得写进幂等名单 ==")
|
|
144
|
+
|
|
145
|
+
_root = _lib("a")
|
|
146
|
+
_p = _seed_expired(_root)
|
|
147
|
+
_b0 = io.open(_p, "rb").read()
|
|
148
|
+
_r1 = _scrub(_root, P_NO)
|
|
149
|
+
_b1 = io.open(_p, "rb").read()
|
|
150
|
+
_rows1 = _rows(_root)
|
|
151
|
+
_dec = [r for r in _rows1 if r.get("op") == "decontaminate"]
|
|
152
|
+
_bat = [r for r in _rows1 if r.get("op") == "decontaminate_batch"]
|
|
153
|
+
_done1 = _get(_r1, "actions") or []
|
|
154
|
+
_done1 = [a.get("done") for a in _done1 if a.get("applied")]
|
|
155
|
+
print(" [读数] A1 done=%s 盘面变化=%s" % (_done1, _b0 != _b1))
|
|
156
|
+
_check("A1 无权身份:两个动作都失败(done 带 weaken_failed:/demote_failed:),盘面零变化",
|
|
157
|
+
bool(_done1) and any(str(d).startswith("weaken_failed:") for d in _done1[0])
|
|
158
|
+
and any(str(d).startswith("demote_failed:") for d in _done1[0])
|
|
159
|
+
and _b0 == _b1, (_done1, _b0 == _b1))
|
|
160
|
+
|
|
161
|
+
print(" [读数] A2 _scrub.jsonl decontaminate 行=%s"
|
|
162
|
+
% [(r.get("kind"), r.get("ok"), r.get("actions")) for r in _dec])
|
|
163
|
+
_check("A2 _scrub.jsonl 该行 ok=False(修前无条件 True:失败被写成已处置)",
|
|
164
|
+
len(_dec) == 1 and _dec[0].get("ok") is False
|
|
165
|
+
and any(str(x).startswith("weaken_failed:") for x in (_dec[0].get("actions") or [])),
|
|
166
|
+
_dec)
|
|
167
|
+
|
|
168
|
+
# 下一轮:有权限身份必须**仍然真正处置**(修前会被幂等名单拦成 skip)
|
|
169
|
+
_sig1 = _sig(_root)
|
|
170
|
+
_r2 = _scrub(_root, P_YES)
|
|
171
|
+
_sig2 = _sig(_root)
|
|
172
|
+
print(" [读数] A3 有权限轮 applied=%s already_handled=%s 盘面签名 %s → %s"
|
|
173
|
+
% (_r2.get("applied"), _r2.get("already_handled"), _sig1, _sig2))
|
|
174
|
+
_check("A3 下一轮有权限身份仍**真正处置**(不是「已处置过(幂等)」)",
|
|
175
|
+
(_r2.get("applied") or 0) >= 1
|
|
176
|
+
and (_r2.get("already_handled") or 0) == 0 and _sig1 != _sig2,
|
|
177
|
+
{k: _r2.get(k) for k in ("applied", "already_handled")})
|
|
178
|
+
|
|
179
|
+
_rows2 = _rows(_root)
|
|
180
|
+
_bat2 = [r for r in _rows2 if r.get("op") == "decontaminate_batch"]
|
|
181
|
+
print(" [读数] A4 批次 ok 序列=%s failed_actions=%s"
|
|
182
|
+
% ([r.get("ok") for r in _bat2], [r.get("failed_actions") for r in _bat2]))
|
|
183
|
+
_check("A4 批次记录与子条一致:失败轮 ok=False/failed_actions=1,成功轮 ok=True/0",
|
|
184
|
+
len(_bat2) == 2 and _bat2[0].get("ok") is False
|
|
185
|
+
and _bat2[0].get("failed_actions") == 1
|
|
186
|
+
and _bat2[1].get("ok") is True
|
|
187
|
+
and _bat2[1].get("failed_actions") == 0, _bat2)
|
|
188
|
+
|
|
189
|
+
_dec2 = [r for r in _rows2 if r.get("op") == "decontaminate"]
|
|
190
|
+
print(" [读数] A5 成功轮 done=%s ok=%s"
|
|
191
|
+
% ([a.get("done") for a in (_r2.get("actions") or []) if a.get("applied")],
|
|
192
|
+
[r.get("ok") for r in _dec2]))
|
|
193
|
+
_check("A5 **过度收紧反证**:有权限身份的成功处置仍得 ok=True(含 demote_state: 不在成功路径上)",
|
|
194
|
+
len(_dec2) == 2 and _dec2[1].get("ok") is True
|
|
195
|
+
and (_r2.get("failed_actions") or 0) == 0, _dec2)
|
|
196
|
+
|
|
197
|
+
# ========================================================= K 组:非恒真对照
|
|
198
|
+
print("== K 组:非恒真对照(含**过度收紧**方向)==")
|
|
199
|
+
|
|
200
|
+
_cases = [
|
|
201
|
+
("全成功", ["weaken", "demote"], True),
|
|
202
|
+
("weaken 失败", ["weaken_failed:AccessDenied"], False),
|
|
203
|
+
("demote 失败", ["demote_failed:ProtectionError"], False),
|
|
204
|
+
("demote_state 失败", ["demote_state:denied"], False),
|
|
205
|
+
("混合:一成一败", ["weaken", "demote_failed:OSError"], False),
|
|
206
|
+
("空列表", [], True),
|
|
207
|
+
("None", None, True),
|
|
208
|
+
("反向:动作名不该被误判(无冒号)", ["weaken_failed"], True),
|
|
209
|
+
("反向:demote_state 无冒号", ["demote_state"], True),
|
|
210
|
+
("反向:名字里含 failed 但不在标记表内的合法动作", ["weaken", "verify_failed_once"], True),
|
|
211
|
+
]
|
|
212
|
+
_got = [(c, scrub._actions_ok(v)) for c, v, _ in _cases]
|
|
213
|
+
_bad = [(c, g, w) for (c, v, w), (c2, g) in zip(_cases, _got) if g != w]
|
|
214
|
+
print(" [读数] K1 _actions_ok 十形态=%s" % _got)
|
|
215
|
+
_check("K1 _actions_ok 三失败形态判 False、成功/空/None 判 True,"
|
|
216
|
+
"且**无冒号的同名字面不被误判**(非恒真 + 不过度收紧)",
|
|
217
|
+
not _bad, _bad)
|
|
218
|
+
|
|
219
|
+
# K2:dry_run 语义不退化(不写 decontaminate 记录、盘面零变化、写批次)
|
|
220
|
+
_kroot = _lib("k2")
|
|
221
|
+
_kp = _seed_expired(_kroot, "k2_exp")
|
|
222
|
+
_kb0 = io.open(_kp, "rb").read()
|
|
223
|
+
_cg = _mk_cg(_kroot, P_YES)
|
|
224
|
+
_rd = call_tool(_cg, "cg", {"op": "scrub", "action": "decontaminate",
|
|
225
|
+
"dry_run": True, "min_severity": "medium"})
|
|
226
|
+
_cg.close()
|
|
227
|
+
_krows = _rows(_kroot)
|
|
228
|
+
print(" [读数] K2 dry_run planned=%s 记录=%s 盘面变化=%s"
|
|
229
|
+
% (_rd.get("planned_dry_run"),
|
|
230
|
+
[r.get("op") for r in _krows], _kb0 != io.open(_kp, "rb").read()))
|
|
231
|
+
_check("K2 dry_run 照旧零副作用(无 decontaminate 记录、盘面零变化、无批次记录)",
|
|
232
|
+
(_rd.get("planned_dry_run") or 0) >= 1
|
|
233
|
+
and not [r for r in _krows if r.get("op") == "decontaminate"]
|
|
234
|
+
and _kb0 == io.open(_kp, "rb").read(), _krows)
|
|
235
|
+
|
|
236
|
+
# K3:_handled 只认 ok(读侧单点未被改宽)
|
|
237
|
+
_kroot3 = _lib("k3")
|
|
238
|
+
_cg3 = _mk_cg(_kroot3, P_YES)
|
|
239
|
+
_cg3.add("k3_a", "PASSED 甲", layer="knowledge", verification_basis="test")
|
|
240
|
+
_cg3.flush()
|
|
241
|
+
scrub._log(_cg3, "decontaminate", node_id="k3_a", kind="expired", ok=False,
|
|
242
|
+
actions=["weaken_failed:AccessDenied"])
|
|
243
|
+
_h_after_fail = sorted(scrub._handled(_cg3))
|
|
244
|
+
scrub._log(_cg3, "decontaminate", node_id="k3_a", kind="expired", ok=True,
|
|
245
|
+
actions=["weaken"])
|
|
246
|
+
_h_after_ok = sorted(scrub._handled(_cg3))
|
|
247
|
+
_cg3.close()
|
|
248
|
+
print(" [读数] K3 ok=False 后名单=%s,ok=True 后名单=%s"
|
|
249
|
+
% (_h_after_fail, _h_after_ok))
|
|
250
|
+
_check("K3 _handled 只认 ok:ok=False 的记录不进幂等名单,ok=True 才进",
|
|
251
|
+
_h_after_fail == [] and _h_after_ok == [("k3_a", "expired")],
|
|
252
|
+
(_h_after_fail, _h_after_ok))
|
|
253
|
+
|
|
254
|
+
# K4:summary 不把失败批次算成成功轮
|
|
255
|
+
_sum = scrub.summary(_cg3) if False else None
|
|
256
|
+
_kroot4 = _lib("k4")
|
|
257
|
+
_cg4 = _mk_cg(_kroot4, P_YES)
|
|
258
|
+
scrub._log(_cg4, "decontaminate_batch", ok=False, applied=1, failed_actions=1)
|
|
259
|
+
scrub._log(_cg4, "decontaminate_batch", ok=True, applied=2, failed_actions=0)
|
|
260
|
+
_s4 = scrub.summary(_cg4)
|
|
261
|
+
_cg4.close()
|
|
262
|
+
print(" [读数] K4 batches=%s decontaminated=%s"
|
|
263
|
+
% (_s4.get("batches"), _s4.get("decontaminated")))
|
|
264
|
+
_check("K4 summary 只把 ok=True 的批次算作成功轮(失败批次不进 batches)",
|
|
265
|
+
_s4.get("batches") == 1 and _s4.get("decontaminated") == 2, _s4)
|
|
266
|
+
|
|
267
|
+
# ========================================================= E 组:AST 钉子 / 枚举 / 族登记
|
|
268
|
+
print("== E 组:AST 钉子 · 枚举完备性 · 族登记 ==")
|
|
269
|
+
|
|
270
|
+
_scrub_src = io.open(os.path.join(_REPO, "md_cg", "scrub.py"),
|
|
271
|
+
encoding="utf-8").read()
|
|
272
|
+
_tree = ast.parse(_scrub_src)
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
# 生效条件:node 为 `_log(...)` 调用节点时返回其**第 2 个位置实参**的字符串值(op),非字面量/缺参返回 None;
|
|
276
|
+
def _op_of_log(node):
|
|
277
|
+
"""取 `_log(cg, op, **rec)` 的 op 字面(第 1 个位置实参是 cg)。"""
|
|
278
|
+
if len(node.args) >= 2 and isinstance(node.args[1], ast.Constant):
|
|
279
|
+
return node.args[1].value
|
|
280
|
+
return None
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
#: #411 的 ok 判据面:**只**覆盖这两条记录(`_handled`/`summary` 消费的就是它们)。
|
|
284
|
+
_TARGET_OPS = ("decontaminate", "decontaminate_batch")
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def _log_ok_values(tree, ops=_TARGET_OPS):
|
|
288
|
+
"""`_log(` 调用里 `ok=` 实参的 AST 节点列表,**按 op 收窄**到 `ops`。
|
|
289
|
+
|
|
290
|
+
为什么按 op 收窄:`scrub.py` 还有 `calibrate` / `sweep` 两条记录也写 `ok=`
|
|
291
|
+
字面(:911 等),但它们的 ok **不被任何幂等读面消费**、记录里也没有失败标记
|
|
292
|
+
通道 ⇒ 不属本族(登记见 E5)。把 AST 钉子铺到全部 `_log(` 上会顺手改动
|
|
293
|
+
本 issue 范围外的记录、并让「本族」与「全仓」两个面混成一个。
|
|
294
|
+
"""
|
|
295
|
+
out = []
|
|
296
|
+
for node in ast.walk(tree):
|
|
297
|
+
if (isinstance(node, ast.Call) and isinstance(node.func, ast.Name)
|
|
298
|
+
and node.func.id == "_log"):
|
|
299
|
+
# _log(cg, op, **rec):op 是**第 2 个位置实参**(第 1 个是 cg)
|
|
300
|
+
op = (_op_of_log(node))
|
|
301
|
+
if op not in ops:
|
|
302
|
+
continue
|
|
303
|
+
for kw in node.keywords:
|
|
304
|
+
if kw.arg == "ok":
|
|
305
|
+
out.append(kw.value)
|
|
306
|
+
return out
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
_oks = _log_ok_values(_tree)
|
|
310
|
+
_shapes = [ast.unparse(v) for v in _oks]
|
|
311
|
+
print(" [读数] E1 _log(ok=) 实参形态=%s" % _shapes)
|
|
312
|
+
# 判据是**绑定链**而不是「字面里出现某个子串」(后者用变量中转就能逃过):
|
|
313
|
+
# 单条记录 ok=_ok,而 _ok 由 _actions_ok(done) 绑定;
|
|
314
|
+
# 批次记录 ok=(n_failed == 0),而 n_failed 由 `if not _ok: n_failed += 1` 汇总。
|
|
315
|
+
_chain = ("_ok = _actions_ok(done)" in _scrub_src
|
|
316
|
+
and "if not _ok:" in _scrub_src
|
|
317
|
+
and "n_failed += 1" in _scrub_src)
|
|
318
|
+
_check("E1 AST:decontaminate / decontaminate_batch 两条记录的 _log(ok=) 只能是"
|
|
319
|
+
"_ok / n_failed == 0 且其绑定链落在 _actions_ok(...) 上,不得出现字面 "
|
|
320
|
+
"True/False(calibrate/sweep 两条已核非本族,见 E5)",
|
|
321
|
+
len(_oks) == 2 and set(_shapes) == {"_ok", "n_failed == 0"} and _chain
|
|
322
|
+
and not any(isinstance(v, ast.Constant) for v in _oks),
|
|
323
|
+
(_shapes, _chain))
|
|
324
|
+
|
|
325
|
+
_handled_src = inspect.getsource(scrub._handled)
|
|
326
|
+
print(" [读数] E2 _handled 体=%r" % _handled_src.strip()[:120])
|
|
327
|
+
_check("E2 读侧单点:_handled 的过滤只读 ok(不引入第二份 _actions_ok 判据)",
|
|
328
|
+
'rec.get("ok")' in _handled_src and "_actions_ok" not in _handled_src,
|
|
329
|
+
_handled_src.strip()[:160])
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
#: **守卫侧独立字面表**:三处失败形态的已知全集。刻意**不**引用 scrub.ACTION_FAIL_MARKS
|
|
333
|
+
#: —— 引用被测常量会变成自指(把常量改成两项,枚举判据跟着变两项 ⇒ 永远自洽、抓不到漏形态)。
|
|
334
|
+
_KNOWN_FAIL_MARKS = ("weaken_failed:", "demote_failed:", "demote_state:")
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
def _fail_forms_in_src(src):
|
|
338
|
+
"""源码里的失败形态:扫每个 `done.append(...)` 实参中的**字符串字面量**,
|
|
339
|
+
取其命中 ACTION_FAIL_MARKS 前缀的那些(与 scrub._actions_ok 同一判据)。"""
|
|
340
|
+
hits = []
|
|
341
|
+
for node in ast.walk(ast.parse(src)):
|
|
342
|
+
if (isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute)
|
|
343
|
+
and node.func.attr == "append" and node.args):
|
|
344
|
+
arg = node.args[0]
|
|
345
|
+
for sub in ast.walk(arg):
|
|
346
|
+
if isinstance(sub, ast.Constant) and isinstance(sub.value, str) \
|
|
347
|
+
and sub.value.startswith(_KNOWN_FAIL_MARKS):
|
|
348
|
+
hits.append(sub.value)
|
|
349
|
+
# f-string:JoinedStr 的首段常量为前缀字面
|
|
350
|
+
if isinstance(sub, ast.JoinedStr) and sub.values:
|
|
351
|
+
head = sub.values[0]
|
|
352
|
+
if (isinstance(head, ast.Constant)
|
|
353
|
+
and isinstance(head.value, str)
|
|
354
|
+
and head.value.startswith(_KNOWN_FAIL_MARKS)):
|
|
355
|
+
hits.append(head.value)
|
|
356
|
+
return sorted(set(hits))
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
_forms = _fail_forms_in_src(_scrub_src)
|
|
360
|
+
print(" [读数] E3 源码失败形态=%s 常量元组=%s"
|
|
361
|
+
% (_forms, list(scrub.ACTION_FAIL_MARKS)))
|
|
362
|
+
_check("E3 枚举完备:源码里 done.append 的失败形态**恰为**守卫侧独立字面表的"
|
|
363
|
+
"三项,且 scrub.ACTION_FAIL_MARKS 与之逐项相等(多=常量元组冗余会过度收紧;少=漏形态)",
|
|
364
|
+
sorted(_forms) == sorted(_KNOWN_FAIL_MARKS)
|
|
365
|
+
and sorted(scrub.ACTION_FAIL_MARKS) == sorted(_KNOWN_FAIL_MARKS),
|
|
366
|
+
(_forms, list(scrub.ACTION_FAIL_MARKS)))
|
|
367
|
+
|
|
368
|
+
_wl = io.open(os.path.join(_REPO, "md_cg", "writelimit.py"),
|
|
369
|
+
encoding="utf-8").read()
|
|
370
|
+
_wl_tidy = "def _already_tidied(" in _wl and "TIDY_TAG" in _wl
|
|
371
|
+
_wl_cov = 'already_covered' in _wl
|
|
372
|
+
print(" [读数] E4 writelimit 登记:_already_tidied=%s already_covered=%s"
|
|
373
|
+
% (_wl_tidy, _wl_cov))
|
|
374
|
+
_check("E4 **已核、非本族**登记:writelimit.py:383 _already_tidied 与 :373 "
|
|
375
|
+
"already_covered 判的是**落盘条目字段**(tags/lifecycle_state、content_sink "
|
|
376
|
+
"的字面动作名)而非本轮结果,其通路无「无条件写成功」写侧、也不是审计记录 "
|
|
377
|
+
"⇒ 不需要同款不变量(防将来被误当漏点)",
|
|
378
|
+
_wl_tidy and _wl_cov)
|
|
379
|
+
|
|
380
|
+
#: 非本族的 _log(ok= 字面落点(已核、登记,防将来被误当漏点)。
|
|
381
|
+
_ADJACENT_OK_SITES = ("calibrate", "sweep")
|
|
382
|
+
_other = sorted({_op_of_log(n) for n in ast.walk(_tree)
|
|
383
|
+
if isinstance(n, ast.Call) and isinstance(n.func, ast.Name)
|
|
384
|
+
and n.func.id == "_log" and _op_of_log(n)
|
|
385
|
+
and _op_of_log(n) not in _TARGET_OPS})
|
|
386
|
+
print(" [读数] E5 其余 _log op=%s" % _other)
|
|
387
|
+
_check("E5 **已核、非本族**登记:calibrate / sweep 的 _log(ok=True) 不消费于任何幂等"
|
|
388
|
+
"读面(_handled/summary 只读 decontaminate(_batch))、记录里也无失败标记通道"
|
|
389
|
+
"⇒ 不需同款不变量(防将来被误当漏点)",
|
|
390
|
+
set(_other) == set(_ADJACENT_OK_SITES), _other)
|
|
391
|
+
|
|
392
|
+
# ---- _guard_kit 骨架①:枚举完备性(喂合成样本给**本守卫自己的**枚举逻辑)----
|
|
393
|
+
_enum_samples = [
|
|
394
|
+
("weaken 失败形态",
|
|
395
|
+
'def f(exc):\n done.append(f"weaken_failed:{type(exc).__name__}")\n',
|
|
396
|
+
True, "syn1.py"),
|
|
397
|
+
("demote 失败形态",
|
|
398
|
+
'def f(exc):\n done.append(f"demote_failed:{type(exc).__name__}")\n',
|
|
399
|
+
True, "syn2.py"),
|
|
400
|
+
("demote_state 失败形态",
|
|
401
|
+
'def f(st):\n done.append("demote" if st else f"demote_state:{st}")\n',
|
|
402
|
+
True, "syn3.py"),
|
|
403
|
+
("反向:成功动作名",
|
|
404
|
+
'def f():\n done.append("weaken")\n done.append("demote")\n',
|
|
405
|
+
False, "syn4.py"),
|
|
406
|
+
("反向:无冒号的同名字面",
|
|
407
|
+
'def f():\n done.append("weaken_failed")\n done.append("demote_state")\n',
|
|
408
|
+
False, "syn5.py"),
|
|
409
|
+
]
|
|
410
|
+
_eok, _edet = _guard_kit.assert_enumeration_complete(
|
|
411
|
+
lambda texts: [h for src in texts.values() for h in _fail_forms_in_src(src)],
|
|
412
|
+
_enum_samples)
|
|
413
|
+
print(" [读数] 骨架① 枚举完备性:%s" % (_edet.get("样本"),))
|
|
414
|
+
_check("骨架① assert_enumeration_complete:合成样本三形态全命中、反向样本零命中",
|
|
415
|
+
_eok, _edet)
|
|
416
|
+
|
|
417
|
+
shutil.rmtree(_TMP, ignore_errors=True)
|
|
418
|
+
|
|
419
|
+
print("")
|
|
420
|
+
if FAILS:
|
|
421
|
+
print("issue #411 结果:%d 失败 → %s" % (len(FAILS), ", ".join(FAILS)))
|
|
422
|
+
else:
|
|
423
|
+
print("issue #411 结果:全部通过")
|
|
424
|
+
|
|
425
|
+
# ========================================================= 定点变异(镜像树)
|
|
426
|
+
_MUTATIONS = (
|
|
427
|
+
("M1 回退写侧单条:ok=_ok → ok=True(#411 的修前形态)",
|
|
428
|
+
(("md_cg/scrub.py", ["ok=_ok,"], ["ok=True,"]),),
|
|
429
|
+
("A2", "A3", "A5", "E1")),
|
|
430
|
+
("M2 _actions_ok 恒 True(判据摘除,失败重新写成已处置)",
|
|
431
|
+
(("md_cg/scrub.py",
|
|
432
|
+
[" return not any(str(a).startswith(ACTION_FAIL_MARKS)",
|
|
433
|
+
" for a in (actions or ()))"],
|
|
434
|
+
[" return True"]),),
|
|
435
|
+
# A5 也红:失败轮被写成已处置 ⇒ 下一轮被幂等名单拦成 skip、成功轮不再出现。
|
|
436
|
+
# K1 也红:三形态全判成功(判据被摘除)。
|
|
437
|
+
("A2", "A3", "A4", "A5", "K1")),
|
|
438
|
+
("M3 **过度收紧方向**:_actions_ok 恒 False(合法成功被误判成失败)",
|
|
439
|
+
(("md_cg/scrub.py",
|
|
440
|
+
[" return not any(str(a).startswith(ACTION_FAIL_MARKS)",
|
|
441
|
+
" for a in (actions or ()))"],
|
|
442
|
+
[" return False"]),),
|
|
443
|
+
("A4", "A5", "K1")),
|
|
444
|
+
("M4 读侧把 ok 判据拆掉(失败行重新进幂等名单)",
|
|
445
|
+
(("md_cg/scrub.py",
|
|
446
|
+
[' if rec.get("op") == "decontaminate" and rec.get("ok"):'],
|
|
447
|
+
[' if rec.get("op") == "decontaminate":']),),
|
|
448
|
+
# A5/K3 也红:失败行进了幂等名单 ⇒ 下一轮不再真处置,且 K3 的「ok=False 不进名单」被推翻。
|
|
449
|
+
("A3", "A5", "E2", "K3")),
|
|
450
|
+
("M5 回退批次写侧:ok=(n_failed == 0) → ok=True",
|
|
451
|
+
(("md_cg/scrub.py", ["ok=(n_failed == 0), applied=n_applied,"],
|
|
452
|
+
["ok=True, applied=n_applied,"]),),
|
|
453
|
+
("A4", "E1")),
|
|
454
|
+
("M6 常量元组退回交接规格两项(漏 demote_state: 第三种形态)",
|
|
455
|
+
(("md_cg/scrub.py",
|
|
456
|
+
['ACTION_FAIL_MARKS = ("weaken_failed:", "demote_failed:", "demote_state:")'],
|
|
457
|
+
['ACTION_FAIL_MARKS = ("weaken_failed:", "demote_failed:")']),),
|
|
458
|
+
("E3", "K1")),
|
|
459
|
+
)
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
def _mirror_build():
|
|
463
|
+
dst = tempfile.mkdtemp(prefix="iss411_mut_")
|
|
464
|
+
for name in ("md_cg", "scripts", "data"):
|
|
465
|
+
src = os.path.join(_REPO, name)
|
|
466
|
+
if os.path.isdir(src):
|
|
467
|
+
shutil.copytree(src, os.path.join(dst, name),
|
|
468
|
+
ignore=shutil.ignore_patterns("__pycache__", "*.pyc"))
|
|
469
|
+
for name in sorted(os.listdir(_REPO)):
|
|
470
|
+
p = os.path.join(_REPO, name)
|
|
471
|
+
if os.path.isfile(p) and name.endswith(".py"):
|
|
472
|
+
shutil.copy2(p, os.path.join(dst, name))
|
|
473
|
+
return dst
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
def _nl_of(path):
|
|
477
|
+
with io.open(path, "rb") as fh:
|
|
478
|
+
raw = fh.read(8192)
|
|
479
|
+
return "\r\n" if b"\r\n" in raw else "\n"
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
def _run_in(tree):
|
|
483
|
+
env = dict(os.environ)
|
|
484
|
+
env["PYTHONPATH"] = tree
|
|
485
|
+
env["PYTHONUTF8"] = "1"
|
|
486
|
+
env["PYTHONDONTWRITEBYTECODE"] = "1"
|
|
487
|
+
pr = subprocess.run([sys.executable, "-X", "utf8", "-m",
|
|
488
|
+
"md_cg.test_issue411_scrub_idempotence"],
|
|
489
|
+
capture_output=True, text=True, encoding="utf-8",
|
|
490
|
+
errors="replace", cwd=tree, env=env, timeout=1800)
|
|
491
|
+
out = (pr.stdout or "") + (pr.stderr or "")
|
|
492
|
+
reds = [ln.split("FAIL ", 1)[1].strip()
|
|
493
|
+
for ln in out.splitlines() if "FAIL " in ln]
|
|
494
|
+
return pr.returncode, reds, out
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
# ---- _guard_kit 骨架②:回退即红(实跑,不接受推演)----
|
|
498
|
+
def _skeleton_revert():
|
|
499
|
+
ok, det = _guard_kit.assert_revert_reddens(
|
|
500
|
+
_mirror_build,
|
|
501
|
+
[("md_cg/scrub.py", "ok=_ok,", "ok=True,")],
|
|
502
|
+
_run_in, ("A2", "A3", "A5", "E1"), "md_cg/scrub.py", timeout=1800)
|
|
503
|
+
print(" [读数] 骨架② 回退即红:%s" % json.dumps(
|
|
504
|
+
{k: v for k, v in det.items() if k != "输出尾部"}, ensure_ascii=False,
|
|
505
|
+
default=str)[:400])
|
|
506
|
+
_check("骨架② assert_revert_reddens:把 ok=_actions_ok(done) 实退回 ok=True ⇒ "
|
|
507
|
+
"守卫转红且红项**恰为** A2/A3/A5/E1", ok, det)
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
def _mutate():
|
|
511
|
+
print("!! 定点变异自证:把修复点改回改动前形态,守卫必须转红")
|
|
512
|
+
_skeleton_revert()
|
|
513
|
+
tree = _mirror_build()
|
|
514
|
+
try:
|
|
515
|
+
rc, reds, out = _run_in(tree)
|
|
516
|
+
print(" 未变异镜像基线:rc=%d 红项=%d(必须 rc=0 且 0 红)" % (rc, len(reds)))
|
|
517
|
+
if rc != 0 or reds:
|
|
518
|
+
print(chr(10).join(out.splitlines()[-30:]))
|
|
519
|
+
for ln in out.splitlines():
|
|
520
|
+
if "[读数]" in ln:
|
|
521
|
+
print(" 修后读数(未变异镜像):" + ln.strip())
|
|
522
|
+
okc, bad = 0, []
|
|
523
|
+
for desc, edits, exp in _MUTATIONS:
|
|
524
|
+
backups, miss = [], []
|
|
525
|
+
for rel, oldp, newp in edits:
|
|
526
|
+
p = os.path.join(tree, rel)
|
|
527
|
+
nl = _nl_of(p)
|
|
528
|
+
old, new = nl.join(oldp), nl.join(newp)
|
|
529
|
+
with io.open(p, encoding="utf-8", newline="") as fh:
|
|
530
|
+
t = fh.read()
|
|
531
|
+
if t.count(old) != 1:
|
|
532
|
+
miss.append("%s —— 锚点命中 %d 次" % (rel, t.count(old)))
|
|
533
|
+
continue
|
|
534
|
+
backups.append((p, t))
|
|
535
|
+
with io.open(p, "w", encoding="utf-8", newline="") as fh:
|
|
536
|
+
fh.write(t.replace(old, new, 1))
|
|
537
|
+
if miss:
|
|
538
|
+
bad.append("%s —— %s" % (desc, ";".join(miss)))
|
|
539
|
+
print(" ANCHOR-MISS " + desc)
|
|
540
|
+
for p, t in backups:
|
|
541
|
+
with io.open(p, "w", encoding="utf-8", newline="") as fh:
|
|
542
|
+
fh.write(t)
|
|
543
|
+
continue
|
|
544
|
+
rc2, reds2, out2 = _run_in(tree)
|
|
545
|
+
for p, t in backups:
|
|
546
|
+
with io.open(p, "w", encoding="utf-8", newline="") as fh:
|
|
547
|
+
fh.write(t)
|
|
548
|
+
hit = sorted({e for r in reds2 for e in exp if r.startswith(e + " ")})
|
|
549
|
+
if rc2 != 0 and hit == sorted(exp) and len(reds2) == len(exp):
|
|
550
|
+
okc += 1
|
|
551
|
+
print(" OK %s 红项=%d 指定命中=%d/%d"
|
|
552
|
+
% (desc, len(reds2), len(hit), len(exp)))
|
|
553
|
+
else:
|
|
554
|
+
bad.append(desc)
|
|
555
|
+
print(" MISMATCH %s 红项=%d 指定命中=%d/%d rc=%d"
|
|
556
|
+
% (desc, len(reds2), len(hit), len(exp), rc2))
|
|
557
|
+
for r in reds2[:14]:
|
|
558
|
+
print(" FAIL " + r)
|
|
559
|
+
print("定点变异自证:%s(%d 条不合格)"
|
|
560
|
+
% ("PASS" if not bad else "FAIL", len(bad)))
|
|
561
|
+
for b in bad:
|
|
562
|
+
print(" 不合格:" + b)
|
|
563
|
+
finally:
|
|
564
|
+
shutil.rmtree(tree, ignore_errors=True)
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
def main():
|
|
568
|
+
if "--mutate" in sys.argv:
|
|
569
|
+
_mutate()
|
|
570
|
+
return 1 if FAILS else 0
|
|
571
|
+
return 0 if not FAILS else 1
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
if __name__ == "__main__":
|
|
575
|
+
sys.exit(main())
|