#!/usr/bin/env python3 """HEL-865 负例复现脚本:总管独立复核《HEL-864-独立复核.md》八组 "同一承诺是谁答应又告诉了谁"角色串绑反例。 零真实模型、零网络(socket 硬拒绝 + HF 离线)、零本地嵌入:S6 判据为纯函数 代入(真实 s6_result 构造器同一入口);既有判据不回归部分复用 audit861 的 两组纯函数节(S6 全套正负例 + S2/S3 总判据)、audit862 的四组复核用例、 audit863 的三组复核用例与 audit864 的七组+未结侧镜像及英文正负例。同一 脚本在修复前(070f4fd)与修复后代码上均可运行: 修复前(--phase prefix,在 070f4fd 工作树上运行)→ 总管复核八组反例 (每次仅替换已结/未结一侧,另一侧为原规范正例)全部 pass=true (复现);结构变体(他/我们/承诺动词换词/英文 her/us/we/I/混排多承诺 小句)同缺口复现;省略继承正例与既有用例维持预期 修复后(默认 postfix)→ 八组反例与结构变体全部判失败;省略槽按预声明 回指规则继承的规范正例(含"我还没有收到")保留通过;audit861/862/ 863/864 全部既有正负例、S2/S3 总判据、英文正负例维持预期 补正口径(固定合成语料领域内的有界槽位绑定,预声明场景目标与回指规则): 全量解析不再只产出 promise/closed/open 三类型——每个小句捕获并核准承诺者 主语、告知接收者、动作、对象与状态,全部绑定同一项场景声明(p1 用户原话 "面试结果出来我周五晚上告诉你":承诺者=用户〔答案框架"你"/"you"〕、告知 接收者=伴侣〔"我"/"me"〕、对象=面试结果)。省略槽按预声明回指规则继承: 承诺小句省略主语→承诺者、省略接收者→场景接收者;状态小句按动词类别继承 (tell 类主语=承诺者;receive 类受收方=场景接收者,未结 receive 主语兼容 接收者未收到告知/承诺者未收到结果两读法;fulfill 类主语=承诺者)。明确 不同接收者(现在已经告诉你了/还没有告诉你/told them)、承诺指向他人 (告诉她/her)、承诺方反转(我答应/我承诺/I promised)、多个小句角色冲突、 未知角色(we/我们/他)一律失败;未知也失败;不加八句/人称禁词黑名单, 不新增模型、不做通用自然语言引擎、不重做实验,只约束本实验判据。 退出码真实依赖正负例:除全部用例满足预期外,还对每个用例做翻转自检 (flip 任一用例的实际结果,用例总判必翻转);任一翻转不改变结论则退出 1。 用法:python -m spike.hel857.audit865 [--phase prefix|postfix] [输出json路径] 退出码:prefix=0 当且仅当八组反例与结构变体全部复现(pass=true)且其余 用例维持预期;postfix=0 当且仅当八组+结构变体全部判失败、省略继承正例与 既有判据不回归、翻转自检通过、权威账与既有证据只读未动。权威嵌入账只读 快照核对含逐行摘要(不补种不回退不双扣)。 """ from __future__ import annotations import hashlib import json import os import socket import sqlite3 import subprocess import sys from pathlib import Path REPO = Path(__file__).resolve().parents[2] LEDGER = Path("/home/xiaomo/multica_workspaces/hello-af23464d222e/" "hel-859-1f079e50f551/workdir/audit-data/embed_ledger.sqlite3") os.environ["HEL857_EMBED_LEDGER"] = str(LEDGER) os.environ.setdefault("HF_HUB_OFFLINE", "1") os.environ.setdefault("TRANSFORMERS_OFFLINE", "1") def deny_network(*a, **k): raise RuntimeError("audit865 blocks network") socket.socket.connect = deny_network socket.socket.connect_ex = deny_network from . import ab_scenarios as A from .audit861 import section_s2_s3_no_regression, section_s6_affirmative from .audit862 import (HELD_S2S3_EXPECT, HELD_S6_EXPECT, ORCH6, REVIEW_CASES, REVIEW_NEGATIVE_NAMES) from .audit863 import ADDITIONAL_CASES from .audit864 import (EN_NEGATIVE, EN_POSITIVE, GOOD_CLOSED, GOOD_OPEN, SEVEN_CLOSED, SEVEN_OPEN_MIRROR) OUT = {"real_network_allowed": False, "real_model_requests": 0, "local_embeddings": 0} PHASE = "postfix" def ledger_snapshot(): """权威账只读快照(含逐行摘要:全部行序列化 SHA256,前后核对用)。""" with sqlite3.connect(f"file:{LEDGER}?mode=ro", uri=True) as c: rows = c.execute("select * from embed_ops order by id").fetchall() return {"counts": dict(c.execute("select kind,sum(items) from embed_ops " "group by kind")), "rows": len(rows), "row_digest": hashlib.sha256( json.dumps(rows).encode()).hexdigest()} PRESERVED_EVIDENCE = [ "ab_scenarios_run1.json", "ab_scenarios.json", "rework858_offline.json", "rework859_offline.json", "rework860_offline.json", "audit859_prefix.json", "audit859_postfix.json", "audit859_reuse860.json", "audit860_prefix.json", "audit860_postfix.json", "audit861_prefix.json", "audit861_postfix.json", "audit861_reuse862.json", "audit862_prefix.json", "audit862_postfix.json", "audit861_reuse863.json", "audit863_prefix.json", "audit863_postfix.json", "audit864_prefix.json", "audit864_postfix.json", "audit861_reuse864.json", "gate0_ledger.json", "gate1_backend.json", "gate2_privacy.json", "preflight.json", "resource_manifest_pre.json", "lock-notes.md"] def evidence_hashes(): res = {} for name in PRESERVED_EVIDENCE: p = REPO / "spike/hel857/results" / name res[name] = (hashlib.sha256(p.read_bytes()).hexdigest() if p.exists() else "missing") return res # --------------------------------------------------------------------------- # 总管《HEL-864-独立复核.md》八组反例(原文逐字;每次仅替换已结/未结一侧, # 另一侧为原规范正例,排除其他原因)。同一真实 s6_result 入口。 def s6_answer(s): return {"answer": s, "ok": True} MANAGER_EIGHT = { "recipient_changed_closed": ("你答应周五晚告诉我面试结果,现在已经告诉你了。", GOOD_OPEN), "recipient_changed_open": (GOOD_CLOSED, "你答应周五晚告诉我面试结果,还没有告诉你。"), "promise_to_someone_else_closed": ("你答应周五晚告诉她面试结果,现在已经告诉我了。", GOOD_OPEN), "promise_to_someone_else_open": (GOOD_CLOSED, "你答应周五晚告诉她面试结果,还没有告诉我。"), "promisor_reversed_closed": ("我答应周五晚告诉你面试结果,现在已经告诉你了。", GOOD_OPEN), "promisor_reversed_open": (GOOD_CLOSED, "我答应周五晚告诉你面试结果,还没有告诉你。"), "english_other_recipient_closed": ("You promised to tell me the interview result, " "and you have already told them.", GOOD_OPEN), "english_other_recipient_open": (GOOD_CLOSED, "You promised to tell me the interview result, " "but you haven't told them yet."), } # 结构变体(证明按角色类绑定而非八句/人称黑名单:同一缺口换代词/换承诺 # 动词/英文换格/混排多承诺小句,修前同样误判成功;both_sides_ta 与 # unknown_subject_ta 在 070f4fd 已被 HEL-864 语法判失败,作双期负例保留)。 STRUCTURAL_NEGATIVES = { "structural_recv_ta_closed": ("你答应周五晚告诉他面试结果,现在已经告诉我了。", GOOD_OPEN), "structural_recv_women_open": (GOOD_CLOSED, "你答应周五晚告诉我们面试结果,还没有告诉我。"), "structural_both_sides_ta_open": (GOOD_CLOSED, "你答应周五晚告诉她面试结果,还没有告诉她。"), "structural_promisor_reversed_chengnuo_closed": ("我承诺周五晚告诉你面试结果,现在已经告诉你了。", GOOD_OPEN), "structural_en_promise_to_her_closed": ("You promised to tell her the interview result, " "and you have already told me.", GOOD_OPEN), "structural_en_recv_us_closed": ("You promised to tell me the interview result, " "and you have already told us.", GOOD_OPEN), "structural_en_unknown_subject_we_closed": ("We promised to tell me the interview result, " "and you have already told me.", GOOD_OPEN), "structural_en_closed_tell_subject_i_closed": ("You promised to tell me the interview result, " "and I have already told you.", GOOD_OPEN), "structural_zh_open_tell_subject_wo_open": (GOOD_CLOSED, "你答应周五晚告诉我面试结果,我还没有告诉你。"), "structural_zh_open_fulfill_subject_wo_open": (GOOD_CLOSED, "你答应周五晚告诉我面试结果,我还没兑现。"), "structural_en_closed_receive_subject_you_closed": ("You promised to tell me the interview result, " "and you have received the result.", GOOD_OPEN), "structural_mixed_promise_recipients_closed": ("你答应周五晚告诉她面试结果,你答应周五晚告诉我面试结果," "现在已经告诉我了。", GOOD_OPEN), "structural_unknown_subject_ta_closed": ("他答应周五晚告诉我面试结果,现在已经告诉我了。", GOOD_OPEN), } # 070f4fd 已判失败(维持负例,两期极性固定): STRUCTURAL_ALWAYS_NEGATIVE = ( "structural_both_sides_ta_open", "structural_en_closed_receive_subject_you_closed", "structural_unknown_subject_ta_closed") # 省略槽按预声明回指规则继承的规范正例(主语/接收者省略、"我还没有收到" # 等已接受等价表达、裸回指/话题形态;两期均须通过——证明绑定按槽位而非 # 按字面禁词)。 EGC = ("You promised to tell me the interview result, " "and you have already told me.") EGO = ("You promised to tell me the interview result, " "but you haven't told me yet.") OMISSION_INHERIT_POSITIVES = { "omit_p_receiver_closed": ("你答应周五晚告诉面试结果,现在已经告诉我了。", GOOD_OPEN), "omit_p_subject_closed": ("答应周五晚告诉我面试结果,现在已经告诉我了。", GOOD_OPEN), "omit_state_receiver_closed": ("你答应周五晚告诉我面试结果,现在已经告诉了。", GOOD_OPEN), "omit_open_receiver_open": (GOOD_CLOSED, "你答应周五晚告诉我面试结果,还没有告诉。"), "omit_open_receive_subject_open": (GOOD_CLOSED, "你答应周五晚告诉我面试结果,还没有收到。"), "bare_anaphor_closed": ("你答应周五晚告诉我面试结果,结果已收到。", GOOD_OPEN), "topic_tell_closed": ("你答应周五晚告诉我面试结果,面试结果已经告诉我了。", GOOD_OPEN), "omit_en_open_receive_subject_open": (EGC, "You promised to tell me the interview result, " "haven't received it yet."), "en_closed_receive_i_closed": ("You promised to tell me the interview result, " "and I have received it.", EGO), } # 总管 review864.py 既有变体(070f4fd 已拒绝,不回归)+ 规范正例。 P_PREFIX = "你答应周五晚告诉我面试结果," HELD_VARIANTS = { "variant_other_object": P_PREFIX + "血压现在已经告诉我了。", "variant_afterthought": P_PREFIX + "已经告诉我了血压。", "variant_denial": P_PREFIX + "现在已经告诉我了,这并不是真的。", "variant_opposite_closed": P_PREFIX + "现在已经告诉我了,还没有告诉我。", "variant_question_no_mark": P_PREFIX + "现在已经告诉我了吧", "variant_condition": "除非你答应周五晚告诉我面试结果,现在已经告诉我了。", } def _record(name: str, resolved: str, unresolved: str, expected: bool) -> dict: result = A.s6_result(ORCH6, s6_answer(resolved), s6_answer(unresolved)) return { "resolved_input": resolved, "unresolved_input": unresolved, "expected_pass": expected, "actual_pass": result["pass"], "resolved_parse": A.parse_supported_answer(resolved), "unresolved_parse": A.parse_supported_answer(unresolved), "result": result, } def section_manager_eight() -> dict: """八组反例:prefix 期预期 pass=true(复现),postfix 期判失败。""" return {name: _record(name, r, u, PHASE == "prefix") for name, (r, u) in MANAGER_EIGHT.items()} def section_structural() -> dict: """结构变体:same-class 换形(prefix 复现/ postfix 失败)与双期负例。""" out = {} for name, (r, u) in STRUCTURAL_NEGATIVES.items(): expected = (False if name in STRUCTURAL_ALWAYS_NEGATIVE else PHASE == "prefix") out[name] = _record(name, r, u, expected) return out def section_omission_positives() -> dict: """省略继承正例:两期均须通过(绑定按槽位+预声明回指,不按字面禁词)。""" return {name: _record(name, r, u, True) for name, (r, u) in OMISSION_INHERIT_POSITIVES.items()} def section_held_previous() -> dict: """audit864 七组+镜像(070f4fd 已判失败,极性固定)与英文正负例。""" out = {} for name, closed in SEVEN_CLOSED.items(): out[f"eightyfour.{name}"] = _record(name, closed, GOOD_OPEN, False) for name, opened in SEVEN_OPEN_MIRROR.items(): out[f"eightyfour.{name}"] = _record(name, GOOD_CLOSED, opened, False) if PHASE == "postfix": for name, (r, u) in EN_POSITIVE.items(): out[f"eightyfour.en.{name}"] = _record(name, r, u, True) for name, (r, u) in EN_NEGATIVE.items(): out[f"eightyfour.en.{name}"] = _record(name, r, u, False) return out def section_held_rounds() -> dict: """HEL-862 四组与 HEL-863 三组:070f4fd 已按预期判失败,极性固定。""" out = {} for name, (closed, opened) in REVIEW_CASES.items(): out[f"review.{name}"] = _record( name, closed, opened, name not in REVIEW_NEGATIVE_NAMES) for name, closed in ADDITIONAL_CASES.items(): out[f"additional.{name}"] = _record( name, closed, "你答应周五晚告诉我面试结果,还没有告诉我。", False) return out def section_held_variants() -> dict: """总管 review864.py 既有变体(不回归)与规范正例。""" out = {f"variant.{name}": _record(name, v, GOOD_OPEN, False) for name, v in HELD_VARIANTS.items()} out["variant.canonical_positive"] = _record( "canonical_positive", GOOD_CLOSED, GOOD_OPEN, True) return out def _case_table() -> tuple[dict, dict]: """全部用例的实际 pass 与预期极性(退出码公式输入)。""" table: dict[str, bool] = {} expect: dict[str, bool] = {} for prefix, section in ( ("manager8", OUT["manager_eight"]), ("structural", OUT["structural_variants"]), ("omission", OUT["omission_positives"]), ("held864", OUT["held_previous"]), ("held_rounds", OUT["held_rounds"]), ("held_variants", OUT["held_variants"])): for name, c in section.items(): key = f"{prefix}.{name}" table[key] = bool(c["actual_pass"]) expect[key] = bool(c["expected_pass"]) for name, res in OUT["held_s6_affirmative"].items(): key = f"held_s6.{name}" table[key] = bool(res["pass"]) expect[key] = HELD_S6_EXPECT[name] for name, res in OUT["held_s2_s3_no_regression"].items(): key = f"held_s2s3.{name}" table[key] = bool(res["pass"]) expect[key] = HELD_S2S3_EXPECT[name] return table, expect def _all_cases_match(table: dict, expect: dict) -> bool: return all(table[k] == expect[k] for k in expect) def _flip_dependence(table: dict, expect: dict) -> dict: """翻转自检:任一用例实际值翻转必须改变用例总判(退出码真实依赖正负例)。""" base = _all_cases_match(table, expect) flips = {} for k in expect: flipped = dict(table) flipped[k] = not flipped[k] flips[k] = _all_cases_match(flipped, expect) != base return {"base_all_match": base, "every_flip_changes_verdict": all( flips.values()), "per_case": flips} # --------------------------------------------------------------------------- def main(argv: list[str]) -> dict: global PHASE argv = list(argv) rest: list[str] = [] PHASE = "postfix" it = iter(argv[1:]) for tok in it: if tok == "--phase": PHASE = next(it, "postfix") elif tok.startswith("--phase="): PHASE = tok.split("=", 1)[1] elif not tok.startswith("--"): rest.append(tok) args = rest OUT["phase"] = PHASE commit = subprocess.run(["git", "rev-parse", "HEAD"], capture_output=True, text=True, cwd=str(REPO)).stdout.strip() OUT["commit"] = commit OUT["ledger_before"] = ledger_snapshot() OUT["preserved_evidence_before"] = evidence_hashes() OUT["manager_eight"] = section_manager_eight() OUT["structural_variants"] = section_structural() OUT["omission_positives"] = section_omission_positives() OUT["held_previous"] = section_held_previous() OUT["held_rounds"] = section_held_rounds() OUT["held_variants"] = section_held_variants() OUT["held_s6_affirmative"] = section_s6_affirmative() OUT["held_s2_s3_no_regression"] = section_s2_s3_no_regression() table, expect = _case_table() OUT["case_expect"] = {k: bool(v) for k, v in expect.items()} OUT["case_actual"] = {k: bool(v) for k, v in table.items()} OUT["all_cases_match_expectation"] = _all_cases_match(table, expect) OUT["flip_dependence"] = _flip_dependence(table, expect) OUT["ledger_after"] = ledger_snapshot() OUT["ledger_unchanged"] = OUT["ledger_before"] == OUT["ledger_after"] OUT["preserved_evidence_after"] = evidence_hashes() OUT["preserved_evidence_unchanged"] = ( OUT["preserved_evidence_before"] == OUT["preserved_evidence_after"]) me = OUT["manager_eight"] st = OUT["structural_variants"] om = OUT["omission_positives"] # ---- prefix:八组反例全部复现(pass=true)---- eight_reproduced = all(c["actual_pass"] for c in me.values()) # ---- postfix:八组反例全部判失败 ---- eight_rejected = not any(c["actual_pass"] for c in me.values()) # 结构变体:prefix 期同缺口复现、postfix 期全部判失败(双期负例除外, # 其极性由 all_cases_match_expectation 核对) structural_reproduced = all( st[n]["actual_pass"] for n in st if n not in STRUCTURAL_ALWAYS_NEGATIVE) structural_rejected = not any(c["actual_pass"] for c in st.values()) # 省略继承正例与规范正例保留 positives_kept = (all(c["actual_pass"] for c in om.values()) and OUT["held_variants"]["variant.canonical_positive"][ "actual_pass"]) OUT["summary"] = { "phase": PHASE, "eight_reproduced": eight_reproduced, "eight_rejected": eight_rejected, "structural_variants_reproduced": structural_reproduced, "structural_variants_rejected": structural_rejected, "omission_inheritance_positives_kept": positives_kept, "all_cases_match_expectation": OUT["all_cases_match_expectation"], "flip_dependence_holds": OUT["flip_dependence"][ "every_flip_changes_verdict"], "ledger_unchanged": OUT["ledger_unchanged"], "preserved_evidence_unchanged": OUT["preserved_evidence_unchanged"], "pass": (eight_reproduced and structural_reproduced and PHASE == "prefix" and OUT["all_cases_match_expectation"] and OUT["flip_dependence"]["every_flip_changes_verdict"] and OUT["ledger_unchanged"] and OUT["preserved_evidence_unchanged"]) or (eight_rejected and structural_rejected and positives_kept and PHASE == "postfix" and OUT["all_cases_match_expectation"] and OUT["flip_dependence"]["every_flip_changes_verdict"] and OUT["ledger_unchanged"] and OUT["preserved_evidence_unchanged"]), } out_path = Path(args[0]) if args else ( REPO / "spike/hel857/results/" f"audit865_{'prefix' if PHASE == 'prefix' else 'postfix'}.json") out_path.parent.mkdir(parents=True, exist_ok=True) out_path.write_text(json.dumps(OUT, ensure_ascii=False, indent=2), encoding="utf-8") print(json.dumps(OUT["summary"] | {"out": str(out_path)}, ensure_ascii=False)) return OUT if __name__ == "__main__": raise SystemExit(0 if main(sys.argv)["summary"]["pass"] else 1)