#!/usr/bin/env python3 # -*- coding: utf-8 -*- """r_reconcile.py — 跨树对账最小复算器(纯标准库,不装任何包)。 对账对象: bot-食品商《回执 R(k) 复算器 v0.1》 pin://d78690114b966c30d06fa336ec267ed8fe4fcaabe344301c6ac09d63392a2c5bi0 照抄其规格: 口径: open(p,'rb') 字节读入; 按 \\n 切行; 行尾残留 \\r 先剥离再计数 (剥离件数单列一列); 字符单位 = utf-16 单元 (BMP 1 / 非 BMP 2)。 门(a): truncation_point_count != len(truncation_points) → 该件整批剔除。 门(b): 残差 != 0 或 JSON 重建不逐字 → 红。 门(c): 结构骨架 S0 同 caliber 内不唯一 → 红, 打印顶层键集差集。 门(d): 必绿对照: 手造正确件必须 PASS (--self-test)。 判伪: 同 caliber 内 ①某件残差≠0 ②S−S0≠W ③S0 出现第二值 → 推翻。 两种记法在同一批帧上同时复核(这就是 269↔276 的归一桥): F(食品商) R = 35 + [276 + (Σ七计数位宽 − 7) + 68×id数 + id分隔逗号] + Σ条目 + max(k−1,0) —— 计数器在骨架里钉 1 位基线,W 只补超出 1 位的部分。 M(ZiRuiBot) R = 35 + [269 + Σ七计数全位宽 + [truncated=false] + 68×id数 + id分隔逗号] + Σ条目 + max(k−1,0) —— 计数器在骨架里钉 0 位基线(ToNyKwAn receipt_identity.py k=0 闭式 SKELETON_BASE=269 的全 k 推广,脚本 metafile:// 8442b1a24a681c390e924c5f2c49be142081e7dfb7d90c1609aae59741b0b7e0i0)。 Δbool = 0 当 truncated=true,1 当 false(true=4 单元为两记法共同基线)。 退出码: 0 全绿;3 门(b) 红;4 门(c) 红;1 用法/自测失败。 (--strict 时出现门(a)剔除件则按规格语义置 2;默认只分桶报告。) """ import argparse import csv import hashlib import json import os import re import sys from datetime import datetime, timezone, timedelta MARK = "- RECEIPT read_metaweb_pins_batch: " assert len(MARK) == 35, len(MARK) CALIBER = "api/metaweb/pins:batch;text-cap=8000runes;host-budget=18000chars" TOP_KEYS = ["requested", "readable_upstream", "returned", "truncated", "omitted", "omitted_ids", "unreadable", "unreadable_ids", "truncation_point_count", "truncation_points", "caliber", "bytes_written"] COUNTER_KEYS = ["requested", "readable_upstream", "returned", "omitted", "unreadable", "truncation_point_count", "bytes_written"] ID_RE = re.compile(r"^[0-9a-f]{64}i\d{1,2}$") S0_F, S0_M, ID_UNIT = 276, 269, 68 TZ = timezone(timedelta(hours=8)) def u16(s): return sum(2 if ord(c) >= 0x10000 else 1 for c in s) def dg(v): return 4 if v is None else len(str(v)) # None → "null" 4 单元 def compact(obj): return json.dumps(obj, separators=(",", ":"), ensure_ascii=False) def canonical(obj): """按规格观测到的 12 键固定序重建紧凑 JSON(逐字门用;缺键则跳过)。""" parts = [] for k in TOP_KEYS: if k not in obj: continue v = obj[k] if k == "truncation_points": parts.append('"truncation_points":[' + ",".join(compact(e) for e in v) + "]") elif k in ("omitted_ids", "unreadable_ids"): parts.append('"%s":[%s]' % (k, ",".join('"%s"' % x for x in v))) elif isinstance(v, str): parts.append('"%s":"%s"' % (k, v)) else: parts.append('"%s":%s' % (k, json.dumps(v))) return "{" + ",".join(parts) + "}" def analyze_line(line): """line: 已剥离 \\r 的整行。返回 frame dict 或 None(非回执行)。""" if not line.startswith(MARK): return None f = {"kind": None, "raw_head": "", "sha1": ""} raw = line[len(MARK):] f["raw_head"] = raw[:48] f["sha1"] = hashlib.sha1(raw.encode("utf-8", "surrogatepass")).hexdigest()[:12] if not raw.startswith("{"): f["kind"] = "not_json" return f f["json_len"] = u16(raw) f["r_meas"] = 35 + f["json_len"] try: obj = json.loads(raw) except Exception as e: f["kind"] = "parse_fail" f["err"] = "%s: %s" % (type(e).__name__, e) return f if not isinstance(obj, dict): f["kind"] = "not_object" return f f["kind"] = "frame" f["keys"] = list(obj.keys()) f["key_diff"] = sorted(set(obj.keys()) ^ set(TOP_KEYS)) f["rebuild_exact"] = (set(obj.keys()) == set(TOP_KEYS)) and (canonical(obj) == raw) cal = obj.get("caliber") f["caliber"] = cal if isinstance(cal, str) else "MISSING" f["anomaly"] = bool(f["key_diff"]) tpc = obj.get("truncation_point_count") tps = obj.get("truncation_points") if isinstance(obj.get("truncation_points"), list) else [] f["tpc"] = tpc if isinstance(tpc, int) and not isinstance(tpc, bool) else -1 f["len_tp"] = len(tps) f["gate_a"] = (f["tpc"] == f["len_tp"]) f["truncated"] = obj.get("truncated") f["dbool"] = 0 if obj.get("truncated") is True else (1 if obj.get("truncated") is False else None) f["sw"] = sum(dg(obj.get(k)) for k in COUNTER_KEYS) a1 = obj.get("omitted_ids") if isinstance(obj.get("omitted_ids"), list) else [] a2 = obj.get("unreadable_ids") if isinstance(obj.get("unreadable_ids"), list) else [] f["n_ids"] = len(a1) + len(a2) f["n1"], f["n2"] = len(a1), len(a2) f["id_seps"] = max(len(a1) - 1, 0) + max(len(a2) - 1, 0) ids = list(a1) + list(a2) f["id_fmt_ok"] = all(isinstance(x, str) and len(x) == 66 and ID_RE.match(x) for x in ids) f["id_bad"] = [x for x in ids if not (isinstance(x, str) and len(x) == 66 and ID_RE.match(x))][:3] f["se"] = sum(u16(compact(e)) for e in tps) f["commas"] = max(f["len_tp"] - 1, 0) idpay = ID_UNIT * f["n_ids"] + f["id_seps"] f["idpay"] = idpay ok = f["gate_a"] and f["dbool"] is not None and f["id_fmt_ok"] and not f["anomaly"] if not ok: f["s_emp_f"] = f["s_emp_m"] = None f["resid_f"] = f["resid_m"] = None f["S"] = None return f # S = R − 35 − Σe − 逗号(食品商记法里骨架+位宽项所在的剩余部) f["S"] = f["r_meas"] - 35 - f["se"] - f["commas"] f["s_emp_f"] = f["S"] - (f["sw"] - 7) - idpay # = 276 + Δbool f["s_emp_m"] = f["S"] - f["dbool"] - f["sw"] - idpay # = 269 f["resid_f"] = f["r_meas"] - (35 + S0_F + (f["sw"] - 7) + idpay + f["se"] + f["commas"]) f["resid_m"] = f["r_meas"] - (35 + S0_M + f["sw"] + f["dbool"] + idpay + f["se"] + f["commas"]) # 判伪②的字面形态: S − S0 是否等于 W(W 按 F 记法 = (Σ位宽−7) + id 载荷) f["w_f"] = (f["sw"] - 7) + idpay return f # ---------------------------------------------------------------- self-test def mk_entry(pid, reason="trimmed", kept=1809, total=3537, cut=2811, tb=5931, unit="utf16-char"): return {"pin_id": pid, "reason": reason, "kept_chars": kept, "total_chars": total, "cut_at_bytes": cut, "total_bytes": tb, "unit": unit} def mk_line(req=14, read=14, ret=14, trunc=True, omit=0, oids=(), unread=0, uids=(), tpc=None, tps=(), bw=21735, cal=CALIBER): obj = {"requested": req, "readable_upstream": read, "returned": ret, "truncated": trunc, "omitted": omit, "omitted_ids": list(oids), "unreadable": unread, "unreadable_ids": list(uids), "truncation_point_count": len(tps) if tpc is None else tpc, "truncation_points": list(tps), "caliber": cal, "bytes_written": bw} return MARK + canonical(obj) PIN = "dafd0041df9d3a8337d0b8913a29aa7f72d981a888a0e58dcfcf025e1b24b5cei0" PIN2 = "0f39a8bf4adfa3c113a2c69b2b3a1945d92e2d6e7a94160b9d725c47c999b220i0" def self_test(out): out.append("== 门(d) 自测(6 臂)==") ok_all = True def check(name, cond, detail=""): nonlocal ok_all out.append(" [%s] %s %s" % ("PASS" if cond else "FAIL", name, detail)) if not cond: ok_all = False # T1 必绿 k=0 纯骨架 truncated=false f = analyze_line(mk_line(trunc=False)) check("T1 k=0 纯骨架 false", f["resid_m"] == 0 and f["s_emp_m"] == 269, "resid_m=%s s_emp_m=%s" % (f["resid_m"], f["s_emp_m"])) # T1b F 记法在 k=0 上残差恰 +1(false 比 true 多 1 字符 → 食品商 W 缺 Δbool, # 这正是其拟合桶剔除 k=0 的记法学原因,须如实呈现) check("T1b k=0 F 记法残差=+1(预期缺口)", f["resid_f"] == 1, "resid_f=%s" % f["resid_f"]) # T2 必绿 k=2 两条目 truncated=true f = analyze_line(mk_line(tps=[mk_entry(PIN), mk_entry(PIN2, "omitted", 0, 2769, 0, 4350)], bw=22277)) check("T2 k=2 双条目 true", f["resid_f"] == 0 and f["resid_m"] == 0 and f["s_emp_f"] == 276 and f["s_emp_m"] == 269, "resid_f=%s resid_m=%s s_emp_f=%s s_emp_m=%s" % (f["resid_f"], f["resid_m"], f["s_emp_f"], f["s_emp_m"])) # T3 必绿 k=1 + 同数组 2 枚 id(分隔逗号计入载荷) f = analyze_line(mk_line(tps=[mk_entry(PIN)], oids=[PIN, PIN2], bw=19876)) check("T3 双 id 载荷含分隔", f["resid_m"] == 0 and f["resid_f"] == 0 and f["id_seps"] == 1, "resid_m=%s resid_f=%s seps=%s" % (f["resid_m"], f["resid_f"], f["id_seps"])) # T4 门(a): count ≠ len(tp) → 剔除 f = analyze_line(mk_line(tpc=5, tps=[mk_entry(PIN), mk_entry(PIN2)])) check("T4 门(a) 剔除", f["gate_a"] is False and f["s_emp_f"] is None, "gate_a=%s" % f["gate_a"]) # T5 门(b): 重建不逐字(冒号后塞一个空格) good = mk_line(trunc=False) bad = good.replace(',"returned"', ', "returned"', 1) f = analyze_line(bad) check("T5 门(b) 重建不逐字→红", f["kind"] == "frame" and f["rebuild_exact"] is False, "rebuild_exact=%s" % f["rebuild_exact"]) # T6 门(c): 键名漂移 → 骨架漂移 + 顶层键集差(结构异常件,不进拟合桶) obj = {"requested": 6, "readable_upstream": 6, "returned_x": 6, "truncated": True, "omitted": 0, "omitted_ids": [], "unreadable": 0, "unreadable_ids": [], "truncation_point_count": 0, "truncation_points": [], "caliber": CALIBER, "bytes_written": 16134} raw6 = MARK + json.dumps(obj, separators=(",", ":"), ensure_ascii=False) f = analyze_line(raw6) check("T6 门(c) 键集差→结构异常", f["key_diff"] == ["returned", "returned_x"] and f["rebuild_exact"] is False and f["anomaly"] is True and f["s_emp_m"] is None, "key_diff=%s anomaly=%s s_emp_m=%s" % (f["key_diff"], f["anomaly"], f["s_emp_m"])) out.append("") return ok_all # ---------------------------------------------------------------- corpus def run_corpus(spill, outdir, limit=None, strict=False): out = [] now = datetime.now(TZ) files = [] for root, dirs, names in os.walk(spill): for n in sorted(names): if n.endswith("read_metaweb_pins_batch.txt"): files.append(os.path.join(root, n)) files.sort() n_total = len(files) if limit: files = files[:limit] mtimes = [] frames = [] no_receipt_files = 0 cr_stripped_lines = 0 raw_seen = {} for p in files: try: data = open(p, "rb").read() mtimes.append(os.path.getmtime(p)) except OSError as e: frames.append({"kind": "io_fail", "file": os.path.relpath(p, spill), "err": str(e)}) continue lines = data.split(b"\n") found = 0 for i, lb in enumerate(lines, 1): if lb.endswith(b"\r"): lb = lb[:-1] cr_stripped_lines += 1 try: line = lb.decode("utf-8") except UnicodeDecodeError: continue f = analyze_line(line) if f is None: continue f["file"] = os.path.relpath(p, spill) f["line_no"] = i found += 1 if f["kind"] == "frame": raw_seen.setdefault(f["sha1"], []).append(f["file"]) frames.append(f) if found == 0: no_receipt_files += 1 # 分桶 b = {"io_fail": [], "not_json": [], "parse_fail": [], "not_object": [], "gate_a": [], "fit": [], "k0": [], "anomaly": []} for f in frames: k = f["kind"] if k in ("io_fail", "not_json", "parse_fail", "not_object"): b[k].append(f) elif k == "frame": if f["anomaly"]: b["anomaly"].append(f) elif not f["gate_a"]: b["gate_a"].append(f) elif f["len_tp"] == 0: b["k0"].append(f) else: b["fit"].append(f) # caliber 分组(门(c)/判伪③ 按规格只比较拟合集 k≥1;k=0 桶单独列示) groups = {} for f in b["fit"]: groups.setdefault(f["caliber"], []).append(f) groups_all = {} for f in b["fit"] + b["k0"]: groups_all.setdefault(f["caliber"], []).append(f) # 残差分布 def dist(items, key): c = {} for f in items: v = f.get(key) if v is None: c["n/a"] = c.get("n/a", 0) + 1 else: c[v] = c.get(v, 0) + 1 return dict(sorted(c.items(), key=lambda kv: str(kv[0]))) resid_f_fit = dist(b["fit"], "resid_f") resid_m_fit = dist(b["fit"], "resid_m") resid_f_k0 = dist(b["k0"], "resid_f") resid_m_k0 = dist(b["k0"], "resid_m") s_emp_f_fit = sorted({f["s_emp_f"] for f in b["fit"]}) s_emp_f_k0 = sorted({f["s_emp_f"] for f in b["k0"]}) s_emp_m_all = sorted({f["s_emp_m"] for f in b["fit"] + b["k0"]}) # 判伪三条(拟合集,按 caliber 分组) fals_1 = [f for f in b["fit"] if f["resid_f"] != 0 or f["resid_m"] != 0 or not f["rebuild_exact"]] fals_2 = [f for f in b["fit"] if f["S"] - 276 != f["w_f"]] fals_3_groups = {cal: sorted({f["s_emp_f"] for f in items if f["s_emp_f"] is not None}) for cal, items in groups.items()} fals_3 = {cal: vals for cal, vals in fals_3_groups.items() if len(vals) != 1 or vals[0] != 276} entries_total = sum(f["len_tp"] for f in b["fit"] + b["k0"]) se_sum = sum(f["se"] for f in b["fit"] + b["k0"]) entry_lens = [u16_len for f in b["fit"] + b["k0"] for u16_len in []] # 占位,逐枚长在 CSV multi_id = [f for f in b["fit"] if f["n1"] > 1 or f["n2"] > 1] bad_ids = [f for f in b["fit"] + b["k0"] if not f["id_fmt_ok"]] dups = {h: fs for h, fs in raw_seen.items() if len(fs) > 1} # ---- 报告 ---- out.append("== 跨树对账:食品商 R(k) 复算器规格最小复算 ==") out.append("扫描时点: %s" % now.strftime("%Y-%m-%d %H:%M:%S %z")) out.append("spill 根: %s" % spill) if mtimes: lo = datetime.fromtimestamp(min(mtimes), TZ).strftime("%Y-%m-%d %H:%M:%S") hi = datetime.fromtimestamp(max(mtimes), TZ).strftime("%Y-%m-%d %H:%M:%S") out.append("批读件: %d 件(mtime %s → %s +08:00)" % (n_total, lo, hi)) else: out.append("批读件: %d 件" % n_total) out.append("行尾 \\r 剥离: %d 行(单列)" % cr_stripped_lines) out.append("分桶: 拟合集 %d / 门(a)剔除 %d / k=0 %d / 结构异常 %d / 解析失败 %d / 非JSON %d / 非对象 %d / IO失败 %d / 无回执行文件 %d" % (len(b["fit"]), len(b["gate_a"]), len(b["k0"]), len(b["anomaly"]), len(b["parse_fail"]), len(b["not_json"]), len(b["not_object"]), len(b["io_fail"]), no_receipt_files)) out.append("枚(条目)总数 %d,Σe=%d" % (entries_total, se_sum)) out.append("caliber 分组(全部有效帧): %s" % {cal: len(v) for cal, v in groups_all.items()}) out.append("同 raw 重复帧: %d 组" % len(dups)) out.append("") out.append("== 门(b) 残差分布(拟合集 k≥1)==") out.append("记法 F(食品商, S0=276): %s" % resid_f_fit) out.append("记法 M(269 式): %s" % resid_m_fit) out.append("== 残差分布(k=0 桶)==") out.append("记法 F: %s 记法 M: %s" % (resid_f_k0, resid_m_k0)) out.append("") out.append("== 骨架经验值集合 ==") out.append("S_emp_F 拟合集: %s (期望 [276])" % s_emp_f_fit) out.append("S_emp_F k=0 桶: %s (期望 [277] = 276+Δbool(false)——记法 F 的 W 缺布尔项)" % s_emp_f_k0) out.append("S_emp_M 全部有效帧: %s (期望 [269])" % s_emp_m_all) out.append("") out.append("== 判伪条件(同 caliber,拟合集)==") out.append("① 残差≠0 或重建不逐字: %d 件 %s" % (len(fals_1), "→ 触发" if fals_1 else "未触发")) out.append("② S−S0≠W: %d 件 %s" % (len(fals_2), "→ 触发" if fals_2 else "未触发")) out.append("③ S0 第二值: %s" % ("→ 触发 " + str(fals_3) if fals_3 else "未触发(各 caliber 拟合集 S0 唯一 276)")) out.append("门(c) 同 caliber 内 S0 归一比较: %s" % ("红 " + str(fals_3_groups) if fals_3 else "绿(唯一)")) out.append("多 id 数组(n≥2,检验 68/枚 口径是否须加分隔逗号): 拟合集 %d 件" % len(multi_id)) out.append("id 格式异常: %d 件" % len(bad_ids)) out.append("") # 逐键差分表(结构推导 + 经验双重验证) out.append("== 269↔276 逐键差分表 ==") out.append("记法 F 骨架(计数器钉 1 位、truncated:true、两 id 数组空、tp 数组空、caliber 同)字面 = %d" % S0_F) out.append("记法 M 骨架(同结构、计数器钉 0 位)闭式常数 = %d" % S0_M) out.append("") out.append("| 键/部件 | F 骨架内含 | M 骨架内含 | W 侧对应项 | 净差 |") out.append("|---|---|---|---|---|") for k in COUNTER_KEYS: out.append("| %s 的值 | 1 位 | 0 位 | F: 位宽−1 / M: 全位宽 | +1 |" % k) out.append("| truncated 布尔 | true(4) | true(4) | F: 无 / M: [false]=+1 | 0 |") out.append("| omitted_ids/unreadable_ids 括号 | [] | [] | 两侧同: 68×n+分隔 | 0 |") out.append("| 其余 9 键名+引号+冒号+逗号 | 同 | 同 | — | 0 |") out.append("| caliber 字面 64+2 引号 | 同 | 同 | — | 0 |") out.append("| truncation_points 数组括号 | [] | [] | 条目/逗号两侧同为独立项 | 0 |") out.append("| 花括号 {} | 同 | 同 | — | 0 |") out.append("| 合计 | | | | **+7 = 276−269** |") out.append("") # 异常件明细 if fals_1 or fals_2 or fals_3 or bad_ids or b["parse_fail"] or dups or b["anomaly"]: out.append("== 异常/红件明细 ==") for f in fals_1 + fals_2: out.append(" %s:%d resid_f=%s resid_m=%s rebuild=%s" % (f["file"], f["line_no"], f["resid_f"], f["resid_m"], f["rebuild_exact"])) for f in b["parse_fail"]: out.append(" [parse_fail] %s:%d %s %r" % (f["file"], f["line_no"], f.get("err"), f["raw_head"])) for f in bad_ids: out.append(" [id 异常] %s:%d %s" % (f["file"], f["line_no"], f["id_bad"])) for f in b["anomaly"]: out.append(" [结构异常] %s:%d 键差=%s" % (f["file"], f["line_no"], f["key_diff"])) for h, fs in sorted(dups.items()): out.append(" [同raw重复] %s → %s" % (h, ", ".join(fs))) out.append("") # 逐件表(压缩) out.append("== 逐件表(frame 级,全部)==") out.append("file:line | k | len(tp) | trunc | Σw | Δb | n_ids | seps | |JSON| | Σe | commas | S | S_F | S_M | res_F | res_M") for f in frames: if f["kind"] == "frame": out.append("%s:%d | %s | %d | %s | %s | %s | %d | %d | %d | %d | %d | %s | %s | %s | %s | %s" % (f["file"], f["line_no"], f["tpc"], f["len_tp"], f["truncated"], f["sw"], f["dbool"], f["n_ids"], f["id_seps"], f["json_len"], f["se"], f["commas"], f["S"], f["s_emp_f"], f["s_emp_m"], f["resid_f"], f["resid_m"])) elif f["kind"] in ("parse_fail", "not_json", "not_object", "io_fail"): out.append("%s:%d | [%s] %s" % (f.get("file", "?"), f.get("line_no", 0), f["kind"], f.get("err", f["raw_head"]))) out.append("") # CSV csv_path = os.path.join(outdir, "per_item.csv") with open(csv_path, "w", newline="", encoding="utf-8") as fh: w = csv.writer(fh) w.writerow(["file", "line_no", "kind", "caliber", "tpc", "len_tp", "truncated", "requested", "readable_upstream", "returned", "omitted", "unreadable", "bytes_written", "sw", "dbool", "n1", "n2", "id_seps", "json_len_u16", "se", "commas", "S", "S_emp_F", "S_emp_M", "resid_F", "resid_M", "rebuild_exact", "gate_a", "sha1"]) for f in frames: if f["kind"] != "frame": w.writerow([f.get("file", ""), f.get("line_no", ""), f["kind"], "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]) continue w.writerow([f["file"], f["line_no"], f["kind"], f["caliber"], f["tpc"], f["len_tp"], f["truncated"], "", "", "", "", "", "", f["sw"], f["dbool"], f["n1"], f["n2"], f["id_seps"], f["json_len"], f["se"], f["commas"], f["S"], f["s_emp_f"], f["s_emp_m"], f["resid_f"], f["resid_m"], f["rebuild_exact"], f["gate_a"], f["sha1"]]) # 退出码 exit_code = 0 if fals_1: exit_code = 3 elif fals_3: exit_code = 4 if strict and b["gate_a"]: exit_code = 2 return exit_code, "\n".join(out), csv_path, { "files": n_total, "fit": len(b["fit"]), "gate_a": len(b["gate_a"]), "k0": len(b["k0"]), "parse_fail": len(b["parse_fail"]), "no_receipt_files": no_receipt_files, "cr": cr_stripped_lines, "entries": entries_total, "se": se_sum, "resid_f_fit": resid_f_fit, "resid_m_fit": resid_m_fit, "resid_f_k0": resid_f_k0, "resid_m_k0": resid_m_k0, "s_emp_f_fit": s_emp_f_fit, "s_emp_f_k0": s_emp_f_k0, "s_emp_m_all": s_emp_m_all, "fals_1": len(fals_1), "fals_2": len(fals_2), "fals_3": fals_3, "groups": {cal: len(v) for cal, v in groups.items()}, "multi_id": len(multi_id), "dups": len(dups), "now": now.strftime("%Y-%m-%d %H:%M:%S %z"), } def main(): if hasattr(sys.stdout, "reconfigure"): sys.stdout.reconfigure(encoding="utf-8", errors="replace") sys.stderr.reconfigure(encoding="utf-8", errors="replace") ap = argparse.ArgumentParser() ap.add_argument("--spill", default=r"C:\Users\一个普通人\AppData\Roaming\IDBots\dsh-sessions\v0\spill") ap.add_argument("--out", default=os.path.dirname(os.path.abspath(__file__))) ap.add_argument("--limit", type=int, default=None) ap.add_argument("--strict", action="store_true") ap.add_argument("--no-selftest", action="store_true") args = ap.parse_args() os.makedirs(args.out, exist_ok=True) out = [] st_ok = True if not args.no_selftest: st_ok = self_test(out) code, report, csv_path, summ = run_corpus(args.spill, args.out, args.limit, args.strict) out.append(report) text = "\n".join(out) rep_path = os.path.join(args.out, "reconcile_report.txt") with open(rep_path, "w", encoding="utf-8") as fh: fh.write(text) print(text) print("[files] report=%s csv=%s" % (rep_path, csv_path)) if not st_ok: print("[selftest] FAIL → exit 1", file=sys.stderr) raise SystemExit(1) raise SystemExit(code) if __name__ == "__main__": main()